public void layoutContainer(Container target) { int barwidth = 0; int i; for (i = 1; i < target.getComponentCount(); i++) { Component m = target.getComponent(i); if (m.isVisible()) { Dimension d = m.getPreferredSize(); if (d.width > barwidth) barwidth = d.width; } } Insets insets = target.insets(); int targetw = target.size().width - insets.left - insets.right; int cw = targetw - barwidth; int targeth = target.size().height - (insets.top + insets.bottom); target.getComponent(0).move(insets.left, insets.top); target.getComponent(0).resize(cw, targeth); cw += insets.left; int h = insets.top; for (i = 1; i < target.getComponentCount(); i++) { Component m = target.getComponent(i); if (m.isVisible()) { Dimension d = m.getPreferredSize(); if (m instanceof DecentScrollbar || m instanceof TextComponent) d.width = barwidth; if (m instanceof Choice && d.width > barwidth) d.width = barwidth; if (m instanceof Label) { h += d.height / 5; d.width = barwidth; } m.move(cw, h); m.resize(d.width, d.height); h += d.height; } } }
public Dimension preferredLayoutSize(Container parent) { JToolBar tb = (JToolBar) parent; Insets insets = tb.getInsets(); Dimension dim = new Dimension(); SeaGlassContext context = getContext(tb); if (tb.getOrientation() == JToolBar.HORIZONTAL) { dim.width = tb.isFloatable() ? SeaGlassIcon.getIconWidth(handleIcon, context) : 0; Dimension compDim; for (int i = 0; i < tb.getComponentCount(); i++) { Component component = tb.getComponent(i); if (component.isVisible()) { compDim = component.getPreferredSize(); dim.width += compDim.width; dim.height = Math.max(dim.height, compDim.height); } } } else { dim.height = tb.isFloatable() ? SeaGlassIcon.getIconHeight(handleIcon, context) : 0; Dimension compDim; for (int i = 0; i < tb.getComponentCount(); i++) { Component component = tb.getComponent(i); if (component.isVisible()) { compDim = component.getPreferredSize(); dim.width = Math.max(dim.width, compDim.width); dim.height += compDim.height; } } } dim.width += insets.left + insets.right; dim.height += insets.top + insets.bottom; context.dispose(); return dim; }
/** * 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 layoutContainer(Container parent) { Insets insets = parent.getInsets(); int maxWidth = parent.getSize().width - (insets.left + insets.right); int maxHeight = parent.getSize().height - (insets.top + insets.bottom); int nComps = parent.getComponentCount(); if (this.sizeUnknown) { setSizes(parent); } Component c; if (nComps < 2) { c = parent.getComponent(0); if (c.isVisible()) { Dimension d = c.getPreferredSize(); c.setBounds(0, 0, d.width, d.height); return; } return; } double radialCurrent = Math.toRadians(SpiderWebPlot.DEFAULT_START_ANGLE); double radialIncrement = 6.283185307179586d / ((double) nComps); int midX = maxWidth / 2; int midY = maxHeight / 2; int a = midX - this.maxCompWidth; int b = midY - this.maxCompHeight; for (int i = 0; i < nComps; i++) { c = parent.getComponent(i); if (c.isVisible()) { d = c.getPreferredSize(); double d2 = (double) midX; double d3 = (double) a; int x = (int) (((r0 - (r0 * Math.cos(radialCurrent))) - (d.getWidth() / DateAxis.DEFAULT_AUTO_RANGE_MINIMUM_SIZE_IN_MILLISECONDS)) + ((double) insets.left)); d2 = (double) midY; d3 = (double) b; c.setBounds( x, (int) (((r0 - (r0 * Math.sin(radialCurrent))) - (d.getHeight() / DateAxis.DEFAULT_AUTO_RANGE_MINIMUM_SIZE_IN_MILLISECONDS)) + ((double) insets.top)), d.width, d.height); } radialCurrent += radialIncrement; } }
public void layoutContainer(Container target) { Insets insets = target.getInsets(); int ncomponents = target.getComponentCount(); int top = 0; int left = insets.left; Dimension tps = target.getPreferredSize(); Dimension targetSize = target.getSize(); Component comp; Dimension ps; if (horizontalOrientation == Orientation.CENTER) left = left + (targetSize.width / 2) - (tps.width / 2); if (horizontalOrientation == Orientation.RIGHT) left = left + targetSize.width - tps.width; for (int i = 0; i < ncomponents; i++) { comp = target.getComponent(i); if (comp.isVisible()) { ps = comp.getPreferredSize(); if (verticalOrientation == Orientation.CENTER) top = (targetSize.height / 2) - (ps.height / 2); else if (verticalOrientation == Orientation.TOP) top = insets.top; else if (verticalOrientation == Orientation.BOTTOM) top = targetSize.height - ps.height - insets.bottom; comp.setBounds(left, top, ps.width, ps.height); left += ps.width + gap; } } }
public void addLayoutComponent(Component comp, Object constraints) { comp.setVisible(autoShowFirstComponent && comp.getParent().getComponentCount() == 1); if (comp.isVisible()) { component = comp; } }
private void setSizes(Container parent) { int nComps = parent.getComponentCount(); Dimension d = null; // Reset preferred/minimum width and height. preferredWidth = 0; preferredHeight = 0; minWidth = 0; minHeight = 0; for (int i = 0; i < nComps; i++) { Component c = parent.getComponent(i); if (c.isVisible()) { d = c.getPreferredSize(); if (i > 0) { preferredWidth += d.width / 2; preferredHeight += vgap; } else { preferredWidth = d.width; } preferredHeight += d.height; minWidth = Math.max(c.getMinimumSize().width, minWidth); minHeight = preferredHeight; } } }
public Dimension minimumLayoutSize(Container target) { Dimension dim = new Dimension(0, 0); int nmembers = target.getComponentCount(); for (int i = 0; i < nmembers; i++) { Component m = target.getComponent(i); if (m.isVisible()) { Dimension d = m.getMinimumSize(); if (fVerticalLayout) { dim.width = Math.max(dim.width, d.width); if (i > 0) { dim.height += fGap; } dim.height += d.height; } else { dim.height = Math.max(dim.height, d.height); if (i > 0) { dim.width += fGap; } dim.width += d.width; } } } Insets insets = target.getInsets(); dim.width += insets.left + insets.right; dim.width += 2 * fBorder.x; dim.height += insets.top + insets.bottom; dim.height += 2 * fBorder.y; return dim; }
/*--------------------------------------------------------------------------*/ public Dimension preferredLayoutSize(Container target) { synchronized (target.getTreeLock()) { Dimension dim = new Dimension(0, 0); int nmembers = target.getComponentCount(); boolean firstVisibleComponent = true; for (int i = 0; i < nmembers; i++) { Component m = target.getComponent(i); if (m.isVisible()) { Dimension d = m.getPreferredSize(); dim.height = Math.max(dim.height, d.height); if (firstVisibleComponent) { firstVisibleComponent = false; } else { dim.width += hgap; } dim.width += d.width; } } Insets insets = target.getInsets(); dim.width += insets.left + insets.right + hgap * 2; dim.height += insets.top + insets.bottom + vgap * 2; return (dim); } }
private boolean accept(Component aComponent) { if (!(aComponent.isVisible() && aComponent.isDisplayable() && aComponent.isFocusable() && aComponent.isEnabled())) { return false; } // Verify that the Component is recursively enabled. Disabling a // heavyweight Container disables its children, whereas disabling // a lightweight Container does not. if (!(aComponent instanceof Window)) { for (Container enableTest = aComponent.getParent(); enableTest != null; enableTest = enableTest.getParent()) { if (!(enableTest.isEnabled() || enableTest.isLightweight())) { return false; } if (enableTest instanceof Window) { break; } } } return true; }
public Dimension preferredLayoutSize(Container target) { Insets insets = target.getInsets(); Dimension compMax = new Dimension(0, 0); int maxheight = target.getBounds().height - (insets.top + insets.bottom + vgap * 2); int nmembers = target.getComponentCount(); int visiblecount = 0; for (int i = 0; i < nmembers; i++) { Component m = target.getComponent(i); if (m.isVisible()) { ++visiblecount; Dimension d = m.getPreferredSize(); compMax.width = Math.max(compMax.width, d.width); compMax.height = Math.max(compMax.height, d.height); } } if (visiblecount > 0) { int nrows = Math.max(1, (maxheight + compMax.height / 4) / compMax.height); int ncols = (visiblecount + nrows - 1) / nrows; compMax.height = compMax.height * nrows + vgap * (nrows - 1); compMax.width = compMax.width * ncols + hgap * (ncols - 1); } compMax.height += insets.top + insets.bottom + vgap * 2; compMax.width += insets.left + insets.right + hgap * 2; return compMax; }
/** * Get the component that corresponds to the given constraint location * * @param key The desired absolute position, either NORTH, SOUTH, EAST, or WEST. * @param ltr Is the component line direction left-to-right? */ private Component getChild(String key, boolean ltr) { Component result = null; if (key == NORTH) { result = (firstLine != null) ? firstLine : north; } else if (key == SOUTH) { result = (lastLine != null) ? lastLine : south; } else if (key == WEST) { result = ltr ? firstItem : lastItem; if (result == null) { result = west; } } else if (key == EAST) { result = ltr ? lastItem : firstItem; if (result == null) { result = east; } } else if (key == CENTER) { result = center; } if (result != null && !result.isVisible()) { result = null; } return result; }
/** * Calculates the preferred size dimensions for the specified panel given the components in the * specified parent container. * * @param target The component to be laid out. * @return A size deemed suitable for laying out the container. * @see #minimumLayoutSize */ public Dimension preferredLayoutSize(Container target) { int count; Component component; Dimension dimension; Insets insets; Dimension ret; synchronized (target.getTreeLock()) { // get the the total height and maximum width component ret = new Dimension(0, 0); count = target.getComponentCount(); for (int i = 0; i < count; i++) { component = target.getComponent(i); if (component.isVisible()) { dimension = component.getPreferredSize(); ret.width = Math.max(ret.width, dimension.width); ret.height += dimension.height; } } insets = target.getInsets(); ret.width += insets.left + insets.right; ret.height += insets.top + insets.bottom; } return (ret); }
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; }
private Component cycle(Component currentComponent, int delta) { int index = -1; loop: for (int i = 0; i < m_Components.length; i++) { Component component = m_Components[i]; for (Component c = currentComponent; c != null; c = c.getParent()) { if (component == c) { index = i; break loop; } } } // try to find enabled component in "delta" direction int initialIndex = index; while (true) { int newIndex = indexCycle(index, delta); if (newIndex == initialIndex) { break; } index = newIndex; // Component component = m_Components[newIndex]; if (component.isEnabled() && component.isVisible() && component.isFocusable()) { return component; } } // not found return currentComponent; }
@Override public void setComponentValues(BaseModelObject baseModelObject) { for (PropertyObjectDefinition property : definitions) { if (propertyFields.containsKey(property) == true) { PropertyField propertyField = propertyFields.get(property); StyledLabel propertyLabel = propertyLabels.get(property); propertyField.setComponentValue(baseModelObject); propertyLabel.setVisible(propertyField.isVisible()); } } boolean visible = false; for (int i = 0; i < contentPanel.getComponentCount(); i++) { Component component = contentPanel.getComponent(i); if (component.isVisible() == true) { visible = true; break; } } setVisible(visible); revalidate(); Dimension preferredSize = contentPanel.getPreferredSize(); contentPanel.setSize(preferredSize); contentPanel.setMinimumSize(preferredSize); }
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 void setSizes(Container parent) { int nComps = parent.getComponentCount(); this.preferredWidth = 0; this.preferredHeight = 0; this.minWidth = 0; this.minHeight = 0; for (int i = 0; i < nComps; i++) { Component c = parent.getComponent(i); if (c.isVisible()) { Dimension d = c.getPreferredSize(); if (this.maxCompWidth < d.width) { this.maxCompWidth = d.width; } if (this.maxCompHeight < d.height) { this.maxCompHeight = d.height; } this.preferredWidth += d.width; this.preferredHeight += d.height; } } this.preferredWidth /= 2; this.preferredHeight /= 2; this.minWidth = this.preferredWidth; this.minHeight = this.preferredHeight; }
public void setSizes(Container parent) { if (sizesSet) return; int n = parent.getComponentCount(); preferredWidth = 0; preferredHeight = 0; minWidth = 0; minHeight = 0; maxComponentWidth = 0; maxComponentHeight = 0; // compute the maximum component widths and heights // and set the preferred size to the sum of the component sizes. for (int i = 0; i < n; i++) { Component c = parent.getComponent(i); if (c.isVisible()) { Dimension d = c.getPreferredSize(); maxComponentWidth = Math.max(maxComponentWidth, d.width); maxComponentHeight = Math.max(maxComponentHeight, d.height); preferredWidth += d.width; preferredHeight += d.height; } } minWidth = preferredWidth / 2; minHeight = preferredHeight / 2; sizesSet = true; }
@Override public boolean testComponent(Component comp) { if (RootPaneContainer.class.isInstance(comp)) { Component glassPane = ((RootPaneContainer) comp).getGlassPane(); return evaluate(glassPane.getName(), name) && glassPane.isVisible(); } return false; }
private void hideDropDownButton() { for (Component component : this.getComponents()) { if (component instanceof AbstractButton && component.isVisible()) { component.setVisible(false); this.revalidate(); } } }
@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); }
@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); }
private boolean isGlue(Component c) { if (c.isVisible() && c instanceof Box.Filler) { Box.Filler f = (Box.Filler) c; Dimension min = f.getMinimumSize(); Dimension pref = f.getPreferredSize(); return min.width == 0 && min.height == 0 && pref.width == 0 && pref.height == 0; } return false; }
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; }
public void unpinTabs() { for (int i = 0; i < this.getTabCount(); i++) { Component tabCom = this.getTabComponentAt(i); if (tabCom != null && tabCom instanceof TabbedPanelTab && tabCom.isVisible()) { TabbedPanelTab jp = (TabbedPanelTab) tabCom; jp.setPinned(false); this.saveTabState(jp.getAbstractPanel()); } } }
/** * Gets current active card in cardsPanel. * * @return */ protected JPanel getCurrentCard() { JPanel card = null; for (Component comp : parent.getCardsPanel().getComponents()) { if (comp.isVisible() == true) { card = (JPanel) comp; } } return card; }
/** * Temporarily lock/unlock the specified tab, eg if its active and mustnt be closed. Locked * (AbstractPanel) tabs will not have the pin/close tab buttons displayed * * @param panel * @param hideable */ public void setTabLocked(AbstractPanel panel, boolean lock) { for (int i = 0; i < this.getTabCount(); i++) { Component tabCom = this.getTabComponentAt(i); if (tabCom != null && tabCom instanceof TabbedPanelTab && tabCom.isVisible()) { TabbedPanelTab jp = (TabbedPanelTab) tabCom; if (panel.equals(jp.getAbstractPanel())) { jp.setLocked(!lock); } } } }
public void layoutContainer(Container target) { Insets insets = target.getInsets(); Dimension size = target.getSize(); Dimension compMax = new Dimension(0, 0); int maxheight = size.height - (insets.top + insets.bottom + vgap * 2); int nmembers = target.getComponentCount(); int visiblecount = 0; for (int i = 0; i < nmembers; i++) { Component m = target.getComponent(i); if (m.isVisible()) { ++visiblecount; Dimension d = m.getPreferredSize(); compMax.width = Math.max(compMax.width, d.width); compMax.height = Math.max(compMax.height, d.height); } } if (visiblecount > 0) { int nrows = Math.max(1, (maxheight + compMax.height / 4) / compMax.height); int ncols = (visiblecount + nrows - 1) / nrows; int row = 0, col = 0, currComp = 0; for (int i = 0; i < nmembers; i++) { Component m = target.getComponent(i); if (m.isVisible()) { Dimension d = m.getPreferredSize(); int x = insets.left + hgap + col * (compMax.width + hgap); int y = insets.top + vgap + row * (compMax.height + vgap); m.setBounds(x, y, d.width, d.height); // move index to next component ++currComp; if (++row >= nrows) { row = 0; ++col; } } } } repaint(); }
public void layoutContainer(Container parent) { synchronized (parent.getTreeLock()) { Insets margin = parent.getInsets(); int x = margin.left; int y = margin.top; int w = parent.getWidth() - (margin.left + margin.right); int h = parent.getHeight() - (margin.top + margin.bottom); Component header = findHeader(parent.getComponents()); if (header != null && header.isVisible()) { Dimension dim = header.getPreferredSize(); header.setBounds(x, y, w, dim.height); y += dim.height; h -= dim.height; } Component body = findBody(parent.getComponents()); if (body != null && body.isVisible()) { body.setBounds(x, y, w, h); } } }