Example usage for java.awt Container getTreeLock

List of usage examples for java.awt Container getTreeLock

Introduction

In this page you can find the example usage for java.awt Container getTreeLock.

Prototype

public final Object getTreeLock() 

Source Link

Document

Gets this component's locking object (the object that owns the thread synchronization monitor) for AWT component-tree and layout operations.

Usage

From source file:Main.java

public static Component[] getComponents(final Container container) {
    synchronized (container.getTreeLock()) {
        return container.getComponents();
    }/* ww w  .j  av  a2s. c om*/
}

From source file:Main.java

private static void doSetIgnoreRepaintInEDT(final Component component, final boolean ignoreRepaint) {
    component.setIgnoreRepaint(ignoreRepaint);

    if (component instanceof Container) {
        Container container = Container.class.cast(component);

        Component[] components = null;

        synchronized (container.getTreeLock()) {
            components = container.getComponents();
        }//from w  w  w  .  ja  v  a 2 s. c om

        for (int i = 0; i < components.length; i++) {
            doSetIgnoreRepaintInEDT(components[i], ignoreRepaint);
        }
    }
}

From source file:CenterLayout.java

/**
 * Returns the minimum size./*from  ww  w  .j av a2  s  .com*/
 * 
 * @param parent
 *          the parent.
 * 
 * @return the minimum size.
 */
public Dimension minimumLayoutSize(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.getMinimumSize();
            return new Dimension(d.width + insets.left + insets.right, d.height + insets.top + insets.bottom);
        } else {
            return new Dimension(insets.left + insets.right, insets.top + insets.bottom);
        }
    }

}

From source file:CenterLayout.java

/**
 * Returns the preferred size.//from w  w  w.j a va2  s. co  m
 * 
 * @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);
        }
    }

}

From source file:com.equitysoft.cellspark.ProportionalLayout.java

/**
 * Lays out the container.//from  www  .j  a  va2 s.  c o m
 */
public void layoutContainer(Container parent) {
    Insets insets = parent.getInsets();
    synchronized (parent.getTreeLock()) {
        int n = parent.getComponentCount();
        Dimension pd = parent.getSize();
        //do layout
        int cnt = 0;
        int totalwid = pd.width - insets.left - insets.right;
        int x = insets.left;
        int cumwid = 0;
        for (int i = 0; i < n; i++) {
            Component c = parent.getComponent(i);
            int wid = proportions[i] * totalwid / total;
            c.setBounds(x, insets.top, wid, pd.height - insets.bottom - insets.top);
            x += wid;
            cnt++;
            if (cnt == num)
                break;
        }
    }
}

From source file:CenterLayout.java

/**
 * Lays out the components.//from   w ww  . j av a  2  s  .c  o m
 * 
 * @param parent
 *          the parent.
 */
public void layoutContainer(final Container parent) {

    synchronized (parent.getTreeLock()) {
        if (parent.getComponentCount() > 0) {
            final Insets insets = parent.getInsets();
            final Dimension parentSize = parent.getSize();
            final Component component = parent.getComponent(0);
            final Dimension componentSize = component.getPreferredSize();
            final int xx = insets.left
                    + (Math.max((parentSize.width - insets.left - insets.right - componentSize.width) / 2, 0));
            final int yy = insets.top + (Math
                    .max((parentSize.height - insets.top - insets.bottom - componentSize.height) / 2, 0));
            component.setBounds(xx, yy, componentSize.width, componentSize.height);
        }
    }

}

From source file:OverlayLayout.java

/**
 * Lays out the specified container./*w w w .  j av a2 s  . c  o m*/
 *
 * @param parent the container to be laid out
 */
public void layoutContainer(final Container parent) {
    synchronized (parent.getTreeLock()) {
        final Insets ins = parent.getInsets();

        final Rectangle bounds = parent.getBounds();
        final int width = bounds.width - ins.left - ins.right;
        final int height = bounds.height - ins.top - ins.bottom;

        final Component[] comps = parent.getComponents();

        for (int i = 0; i < comps.length; i++) {
            final Component c = comps[i];
            if ((comps[i].isVisible() == false) && this.ignoreInvisible) {
                continue;
            }
            c.setBounds(ins.left, ins.top, width, height);
        }
    }
}

From source file:OverlayLayout.java

/**
 * 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/*from w w w . j av a 2 s. c om*/
 */
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);
    }
}

From source file:OverlayLayout.java

/**
 * Calculates the preferred size dimensions for the specified
 * container, given the components it contains.
 *
 * @param parent the container to be laid out
 * @return the preferred size computed for the parent.
 * @see #minimumLayoutSize/*w  w w .jav a  2  s  . co m*/
 */
public Dimension preferredLayoutSize(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].getPreferredSize();
            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);
    }
}

From source file:EdgeLayoutExample.java

public Dimension preferredLayoutSize(Container parent) {
    synchronized (parent.getTreeLock()) {
        int width = 0;
        int height = 0;

        //Add the preferred widths of all EAST/WEST components
        //Add the preferred height of all NORTH/SOUTH components
        for (int i = 0; i < this.components.size(); i++) {
            Component c = (Component) this.components.get(i);
            if (this.constraints.get(c).equals(WEST) || this.constraints.get(c).equals(EAST)) {
                width += c.getPreferredSize().getWidth();
            } else {
                height += c.getPreferredSize().getHeight();
            }/*from  www .  j a  v a 2 s  .  c  o m*/
        }

        width += parent.getInsets().right + parent.getInsets().left;
        height += parent.getInsets().top + parent.getInsets().bottom;

        return new Dimension(width, height);
    }
}