Example usage for java.awt Component getHeight

List of usage examples for java.awt Component getHeight

Introduction

In this page you can find the example usage for java.awt Component getHeight.

Prototype

public int getHeight() 

Source Link

Document

Returns the current height of this component.

Usage

From source file:UserInterface.GarbageCollectorRole.GarbageCollectorWorkAreaJPanel.java

public static BufferedImage getScreenShot(Component component) {
    BufferedImage image = new BufferedImage(component.getWidth(), component.getHeight(),
            BufferedImage.TYPE_INT_RGB);
    component.paint(image.getGraphics());
    return image;
}

From source file:org.wandora.application.gui.topicpanels.webview.WebViewPanel.java

private void handleComponentEvent(ComponentEvent e) {
    try {//from w w  w .  j a v  a  2s.  c om
        Component c = this;
        if (this.getParent() != null)
            c = this.getParent();

        final int w = c.getWidth();
        final int h = c.getHeight() - 35;
        Dimension d = new Dimension(w, h);

        if (this.getParent() != null) {
            this.setPreferredSize(d);
            this.setMinimumSize(d);
            this.setMaximumSize(d);
        }

        if (webView != null && w > 1 && h > 1) {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    webView.setMinSize(w, h);
                    webView.setMaxSize(w, h);
                    webView.setPrefSize(w, h);
                }
            });
        }
        revalidate();
        repaint();
    } catch (Exception ex) {
    }
}

From source file:FirstStatMain.java

private static BufferedImage getScreenShot(Component com) {
    BufferedImage image = new BufferedImage(com.getWidth(), com.getHeight(), BufferedImage.TYPE_INT_RGB);
    com.paint(image.getGraphics());/*from www . j  a  v  a  2  s  .c o  m*/
    return image;
}

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/**
 * Sets the location of the specified child relative to the location
 * of the specified parent and then makes it visible, and size to fill window.
 * This method is mainly useful for windows, frames and dialogs. 
 * /*from ww  w .j a  v a  2 s. com*/
 * @param parentBounds    The bounds of the visible parent.
 * @param child     The child to display.
 * @param max      The maximum size of the window.
 */
public static void setLocationRelativeToAndSizeToWindow(Rectangle parentBounds, Component child,
        Dimension max) {
    if (child == null)
        return;
    if (parentBounds == null)
        parentBounds = new Rectangle(0, 0, 5, 5);
    if (max == null)
        max = new Dimension(5, 5);
    int x = (int) (parentBounds.getX() + parentBounds.getWidth());
    int y = (int) parentBounds.getY();
    int childWidth = child.getWidth();
    int childHeight = child.getHeight();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    if (x + childWidth > screenSize.getWidth()) {
        if (childWidth < parentBounds.getX())
            x = (int) (parentBounds.getX()) - childWidth;
        else
            x = (int) (screenSize.getWidth() - childWidth);
    }
    child.setLocation(x, y);
    int newHeight = (int) screenSize.getHeight() - y - 10;
    int newWidth = (int) screenSize.getWidth() - x - 10;

    if (newWidth > childWidth)
        childWidth = newWidth;
    if (newHeight > childHeight)
        childHeight = newHeight;

    if (childWidth > max.getWidth())
        childWidth = (int) max.getWidth();
    if (childHeight > max.getHeight())
        childHeight = (int) max.getHeight();

    child.setSize(childWidth, childHeight);
    child.setVisible(true);
}

From source file:edu.uara.gui.tableeditor.ChartGenerationFrame.java

private void panelAncestorResized(java.awt.event.HierarchyEvent evt) {
    //handle resize
    //        Component parent = evt.getChangedParent();
    Component parent = this.splitPane;
    Component comp = evt.getComponent();

    if (comp != null && parent != null) {
        comp.setSize(parent.getWidth(), this.splitPane.getDividerLocation());
        String s = String.format("Current Width = %1$s" + " Height = %2$s", comp.getWidth(), comp.getHeight());

        this.updateStatus(s);

    }/*w  w w  .  j ava 2 s  .c om*/
}

From source file:self.philbrown.javaQuery.$.java

/**
 * Animates the selected views out of its parent by sliding it down, past its bottom
 * @param options use to modify the behavior of the animation
 *//*from w  ww . ja va2s  . co m*/
@SuppressWarnings("unchecked")
public void slideDown(final AnimationOptions options) {
    for (final Component view : this.views) {
        Component parent = view.getParent();
        float y = 0;
        if (parent != null) {
            y = parent.getHeight();
        } else {
            Rectangle display = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();

            y = display.height;
        }
        $.with(view).animate(QuickMap.qm(QuickEntry.qe("y", y)), options);
    }

}

From source file:self.philbrown.javaQuery.$.java

/**
 * Triggers a click event on the views in the current selection
 * @return this/*from  w  w  w.  ja v a2 s  .com*/
 */
public $ click() {
    for (Component view : this.views) {
        for (MouseListener ml : view.getMouseListeners()) {
            ml.mousePressed(new MouseEvent(view, 0, 0, 0, view.getWidth() / 2, view.getHeight() / 2, 1, false));
        }
    }
    return this;
}

From source file:self.philbrown.javaQuery.$.java

/**
 * Triggers a long-click event on this each view in the current selection
 * @return this//from  w  w w. java2  s.c  o m
 */
public $ dblclick() {
    for (Component view : this.views) {
        for (MouseListener ml : view.getMouseListeners()) {
            ml.mousePressed(new MouseEvent(view, 0, 0, 0, view.getWidth() / 2, view.getHeight() / 2, 2, false));
        }
    }
    return this;
}

From source file:self.philbrown.javaQuery.$.java

/**
 * Interprets the CSS-style String and sets the value
 * @param view the view that will change.
 * @param key the name of the attribute//w ww.  j  a  va  2s . c  o m
 * @param _value the end animation value
 * @return the computed value
 */
private Object getAnimationValue(Component view, String key, String _value) {
    Object value = null;

    String[] split = (_value).split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)");
    if (split.length == 1) {
        if (split[0].contains(".")) {
            value = Float.valueOf(split[0]);
        } else {
            value = Integer.valueOf(split[0]);
        }
    } else {
        if (split.length > 2) {
            Log.w("javaQuery", "parsererror for key " + key);
            return null;
        }
        if (split[1].equalsIgnoreCase("px")) {
            //this is the default. Just determine if float or int
            if (split[0].contains(".")) {
                value = Float.valueOf(split[0]);
            } else {
                value = Integer.valueOf(split[0]);
            }
        } else if (split[1].equalsIgnoreCase("dip") || split[1].equalsIgnoreCase("dp")
                || split[1].equalsIgnoreCase("sp")) {
            Log.w("$", "Dimension not supported");
            if (split[0].contains(".")) {
                value = Float.valueOf(split[0]);
            } else {
                value = Integer.valueOf(split[0]);
            }
        } else if (split[1].equalsIgnoreCase("in")) {
            float pt = view(0).getGraphics().getFontMetrics().getFont().deriveFont(1).getSize2D() / 72;
            if (split[0].contains(".")) {
                value = Float.parseFloat(split[0]) * pt;
            } else {
                value = Integer.parseInt(split[0]) * pt;
            }
        } else if (split[1].equalsIgnoreCase("mm")) {
            float pt = view(0).getGraphics().getFontMetrics().getFont().deriveFont(1).getSize2D() / 72;
            if (split[0].contains(".")) {
                value = Float.parseFloat(split[0]) * pt / 25.4;
            } else {
                value = Integer.parseInt(split[0]) * pt / 25.4;
            }
        } else if (split[1].equalsIgnoreCase("pt")) {
            if (split[0].contains(".")) {
                value = view(0).getGraphics().getFontMetrics().getFont().deriveFont(Float.parseFloat(split[0]))
                        .getSize2D();
            } else {
                value = view(0).getGraphics().getFontMetrics().getFont().deriveFont(Integer.parseInt(split[0]))
                        .getSize2D();
            }
        } else if (split[1].equals("%")) {
            Rectangle windowBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
            Component parent = view.getParent();
            float pixels = 0;
            if (parent == null) {
                pixels = windowBounds.width;
                //use best guess for width or height dpi
                if (split[0].equalsIgnoreCase("y") || split[0].equalsIgnoreCase("top")
                        || split[0].equalsIgnoreCase("bottom")) {
                    pixels = windowBounds.height;
                }
            } else {
                pixels = parent.getWidth();
                if (split[0].equalsIgnoreCase("y") || split[0].equalsIgnoreCase("top")
                        || split[0].equalsIgnoreCase("bottom")) {
                    pixels = parent.getHeight();
                }
            }
            float percent = 0;
            if (pixels != 0)
                percent = Float.valueOf(split[0]) / 100 * pixels;
            if (split[0].contains(".")) {
                value = percent;
            } else {
                value = (int) percent;
            }
        } else {
            Log.w("javaQuery", "invalid units for Object with key " + key);
            return null;
        }
    }
    return value;
}

From source file:org.pentaho.ui.xul.swing.tags.SwingGrid.java

@Override
public void layout() {

    if (this.getChildNodes().size() < 2) {
        logger.warn("Grid does not contain Column and Row children");
        return;/*from ww w.jav a 2  s . c  o m*/
    }

    XulComponent columns = this.getChildNodes().get(0);
    XulComponent rows = this.getChildNodes().get(1);

    int colCount = 0;
    int rowCount = 0;
    float colFlexTotal = 0;
    float rowTotalFlex = 0;
    for (XulComponent col : columns.getChildNodes()) {
        if (col.getFlex() > 0) {
            colFlexTotal += col.getFlex();
        }
        colCount++;
    }

    for (XulComponent row : rows.getChildNodes()) {
        if (row.getFlex() > 0) {
            rowTotalFlex += row.getFlex();
        }
        rowCount++;
    }

    for (XulComponent row : rows.getChildNodes()) {
        gc.gridx = 0;

        for (XulComponent xulComp : row.getChildNodes()) {
            gc.weightx = 0.0;
            gc.gridwidth = 1;
            gc.gridheight = 1;
            gc.weighty = 0.0;
            gc.anchor = GridBagConstraints.NORTHWEST;
            gc.fill = GridBagConstraints.NONE;

            Component comp = (Component) xulComp.getManagedObject();
            float colFlex = columns.getChildNodes().get(gc.gridx).getFlex();
            int rowFlex = row.getFlex();

            Align colAlignment = null;
            Align rowAlignment = null;
            String colAlignmentStr = xulComp.getAlign();
            String rowAlignStr = row.getAlign();
            if (colAlignmentStr != null) {
                colAlignment = Align.valueOf(colAlignmentStr);
            }
            if (rowAlignStr != null) {
                rowAlignment = Align.valueOf(rowAlignStr);
            }

            if (colFlex > 0) {
                gc.weightx = (colFlex / colFlexTotal);
            }
            if (rowFlex > 0) {
                gc.weighty = (rowFlex / rowTotalFlex);
            }
            if (colAlignment == Align.STRETCH && xulComp.getFlex() > 0) {
                gc.fill = GridBagConstraints.BOTH;
            } else if (colAlignment == Align.STRETCH) {
                gc.fill = GridBagConstraints.HORIZONTAL;
            } else if (xulComp.getFlex() > 0) {
                gc.fill = GridBagConstraints.VERTICAL;
            }

            if (row.getChildNodes().indexOf(xulComp) + 1 == row.getChildNodes().size()) {
                gc.gridwidth = GridBagConstraints.REMAINDER;
            } else {
                gc.gridwidth = 1;
            }
            if (rows.getChildNodes().indexOf(row) + 1 == rows.getChildNodes().size()) {
                gc.gridheight = GridBagConstraints.REMAINDER;
            } else {
                gc.gridheight = 1;
            }

            // gc.gridheight = row.getFlex() + 1;

            if (colAlignment != null && rowAlignment != null) {
                switch (rowAlignment) {
                case START:
                    switch (colAlignment) {
                    case START:
                        gc.anchor = GridBagConstraints.NORTHWEST;
                        break;
                    case CENTER:
                        gc.anchor = GridBagConstraints.NORTH;
                        break;
                    case END:
                        gc.anchor = GridBagConstraints.NORTHEAST;
                        break;
                    }
                    break;
                case CENTER:
                    switch (colAlignment) {
                    case START:
                        gc.anchor = GridBagConstraints.WEST;
                        break;
                    case CENTER:
                        gc.anchor = GridBagConstraints.CENTER;
                        break;
                    case END:
                        gc.anchor = GridBagConstraints.EAST;
                        break;
                    }
                    break;
                case END:
                    switch (colAlignment) {
                    case START:
                        gc.anchor = GridBagConstraints.SOUTHWEST;
                        break;
                    case CENTER:
                        gc.anchor = GridBagConstraints.SOUTH;
                        break;
                    case END:
                        gc.anchor = GridBagConstraints.SOUTHEAST;
                        break;
                    }
                }
            } else if (rowAlignment != null) {
                switch (rowAlignment) {
                case START:
                    gc.anchor = GridBagConstraints.NORTHWEST;
                    break;
                case CENTER:
                    gc.anchor = GridBagConstraints.WEST;
                    break;
                case END:
                    gc.anchor = GridBagConstraints.SOUTHWEST;
                    break;
                }
            } else if (colAlignment != null) {

                switch (colAlignment) {
                case START:
                    gc.anchor = GridBagConstraints.NORTHWEST;
                    break;
                case CENTER:
                    gc.anchor = GridBagConstraints.NORTH;
                    break;
                case END:
                    gc.anchor = GridBagConstraints.NORTHEAST;
                    break;
                }
            }

            if (comp.getWidth() > 0 || comp.getHeight() > 0) {
                Dimension minSize = comp.getMinimumSize();
                Dimension prefSize = comp.getPreferredSize();

                if (comp.getWidth() > 0) {
                    minSize.width = comp.getWidth();
                    prefSize.width = comp.getWidth();
                }
                if (comp.getHeight() > 0) {
                    minSize.height = comp.getHeight();
                    prefSize.height = comp.getHeight();
                }
                comp.setMinimumSize(minSize);
                comp.setPreferredSize(prefSize);
            } else {
                comp.setPreferredSize(comp.getMinimumSize());
            }

            grid.add(comp, gc);
            gc.gridx++;
        }

        gc.gridy++;
    }

    if (rowTotalFlex == 0) {
        // Add in an extra row at the bottom to push others up
        gc.gridy++;
        gc.weighty = 1;
        gc.fill = gc.REMAINDER;
        grid.add(Box.createGlue(), gc);
    }
    this.initialized = true;
}