Java Code Examples for java.awt.Component#getHeight()

The following examples show how to use java.awt.Component#getHeight() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * method to get to know whether the AbstractButton with the given key is on Screen
 *
 * @param dockableKey
 *            i18nKey of the wanted AbstractButton
 * @return returns 0 if the AbstractButton is on the Screen, 1 if the AbstractButton is on
 *         Screen but the user can not see it with the current settings of the perspective and
 *         -1 if the AbstractButton is not on the Screen.
 */
public static int isButtonOnScreen(final String buttonKey) {
	// find the Button and return -1 if we can not find it
	Component onScreen;
	try {
		onScreen = BubbleWindow.findButton(buttonKey, RapidMinerGUI.getMainFrame());
	} catch (NullPointerException e) {
		return OBJECT_NOT_ON_SCREEN;
	}
	if (onScreen == null) {
		return OBJECT_NOT_ON_SCREEN;
	}
	// detect whether the Button is viewable
	int xposition = onScreen.getLocationOnScreen().x;
	int yposition = onScreen.getLocationOnScreen().y;
	int otherXposition = xposition + onScreen.getWidth();
	int otherYposition = yposition + onScreen.getHeight();
	Window frame = RapidMinerGUI.getMainFrame();
	if (otherXposition <= frame.getWidth() && otherYposition <= frame.getHeight() && xposition > 0 && yposition > 0) {
		return OBJECT_SHOWING_ON_SCREEN;
	} else {
		return OBJECT_NOT_SHOWING;
	}
}
 
Example 2
public Polygon getInteriorPolygon(Component c) {
    NimbusEditorTabCellRenderer ren = (NimbusEditorTabCellRenderer) c;

    Insets ins = getBorderInsets(c);
    Polygon p = new Polygon();
    int x = 0;
    int y = 0;

    int width = c.getWidth() + 10;
    int height = c.getHeight() - 4;

    //Modified to return rectangle
    p.addPoint(x, y);
    p.addPoint(x + width, y);
    p.addPoint(x + width, y + height);
    p.addPoint(x, y + height);
    return p;
}
 
Example 3
/**
 * Creates a WGL-based backbuffer for the given peer and returns the
 * image wrapper.
 */
@Override
public VolatileImage createBackBuffer(WComponentPeer peer) {
    Component target = (Component)peer.getTarget();
    return new SunVolatileImage(target,
                                target.getWidth(), target.getHeight(),
                                Boolean.TRUE);
}
 
Example 4
Source Project: lsdpatch   File: StretchIcon.java    License: MIT License 5 votes vote down vote up
/**
 * Paints the icon. The image is reduced or magnified to fit the component to which it is painted.
 * <P>
 * If the proportion has not been specified, or has been specified as <code>true</code>, the aspect ratio of the image will be preserved
 * by padding and centering the image horizontally or vertically. Otherwise the image may be distorted to fill the component it is
 * painted to.
 * <P>
 * If this icon has no image observer,this method uses the <code>c</code> component as the observer.
 *
 * @param c the component to which the Icon is painted. This is used as the observer if this icon has no image observer
 * @param g the graphics context
 * @param x not used.
 * @param y not used.
 *
 * @see ImageIcon#paintIcon(java.awt.Component, java.awt.Graphics, int, int)
 */
@Override
public synchronized void paintIcon(Component c, Graphics g, int x, int y)
{
    Image image = getImage();
    if (image == null)
    {
        return;
    }
    Insets insets = ((Container) c).getInsets();
    x = insets.left;
    y = insets.top;

    int w = c.getWidth() - x - insets.right;
    int h = c.getHeight() - y - insets.bottom;

    if (proportionate)
    {
        int iw = image.getWidth(c);
        int ih = image.getHeight(c);

        if ((iw * h) < (ih * w))
        {
            iw = (h * iw) / ih;
            x += (w - iw) / 2;
            w = iw;
        }
        else
        {
            ih = (w * ih) / iw;
            y += (h - ih) / 2;
            h = ih;
        }
    }
    ImageObserver io = getImageObserver();
    g.drawImage(image, x, y, w, h, io == null ? c : io);
}
 
Example 5
private void handleComponentEvent(ComponentEvent e) {
    try {
        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) {}
}
 
Example 6
/**
 * Check whether this screen point lies within the bound of the
 * provided component.
 *
 * @param component the provided component
 * @return true if within the component, false otherwise
 */
public boolean isInComponent (Component component)
{
    Rectangle bounds = new Rectangle(
            0,
            0,
            component.getWidth(),
            component.getHeight());

    return bounds.contains(getLocalPoint(component));
}
 
Example 7
static void mouseClickOnComp(Robot r, Component comp) {
    Point loc = comp.getLocationOnScreen();
    loc.x += comp.getWidth() / 2;
    loc.y += comp.getHeight() / 2;
    r.mouseMove(loc.x, loc.y);
    r.delay(10);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.delay(10);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
}
 
Example 8
/**
 * Checks if component's rectangle is inside view port (no scrolling
 * necessary).
 *
 * @param comp a subcomponent defining coordinate system.
 * @param x coordinate
 * @param y coordinate
 * @param width rectangle width
 * @param height rectangle height
 * @return true if pointed subcomponent rectangle is inside the scrolling
 * area.
 */
public boolean checkInside(Component comp, int x, int y, int width, int height) {
    Point toPoint = SwingUtilities.
            convertPoint(comp, x, y, getSource());
    if (toPoint.x < getHAdjustable().getValue()) {
        return false;
    }
    if (comp.getWidth() > getSource().getWidth()) {
        if (toPoint.x > 0) {
            return false;
        }
    } else if (toPoint.x + comp.getWidth()
            > getHAdjustable().getValue() + getSource().getWidth()) {
        return false;
    }
    if (toPoint.y < getVAdjustable().getValue()) {
        return false;
    }
    if (comp.getHeight() > getSource().getHeight()) {
        if (toPoint.y > 0) {
            return false;
        }
    } else if (toPoint.y + comp.getHeight()
            > getVAdjustable().getValue() + getSource().getHeight()) {
        return false;
    }
    return true;
}
 
Example 9
/**
 * Creates a VolatileImage that essentially wraps the target Component's
 * backbuffer, using the provided backbuffer handle.
 */
public VolatileImage createBackBufferImage(Component target,
                                           long backBuffer)
{
    return new SunVolatileImage(target,
                                target.getWidth(), target.getHeight(),
                                Long.valueOf(backBuffer));
}
 
Example 10
/**
 * Creates a WGL-based backbuffer for the given peer and returns the
 * image wrapper.
 */
@Override
public VolatileImage createBackBuffer(WComponentPeer peer) {
    Component target = (Component)peer.getTarget();
    return new SunVolatileImage(target,
                                target.getWidth(), target.getHeight(),
                                Boolean.TRUE);
}
 
Example 11
Source Project: netbeans   File: SlideGestureRecognizer.java    License: Apache License 2.0 5 votes vote down vote up
/** @return Area in which automatic slide in is preserved. Can return
 * null signalizing that components making active area bounds are not yet 
 * ready or showing.
 */
private Rectangle computeActiveArea() {
    Component slidedComp = slideBar.getSlidedComp();
    if (slidedComp == null || !slidedComp.isShowing()) {
        return null;
    }
    
    Point slideBarLoc = slideBar.getLocationOnScreen();
    Rectangle actArea = new Rectangle(slideBarLoc.x - 1, slideBarLoc.y - 1,
                            slideBar.getWidth() - 1, slideBar.getHeight() - 1);
    
    Point slidedCompLoc = slidedComp.getLocationOnScreen();
    
    int slidex = slidedCompLoc.x;
    int slidey = slidedCompLoc.y;
    int slideh = slidedComp.getHeight();
    int slidew = slidedComp.getWidth();
    int orientation = slideBar.getModel().getOrientation();
    if (orientation == SlideBarDataModel.WEST) {
        slidew = slidew + ResizeGestureRecognizer.RESIZE_BUFFER;
    }
    if (orientation == SlideBarDataModel.EAST) {
        slidew = slidew + ResizeGestureRecognizer.RESIZE_BUFFER;
        slidex = slidex - ResizeGestureRecognizer.RESIZE_BUFFER;
    }
    if (orientation == SlideBarDataModel.SOUTH) {
        slideh = slideh + ResizeGestureRecognizer.RESIZE_BUFFER;
        slidey = slidey - ResizeGestureRecognizer.RESIZE_BUFFER;
    }
    if (orientation == SlideBarDataModel.NORTH) {
        slideh = slideh + ResizeGestureRecognizer.RESIZE_BUFFER;
    }
    actArea = SwingUtilities.computeUnion(
        slidex, slidey, slidew,
        slideh, actArea);
    
    return actArea;
}
 
Example 12
Source Project: FlatLaf   File: FlatInspector.java    License: Apache License 2.0 4 votes vote down vote up
private String buildToolTipText( Component c ) {
	String name = c.getClass().getName();
	name = name.substring( name.lastIndexOf( '.' ) + 1 );

	String text =
		"Class: " + name + " (" + c.getClass().getPackage().getName() + ")\n" +
		"Size: " + c.getWidth() + ',' + c.getHeight() + "  @ " + c.getX() + ',' + c.getY() + '\n';

	if( c instanceof Container )
		text += "Insets: " + toString( ((Container)c).getInsets() ) + '\n';

	Insets margin = null;
	if( c instanceof AbstractButton )
		margin = ((AbstractButton) c).getMargin();
	else if( c instanceof JTextComponent )
		margin = ((JTextComponent) c).getMargin();
	else if( c instanceof JMenuBar )
		margin = ((JMenuBar) c).getMargin();
	else if( c instanceof JToolBar )
		margin = ((JToolBar) c).getMargin();

	if( margin != null )
		text += "Margin: " + toString( margin ) + '\n';

	Dimension prefSize = c.getPreferredSize();
	Dimension minSize = c.getMinimumSize();
	Dimension maxSize = c.getMaximumSize();
	text += "Pref size: " + prefSize.width + ',' + prefSize.height + '\n' +
		"Min size: " + minSize.width + ',' + minSize.height + '\n' +
		"Max size: " + maxSize.width + ',' + maxSize.height + '\n';

	if( c instanceof JComponent )
		text += "Border: " + toString( ((JComponent)c).getBorder() ) + '\n';

	text += "Background: " + toString( c.getBackground() ) + '\n' +
		"Foreground: " + toString( c.getForeground() ) + '\n' +
		"Font: " + toString( c.getFont() ) + '\n';

	if( c instanceof JComponent ) {
		try {
			Field f = JComponent.class.getDeclaredField( "ui" );
			f.setAccessible( true );
			Object ui = f.get( c );
			text += "UI: " + (ui != null ? ui.getClass().getName() : "null") + '\n';
		} catch( NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex ) {
			// ignore
		}
	}

	if( c instanceof Container ) {
		LayoutManager layout = ((Container)c).getLayout();
		if( layout != null )
			text += "Layout: " + layout.getClass().getName() + '\n';
	}

	text += "Enabled: " + c.isEnabled() + '\n';
	text += "Opaque: " + c.isOpaque() + (c instanceof JComponent &&
		FlatUIUtils.hasOpaqueBeenExplicitlySet( (JComponent) c ) ? " EXPLICIT" : "") + '\n';
	if( c instanceof AbstractButton )
		text += "ContentAreaFilled: " + ((AbstractButton)c).isContentAreaFilled() + '\n';
	text += "Focusable: " + c.isFocusable() + '\n';
	text += "Left-to-right: " + c.getComponentOrientation().isLeftToRight() + '\n';
	text += "Parent: " + (c.getParent() != null ? c.getParent().getClass().getName() : "null");

	if( inspectParentLevel > 0 )
		text += "\n\nParent level: " + inspectParentLevel;

	if( inspectParentLevel > 0 )
		text += "\n(press Ctrl/Shift to increase/decrease level)";
	else
		text += "\n\n(press Ctrl key to inspect parent)";

	return text;
}
 
Example 13
Source Project: astor   File: ExampleUtils.java    License: GNU General Public License v2.0 4 votes vote down vote up
private static BufferedImage getScreenShot(Component component) {
    BufferedImage image = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_RGB);
    // call the Component's paint method, using the Graphics object of the image.
    component.paint(image.getGraphics());
    return image;
}
 
Example 14
public float getHeight (Component widget) {
	return widget.getHeight();
}
 
Example 15
Source Project: astor   File: ExampleUtils.java    License: GNU General Public License v2.0 4 votes vote down vote up
private static BufferedImage getScreenShot(Component component) {
    BufferedImage image = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_RGB);
    // call the Component's paint method, using the Graphics object of the image.
    component.paint(image.getGraphics());
    return image;
}
 
Example 16
protected Rectangle getControlButtonsRectangle( Container parent ) {
    Component c = getControlButtons();
    return new Rectangle( parent.getWidth()-c.getWidth()-4, 2, c.getWidth(), c.getHeight() );
}
 
Example 17
Source Project: astor   File: ExampleUtils.java    License: GNU General Public License v2.0 4 votes vote down vote up
private static BufferedImage getScreenShot(Component component) {
    BufferedImage image = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_RGB);
    // call the Component's paint method, using the Graphics object of the image.
    component.paint(image.getGraphics());
    return image;
}
 
Example 18
/**
 * This method is called from WComponentPeer when a surface data is replaced
 * REMIND: while the default pipeline doesn't support flipping, it may
 * happen that the accelerated device may have this graphics config
 * (like if the device restoration failed when one device exits fs mode
 * while others remain).
 */
public VolatileImage createBackBuffer(WComponentPeer peer) {
    Component target = (Component)peer.getTarget();
    return new SunVolatileImage(target,
                                target.getWidth(), target.getHeight(),
                                Boolean.TRUE);
}
 
Example 19
Source Project: pdfxtk   File: GraphPanelEditor.java    License: Apache License 2.0 votes vote down vote up
int card(Component c) {return c.getY() + c.getHeight();} 
Example 20
Source Project: pdfxtk   File: GraphPanelEditor.java    License: Apache License 2.0 votes vote down vote up
int card(Component c) {return c.getY() + c.getHeight() / 2;}