Java Code Examples for java.awt.Container#getTreeLock()
The following examples show how to use
java.awt.Container#getTreeLock() .
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
Source File: ModifiedFlowLayout.java From openAGV with Apache License 2.0 | 6 votes |
private Dimension computeMinSize(Container target) { synchronized (target.getTreeLock()) { int minx = Integer.MAX_VALUE; int miny = Integer.MIN_VALUE; boolean foundOne = false; int n = target.getComponentCount(); for (int i = 0; i < n; i++) { Component c = target.getComponent(i); if (c.isVisible()) { foundOne = true; Dimension d = c.getPreferredSize(); minx = Math.min(minx, d.width); miny = Math.min(miny, d.height); } } if (foundOne) { return new Dimension(minx, miny); } return new Dimension(0, 0); } }
Example 2
Source File: VerticalLayout.java From ccu-historian with GNU General Public License v3.0 | 6 votes |
/** * Calculates the minimum size dimensions for the specified * panel given the components in the specified parent container. * * @param parent the component to be laid out * @return the minimul layoutsize * @see #preferredLayoutSize */ public Dimension minimumLayoutSize(final Container parent) { synchronized (parent.getTreeLock()) { final Insets ins = parent.getInsets(); final Component[] comps = parent.getComponents(); int height = ins.top + ins.bottom; int width = ins.left + ins.right; for (int i = 0; i < comps.length; i++) { if (comps[i].isVisible() == false) { continue; } final Dimension min = comps[i].getMinimumSize(); height += min.height; if (min.width > width) { width = min.width; } } return new Dimension(width + ins.left + ins.right, height + ins.top + ins.bottom); } }
Example 3
Source File: OverlayLayout.java From ccu-historian with GNU General Public License v3.0 | 6 votes |
/** * Calculates the minimum size dimensions for the specified * container, given the components it contains. * * @param parent the component to be laid out * @return the minimum size computed for the parent. * @see #preferredLayoutSize */ public Dimension minimumLayoutSize(final Container parent) { synchronized (parent.getTreeLock()) { final Insets ins = parent.getInsets(); final Component[] comps = parent.getComponents(); int height = 0; int width = 0; for (int i = 0; i < comps.length; i++) { if ((comps[i].isVisible() == false) && this.ignoreInvisible) { continue; } final Dimension pref = comps[i].getMinimumSize(); if (pref.height > height) { height = pref.height; } if (pref.width > width) { width = pref.width; } } return new Dimension(width + ins.left + ins.right, height + ins.top + ins.bottom); } }
Example 4
Source File: CenterLayout.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
/** * Returns the preferred size. * * @param parent * the parent. * @return the preferred size. */ public Dimension preferredLayoutSize( final Container parent ) { synchronized ( parent.getTreeLock() ) { final Insets insets = parent.getInsets(); if ( parent.getComponentCount() > 0 ) { final Component component = parent.getComponent( 0 ); final Dimension d = component.getPreferredSize(); return new Dimension( (int) d.getWidth() + insets.left + insets.right, (int) d.getHeight() + insets.top + insets.bottom ); } else { return new Dimension( insets.left + insets.right, insets.top + insets.bottom ); } } }
Example 5
Source File: DynamicGridLayout.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
@Override public Dimension minimumLayoutSize(Container parent) { synchronized (parent.getTreeLock()) { return calculateSize(parent, Component::getMinimumSize); } }
Example 6
Source File: GroupLayout.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
/** * Invalidates the layout, indicating that if the layout manager * has cached information it should be discarded. * * @param parent the {@code Container} hosting this LayoutManager * @throws IllegalArgumentException if {@code parent} is not * the same {@code Container} that this was created with */ public void invalidateLayout(Container parent) { checkParent(parent); // invalidateLayout is called from Container.invalidate, which // does NOT grab the treelock. All other methods do. To make sure // there aren't any possible threading problems we grab the tree lock // here. synchronized(parent.getTreeLock()) { isValid = false; } }
Example 7
Source File: GridLayout2.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
@Override public Dimension preferredLayoutSize(Container parent) { //System.err.println("preferredLayoutSize"); synchronized (parent.getTreeLock()) { Insets insets = parent.getInsets(); int ncomponents = parent.getComponentCount(); int nrows = getRows(); int ncols = getColumns(); if (nrows > 0) { ncols = (ncomponents + nrows - 1) / nrows; } else { nrows = (ncomponents + ncols - 1) / ncols; } int[] w = new int[ncols]; int[] h = new int[nrows]; for (int i = 0; i < ncomponents; i++) { int r = i / ncols; int c = i % ncols; Component comp = parent.getComponent(i); Dimension d = comp.getPreferredSize(); if (w[c] < d.width) { w[c] = d.width; } if (h[r] < d.height) { h[r] = d.height; } } int nw = 0; for (int j = 0; j < ncols; j++) { nw += w[j]; } int nh = 0; for (int i = 0; i < nrows; i++) { nh += h[i]; } return new Dimension(insets.left + insets.right + nw + (ncols - 1) * getHgap(), insets.top + insets.bottom + nh + (nrows - 1) * getVgap()); } }
Example 8
Source File: FormLayout.java From LGoodDatePicker with MIT License | 5 votes |
/** * Computes and returns the horizontal and vertical grid origins. Performs the same layout * process as {@code #layoutContainer} but does not layout the components.<p> * * This method has been added only to make it easier to debug the form layout. <strong>You must * not call this method directly; It may be removed in a future release or the visibility may be * reduced.</strong> * * @param parent the {@code Container} to inspect * @return an object that comprises the grid x and y origins */ public LayoutInfo getLayoutInfo(Container parent) { synchronized (parent.getTreeLock()) { initializeColAndRowComponentLists(); Dimension size = parent.getSize(); Insets insets = parent.getInsets(); int totalWidth = size.width - insets.left - insets.right; int totalHeight = size.height - insets.top - insets.bottom; int[] x = computeGridOrigins(parent, totalWidth, insets.left, colSpecs, colComponents, colGroupIndices, minimumWidthMeasure, preferredWidthMeasure ); int[] y = computeGridOrigins(parent, totalHeight, insets.top, rowSpecs, rowComponents, rowGroupIndices, minimumHeightMeasure, preferredHeightMeasure ); return new LayoutInfo(x, y); } }
Example 9
Source File: LCBLayout.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Returns the preferred size using this layout manager. * * @param parent the parent. * * @return the preferred size using this layout manager. */ public Dimension preferredLayoutSize(Container parent) { synchronized (parent.getTreeLock()) { Insets insets = parent.getInsets(); int ncomponents = parent.getComponentCount(); int nrows = ncomponents / COLUMNS; for (int c = 0; c < COLUMNS; c++) { for (int r = 0; r < nrows; r++) { Component component = parent.getComponent(r * COLUMNS + c); Dimension d = component.getPreferredSize(); if (this.colWidth[c] < d.width) { this.colWidth[c] = d.width; } if (this.rowHeight[r] < d.height) { this.rowHeight[r] = d.height; } } } int totalHeight = this.vGap * (nrows - 1); for (int r = 0; r < nrows; r++) { totalHeight = totalHeight + this.rowHeight[r]; } int totalWidth = this.colWidth[0] + this.labelGap + this.colWidth[1] + this.buttonGap + this.colWidth[2]; return new Dimension(insets.left + insets.right + totalWidth + this.labelGap + this.buttonGap, insets.top + insets.bottom + totalHeight + this.vGap); } }
Example 10
Source File: SmartFlowLayout.java From workcraft with MIT License | 5 votes |
@Override public Dimension preferredLayoutSize(Container target) { synchronized (target.getTreeLock()) { applyLayout = false; return doLayout(target); } }
Example 11
Source File: VerticalFlowLayout.java From openchemlib-js with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Description of the Method * *@param target Description of Parameter *@return Description of the Returned Value */ public Dimension minimumLayoutSize(Container target) { synchronized (target.getTreeLock()) { Dimension dim = new Dimension(0, 0); int nmembers = target.getComponentCount(); boolean firstVisibleComponent = true; for (int ii = 0; ii < nmembers; ii++) { Component m = target.getComponent(ii); if (m.isVisible()) { Dimension d = m.getPreferredSize(); dim.width = Math.max(dim.width, d.width); if (firstVisibleComponent) { firstVisibleComponent = false; } else { dim.height += _vgap; } dim.height += d.height; } } Insets insets = target.getInsets(); dim.width += insets.left + insets.right + _hgap * 2; dim.height += insets.top + insets.bottom + _vgap * 2; return dim; } }
Example 12
Source File: FilterBar.java From pcgen with GNU Lesser General Public License v2.1 | 4 votes |
@Override public Dimension minimumLayoutSize(Container target) { synchronized (target.getTreeLock()) { Dimension dim = new Dimension(0, 0); int nmembers = target.getComponentCount(); Insets insets = target.getInsets(); int maxwidth = target.getWidth() - (insets.left + insets.right + getHgap() * 2); int width = 0; int height = 0; int component = 0; for (int i = 0; i < nmembers; i++, component++) { Component m = target.getComponent(i); if (m.isVisible()) { Dimension d = m.getMinimumSize(); if (component > 0) { if (width + d.width > maxwidth) { dim.width = Math.max(dim.width, width); dim.height += height + getVgap(); width = 0; height = 0; component = 0; } width += getHgap(); } height = Math.max(height, d.height); width += d.width; } } dim.width = Math.max(dim.width, width); dim.height += height; dim.width += insets.left + insets.right + getHgap() * 2; dim.height += insets.top + insets.bottom + getVgap() * 2; return dim; } }
Example 13
Source File: FilterBar.java From pcgen with GNU Lesser General Public License v2.1 | 4 votes |
@Override public Dimension minimumLayoutSize(Container target) { synchronized (target.getTreeLock()) { Dimension dim = new Dimension(0, 0); int nmembers = target.getComponentCount(); Insets insets = target.getInsets(); int maxwidth = target.getWidth() - (insets.left + insets.right + getHgap() * 2); int width = 0; int height = 0; int component = 0; for (int i = 0; i < nmembers; i++, component++) { Component m = target.getComponent(i); if (m.isVisible()) { Dimension d = m.getMinimumSize(); if (component > 0) { if (width + d.width > maxwidth) { dim.width = Math.max(dim.width, width); dim.height += height + getVgap(); width = 0; height = 0; component = 0; } width += getHgap(); } height = Math.max(height, d.height); width += d.width; } } dim.width = Math.max(dim.width, width); dim.height += height; dim.width += insets.left + insets.right + getHgap() * 2; dim.height += insets.top + insets.bottom + getVgap() * 2; return dim; } }
Example 14
Source File: WrapLayout.java From jpexs-decompiler with GNU General Public License v3.0 | 4 votes |
/** * Returns the minimum or preferred dimension needed to layout the target * container. * * @param target target to get layout size for * @param preferred should preferred size be calculated * @return the dimension to layout the target container */ private Dimension layoutSize(Container target, boolean preferred) { synchronized (target.getTreeLock()) { // Each row must fit with the width allocated to the containter. // When the container width = 0, the preferred width of the container // has not yet been calculated so lets ask for the maximum. int targetWidth = target.getSize().width; if (targetWidth == 0) { targetWidth = Integer.MAX_VALUE; } int hgap = getHgap(); int vgap = getVgap(); Insets insets = target.getInsets(); int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2); int maxWidth = targetWidth - horizontalInsetsAndGap; // Fit components into the allowed width Dimension dim = new Dimension(0, 0); int rowWidth = 0; int rowHeight = 0; int nmembers = target.getComponentCount(); for (int i = 0; i < nmembers; i++) { Component m = target.getComponent(i); if (m.isVisible()) { Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize(); // Can't add the component to current row. Start a new row. if (rowWidth + d.width > maxWidth) { addRow(dim, rowWidth, rowHeight); rowWidth = 0; rowHeight = 0; } // Add a horizontal gap for all components after the first if (rowWidth != 0) { rowWidth += hgap; } rowWidth += d.width; rowHeight = Math.max(rowHeight, d.height); } } addRow(dim, rowWidth, rowHeight); dim.width += horizontalInsetsAndGap; dim.height += insets.top + insets.bottom + vgap * 2; // When using a scroll pane or the DecoratedLookAndFeel we need to // make sure the preferred size is less than the size of the // target containter so shrinking the container size works // correctly. Removing the horizontal gap is an easy way to do this. Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target); if (scrollPane != null && target.isValid()) { dim.width -= (hgap + 1); } return dim; } }
Example 15
Source File: WrapLayout.java From COMP3204 with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Returns the minimum or preferred dimension needed to layout the target * container. * * @param target * target to get layout size for * @param preferred * should preferred size be calculated * @return the dimension to layout the target container */ private Dimension layoutSize(Container target, boolean preferred) { synchronized (target.getTreeLock()) { // Each row must fit with the width allocated to the containter. // When the container width = 0, the preferred width of the // container // has not yet been calculated so lets ask for the maximum. int targetWidth = target.getSize().width; if (targetWidth == 0) targetWidth = Integer.MAX_VALUE; final int hgap = getHgap(); final int vgap = getVgap(); final Insets insets = target.getInsets(); final int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2); final int maxWidth = targetWidth - horizontalInsetsAndGap; // Fit components into the allowed width final Dimension dim = new Dimension(0, 0); int rowWidth = 0; int rowHeight = 0; final int nmembers = target.getComponentCount(); for (int i = 0; i < nmembers; i++) { final Component m = target.getComponent(i); if (m.isVisible()) { final Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize(); // Can't add the component to current row. Start a new row. if (rowWidth + d.width > maxWidth) { addRow(dim, rowWidth, rowHeight); rowWidth = 0; rowHeight = 0; } // Add a horizontal gap for all components after the first if (rowWidth != 0) { rowWidth += hgap; } rowWidth += d.width; rowHeight = Math.max(rowHeight, d.height); } } addRow(dim, rowWidth, rowHeight); dim.width += horizontalInsetsAndGap; dim.height += insets.top + insets.bottom + vgap * 2; // When using a scroll pane or the DecoratedLookAndFeel we need to // make sure the preferred size is less than the size of the // target containter so shrinking the container size works // correctly. Removing the horizontal gap is an easy way to do this. final Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target); if (scrollPane != null && target.isValid()) { dim.width -= (hgap + 1); } return dim; } }
Example 16
Source File: LayerButtonLayout.java From Pixelitor with GNU General Public License v3.0 | 4 votes |
@Override public Dimension preferredLayoutSize(Container parent) { synchronized (parent.getTreeLock()) { return new Dimension(100, height); } }
Example 17
Source File: WrapLayout.java From triplea with GNU General Public License v3.0 | 4 votes |
/** * Returns the minimum or preferred dimension needed to layout the target container. * * @param target target to get layout size for * @param preferred should preferred size be calculated * @return the dimension to layout the target container */ private Dimension layoutSize(final Container target, final boolean preferred) { synchronized (target.getTreeLock()) { // Each row must fit with the width allocated to the containter. // When the container width = 0, the preferred width of the container // has not yet been calculated, so use the FlowLayout implementation which // lays everything out in a line. Also schedule a revalidation so that // the actual size is realized. final int targetWidth = target.getWidth(); if (targetWidth == 0) { scheduleRevalidate(target); return preferred ? super.preferredLayoutSize(target) : super.minimumLayoutSize(target); } final int hgap = getHgap(); final int vgap = getVgap(); final Insets insets = target.getInsets(); final int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2); final int maxWidth = targetWidth - horizontalInsetsAndGap; // Fit components into the allowed width final Dimension dim = new Dimension(0, 0); int rowWidth = 0; int rowHeight = 0; final int nmembers = target.getComponentCount(); for (int i = 0; i < nmembers; i++) { final Component m = target.getComponent(i); if (m.isVisible()) { final Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize(); // Can't add the component to current row. Start a new row. if (rowWidth + d.width > maxWidth) { addRow(dim, rowWidth, rowHeight); rowWidth = 0; rowHeight = 0; } // Add a horizontal gap for all components after the first if (rowWidth != 0) { rowWidth += hgap; } rowWidth += d.width; rowHeight = Math.max(rowHeight, d.height); } } addRow(dim, rowWidth, rowHeight); dim.width += horizontalInsetsAndGap; dim.height += insets.top + insets.bottom + vgap * 2; // When using a scroll pane or the DecoratedLookAndFeel we need to make sure the preferred // size is less than the size of the target containter so shrinking the container size works // correctly. Removing the horizontal gap is an easy way to do this. final Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target); if (scrollPane != null && target.isValid()) { dim.width -= (hgap + 1); } return dim; } }
Example 18
Source File: ColumnLayout.java From gcs with Mozilla Public License 2.0 | 4 votes |
@Override public Dimension maximumLayoutSize(Container parent) { Scale scale = Scale.get(parent); long height = 0; long width = (long) (mColumns - 1) * scale.scale(mHGap); synchronized (parent.getTreeLock()) { Insets insets = parent.getInsets(); int compCount = parent.getComponentCount(); int[] widths = new int[mColumns]; int rows = 1 + (compCount - 1) / mColumns; int i; width += insets.left + insets.right; for (int y = 0; y < rows; y++) { int rowHeight = 0; for (int x = 0; x < mColumns; x++) { i = y * mColumns + x; if (i < compCount) { Dimension size = parent.getComponent(i).getMaximumSize(); if (size.height > rowHeight) { rowHeight = size.height; } if (size.width > widths[x]) { widths[x] = size.width; } } } height += rowHeight; } height += insets.top + insets.bottom; if (rows > 0) { height += (long) (rows - 1) * scale.scale(mVGap); } for (i = 0; i < mColumns; i++) { width += widths[i]; } } if (width > LayoutSize.MAXIMUM_SIZE) { width = LayoutSize.MAXIMUM_SIZE; } if (height > LayoutSize.MAXIMUM_SIZE) { height = LayoutSize.MAXIMUM_SIZE; } return new Dimension((int) width, (int) height); }
Example 19
Source File: WrapLayout.java From Briss-2.0 with GNU General Public License v3.0 | 4 votes |
/** * Returns the minimum or preferred dimension needed to layout the target * container. * * @param target target to get layout size for * @param preferred should preferred size be calculated * @return the dimension to layout the target container */ private Dimension layoutSize(final Container target, final boolean preferred) { synchronized (target.getTreeLock()) { // Each row must fit with the width allocated to the containter. // When the container width = 0, the preferred width of the // container // has not yet been calculated so lets ask for the maximum. int targetWidth = target.getSize().width; if (targetWidth == 0) { targetWidth = Integer.MAX_VALUE; } int hgap = getHgap(); int vgap = getVgap(); Insets insets = target.getInsets(); int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2); int maxWidth = targetWidth - horizontalInsetsAndGap; // Fit components into the allowed width Dimension dim = new Dimension(0, 0); int rowWidth = 0; int rowHeight = 0; int nmembers = target.getComponentCount(); for (int i = 0; i < nmembers; i++) { Component m = target.getComponent(i); if (m.isVisible()) { Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize(); // Can't add the component to current row. Start a new row. if (rowWidth + d.width > maxWidth) { addRow(dim, rowWidth, rowHeight); rowWidth = 0; rowHeight = 0; } // Add a horizontal gap for all components after the first if (rowWidth != 0) { rowWidth += hgap; } rowWidth += d.width; rowHeight = Math.max(rowHeight, d.height); } } addRow(dim, rowWidth, rowHeight); dim.width += horizontalInsetsAndGap; dim.height += insets.top + insets.bottom + vgap * 2; // When using a scroll pane or the DecoratedLookAndFeel we need to // make sure the preferred size is less than the size of the // target containter so shrinking the container size works // correctly. Removing the horizontal gap is an easy way to do this. Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target); if (scrollPane != null) { dim.width -= (hgap + 1); } return dim; } }
Example 20
Source File: StackLayout.java From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License | votes |
public Dimension preferredLayoutSize(Container parent) { synchronized (parent.getTreeLock()) { int width = 0; int height = 0; for (Component comp: components) { Dimension size = comp.getPreferredSize(); width = Math.max(size.width, width); height = Math.max(size.height, height); } Insets insets = parent.getInsets(); width += insets.left + insets.right; height += insets.top + insets.bottom; return new Dimension(width, height); } }