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

The following examples show how to use java.awt.Dimension#equals() . 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
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 2
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 3
Source Project: ghidra   File: FGVertexListingPanel.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Dimension getPreferredSize() {
	Dimension preferredSize = super.getPreferredSize();
	if (preferredSize.equals(lastParentPreferredSize) && preferredSizeCache != null) {
		return preferredSizeCache;
	}

	lastParentPreferredSize = preferredSize;
	LayoutModel layoutModel = getLayoutModel();
	List<Layout> layouts = getAllLayouts(layoutModel);
	int largestWidth = 0;
	for (Layout layout : layouts) {
		int width = layout.getCompressableWidth();
		if (width > largestWidth) {
			largestWidth = width;
		}
	}

	preferredSize.width = largestWidth;
	preferredSizeCache = preferredSize;
	return preferredSize;
}
 
Example 4
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 5
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 6
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
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 8
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 9
Source Project: netbeans   File: CompletionLayoutPopup.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 10
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 11
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 12
Source Project: netbeans   File: NbPresenter.java    License: Apache License 2.0 5 votes vote down vote up
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 13
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 14
Source Project: netbeans   File: CompletionLayoutPopup.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 15
/**
 * 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 16
/**
 * 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 17
/**
 * 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 18
Source Project: jdk8u60   File: SortItem.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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
/**
 * 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
Source Project: NBANDROID-V2   File: SdksCustomizer.java    License: Apache License 2.0 4 votes vote down vote up
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);
    }
}