Example usage for java.awt Dimension getWidth

List of usage examples for java.awt Dimension getWidth

Introduction

In this page you can find the example usage for java.awt Dimension getWidth.

Prototype

public double getWidth() 

Source Link

Usage

From source file:Main.java

public static void setCenter(Component component, Component component1) {
    Point point;//from  ww w  . j a  v  a 2 s.  co m
    Dimension dimension;
    if (component != null) {
        point = component.getLocation();
        dimension = component.getSize();
    } else {
        dimension = Toolkit.getDefaultToolkit().getScreenSize();
        point = new Point(0, 0);
    }
    Dimension dimension1 = Toolkit.getDefaultToolkit().getScreenSize();
    point.setLocation((double) point.x + dimension.getWidth() / 2D,
            (double) point.y + dimension.getHeight() / 2D);
    Point point1 = new Point(point.x - component1.getWidth() / 2, point.y - component1.getHeight() / 2);
    if (point1.y < 0)
        point1.y = 0;
    if (point1.x < 0)
        point1.y = 0;
    if (point1.x + component1.getWidth() > dimension1.width)
        point1.x = dimension1.width - component1.getWidth();
    if (point1.y + component1.getHeight() > dimension1.height)
        point1.y = dimension1.height - component1.getHeight();
    component1.setLocation(point1);
}

From source file:Main.java

public static Point getScreenCenterLocation(Window w) {
    Dimension size = w.getSize();
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    double desktopHeight = toolkit.getScreenSize().getHeight();
    double desktopWidth = toolkit.getScreenSize().getWidth();

    // To the left (hack for Ngoc's dual display)
    if (desktopWidth > 1600) {
        desktopWidth += 1600;/*  w ww . ja  va2  s.c  o m*/
    }
    Point location = new Point();
    location.x = (int) (desktopWidth - size.getWidth()) / 2;
    location.y = (int) (desktopHeight - size.getHeight()) / 2;
    return location;
}

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//from   ww w.  jav  a 2  s. 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.galenframework.utils.GalenUtils.java

public static void autoAdjustBrowserWindowSizeToFitViewport(WebDriver driver, int width, int height) {
    driver.manage().window().setSize(new org.openqa.selenium.Dimension(width, height));
    Dimension viewport = getViewportArea(driver);

    if (viewport.getWidth() < width) {
        int delta = (int) (width - viewport.getWidth());

        driver.manage().window().setSize(new org.openqa.selenium.Dimension(width + delta, height));
    }//from   ww w.  j a  v  a  2s .  c  o  m
}

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 .java  2  s.  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.che.software.testato.util.jung.DiagramGraphistUtil.java

/**
 * Return the layout corresponding to the parameters.
 * /*w w w . ja v  a  2s  .  co m*/
 * @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.
 * /*from w  w  w  . j  a v  a  2  s  .c  om*/
 * @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  w  w. j  a  v a  2s. c  om*/
 * @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: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  ww  w .  ja v  a 2  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:mulavito.gui.components.LayerViewer.java

public static void autoZoomViewer(VisualizationViewer<?, ?> vv, LayerViewer<?, ?> home, Directions direction) {
    if (vv == null || home == null)
        return;//from   ww w .j  ava  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);
}