Java Code Examples for java.awt.Dimension.equals()

The following are Jave code examples for showing how to use equals() of the java.awt.Dimension 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: iiif-apis   File: SizeRequest.java   View Source Code Vote up 6 votes
/**
 * Get the canonical form of this request.
 *
 * @See http://iiif.io/api/image/2.1/#canonical-uri-syntax
 */
public String getCanonicalForm(Dimension nativeSize, ImageApiProfile profile) {
  Dimension resolved = this.resolve(nativeSize, profile);
  // "w," requests are already canonical
  double nativeRatio = nativeSize.getWidth() / nativeSize.getHeight();
  double resolvedRatio = resolved.getWidth() / resolved.getHeight();
  if (resolved.equals(nativeSize)) {
    return "full";
  } else if (this.width != null && this.height == null) {
    return this.toString();
  } else if (Math.floor(resolvedRatio * nativeSize.getHeight()) == nativeSize.getWidth() ||
             Math.ceil(resolvedRatio * nativeSize.getHeight()) == nativeSize.getWidth()) {
    return String.format("%d,", resolved.width);
  } else {
    return String.format("%d,%d", resolved.width, resolved.height);
  }
}
 
Example 2
Project: incubator-netbeans   File: NotifyExcPanel.java   View Source Code Vote up 6 votes
private void ensurePreferredSize() {
    if( null != lastBounds ) {
        return; //we remember the last window position
    } //we remember the last window position
    Dimension sz = dialog.getSize();
    Dimension pref = dialog.getPreferredSize();
    if (pref.height == 0) {
        pref.height = SIZE_PREFERRED_HEIGHT;
    }
    if (pref.width == 0) {
        pref.width = SIZE_PREFERRED_WIDTH;
    }
    if (!sz.equals(pref)) {
        dialog.setSize(pref.width, pref.height);
        dialog.validate();
        dialog.repaint();
    }
}
 
Example 3
Project: incubator-netbeans   File: IOConnector.java   View Source Code Vote up 6 votes
@Override
public void propertyChange(PropertyChangeEvent evt) {
    if (task != null && IOResizable.PROP_SIZE.equals(evt.getPropertyName())) {
        IOResizable.Size newVal = (IOResizable.Size) evt.getNewValue();
        if (newVal != null) {
            Dimension newCells = newVal.cells;
            Dimension newPixels = newVal.pixels;
            if (newCells == null || newPixels == null) {
                throw new NullPointerException();
            }

            if (newCells.equals(this.cells) && newPixels.equals(this.pixels)) {
                return;
            }

            this.cells = new Dimension(newCells);
            this.pixels = new Dimension(newPixels);
            task.schedule(1000);
        }
    }
}
 
Example 4
Project: jdk8u-jdk   File: TextAreaTwicePack.java   View Source Code Vote up 6 votes
public static void main(final String[] args) {
    final Frame frame = new Frame();
    final TextArea ta = new TextArea();
    frame.add(ta);
    frame.pack();
    frame.setVisible(true);
    sleep();
    final Dimension before = frame.getSize();
    frame.pack();
    final Dimension after = frame.getSize();
    if (!after.equals(before)) {
        throw new RuntimeException(
                "Expected size: " + before + ", actual size: " + after);
    }
    frame.dispose();
}
 
Example 5
Project: jdk8u-jdk   File: MaximizedNormalBoundsUndecoratedTest.java   View Source Code Vote up 6 votes
boolean doTest() {
    Dimension beforeMaximizeCalled = new Dimension(300,300);

    frame = new Frame("Test Frame");
    frame.setUndecorated(true);
    frame.setFocusable(true);
    frame.setSize(beforeMaximizeCalled);
    frame.setVisible(true);
    frame.setExtendedState(Frame.MAXIMIZED_BOTH);
    frame.setExtendedState(Frame.NORMAL);

    Dimension afterMaximizedCalled= frame.getBounds().getSize();

    frame.dispose();

    if (beforeMaximizeCalled.equals(afterMaximizedCalled)) {
        return true;
    }
    return false;
}
 
Example 6
Project: openjdk-jdk10   File: TextAreaTwicePack.java   View Source Code Vote up 6 votes
public static void main(final String[] args) {
    final Frame frame = new Frame();
    final TextArea ta = new TextArea();
    frame.add(ta);
    frame.pack();
    frame.setVisible(true);
    sleep();
    final Dimension before = frame.getSize();
    frame.pack();
    final Dimension after = frame.getSize();
    if (!after.equals(before)) {
        throw new RuntimeException(
                "Expected size: " + before + ", actual size: " + after);
    }
    frame.dispose();
}
 
Example 7
Project: openjdk-jdk10   File: IsToolkitUseTheMainScreen.java   View Source Code Vote up 6 votes
private static void testHeadful() {
    GraphicsEnvironment ge
            = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc
            = ge.getDefaultScreenDevice().getDefaultConfiguration();
    Dimension gcSize = gc.getBounds().getSize();
    ColorModel gcCM = gc.getColorModel();

    Dimension toolkitSize = Toolkit.getDefaultToolkit().getScreenSize();
    ColorModel toolkitCM = Toolkit.getDefaultToolkit().getColorModel();

    if (!gcSize.equals(toolkitSize)) {
        System.err.println("Toolkit size = " + toolkitSize);
        System.err.println("GraphicsConfiguration size = " + gcSize);
        throw new RuntimeException("Incorrect size");
    }
    if (!gcCM.equals(toolkitCM)) {
        System.err.println("Toolkit color model = " + toolkitCM);
        System.err.println("GraphicsConfiguration color model = " + gcCM);
        throw new RuntimeException("Incorrect color model");
    }
}
 
Example 8
Project: openjdk-jdk10   File: MaximizedNormalBoundsUndecoratedTest.java   View Source Code Vote up 6 votes
boolean doTest() {
    Dimension beforeMaximizeCalled = new Dimension(300,300);

    frame = new Frame("Test Frame");
    frame.setUndecorated(true);
    frame.setFocusable(true);
    frame.setSize(beforeMaximizeCalled);
    frame.setVisible(true);
    frame.setExtendedState(Frame.MAXIMIZED_BOTH);
    frame.setExtendedState(Frame.NORMAL);

    Dimension afterMaximizedCalled= frame.getBounds().getSize();

    frame.dispose();

    if (beforeMaximizeCalled.equals(afterMaximizedCalled)) {
        return true;
    }
    return false;
}
 
Example 9
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 10
Project: incubator-netbeans   File: NbPresenter.java   View Source Code Vote up 5 votes
private void initBounds() {
    Window w = findFocusedWindow();
    if( null != w ) {
        //#133235 - dialog windows should be centered on the main app window, not the whole screen
        setLocationRelativeTo( w );
        Rectangle screen = Utilities.getUsableScreenBounds( w.getGraphicsConfiguration() );
        Rectangle bounds = getBounds();
        int dx = bounds.x;
        int dy = bounds.y;
        // bottom
        if (dy + bounds.height > screen.y + screen.height) {
            dy = screen.y + screen.height - bounds.height;
        }
        // top
        if (dy < screen.y) {
            dy = screen.y;
        }
        // right
        if (dx + bounds.width > screen.x + screen.width) {
            dx = screen.x + screen.width - bounds.width;
        }
        // left
        if (dx < screen.x) {
            dx = screen.x;
        }
        setLocation( dx, dy );
    } else {
        //just center the dialog on the screen and let's hope it'll be
        //the correct one in multi-monitor setup
        Dimension size = getSize();
        Rectangle centerBounds = Utilities.findCenterBounds(size);
        if(size.equals(centerBounds.getSize())) {
            setLocation(centerBounds.x, centerBounds.y);
        } else {
            setBounds(centerBounds);
        }
    }
}
 
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 = 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 12
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 13
Project: rapidminer   File: ProcessRendererView.java   View Source Code Vote up 5 votes
/**
 * Update preferred size of this {@link JComponent} and updates the subprocess extension buttons
 * as well.
 */
private void updateComponentSize() {
	Dimension newSize = new Dimension((int) controller.getTotalWidth(), (int) controller.getTotalHeight());
	updateExtensionButtons();
	if (!newSize.equals(getPreferredSize())) {
		setPreferredSize(newSize);
		revalidate();
	}
}
 
Example 14
Project: jdk8u-jdk   File: FullScreenInsets.java   View Source Code Vote up 5 votes
private static void testSize(final Dimension actual, final Dimension exp) {
    if (!exp.equals(actual)) {
        System.err.println(" Wrong window size:" +
                           " Expected: " + exp + " Actual: " + actual);
        passed = false;
    }
}
 
Example 15
Project: openjdk-jdk10   File: FullScreenInsets.java   View Source Code Vote up 5 votes
private static void testSize(final Dimension actual, final Dimension exp) {
    if (!exp.equals(actual)) {
        System.err.println(" Wrong window size:" +
                           " Expected: " + exp + " Actual: " + actual);
        passed = false;
    }
}
 
Example 16
Project: incubator-netbeans   File: PlatformsCustomizer.java   View Source Code Vote up 4 votes
private void selectPlatform (Node pNode) {
    Component active = null;
    for (Component c : cards.getComponents()) {
        if (c.isVisible() &&
            (c == jPanel1 || c == messageArea)) {
                active = c;
                break;
        }
    }
    final Dimension lastSize = active == null ?
        null :
        active.getSize();
    this.clientArea.removeAll();
    this.messageArea.removeAll();
    this.removeButton.setEnabled (false);
    if (pNode == null) {
        ((CardLayout)cards.getLayout()).last(cards);
        return;
    }
    JComponent target = messageArea;
    JComponent owner = messageArea;
    JavaPlatform platform = pNode.getLookup().lookup(JavaPlatform.class);
    if (pNode != getExplorerManager().getRootContext()) {
        if (platform != null) {
            this.removeButton.setEnabled (canRemove(platform, pNode.getLookup().lookup(DataObject.class)));
            if (!platform.getInstallFolders().isEmpty()) {
                this.platformName.setText(pNode.getDisplayName());
                for (FileObject installFolder : platform.getInstallFolders()) {
                    File file = FileUtil.toFile(installFolder);
                    if (file != null) {
                        this.platformHome.setText (file.getAbsolutePath());
                    }
                }
                target = clientArea;
                owner = jPanel1;
            }
        }
        Component component = null;
        if (pNode.hasCustomizer()) {
            component = pNode.getCustomizer();
        }
        if (component == null) {
            final PropertySheet sp = new PropertySheet();
            sp.setNodes(new Node[] {pNode});
            component = sp;
        }
        addComponent(target, component);
    }
    if (lastSize != null) {
        final Dimension newSize = owner.getPreferredSize();
        final Dimension updatedSize = new Dimension(
            Math.max(lastSize.width, newSize.width),
            Math.max(lastSize.height, newSize.height));
        if (!newSize.equals(updatedSize)) {
            owner.setPreferredSize(updatedSize);
        }
    }
    target.revalidate();
    CardLayout cl = (CardLayout) cards.getLayout();
    if (target == clientArea) {
        cl.first (cards);
    }
    else {
        cl.last (cards);
    }
}
 
Example 17
Project: NBANDROID-V2   File: SdksCustomizer.java   View Source Code Vote up 4 votes
private void selectPlatform(Node pNode) {
    Component active = null;
    for (Component c : cards.getComponents()) {
        if (c.isVisible()
                && (c == jPanel1 || c == messageArea)) {
            active = c;
            break;
        }
    }
    final Dimension lastSize = active == null
            ? null
            : active.getSize();
    this.clientArea.removeAll();
    this.messageArea.removeAll();
    this.removeButton.setEnabled(false);
    if (pNode == null) {
        ((CardLayout) cards.getLayout()).last(cards);
        return;
    }
    JComponent target = messageArea;
    JComponent owner = messageArea;
    selectedPlatform = pNode.getLookup().lookup(AndroidSdk.class);
    if (pNode != getExplorerManager().getRootContext()) {
        if (selectedPlatform != null) {
            mkDefault.setEnabled(!selectedPlatform.isDefaultSdk());
            this.removeButton.setEnabled(!selectedPlatform.isDefaultSdk());
            if (!selectedPlatform.getInstallFolders().isEmpty()) {
                this.platformName.setText(pNode.getDisplayName());
                for (FileObject installFolder : selectedPlatform.getInstallFolders()) {
                    File file = FileUtil.toFile(installFolder);
                    if (file != null) {
                        this.platformHome.setText(file.getAbsolutePath());
                    }
                }
                target = clientArea;
                owner = jPanel1;
            }
        } else {
            removeButton.setEnabled(false);
            mkDefault.setEnabled(false);
        }
        Component component = null;
        if (pNode.hasCustomizer()) {
            component = pNode.getCustomizer();
        }
        if (component == null) {
            final PropertySheet sp = new PropertySheet();
            sp.setNodes(new Node[]{pNode});
            component = sp;
        }
        addComponent(target, component);
    }
    if (lastSize != null) {
        final Dimension newSize = owner.getPreferredSize();
        final Dimension updatedSize = new Dimension(
                Math.max(lastSize.width, newSize.width),
                Math.max(lastSize.height, newSize.height));
        if (!newSize.equals(updatedSize)) {
            owner.setPreferredSize(updatedSize);
        }
    }
    target.revalidate();
    CardLayout cl = (CardLayout) cards.getLayout();
    if (target == clientArea) {
        cl.first(cards);
    } else {
        cl.last(cards);
    }
}
 
Example 18
Project: OpenJSharp   File: SortItem.java   View Source Code Vote up 4 votes
/**
 * Paint the array of numbers as a list
 * of horizontal lines of varying lengths.
 */
@Override
public void paint(Graphics g) {
    int a[] = arr;
    int y = 0;
    int deltaY = 0, deltaX = 0, evenY = 0;

    Dimension currentSize = getSize();
    int currentHeight = currentSize.height;
    int currentWidth = currentSize.width;

    // Check to see if the applet has been resized since it
    // started running.  If so, need the deltas to make sure
    // the applet is centered in its containing panel.
    // The evenX and evenY are because the high and low
    // watermarks are calculated from the top, but the rest
    // of the lines are calculated from the bottom, which
    // can lead to a discrepancy if the window is not an
    // even size.
    if (!currentSize.equals(initialSize)) {
        evenY = (currentHeight - initialSize.height) % 2;
        deltaY = (currentHeight - initialSize.height) / 2;
        deltaX = (currentWidth - initialSize.width) / 2;

        if (deltaY < 0) {
            deltaY = 0;
            evenY = 0;
        }
        if (deltaX < 0) {
            deltaX = 0;
        }
    }

    // Erase old lines
    g.setColor(getBackground());
    y = currentHeight - deltaY - 1;
    for (int i = a.length; --i >= 0; y -= 2) {
        g.drawLine(deltaX + arr[i], y, currentWidth, y);
    }

    // Draw new lines
    g.setColor(Color.black);
    y = currentHeight - deltaY - 1;
    for (int i = a.length; --i >= 0; y -= 2) {
        g.drawLine(deltaX, y, deltaX + arr[i], y);
    }

    if (h1 >= 0) {
        g.setColor(Color.red);
        y = deltaY + evenY + h1 * 2 + 1;
        g.drawLine(deltaX, y, deltaX + initialSize.width, y);
    }
    if (h2 >= 0) {
        g.setColor(Color.blue);
        y = deltaY + evenY + h2 * 2 + 1;
        g.drawLine(deltaX, y, deltaX + initialSize.width, y);
    }
}
 
Example 19
Project: jdk8u-jdk   File: SortItem.java   View Source Code Vote up 4 votes
/**
 * Paint the array of numbers as a list
 * of horizontal lines of varying lengths.
 */
@Override
public void paint(Graphics g) {
    int a[] = arr;
    int y = 0;
    int deltaY = 0, deltaX = 0, evenY = 0;

    Dimension currentSize = getSize();
    int currentHeight = currentSize.height;
    int currentWidth = currentSize.width;

    // Check to see if the applet has been resized since it
    // started running.  If so, need the deltas to make sure
    // the applet is centered in its containing panel.
    // The evenX and evenY are because the high and low
    // watermarks are calculated from the top, but the rest
    // of the lines are calculated from the bottom, which
    // can lead to a discrepancy if the window is not an
    // even size.
    if (!currentSize.equals(initialSize)) {
        evenY = (currentHeight - initialSize.height) % 2;
        deltaY = (currentHeight - initialSize.height) / 2;
        deltaX = (currentWidth - initialSize.width) / 2;

        if (deltaY < 0) {
            deltaY = 0;
            evenY = 0;
        }
        if (deltaX < 0) {
            deltaX = 0;
        }
    }

    // Erase old lines
    g.setColor(getBackground());
    y = currentHeight - deltaY - 1;
    for (int i = a.length; --i >= 0; y -= 2) {
        g.drawLine(deltaX + arr[i], y, currentWidth, y);
    }

    // Draw new lines
    g.setColor(Color.black);
    y = currentHeight - deltaY - 1;
    for (int i = a.length; --i >= 0; y -= 2) {
        g.drawLine(deltaX, y, deltaX + arr[i], y);
    }

    if (h1 >= 0) {
        g.setColor(Color.red);
        y = deltaY + evenY + h1 * 2 + 1;
        g.drawLine(deltaX, y, deltaX + initialSize.width, y);
    }
    if (h2 >= 0) {
        g.setColor(Color.blue);
        y = deltaY + evenY + h2 * 2 + 1;
        g.drawLine(deltaX, y, deltaX + initialSize.width, y);
    }
}
 
Example 20
Project: openjdk-jdk10   File: SortItem.java   View Source Code Vote up 4 votes
/**
 * Paint the array of numbers as a list
 * of horizontal lines of varying lengths.
 */
@Override
public void paint(Graphics g) {
    int a[] = arr;
    int y = 0;
    int deltaY = 0, deltaX = 0, evenY = 0;

    Dimension currentSize = getSize();
    int currentHeight = currentSize.height;
    int currentWidth = currentSize.width;

    // Check to see if the applet has been resized since it
    // started running.  If so, need the deltas to make sure
    // the applet is centered in its containing panel.
    // The evenX and evenY are because the high and low
    // watermarks are calculated from the top, but the rest
    // of the lines are calculated from the bottom, which
    // can lead to a discrepancy if the window is not an
    // even size.
    if (!currentSize.equals(initialSize)) {
        evenY = (currentHeight - initialSize.height) % 2;
        deltaY = (currentHeight - initialSize.height) / 2;
        deltaX = (currentWidth - initialSize.width) / 2;

        if (deltaY < 0) {
            deltaY = 0;
            evenY = 0;
        }
        if (deltaX < 0) {
            deltaX = 0;
        }
    }

    // Erase old lines
    g.setColor(getBackground());
    y = currentHeight - deltaY - 1;
    for (int i = a.length; --i >= 0; y -= 2) {
        g.drawLine(deltaX + arr[i], y, currentWidth, y);
    }

    // Draw new lines
    g.setColor(Color.black);
    y = currentHeight - deltaY - 1;
    for (int i = a.length; --i >= 0; y -= 2) {
        g.drawLine(deltaX, y, deltaX + arr[i], y);
    }

    if (h1 >= 0) {
        g.setColor(Color.red);
        y = deltaY + evenY + h1 * 2 + 1;
        g.drawLine(deltaX, y, deltaX + initialSize.width, y);
    }
    if (h2 >= 0) {
        g.setColor(Color.blue);
        y = deltaY + evenY + h2 * 2 + 1;
        g.drawLine(deltaX, y, deltaX + initialSize.width, y);
    }
}