javax.swing.JComponent#getBounds ( )源码实例Demo

下面列出了javax.swing.JComponent#getBounds ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: wandora   文件: Connector.java
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
    }
    
}
 
源代码2 项目: ghidra   文件: AbstractDockingTest.java
/**
 * 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);
}
 
源代码3 项目: netbeans   文件: WinClassicViewTabDisplayerUI.java
/**
 * 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);
}
 
源代码4 项目: netbeans   文件: MetalViewTabDisplayerUI.java
/**
 * 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);
}
 
源代码5 项目: pumpernickel   文件: AnimatedLayout.java
/**
 * 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;
}
 
源代码6 项目: netbeans   文件: BalloonManager.java
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 );
    }
}
 
源代码7 项目: netbeans   文件: BalloonManager.java
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 );
    }
}
 
源代码8 项目: pumpernickel   文件: SplayedLayout.java
Plan(JComponent container, boolean horizontal) {
	this.container = container;
	info = new PlanInfo(horizontal, container.getBounds());
}
 
源代码9 项目: pumpernickel   文件: SpotlightPanel.java
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));
	}

}
 
源代码10 项目: pumpernickel   文件: CustomizedToolbar.java
/**
 * 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;
}
 
源代码11 项目: pumpernickel   文件: MoveUIEffect.java
public MoveUIEffect(JComponent comp, Rectangle newBounds) {
	this(comp, comp.getBounds(), newBounds);
}