List of usage examples for java.awt Dimension getHeight
public double getHeight()
From source file:Main.java
/** * Determine the maximum size for a 2-state button with the specified text and icons. * This can be used to make sure that a button doesn't resize during state change. * * @param button the UI of this JButton is used for size determination * @param string1 text for 1st mode//w w w . ja v a 2s. c o m * @param icon1 icon for 1st mode * @param string2 text for 2nd mode * @param icon2 icon for 2nd mode * @return the Dimension that contains both modes for the button. */ public static Dimension getMaxDimension(JButton button, String string1, ImageIcon icon1, String string2, ImageIcon icon2) { String originalText = button.getText(); Icon originalIcon = button.getIcon(); // Get dimensions for "Play" state button.setText(string1); button.setIcon(icon1); Dimension playSize = button.getUI().getPreferredSize(button); // Get dimensions for "Pause" state button.setText(string2); button.setIcon(icon2); Dimension pauseSize = button.getUI().getPreferredSize(button); // Restore original text and icon button.setText(originalText); button.setIcon(originalIcon); // Return max dimensions int maxWidth = (int) Math.max(playSize.getWidth(), pauseSize.getWidth()); int maxHeight = (int) Math.max(playSize.getHeight(), pauseSize.getHeight()); return new Dimension(maxWidth, maxHeight); }
From source file:com.che.software.testato.util.jung.DiagramGraphistUtil.java
/** * Return the layout corresponding to the parameters. * // w ww . j a v a 2 s . c om * @author Clement HELIOU (clement.heliou@che-software.com). * @param mapDiagram the map diagram to put into the layout. * @param algorithm the desired algorithm. * @param imageSize the desired image size. * @return the resulting layout object. * @since July, 2011. */ private static Layout<Intention, MapArrow> getMapLayoutFromAlgorithmAndSize( DirectedGraph<Intention, MapArrow> mapDiagram, DrawingAlgorithm algorithm, Dimension imageSize) { LOGGER.debug("getMapLayoutFromAlgorithmAndSize(" + algorithm + "," + imageSize.getHeight() + "," + imageSize.getWidth() + ")."); Layout<Intention, MapArrow> layout = null; switch (algorithm) { case CIRCLE: layout = new CircleLayout<Intention, MapArrow>(mapDiagram); break; case FR: layout = new FRLayout<Intention, MapArrow>(mapDiagram); break; case FR2: layout = new FRLayout2<Intention, MapArrow>(mapDiagram); break; case ISOM: layout = new ISOMLayout<Intention, MapArrow>(mapDiagram); break; case KK: layout = new KKLayout<Intention, MapArrow>(mapDiagram); break; case SPRING: layout = new SpringLayout<Intention, MapArrow>(mapDiagram); break; case SPRING2: layout = new SpringLayout2<Intention, MapArrow>(mapDiagram); break; default: // Doesn't happened. break; } layout.setSize(imageSize); return layout; }
From source file:com.che.software.testato.util.jung.DiagramGraphistUtil.java
/** * Return the layout corresponding to the parameters. * //www .j a va2s . com * @author Clement HELIOU (clement.heliou@che-software.com). * @param proceduralDiagram the procedural diagram to put into the layout. * @param algorithm the desired algorithm. * @param imageSize the desired image size. * @return the resulting layout object. * @since July, 2011. */ private static Layout<Element, ProceduralArrow> getProceduralLayoutFromAlgorithmAndSize( DirectedGraph<Element, ProceduralArrow> proceduralDiagram, DrawingAlgorithm algorithm, Dimension imageSize) { LOGGER.debug("getProceduralLayoutFromAlgorithmAndSize(" + proceduralDiagram + "," + algorithm + "," + imageSize.getHeight() + "," + imageSize.getWidth() + ")."); Layout<Element, ProceduralArrow> layout = null; switch (algorithm) { case CIRCLE: layout = new CircleLayout<Element, ProceduralArrow>(proceduralDiagram); break; case FR: layout = new FRLayout<Element, ProceduralArrow>(proceduralDiagram); break; case FR2: layout = new FRLayout2<Element, ProceduralArrow>(proceduralDiagram); break; case ISOM: layout = new ISOMLayout<Element, ProceduralArrow>(proceduralDiagram); break; case KK: layout = new KKLayout<Element, ProceduralArrow>(proceduralDiagram); break; case SPRING: layout = new SpringLayout<Element, ProceduralArrow>(proceduralDiagram); break; case SPRING2: layout = new SpringLayout2<Element, ProceduralArrow>(proceduralDiagram); break; default: // Doesn't happened. break; } layout.setSize(imageSize); return layout; }
From source file:com.che.software.testato.util.jung.DiagramGraphistUtil.java
/** * Returns the object containing the colorized version of a procedural * diagram with given algorithm and size. * //w ww .jav a2 s . c o m * @author Clement HELIOU (clement.heliou@che-software.com). * @param proceduralDiagram the procedural diagram to colorized. * @param algorithm the algorithm to used. * @param imageSize the desired image size. * @return the resulting object. * @since July, 2011. */ public static VisualizationImageServer<Element, ProceduralArrow> getColorizedProceduralDiagramFromAlgorithmAndSize( DirectedGraph<Element, ProceduralArrow> proceduralDiagram, DrawingAlgorithm algorithm, Dimension imageSize) { LOGGER.debug("getColorizedProceduralDiagramFromAlgorithmAndSize(" + proceduralDiagram + "," + algorithm + "," + imageSize.getHeight() + "," + imageSize.getWidth() + ")."); Layout<Element, ProceduralArrow> layout = DiagramGraphistUtil .getProceduralLayoutFromAlgorithmAndSize(proceduralDiagram, algorithm, imageSize); VisualizationImageServer<Element, ProceduralArrow> vis = new VisualizationImageServer<Element, ProceduralArrow>( layout, imageSize); vis.getRenderContext().setArrowDrawPaintTransformer(PROC_ARROW_PAINT); vis.getRenderContext().setArrowFillPaintTransformer(PROC_ARROW_PAINT); vis.getRenderContext().setEdgeArrowStrokeTransformer(PROC_ARROW_STROKE); vis.getRenderContext().setEdgeDrawPaintTransformer(PROC_ARROW_PAINT); vis.getRenderContext().setEdgeFontTransformer(PROC_ARROW_FONT); vis.getRenderContext().setEdgeLabelTransformer(PROC_ARROW_LABEL); vis.getRenderContext().setEdgeShapeTransformer(PROC_ARROW_SHAPE); vis.getRenderContext().setEdgeStrokeTransformer(PROC_ARROW_STROKE); vis.getRenderContext().setLabelOffset(LABEL_OFFSET); vis.getRenderContext().setVertexDrawPaintTransformer(PROC_BORDER_ELEMENT_PAINT); vis.getRenderContext().setVertexFillPaintTransformer(PROC_ELEMENT_PAINT); vis.getRenderContext().setVertexFontTransformer(PROC_ELEMENT_FONT); vis.getRenderContext().setVertexLabelTransformer(PROC_ELEMENT_LABEL); vis.getRenderContext().setVertexShapeTransformer(PROC_ELEMENT_SHAPE); vis.getRenderContext().setVertexStrokeTransformer(PROC_ELEMENT_STROKE); vis.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR); vis.setBackground(Color.WHITE); vis.validate(); return vis; }
From source file:eu.delving.sip.Application.java
private static void memoryNotConfigured() { String os = System.getProperty("os.name"); Runtime rt = Runtime.getRuntime(); int totalMemory = (int) (rt.totalMemory() / 1024 / 1024); StringBuilder out = new StringBuilder(); String JAR_NAME = "SIP-Creator-2014-XX-XX.jar"; if (os.startsWith("Windows")) { out.append(":: SIP-Creator Startup Batch file for Windows (more memory than ").append(totalMemory) .append("Mb)\n"); out.append("java -jar -Xms1024m -Xmx1024m ").append(JAR_NAME); } else if (os.startsWith("Mac")) { out.append("# SIP-Creator Startup Script for Mac OSX (more memory than ").append(totalMemory) .append("Mb)\n"); out.append("java -jar -Xms1024m -Xmx1024m ").append(JAR_NAME); } else {//from w w w .ja v a2s . c o m System.out.println("Unrecognized OS: " + os); } String script = out.toString(); final JDialog dialog = new JDialog(null, "Memory Not Configured Yet!", Dialog.ModalityType.APPLICATION_MODAL); JTextArea scriptArea = new JTextArea(3, 40); scriptArea.setText(script); scriptArea.setSelectionStart(0); scriptArea.setSelectionEnd(script.length()); JPanel scriptPanel = new JPanel(new BorderLayout()); scriptPanel.setBorder(BorderFactory.createTitledBorder("Script File")); scriptPanel.add(scriptArea, BorderLayout.CENTER); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); buttonPanel.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15)); JButton ok = new JButton("OK, Continue anyway"); ok.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialog.setVisible(false); EventQueue.invokeLater(LAUNCH); } }); buttonPanel.add(ok); JPanel centralPanel = new JPanel(new GridLayout(0, 1)); centralPanel.setBorder(BorderFactory.createEmptyBorder(15, 25, 15, 25)); centralPanel.add( new JLabel("<html><b>The SIP-Creator started directly can have too little default memory allocated." + "<br>It should be started with the following script:</b>")); centralPanel.add(scriptPanel); centralPanel.add(new JLabel( "<html><b>Please copy the above text into a batch or script file and execute that instead.</b>")); dialog.getContentPane().add(centralPanel, BorderLayout.CENTER); dialog.getContentPane().add(buttonPanel, BorderLayout.SOUTH); dialog.pack(); Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - dialog.getWidth()) / 2); int y = (int) ((dimension.getHeight() - dialog.getHeight()) / 2); dialog.setLocation(x, y); dialog.setVisible(true); }
From source file:com.clank.launcher.swing.SwingHelper.java
/** * Equalize the width of the given components. * * @param component component/*from ww w .ja va2 s . c om*/ */ public static void equalWidth(Component... component) { double widest = 0; for (Component comp : component) { Dimension dim = comp.getPreferredSize(); if (dim.getWidth() > widest) { widest = dim.getWidth(); } } for (Component comp : component) { Dimension dim = comp.getPreferredSize(); comp.setPreferredSize(new Dimension((int) widest, (int) dim.getHeight())); } }
From source file:util.WebUtil.java
public static Dimension getDimension(Dimension d, int mw, int mh) { int w = (int) d.getWidth(); int h = (int) d.getHeight(); int nh = h;//from w w w .j a v a2 s .c o m int nw = w; if (w > mw) { float r = (float) mw / (float) w; nh = (int) ((float) h * (float) r); nw = mw; } if (nh > mh) { float r = (float) mh / (float) nh; nw = (int) ((float) nw * (float) r); nh = mh; } d.setSize(nw, nh); return d; }
From source file:cc.kune.core.server.manager.file.ImageUtilsDefault.java
/** * Scale image./*from ww w . j ava 2s . com*/ * * @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: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 *//*w ww . j a v a 2s. com*/ 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:mulavito.gui.components.LayerViewer.java
public static void autoZoomViewer(VisualizationViewer<?, ?> vv, LayerViewer<?, ?> home, Directions direction) { if (vv == null || home == null) return;//from w ww .j a v a 2 s. c o m // reset transforms MutableTransformer layoutTrans = vv.getRenderContext().getMultiLayerTransformer() .getTransformer(edu.uci.ics.jung.visualization.Layer.LAYOUT); layoutTrans.setToIdentity(); MutableTransformer viewTrans = vv.getRenderContext().getMultiLayerTransformer() .getTransformer(edu.uci.ics.jung.visualization.Layer.VIEW); viewTrans.setToIdentity(); Dimension dim = vv.getSize(); Rectangle2D.Double graphBounds = home.getGraphBoundsCache(); CrossoverScalingControl scaler = new CrossoverScalingControl(); // Scale using crossover scaler, so vertices will not grow // larger than they are in original double factor = Double.POSITIVE_INFINITY; if (direction == Directions.HORIZONTAL || direction == Directions.BOTH) factor = dim.getWidth() / graphBounds.width; if (direction == Directions.VERTICAL || direction == Directions.BOTH || Double.isInfinite(factor)) factor = Math.min(factor, dim.getHeight() / graphBounds.height); scaler.scale(vv, (float) factor, vv.getCenter()); // Translate center of graph to center of vv. Point2D lvc = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(vv.getCenter()); double dx = (lvc.getX() - graphBounds.getCenterX()); double dy = (lvc.getY() - graphBounds.getCenterY()); layoutTrans.translate(dx, dy); }