/** * Calculates the maximum size dimensions for the specified panal given the components in the * specified parent container. */ public Dimension maximumLayoutSize(Container target) { synchronized (target.getTreeLock()) { Dimension dim = new Dimension(0, 0); int size = actions.size(); if ((grip != null) && grip.isVisible()) { Dimension d = grip.getPreferredSize(); dim.width += d.width; dim.width += hgap; } Component last = null; for (int i = 0; i < size; i++) { Component comp = (Component) actions.elementAt(i); if (comp.isVisible()) { Dimension d = comp.getPreferredSize(); dim.width += d.width; dim.height = Math.max(dim.height, d.height); dim.width += hgap; last = comp; } } if (last != null) { Dimension prefSize = last.getPreferredSize(); Dimension maxSize = last.getMaximumSize(); if (prefSize != maxSize) { dim.width = dim.width - prefSize.width + maxSize.width; dim.height = Math.max(dim.height, maxSize.height); } } Insets insets = target.getInsets(); dim.width += insets.left + insets.right; dim.height += insets.top + insets.bottom; return dim; } }
public void enableControlPanel() { boolean bVisible = false; int nmembers = buttonPane.getComponentCount(); for (int k = 0; k < nmembers; k++) { Component comp = buttonPane.getComponent(k); if (comp != null) { if (comp.isVisible() || comp.isEnabled()) { bVisible = true; break; } } } if (bVisible && !buttonPane.isVisible()) { Dimension dim = getSize(); Dimension dim1 = buttonPane.getPreferredSize(); int w = dim.width; int h = dim.height + dim1.height; if (dim1.width > w) w = dim1.width; if (w < 300) w = 300; if (h < 200) h = 200; setSize(w, h); } buttonPane.setVisible(bVisible); }
private boolean is(boolean first) { Container parent = getParent(); if (parent == null) return false; int max = first ? Integer.MAX_VALUE : 0; ToolWindowAnchor anchor = getAnchor(); Component c = null; int count = parent.getComponentCount(); for (int i = 0; i < count; i++) { Component component = parent.getComponent(i); if (!component.isVisible()) continue; Rectangle r = component.getBounds(); if (anchor == ToolWindowAnchor.LEFT || anchor == ToolWindowAnchor.RIGHT) { if (first && (max > r.y) || (!first && max < r.y)) { max = r.y; c = component; } } else { if (first && (max > r.x) || (!first && max < r.x)) { max = r.x; c = component; } } } return c == this; }
@Override public Dimension minimumLayoutSize(Container parent) { Component toolbar = parent.getComponent(0); Dimension toolbarSize = toolbar.isVisible() ? toolbar.getMinimumSize() : new Dimension(); Dimension contentSize = parent.getComponent(1).getMinimumSize(); return new Dimension( Math.max(toolbarSize.width, contentSize.width), toolbarSize.height + contentSize.height); }
private void hideDropDownButton() { for (Component component : this.getComponents()) { if (component instanceof AbstractButton && component.isVisible()) { component.setVisible(false); this.revalidate(); } } }
@Override public void layoutContainer(Container parent) { int width = parent.getWidth(); int height = parent.getHeight(); Component toolbar = parent.getComponent(0); Dimension toolbarSize = toolbar.isVisible() ? toolbar.getPreferredSize() : new Dimension(); toolbar.setBounds(0, 0, width, toolbarSize.height); parent.getComponent(1).setBounds(0, toolbarSize.height, width, height - toolbarSize.height); }
public static final Component getVisibleChildAt(Container container, Point point) { for (int i = 0; i < container.getComponentCount(); i++) { Component component = container.getComponent(i); if (component.isVisible() && component.contains(point.x - component.getX(), point.y - component.getY())) return component; } return null; }
/** Lays out the container in the specified panel. */ public void layoutContainer(Container target) { synchronized (target.getTreeLock()) { Insets insets = target.getInsets(); Dimension dim = target.getSize(); int fullHeight = dim.height; int bottom = dim.height - insets.bottom - 1; int top = 0 + insets.top; int left = insets.left; int maxPosition = dim.width - (insets.left + insets.right) - hgap; int right = dim.width - insets.right; maxPosition = right; int height = bottom - top; int size = actions.size(); int w, h; if ((grip != null) && grip.isVisible()) { Dimension d = grip.getPreferredSize(); grip.setBounds(left, top + vgap, d.width, bottom - top - 2 * vgap); left += d.width; left += hgap; } for (int i = 0; i < size; i++) { left += hgap; Component comp = (Component) actions.elementAt(i); Dimension d; Dimension minSize = comp.getMinimumSize(); if (i == size - 1) d = comp.getMaximumSize(); else d = comp.getPreferredSize(); w = d.width; h = Math.min(height, d.height); if ((left < maxPosition) && (left + w > maxPosition)) { if (maxPosition - left >= minSize.width) w = maxPosition - left; } comp.setBounds(left, (fullHeight - d.height) / 2, w, h); // if (i == size - 1) // d = comp.getMaximumSize(); // else // d = comp.getPreferredSize(); // if ((left + d.width) > right) // w = right - left; // else // w = d.width; // h = Math.min (height, d.height); // comp.setBounds (left, (fullHeight - d.height)/2, w, h); left += d.width; } } }
public void layoutContainer(Container parent) { Insets insets = parent.getInsets(); Component c; c = parent.getComponent(0); if (c.isVisible()) { c.setBounds(insets.left + 152, insets.top + 64, 176, 24); } c = parent.getComponent(1); if (c.isVisible()) { c.setBounds(insets.left + 152, insets.top + 96, 176, 24); } c = parent.getComponent(2); if (c.isVisible()) { c.setBounds(insets.left + 72, insets.top + 8, 184, 32); } c = parent.getComponent(3); if (c.isVisible()) { c.setBounds(insets.left + 16, insets.top + 64, 128, 24); } c = parent.getComponent(4); if (c.isVisible()) { c.setBounds(insets.left + 16, insets.top + 96, 128, 24); } c = parent.getComponent(5); if (c.isVisible()) { c.setBounds(insets.left + 56, insets.top + 176, 96, 32); } c = parent.getComponent(6); if (c.isVisible()) { c.setBounds(insets.left + 176, insets.top + 176, 96, 32); } c = parent.getComponent(7); if (c.isVisible()) { c.setBounds(insets.left + 152, insets.top + 128, 176, 24); } c = parent.getComponent(8); if (c.isVisible()) { c.setBounds(insets.left + 16, insets.top + 128, 128, 24); } }
/** * Iterates all child components and calculates the space enough to keep all of them assuming that * the width is fixed. */ private Dimension calculateSize(int maxRowWidth) { FlowLayout layout = (FlowLayout) getLayout(); int height = 0; int currentRowWidth = 0; int currentRowHeight = 0; for (int i = 0, count = getComponentCount(); i < count; ++i) { Component comp = getComponent(i); Dimension bounds = comp.getPreferredSize(); if (!comp.isVisible()) { continue; } currentRowHeight = Math.max(currentRowHeight, bounds.height); if (currentRowWidth + layout.getHgap() + bounds.width <= maxRowWidth) { if (bounds.width != 0) { currentRowWidth += bounds.width + layout.getHgap(); } continue; } height += currentRowHeight + layout.getVgap(); currentRowWidth = bounds.width; currentRowHeight = bounds.height; } return new Dimension(maxRowWidth, height + currentRowHeight + 2 * layout.getVgap()); }
public static boolean isFocusable(Component component) { return component.isFocusable() && component.isDisplayable() && component.isVisible() && component.isEnabled(); }
public static boolean isOnlyVisibleComponent(Component component) { return component != null && component.isVisible() && getVisibleChildrenCount(component.getParent()) == 1; }