Java Code Examples for java.awt.Rectangle.getSize()

The following are Jave code examples for showing how to use getSize() of the java.awt.Rectangle class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: rapidminer   File: ComboBoxUI.java   View Source Code Vote up 6 votes
private Point getPopupLocation() {
	Dimension popupSize = new Dimension((int) this.comboBox.getSize().getWidth(), (int) this.comboBox.getSize()
			.getHeight());
	Insets insets = getInsets();
	popupSize.setSize(popupSize.width - (insets.right + insets.left),
			getPopupHeightForRowCount(this.comboBox.getMaximumRowCount()));
	Rectangle popupBounds = computePopupBounds(0, this.comboBox.getBounds().height, popupSize.width,
			popupSize.height);
	Dimension scrollSize = popupBounds.getSize();
	Point popupLocation = popupBounds.getLocation();

	this.scroller.setMaximumSize(scrollSize);
	this.scroller.setPreferredSize(scrollSize);
	this.scroller.setMinimumSize(scrollSize);

	this.list.revalidate();
	return popupLocation;
}
 
Example 2
Project: openjdk-jdk10   File: XlibUtil.java   View Source Code Vote up 6 votes
/**
 * Translates the given rectangle from one window to another.
 * Returns null if the translation is failed
 */
static Rectangle translateCoordinates(long src, long dst, Rectangle r,
                                      int scale)
{
    Point translatedLoc = translateCoordinates(src, dst, r.getLocation(),
                                               scale);

    if (translatedLoc == null)
    {
        return null;
    }
    else
    {
        return new Rectangle(translatedLoc, r.getSize());
    }
}
 
Example 3
Project: openjdk-jdk10   File: AquaComboBoxPopup.java   View Source Code Vote up 6 votes
protected Rectangle adjustPopupAndGetBounds() {
    if (isPopDown != isPopdown()) {
        updateContents(true);
    }

    final Dimension popupSize = getBestPopupSizeForRowCount(comboBox.getMaximumRowCount());
    final Rectangle popupBounds = computePopupBounds(0, comboBox.getBounds().height, popupSize.width, popupSize.height);
    if (popupBounds == null) return null; // returning null means don't show anything

    final Dimension realPopupSize = popupBounds.getSize();
    scroller.setMaximumSize(realPopupSize);
    scroller.setPreferredSize(realPopupSize);
    scroller.setMinimumSize(realPopupSize);
    list.invalidate();

    final int selectedIndex = comboBox.getSelectedIndex();
    if (selectedIndex == -1) {
        list.clearSelection();
    } else {
        list.setSelectedIndex(selectedIndex);
    }
    list.ensureIndexIsVisible(list.getSelectedIndex());

    return popupBounds;
}
 
Example 4
Project: incubator-netbeans   File: DependencyGraphScene.java   View Source Code Vote up 5 votes
@Override
protected void performLayout() {
    Rectangle rectangle = null;
    List<? extends Widget> toFit = widgets != null ? widgets : depScene.getChildren();
    if (toFit == null) {
        return;
    }

    for (Widget widget : toFit) {
        Rectangle bounds = widget.getBounds();
        if (bounds == null) {
            continue;
        }
        if (rectangle == null) {
            rectangle = widget.convertLocalToScene(bounds);
        } else {
            rectangle = rectangle.union(widget.convertLocalToScene(bounds));
        }
    }
    // margin around
    if (widgets == null) {
        rectangle.grow(5, 5);
    } else {
        rectangle.grow(25, 25);
    }
    Dimension dim = rectangle.getSize();
    Dimension viewDim = parentScrollPane.getViewportBorderBounds().getSize ();
    double zf = Math.min ((double) viewDim.width / dim.width, (double) viewDim.height / dim.height);
    if (depScene.isAnimated()) {
        if (widgets == null) {
            depScene.getSceneAnimator().animateZoomFactor(zf);
        } else {
            CenteredZoomAnimator cza = new CenteredZoomAnimator(depScene.getSceneAnimator());
            cza.setZoomFactor(zf,
                    new Point((int)rectangle.getCenterX(), (int)rectangle.getCenterY()));
        }
    } else {
        depScene.setMyZoomFactor (zf);
    }
}
 
Example 5
Project: incubator-netbeans   File: DefaultAnchorShapeResolver.java   View Source Code Vote up 5 votes
private Rectangle getSourceBounds()
{
    Widget source = connection.getSourceAnchor().getRelatedWidget();
         
    if(source != null)
    {
        Point sourceLocation = source.getLocation();
        Rectangle clientArea = source.getClientArea();
        return new Rectangle(sourceLocation, clientArea.getSize());
    }
    
    return null;
}
 
Example 6
Project: incubator-netbeans   File: DefaultAnchorShapeResolver.java   View Source Code Vote up 5 votes
private Rectangle getTargetBounds()
{
    Widget target = connection.getTargetAnchor().getRelatedWidget();
            
    if(target != null)
    {
        Point targetLocation = target.getLocation();
        Rectangle targetArea = target.getClientArea();
        return new Rectangle(targetLocation, targetArea.getSize());
    }
    
    return null;
}
 
Example 7
Project: incubator-netbeans   File: CompletionLayoutPopup.java   View Source Code Vote up 5 votes
/**
 * Create and display the popup at the given bounds.
 *
 * @param popupBounds location and size of the popup.
 * @param displayAboveCaret whether the popup is displayed above the anchor
 *  bounds or below them (it does not be right above them).
 */
private void show(Rectangle popupBounds, boolean displayAboveCaret) {
    // Hide the original popup if exists
    if (popup != null) {
        popup.hide();
        popup = null;
    }
    
    // Explicitly set the preferred size
    Dimension origPrefSize = getPreferredSize();
    Dimension newPrefSize = popupBounds.getSize();
    JComponent contComp = getContentComponent();
    if (contComp == null){
        return;
    }
    contComp.setPreferredSize(newPrefSize);
    showRetainedPreferredSize = newPrefSize.equals(origPrefSize);
    
    PopupFactory factory = PopupFactory.getSharedInstance();
    // Lightweight completion popups don't work well on the Mac - trying
    // to click on its scrollbars etc. will cause the window to be hidden,
    // so force a heavyweight parent by passing in owner==null. (#96717)
    
    JTextComponent owner = layout.getEditorComponent();
    if(owner != null && owner.getClientProperty("ForceHeavyweightCompletionPopup") != null) {
        owner = null;
    }
    
    // #76648: Autocomplete box is too close to text
    if(displayAboveCaret && Utilities.isMac()) {
        popupBounds.y -= 10;
    }
    
    popup = factory.getPopup(owner, contComp, popupBounds.x, popupBounds.y);
    popup.show();

    this.popupBounds = popupBounds;
    this.displayAboveCaret = displayAboveCaret;
}
 
Example 8
Project: incubator-netbeans   File: DesktopImpl.java   View Source Code Vote up 5 votes
/** Returns bounds of last button in sliding view to which given
 * operation belongs. Bounds are relative to desktop layered pane.
 */
private Rectangle computeLastButtonBounds(SlideOperation operation) {
    String side = operation.getSide();
    SlidingView view = findView(side);
    Rectangle screenRect = view.getTabBounds(view.getTopComponents().size() - 1);
    Point leftTop = screenRect.getLocation();
    
    if (Constants.BOTTOM.equals(side)) {
        leftTop.y += desktop.getHeight() - view.getComponent().getPreferredSize().height;
    } else if (Constants.RIGHT.equals(side)) {
        leftTop.x += desktop.getWidth() - view.getComponent().getPreferredSize().width;
    }
    
    return new Rectangle(leftTop, screenRect.getSize());
}
 
Example 9
Project: incubator-netbeans   File: ScaleFx.java   View Source Code Vote up 5 votes
public void showEffect(JLayeredPane pane, Integer layer, SlideOperation operation) {
    this.pane = pane;
    this.operation = operation;
    Component comp = operation.getComponent();
    Graphics2D gr2d = (Graphics2D)pane.getGraphics();
    Rectangle start = operation.getStartBounds();
    Rectangle finish = operation.getFinishBounds();
    Dimension finishSize = finish.getSize();
    Dimension startSize = start.getSize();
    Rectangle current = start;
    Image compImage = preparedImage;

   /* if (compImage == null) {
        if (finishSize.width * finishSize.height > startSize.width * startSize.height) {
            compImage = renderCompIntoImage(comp, finishSize, pane);
        } else {
            compImage = renderCompIntoImage(comp, startSize, pane);
        }
    }*/
    pane.add(stretchedImage, layer);
    
    path = computePath(start, finish);
    
    curIter = 1;
    if (compImage != null) {
        stretchedImage.setOrigImage(compImage);
    } else {
        if (finishSize.width * finishSize.height > startSize.width * startSize.height) {
            stretchedImage.setComp(comp, finishSize);
        } else {
            stretchedImage.setComp(comp, startSize);
        }
    }
    stretchedImage.setBoundsAndAlpha(start, initialAlpha);
    
    getTimer().start();
}
 
Example 10
Project: incubator-netbeans   File: CompletionLayoutPopup.java   View Source Code Vote up 5 votes
/**
 * Create and display the popup at the given bounds.
 *
 * @param popupBounds location and size of the popup.
 * @param displayAboveCaret whether the popup is displayed above the anchor
 *  bounds or below them (it does not be right above them).
 */
private void show(Rectangle popupBounds, boolean displayAboveCaret) {
    // Hide the original popup if exists
    if (popup != null) {
        popup.hide();
        popup = null;
    }
    
    // Explicitly set the preferred size
    Dimension origPrefSize = getPreferredSize();
    Dimension newPrefSize = popupBounds.getSize();
    JComponent contComp = getContentComponent();
    if (contComp == null){
        return;
    }
    contComp.setPreferredSize(newPrefSize);
    showRetainedPreferredSize = newPrefSize.equals(origPrefSize);
    
    PopupFactory factory = PopupFactory.getSharedInstance();
    // Lightweight completion popups don't work well on the Mac - trying
    // to click on its scrollbars etc. will cause the window to be hidden,
    // so force a heavyweight parent by passing in owner==null. (#96717)
    
    JTextComponent owner = layout.getEditorComponent();
    if(owner != null && owner.getClientProperty("ForceHeavyweightCompletionPopup") != null) {
        owner = null;
    }
    
    // #76648: Autocomplete box is too close to text
    if(displayAboveCaret && Utilities.isMac()) {
        popupBounds.y -= 10;
    }
    
    popup = factory.getPopup(owner, contComp, popupBounds.x, popupBounds.y);
    popup.show();

    this.popupBounds = popupBounds;
    this.displayAboveCaret = displayAboveCaret;
}
 
Example 11
Project: incubator-netbeans   File: CompletionLayoutPopup.java   View Source Code Vote up 5 votes
/**
 * Create and display the popup at the given bounds.
 *
 * @param popupBounds location and size of the popup.
 * @param displayAboveCaret whether the popup is displayed above the anchor
 *  bounds or below them (it does not be right above them).
 */
private void show(Rectangle popupBounds, boolean displayAboveCaret) {
    // Hide the original popup if exists
    if (popup != null) {
        popup.hide();
        popup = null;
    }

    // Explicitly set the preferred size
    Dimension origPrefSize = getPreferredSize();
    Dimension newPrefSize = popupBounds.getSize();
    JComponent contComp = getContentComponent();
    if (contComp == null){
        return;
    }
    contComp.setPreferredSize(newPrefSize);
    showRetainedPreferredSize = newPrefSize.equals(origPrefSize);

    PopupFactory factory = PopupFactory.getSharedInstance();
    // Lightweight completion popups don't work well on the Mac - trying
    // to click on its scrollbars etc. will cause the window to be hidden,
    // so force a heavyweight parent by passing in owner==null. (#96717)

    JTextComponent owner = getEditorComponent();
    if(owner != null && owner.getClientProperty("ForceHeavyweightCompletionPopup") != null) { //NOI18N
        owner = null;
    }

    // #76648: Autocomplete box is too close to text
    if(displayAboveCaret && Utilities.isMac()) {
        popupBounds.y -= 10;
    }

    popup = factory.getPopup(owner, contComp, popupBounds.x, popupBounds.y);
    popup.show();

    this.popupBounds = popupBounds;
    this.displayAboveCaret = displayAboveCaret;
}
 
Example 12
Project: VASSAL-src   File: Map.java   View Source Code Vote up 5 votes
/**
   * @return the size of the map in pixels at 100% zoom,
   * including the edge buffer
   */
// FIXME: why synchronized?
  public synchronized Dimension mapSize() {
    final Rectangle r = new Rectangle(0,0);
    for (Board b : boards) r.add(b.bounds());
    r.width += edgeBuffer.width;
    r.height += edgeBuffer.height;
    return r.getSize();
  }
 
Example 13
Project: VASSAL-src   File: PlayerHand.java   View Source Code Vote up 5 votes
public Dimension mapSize() {
  final Rectangle r = new Rectangle(0,0,200,200);
  r.add(new Rectangle(super.mapSize()));

  for (GamePiece p : pieces.getPieces()) {
    final Rectangle bb = boundingBoxOf(p);
    if (bb != null) {
      r.add(bb);
    }
  }

  return r.getSize();
}
 
Example 14
Project: OpenJSharp   File: BasicGraphicsUtils.java   View Source Code Vote up 5 votes
public static Dimension getPreferredButtonSize(AbstractButton b, int textIconGap)
{
    if(b.getComponentCount() > 0) {
        return null;
    }

    Icon icon = b.getIcon();
    String text = b.getText();

    Font font = b.getFont();
    FontMetrics fm = b.getFontMetrics(font);

    Rectangle iconR = new Rectangle();
    Rectangle textR = new Rectangle();
    Rectangle viewR = new Rectangle(Short.MAX_VALUE, Short.MAX_VALUE);

    SwingUtilities.layoutCompoundLabel(
        b, fm, text, icon,
        b.getVerticalAlignment(), b.getHorizontalAlignment(),
        b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
        viewR, iconR, textR, (text == null ? 0 : textIconGap)
    );

    /* The preferred size of the button is the size of
     * the text and icon rectangles plus the buttons insets.
     */

    Rectangle r = iconR.union(textR);

    Insets insets = b.getInsets();
    r.width += insets.left + insets.right;
    r.height += insets.top + insets.bottom;

    return r.getSize();
}
 
Example 15
Project: OpenJSharp   File: XlibUtil.java   View Source Code Vote up 5 votes
/**
 * Translates the given rectangle from one window to another.
 * Returns null if the translation is failed
 */
static Rectangle translateCoordinates(long src, long dst, Rectangle r)
{
    Point translatedLoc = translateCoordinates(src, dst, r.getLocation());
    if (translatedLoc == null)
    {
        return null;
    }
    else
    {
        return new Rectangle(translatedLoc, r.getSize());
    }
}
 
Example 16
Project: jdk8u-jdk   File: BasicGraphicsUtils.java   View Source Code Vote up 5 votes
public static Dimension getPreferredButtonSize(AbstractButton b, int textIconGap)
{
    if(b.getComponentCount() > 0) {
        return null;
    }

    Icon icon = b.getIcon();
    String text = b.getText();

    Font font = b.getFont();
    FontMetrics fm = b.getFontMetrics(font);

    Rectangle iconR = new Rectangle();
    Rectangle textR = new Rectangle();
    Rectangle viewR = new Rectangle(Short.MAX_VALUE, Short.MAX_VALUE);

    SwingUtilities.layoutCompoundLabel(
        b, fm, text, icon,
        b.getVerticalAlignment(), b.getHorizontalAlignment(),
        b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
        viewR, iconR, textR, (text == null ? 0 : textIconGap)
    );

    /* The preferred size of the button is the size of
     * the text and icon rectangles plus the buttons insets.
     */

    Rectangle r = iconR.union(textR);

    Insets insets = b.getInsets();
    r.width += insets.left + insets.right;
    r.height += insets.top + insets.bottom;

    return r.getSize();
}
 
Example 17
Project: jdk8u-jdk   File: XlibUtil.java   View Source Code Vote up 5 votes
/**
 * Translates the given rectangle from one window to another.
 * Returns null if the translation is failed
 */
static Rectangle translateCoordinates(long src, long dst, Rectangle r)
{
    Point translatedLoc = translateCoordinates(src, dst, r.getLocation());
    if (translatedLoc == null)
    {
        return null;
    }
    else
    {
        return new Rectangle(translatedLoc, r.getSize());
    }
}
 
Example 18
Project: openjdk-jdk10   File: BlockWidget.java   View Source Code Vote up 5 votes
public Dimension getSize() {
    Rectangle bounds = getBounds();
    if (bounds != null) {
        return bounds.getSize();
    } else {
        return MIN_SIZE;
    }
}
 
Example 19
Project: openjdk-jdk10   File: BasicGraphicsUtils.java   View Source Code Vote up 5 votes
/**
 * Returns the preferred size of the button.
 *
 * @param b an instance of {@code AbstractButton}
 * @param textIconGap a gap between text and icon
 * @return the preferred size of the button
 */
public static Dimension getPreferredButtonSize(AbstractButton b, int textIconGap)
{
    if(b.getComponentCount() > 0) {
        return null;
    }

    Icon icon = b.getIcon();
    String text = b.getText();

    Font font = b.getFont();
    FontMetrics fm = b.getFontMetrics(font);

    Rectangle iconR = new Rectangle();
    Rectangle textR = new Rectangle();
    Rectangle viewR = new Rectangle(Short.MAX_VALUE, Short.MAX_VALUE);

    SwingUtilities.layoutCompoundLabel(
        b, fm, text, icon,
        b.getVerticalAlignment(), b.getHorizontalAlignment(),
        b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
        viewR, iconR, textR, (text == null ? 0 : textIconGap)
    );

    /* The preferred size of the button is the size of
     * the text and icon rectangles plus the buttons insets.
     */

    Rectangle r = iconR.union(textR);

    Insets insets = b.getInsets();
    r.width += insets.left + insets.right;
    r.height += insets.top + insets.bottom;

    return r.getSize();
}
 
Example 20
Project: ramus   File: AbstractTemplate.java   View Source Code Vote up 4 votes
private void createPainter(final Rectangle rectangle) {
    painter = new PIDEF0painter(base, rectangle.getSize(), dataPlugin);
    rect = rectangle;
    refresh = false;
}