Java Code Examples for javax.swing.JComponent#getBounds()

The following examples show how to use javax.swing.JComponent#getBounds() . 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
Source File: Connector.java    From wandora with GNU General Public License v3.0 6 votes vote down vote up
protected Point clampPoint(Point p,JComponent c,int margin,ConnectorAnchor anchor){
    Point cp=getRootCoordinates(c,0,0);
    Rectangle rect=c.getBounds();
    int w=rect.width;
    int h=rect.height;
    
    switch(anchor.getExitDirection()){
        case LEFT:
            return new Point(cp.x,Math.max(cp.y+margin, Math.min(cp.y+h-margin,p.y)));
        case RIGHT:
            return new Point(cp.x+w,Math.max(cp.y+margin, Math.min(cp.y+h-margin,p.y)));
        case UP:
            return new Point(Math.max(cp.x+margin, Math.min(cp.x+w-margin,p.x)),cp.y);
        case DOWN:
            return new Point(Math.max(cp.x+margin, Math.min(cp.x+w-margin,p.x)),cp.y+h);
        default:
            throw new RuntimeException("unknown exit direction"); // shouldn't happen, case for all possible directions
    }
    
}
 
Example 2
Source File: AbstractDockingTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Performs a single left mouse click in the center of the given provider.  This is
 * useful when trying to  make a provider the active provider, while making sure
 * that one of the provider's components has focus.
 *
 * @param provider The provider to click
 * @return the actual Java JComponent that was clicked.
 * @see #clickComponentProvider(ComponentProvider, int, int, int, int, int, boolean)
 */
public static Component clickComponentProvider(ComponentProvider provider) {

	JComponent component = provider.getComponent();
	DockableComponent dockableComponent = getDockableComponent(component);
	selectTabIfAvailable(dockableComponent);
	Rectangle bounds = component.getBounds();
	int centerX = (bounds.x + bounds.width) >> 1;
	int centerY = (bounds.y + bounds.height) >> 1;

	return clickComponentProvider(provider, MouseEvent.BUTTON1, centerX, centerY, 1, 0, false);
}
 
Example 3
Source File: WinClassicViewTabDisplayerUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Paints lower border, bottom line, separating tabs from content
 */
protected void paintOverallBorder(Graphics g, JComponent c) {
    if (isGenericUI) {
        return;
    }
    Rectangle r = c.getBounds();
    g.setColor(UIManager.getColor("InternalFrame.borderDarkShadow")); //NOI18N
    g.drawLine(0, r.height - 1, r.width - 1, r.height - 1);
}
 
Example 4
Source File: MetalViewTabDisplayerUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Paints bottom "activation" line
 */
private void paintBottomBorder(Graphics g, JComponent c) {
    Color color = isActive() ? getActBgColor() : getInactBgColor();
    g.setColor(color);
    Rectangle bounds = c.getBounds();
    g.fillRect(1, bounds.height - 3, bounds.width - 1, 2);
    g.setColor(getBorderShadow());
    g.drawLine(1, bounds.height - 1, bounds.width - 1, bounds.height - 1);
}
 
Example 5
Source File: AnimatedLayout.java    From pumpernickel with MIT License 5 votes vote down vote up
/**
 * Nudge a component towards the destination.
 * 
 * @param c
 *            the component to nudge.
 * @param dest
 *            the target bounds for the component.
 * @return true when the component is at the desired location
 */
protected static boolean nudge(JComponent c, Rectangle dest) {
	Rectangle bounds = c.getBounds();

	double lastDX = getDouble(c, PROPERTY_LAST_DX, 0);
	double lastDY = getDouble(c, PROPERTY_LAST_DY, 0);
	double lastDW = getDouble(c, PROPERTY_LAST_DW, 0);
	double lastDH = getDouble(c, PROPERTY_LAST_DH, 0);

	double dx = dest.x - bounds.x;
	double dy = dest.y - bounds.y;
	double dw = dest.width - bounds.width;
	double dh = dest.height - bounds.height;

	dx = limit(.5 * sign(dx) * Math.pow(Math.abs(dx), .7) + .5 * lastDX, dx);
	dy = limit(.5 * sign(dy) * Math.pow(Math.abs(dy), .7) + .5 * lastDY, dy);
	dw = limit(.5 * sign(dw) * Math.pow(Math.abs(dw), .7) + .5 * lastDW, dw);
	dh = limit(.5 * sign(dh) * Math.pow(Math.abs(dh), .7) + .5 * lastDH, dh);

	c.putClientProperty(PROPERTY_LAST_DX, new Double(dx));
	c.putClientProperty(PROPERTY_LAST_DY, new Double(dy));
	c.putClientProperty(PROPERTY_LAST_DW, new Double(dw));
	c.putClientProperty(PROPERTY_LAST_DH, new Double(dh));

	if (Math.abs(dx) < 1.2 && Math.abs(dy) < 1.2 && Math.abs(dw) < 1.2
			&& Math.abs(dh) < 1.2) {
		c.setBounds(dest);
		return true;
	}

	bounds.x += (int) (dx + .5);
	bounds.y += (int) (dy + .5);
	bounds.width += (int) (dw + .5);
	bounds.height += (int) (dh + .5);

	c.setBounds(bounds);

	return false;
}
 
Example 6
Source File: BalloonManager.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static void configureBalloon( Balloon balloon, JLayeredPane pane, JComponent ownerComp ) {
    Rectangle ownerCompBounds = ownerComp.getBounds();
    ownerCompBounds = SwingUtilities.convertRectangle( ownerComp.getParent(), ownerCompBounds, pane );
    
    int paneWidth = pane.getWidth();
    int paneHeight = pane.getHeight();
    
    Dimension balloonSize = balloon.getPreferredSize();
    balloonSize.height += Balloon.ARC;
    
    //first try lower right corner
    if( ownerCompBounds.x + ownerCompBounds.width + balloonSize.width < paneWidth
        && 
        ownerCompBounds.y + ownerCompBounds.height + balloonSize.height + Balloon.ARC < paneHeight ) {
        
        balloon.setArrowLocation( GridBagConstraints.SOUTHEAST );
        balloon.setBounds( ownerCompBounds.x+ownerCompBounds.width-Balloon.ARC/2, 
                ownerCompBounds.y+ownerCompBounds.height, balloonSize.width+Balloon.ARC, balloonSize.height );
    
    //upper right corner
    } else  if( ownerCompBounds.x + ownerCompBounds.width + balloonSize.width < paneWidth
                && 
                ownerCompBounds.y - balloonSize.height - Balloon.ARC > 0 ) {
        
        balloon.setArrowLocation( GridBagConstraints.NORTHEAST );
        balloon.setBounds( ownerCompBounds.x+ownerCompBounds.width-Balloon.ARC/2, 
                ownerCompBounds.y-balloonSize.height, balloonSize.width+Balloon.ARC, balloonSize.height );
    
    //lower left corner
    } else  if( ownerCompBounds.x - balloonSize.width > 0
                && 
                ownerCompBounds.y + ownerCompBounds.height + balloonSize.height + Balloon.ARC < paneHeight ) {
        
        balloon.setArrowLocation( GridBagConstraints.SOUTHWEST );
        balloon.setBounds( ownerCompBounds.x-balloonSize.width+Balloon.ARC/2, 
                ownerCompBounds.y+ownerCompBounds.height, balloonSize.width+Balloon.ARC, balloonSize.height );
    //upper left corent
    } else {
        balloon.setArrowLocation( GridBagConstraints.NORTHWEST );
        balloon.setBounds( ownerCompBounds.x-balloonSize.width/*+Balloon.ARC/2*/, 
                ownerCompBounds.y-balloonSize.height, balloonSize.width+Balloon.ARC, balloonSize.height );
    }
}
 
Example 7
Source File: BalloonManager.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static void configureBalloon( Balloon balloon, JLayeredPane pane, JComponent ownerComp ) {
    Rectangle ownerCompBounds = ownerComp.getBounds();
    ownerCompBounds = SwingUtilities.convertRectangle( ownerComp.getParent(), ownerCompBounds, pane );
    
    int paneWidth = pane.getWidth();
    int paneHeight = pane.getHeight();
    
    Dimension balloonSize = balloon.getPreferredSize();
    balloonSize.height += Balloon.ARC;
    
    //first try lower right corner
    if( ownerCompBounds.x + ownerCompBounds.width + balloonSize.width < paneWidth
        && 
        ownerCompBounds.y + ownerCompBounds.height + balloonSize.height + Balloon.ARC < paneHeight ) {
        
        balloon.setArrowLocation( GridBagConstraints.SOUTHEAST );
        balloon.setBounds( ownerCompBounds.x+ownerCompBounds.width-Balloon.ARC/2, 
                ownerCompBounds.y+ownerCompBounds.height, balloonSize.width+Balloon.ARC, balloonSize.height );
    
    //upper right corner
    } else  if( ownerCompBounds.x + ownerCompBounds.width + balloonSize.width < paneWidth
                && 
                ownerCompBounds.y - balloonSize.height - Balloon.ARC > 0 ) {
        
        balloon.setArrowLocation( GridBagConstraints.NORTHEAST );
        balloon.setBounds( ownerCompBounds.x+ownerCompBounds.width-Balloon.ARC/2, 
                ownerCompBounds.y-balloonSize.height, balloonSize.width+Balloon.ARC, balloonSize.height );
    
    //lower left corner
    } else  if( ownerCompBounds.x - balloonSize.width > 0
                && 
                ownerCompBounds.y + ownerCompBounds.height + balloonSize.height + Balloon.ARC < paneHeight ) {
        
        balloon.setArrowLocation( GridBagConstraints.SOUTHWEST );
        balloon.setBounds( ownerCompBounds.x-balloonSize.width+Balloon.ARC/2, 
                ownerCompBounds.y+ownerCompBounds.height, balloonSize.width+Balloon.ARC, balloonSize.height );
    //upper left corent
    } else {
        balloon.setArrowLocation( GridBagConstraints.NORTHWEST );
        balloon.setBounds( ownerCompBounds.x-balloonSize.width/*+Balloon.ARC/2*/, 
                ownerCompBounds.y-balloonSize.height, balloonSize.width+Balloon.ARC, balloonSize.height );
    }
}
 
Example 8
Source File: SplayedLayout.java    From pumpernickel with MIT License 4 votes vote down vote up
Plan(JComponent container, boolean horizontal) {
	this.container = container;
	info = new PlanInfo(horizontal, container.getBounds());
}
 
Example 9
Source File: SpotlightPanel.java    From pumpernickel with MIT License 4 votes vote down vote up
protected void recalculateHighlight(boolean forceImmediateUpdate) {
	Rectangle highlightSum = null;
	for (JComponent h : highlightedComponents) {
		if (h.isShowing() && h.getParent() != null) {
			Rectangle r = h.getBounds();
			r = SwingUtilities.convertRectangle(h.getParent(), r, this);
			if (highlightSum == null) {
				highlightSum = r;
			} else {
				highlightSum.add(r);
			}
		}
	}

	if (highlightSum == null) {
		putClientProperty(TARGET_ALPHA, 0f);
	} else {
		putClientProperty(TARGET_ALPHA, 1f);
		putClientProperty(TARGET_X, (float) highlightSum.getX());
		putClientProperty(TARGET_Y, (float) highlightSum.getY());
		putClientProperty(TARGET_WIDTH, (float) highlightSum.getWidth());
		putClientProperty(TARGET_HEIGHT, (float) highlightSum.getHeight());
	}

	if (getClientProperty(REAL_X) == null) {
		putClientProperty(REAL_ALPHA, 0);
		putClientProperty(REAL_X, getClientProperty(TARGET_X));
		putClientProperty(REAL_Y, getClientProperty(TARGET_Y));
		putClientProperty(REAL_WIDTH, getClientProperty(TARGET_WIDTH));
		putClientProperty(REAL_HEIGHT, getClientProperty(TARGET_HEIGHT));
	}

	if (forceImmediateUpdate) {
		putClientProperty(REAL_ALPHA, getClientProperty(TARGET_ALPHA));
		putClientProperty(REAL_X, getClientProperty(TARGET_X));
		putClientProperty(REAL_Y, getClientProperty(TARGET_Y));
		putClientProperty(REAL_WIDTH, getClientProperty(TARGET_WIDTH));
		putClientProperty(REAL_HEIGHT, getClientProperty(TARGET_HEIGHT));
	}

}
 
Example 10
Source File: CustomizedToolbar.java    From pumpernickel with MIT License 4 votes vote down vote up
/**
 * Returns the contents (by name, in order of appearance) after factoring in
 * the point that the mouse is current at point p. (This means the component
 * that is currently being dragged will offset everything and appear near
 * point p.)
 */
private String[] getContents(Point p) {
	if (draggingComponent == null || draggingDefaults) {
		return getContents();
	}

	Rectangle toolbarBounds = new Rectangle(0, 0, getWidth(), getHeight());

	boolean verticallyInside = p.y >= 0 && p.y <= toolbarBounds.height;

	String[] order = getContents();

	if ((!verticallyInside) && draggingFromToolbar == false) {
		return order;
	}

	int a = 0;
	Component theComponent = getComponent(draggingComponent);
	if (hideActiveComponents)
		theComponent.setVisible(false);
	while (a < order.length) {
		if (order[a].equals(draggingComponent)) {
			order = remove(order, a);
		} else {
			a++;
		}
	}

	if ((!verticallyInside) && draggingFromToolbar) {
		return order;
	}

	for (a = 0; a < order.length; a++) {
		JComponent c = getComponent(order[a]);
		Rectangle r = c.getBounds();
		if (p.x < r.x + r.width / 2) {
			order = insert(order, draggingComponent, a);
			return order;
		}
	}

	order = insert(order, draggingComponent, order.length);
	return order;
}
 
Example 11
Source File: MoveUIEffect.java    From pumpernickel with MIT License 4 votes vote down vote up
public MoveUIEffect(JComponent comp, Rectangle newBounds) {
	this(comp, comp.getBounds(), newBounds);
}