List of usage examples for java.awt Dimension getWidth
public double getWidth()
From source file:com.moviejukebox.scanner.artwork.PosterScanner.java
/** * Validate the poster against the provided dimensions and aspect * * Get the size of the file at the end of the URL Taken from: * http://forums.sun.com/thread.jspa?threadID=528155&messageID=2537096 * * @param posterImage Poster image to check * @param posterWidth The width to check * @param posterHeight The height to check * @param checkAspect Should the aspect ratio be checked * @return True if the poster is good, false otherwise *//*from ww w .jav a 2s .c o m*/ public static boolean validatePoster(IImage posterImage, int posterWidth, int posterHeight, boolean checkAspect) { float urlAspect; if (!POSTER_VALIDATE) { return Boolean.TRUE; } if (StringTools.isNotValidString(posterImage.getUrl())) { return Boolean.FALSE; } Dimension imageDimension = getUrlDimensions(posterImage.getUrl()); double urlWidth = imageDimension.getWidth(); double urlHeight = imageDimension.getHeight(); // Check if we need to cut the poster into a sub image if (StringTools.isValidString(posterImage.getSubimage())) { StringTokenizer st = new StringTokenizer(posterImage.getSubimage(), ", "); int x = Integer.parseInt(st.nextToken()); int y = Integer.parseInt(st.nextToken()); int l = Integer.parseInt(st.nextToken()); int h = Integer.parseInt(st.nextToken()); urlWidth = urlWidth * l / 100 - urlWidth * x / 100; urlHeight = urlHeight * h / 100 - urlHeight * y / 100; } urlAspect = (float) urlWidth / (float) urlHeight; if (checkAspect && urlAspect > 1.0) { LOG.debug("{} rejected: URL is landscape format", posterImage); return Boolean.FALSE; } // Adjust poster width / height by the ValidateMatch figure int newPosterWidth = (posterWidth * POSTER_VALIDATE_MATCH) / 100; int newPosterHeight = (posterHeight * POSTER_VALIDATE_MATCH) / 100; if (urlWidth < newPosterWidth) { LOG.debug("{} rejected: URL width ({}) is smaller than poster width ({})", posterImage, urlWidth, newPosterWidth); return Boolean.FALSE; } if (urlHeight < newPosterHeight) { LOG.debug("{} rejected: URL height ({}) is smaller than poster height ({})", posterImage, urlHeight, newPosterHeight); return Boolean.FALSE; } return Boolean.TRUE; }
From source file:cc.kune.core.server.manager.file.ImageUtilsDefault.java
/** * Scale image.//from www .j a v a2 s. c o m * * @param fileOrig * the file orig * @param fileDest * the file dest * @param dimension * the dimension * @return true, if successful * @throws MagickException * the magick exception * @throws FileNotFoundException * the file not found exception */ public static boolean scaleImage(final String fileOrig, final String fileDest, final Dimension dimension) throws MagickException, FileNotFoundException { checkExist(fileOrig); final MagickImage imageOrig = readImage(fileOrig); return scaleImage(imageOrig, fileDest, (int) dimension.getWidth(), (int) dimension.getHeight()); }
From source file:org.revager.tools.GUITools.java
/** * Sets the location of the given window to cursor position. * //from w w w .j ava2 s.c om * @param win * the window for which the location is to be set */ public static void setLocationToCursorPos(Window win) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); double cursorPosX = MouseInfo.getPointerInfo().getLocation().getX(); double cursorPosY = MouseInfo.getPointerInfo().getLocation().getY(); double screenWidth = screenSize.getWidth(); double screenHeight = screenSize.getHeight() - 40; double winWidth = win.getSize().getWidth(); double winHeight = win.getSize().getHeight(); int winPosX = (int) cursorPosX; int winPosY = (int) cursorPosY; // If the window would break the screen size if (cursorPosX + winWidth > screenWidth) { winPosX = (int) (screenWidth - winWidth); } if (cursorPosY + winHeight > screenHeight) { winPosY = (int) (screenHeight - winHeight); } win.setLocation(new Point(winPosX, winPosY)); }
From source file:net.chaosserver.timelord.swingui.SwingUtil.java
/** * Repair location is designed to detect if a box is partially * off-screen and move the box back onto the screen. * * @param component component to repair/* w ww. ja v a 2 s. co m*/ */ public static void repairLocation(Component component) { Point locationPoint = component.getLocation(); Point locationOnScreenPoint = null; if (component.isVisible()) { locationOnScreenPoint = component.getLocationOnScreen(); } Dimension componentSize = component.getSize(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); if (log.isDebugEnabled()) { log.debug("Repairing location on [" + component.getClass().getName() + "]. Original location point = [" + locationPoint + "] and location on screen point = [" + locationOnScreenPoint + "]. The screen size is [" + screenSize + "] and the component size is [" + componentSize + "]"); } // Is the dialog to far to the left? Then fix. if (locationPoint.getX() < 0) { locationPoint.setLocation(0, locationPoint.getY()); } if (locationPoint.getY() < 0) { locationPoint.setLocation(locationPoint.getX(), 0); } // component.setLocation(locationPoint); // Is the dialog too wide? if (locationPoint.getX() + componentSize.getWidth() > screenSize.getWidth()) { componentSize.width = (int) (screenSize.getWidth() - locationPoint.getX()); } if (locationPoint.getY() + componentSize.getHeight() > screenSize.getHeight()) { componentSize.height = (int) (screenSize.getHeight() - locationPoint.getY()); } // component.setSize(componentSize); }
From source file:org.jamwiki.parser.image.ImageUtil.java
/** * Determine scaled dimensions for images stored on the filesystem. *//* w ww. ja va 2s .co m*/ private static Dimension calculateIncrementalDimensionsForImageFile(WikiImage wikiImage, Dimension originalDimensions, int incrementalWidth, int incrementalHeight) throws IOException { // check to see if an image with the desired dimensions already exists on the filesystem String newUrl = buildImagePath(wikiImage.getUrl(), (int) originalDimensions.getWidth(), incrementalWidth); File newImageFile = ImageUtil.buildAbsoluteFile(newUrl); if (newImageFile.exists()) { return new Dimension(incrementalWidth, incrementalHeight); } // otherwise generate a scaled instance File imageFile = ImageUtil.buildAbsoluteFile(wikiImage.getUrl()); BufferedImage bufferedImage = ImageProcessor.resizeImage(imageFile, incrementalWidth, incrementalHeight); newUrl = buildImagePath(wikiImage.getUrl(), (int) originalDimensions.getWidth(), bufferedImage.getWidth()); newImageFile = ImageUtil.buildAbsoluteFile(newUrl); ImageProcessor.saveImage(bufferedImage, newImageFile); return new Dimension(bufferedImage.getWidth(), bufferedImage.getHeight()); }
From source file:AppPackage.HumidityGraph.java
/** * *//*from w ww . ja va 2 s.c om*/ public HumidityGraph() { try { JFrame window = new JFrame(); window.setSize(1000, 615); window.setBackground(Color.blue); Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - window.getWidth()) / 2); int y = (int) ((dimension.getHeight() - window.getHeight()) / 2); window.setLocation(x, y); XYSeries series = new XYSeries("Humidity "); XYSeriesCollection dataset = new XYSeriesCollection(series); JFreeChart chart = ChartFactory.createXYLineChart("Humidity against Time", "Time(seconds)", "Humidity(percentage)", dataset); window.add(new ChartPanel(chart), BorderLayout.CENTER); window.setVisible(true); } catch (Exception e) { System.out.print("Chart exception:" + e); } initComponents(); }
From source file:org.jamwiki.parser.image.ImageUtil.java
/** * Determine the scaled dimensions, rounded to an increment for performance reasons, * given a max width and height. For example, if the original dimensions are 800x400, * the max width height are 200, and the increment is 400, the result is 400x200. *///from w ww . j a va 2 s.c o m private static Dimension calculateIncrementalDimensions(WikiImage wikiImage, Dimension originalDimensions, Dimension scaledDimensions, WikiFileVersion fileVersion) throws IOException { int increment = Environment.getIntValue(Environment.PROP_IMAGE_RESIZE_INCREMENT); // use width for incremental resizing int incrementalWidth = calculateImageIncrement(scaledDimensions.getWidth()); if (increment <= 0 || incrementalWidth >= originalDimensions.getWidth()) { // let the browser scale the image return originalDimensions; } int incrementalHeight = (int) Math .round(((double) incrementalWidth / (double) originalDimensions.getWidth()) * (double) originalDimensions.getHeight()); if (isImagesOnFS()) { return calculateIncrementalDimensionsForImageFile(wikiImage, originalDimensions, incrementalWidth, incrementalHeight); } else { return calculateIncrementalDimensionsForImageBlob(wikiImage, incrementalWidth, incrementalHeight, fileVersion); } }
From source file:JSplash.java
private void center() { Dimension scr = Toolkit.getDefaultToolkit().getScreenSize(); int nX = (int) (scr.getWidth() - getWidth()) / 2; int nY = (int) (scr.getHeight() - getHeight()) / 2; setLocation(nX, nY);/* w ww . j a va 2 s .c o m*/ }
From source file:AppPackage.Temperature.java
public Temperature() { try {//from ww w . j a va 2 s . c o m JFrame window = new JFrame(); window.setSize(1000, 615); window.setBackground(Color.blue.darker()); double value = 55; Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - window.getWidth()) / 2); int y = (int) ((dimension.getHeight() - window.getHeight()) / 2); window.setLocation(x, y); DefaultValueDataset dataset = new DefaultValueDataset(value); ThermometerPlot thermometerplot = new ThermometerPlot(dataset); thermometerplot.setSubrangePaint(0, Color.green.darker()); thermometerplot.setSubrangePaint(1, Color.orange); thermometerplot.setSubrangePaint(2, Color.red); JFreeChart jfreechart = new JFreeChart("Temperature readings", JFreeChart.DEFAULT_TITLE_FONT, thermometerplot, true); thermometerplot.setInsets(new RectangleInsets(5D, 5D, 5D, 5D)); thermometerplot.setPadding(new RectangleInsets(10D, 10D, 10D, 10D)); thermometerplot.setThermometerStroke(new BasicStroke(2.0F)); thermometerplot.setThermometerPaint(Color.BLUE); thermometerplot.setGap(3); window.add(new ChartPanel(jfreechart), BorderLayout.CENTER); window.setVisible(true); } catch (Exception e) { System.out.print("Chart exception:" + e); } initComponents(); }
From source file:AppPackage.humidity.java
public humidity() { try {/*from ww w . j a va 2 s.co m*/ JFrame window = new JFrame(); window.setSize(1000, 615); window.setBackground(Color.blue.darker()); double value = 45; Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - window.getWidth()) / 2); int y = (int) ((dimension.getHeight() - window.getHeight()) / 2); window.setLocation(x, y); DefaultValueDataset dataset = new DefaultValueDataset(value); ThermometerPlot thermometerplot = new ThermometerPlot(dataset); thermometerplot.setSubrangePaint(0, Color.green.darker()); thermometerplot.setSubrangePaint(1, Color.orange); thermometerplot.setSubrangePaint(2, Color.red); JFreeChart jfreechart = new JFreeChart("Humidity readings", JFreeChart.DEFAULT_TITLE_FONT, thermometerplot, true); thermometerplot.setInsets(new RectangleInsets(5D, 5D, 5D, 5D)); thermometerplot.setPadding(new RectangleInsets(10D, 10D, 10D, 10D)); thermometerplot.setThermometerStroke(new BasicStroke(2.0F)); thermometerplot.setThermometerPaint(Color.BLUE); thermometerplot.setUnits(0); thermometerplot.setGap(3); window.add(new ChartPanel(jfreechart), BorderLayout.CENTER); window.setVisible(true); } catch (Exception e) { System.out.print("Chart exception:" + e); } initComponents(); }