Example usage for java.awt Component getTreeLock

List of usage examples for java.awt Component getTreeLock

Introduction

In this page you can find the example usage for java.awt Component 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 void swingDispatch(MouseEvent e, Point point, final Component component) {
    synchronized (component.getTreeLock()) {
        if (component instanceof Container) {
            Container container = (Container) component;
            for (int i = container.getComponentCount(); i-- != 0;) {
                Component child = container.getComponent(i);
                Rectangle r = child.getBounds();
                if (r.contains(point)) {
                    swingDispatch(e, new Point(point.x - r.x, point.y - r.y), child);
                    return;
                }/* w w  w . j  a  v  a  2s . c  o m*/
            }
        }
    }
    final MouseEvent adapted = convertMouseEvent(e, component, point);
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            component.dispatchEvent(adapted);
        }
    });
}

From source file:net.imglib2.script.analysis.ChartUtils.java

private static final void layoutComponent(final Component c) {
    synchronized (c.getTreeLock()) {
        c.doLayout();//w  w w .  jav  a 2s. c  o m
        if (c instanceof Container) {
            for (final Component child : ((Container) c).getComponents()) {
                layoutComponent(child);
            }
        }
    }
    c.validate();
}

From source file:script.imglib.analysis.ChartUtils.java

private static final void layoutComponent(final Component c) {
    synchronized (c.getTreeLock()) {
        c.doLayout();/*  w  w  w  . jav  a2s .co  m*/
        if (c instanceof Container) {
            for (Component child : ((Container) c).getComponents()) {
                layoutComponent(child);
            }
        }
    }
    c.validate();
}

From source file:StackLayout.java

public void removeLayoutComponent(Component comp) {
    synchronized (comp.getTreeLock()) {
        if (comp == getVisibleComponent()) {
            visibleComp = null;//w ww .  j a  va  2s.c o  m
        }
        // kick out removed component as visible, so that others
        // don't have problems with hidden components
        comp.setVisible(true);
    }
}

From source file:StackLayout.java

/**
 * ********** Implementation of LayoutManager interface *********
 *///from  w w w. ja  v a 2s. co m

public void addLayoutComponent(String name, Component comp) {
    synchronized (comp.getTreeLock()) {
        comp.setVisible(false);
        // keep consistency if showComponent was already called on this
        // component before
        if (comp == getVisibleComponent()) {
            visibleComp = null;
        }
        /*System.out.println("Border dump for " + comp.getName());
        borderDump((javax.swing.JComponent)comp, "");*/
    }
}

From source file:EdgeLayoutExample.java

public void removeLayoutComponent(Component comp) {
    synchronized (comp.getTreeLock()) {
        this.components.remove(comp);
        this.constraints.remove(comp);
    }//from www .  j av a2  s .com
}

From source file:EdgeLayoutExample.java

public void addLayoutComponent(Component comp, Object constraints) {
    synchronized (comp.getTreeLock()) {
        if (constraints instanceof String && comp != null) {
            this.components.add(comp);
            this.constraints.put(comp, constraints);
        } else {/*from w ww . jav a 2 s.c  om*/
            throw new IllegalArgumentException("Invalid component constraints.");
        }
    }
}

From source file:TableLayout.java

/**
 * Removes the specified component from the layout.
 *///from w w  w  .j a v a2s .co  m

public void removeLayoutComponent(Component component) {
    synchronized (component.getTreeLock()) {
        int rowCount = rows.size();
        outer: for (int i = 0; i < rowCount; i++) {
            Component[] row = (Component[]) rows.elementAt(i);
            for (int j = 0; j < row.length; j++) {
                if (row[j] == component) {
                    row[j] = null;
                    break outer;
                }
            }
        }

        // Remove any empty rows at the end.
        for (int i = rowCount - 1; i >= 0; i--) {
            Component[] row = (Component[]) rows.elementAt(i);
            boolean isEmpty = true;
            for (int j = 0; j < row.length; j++) {
                if (row[j] != null) {
                    isEmpty = false;
                    break;
                }
            }
            if (isEmpty)
                rows.removeElementAt(i);
            else
                break;
        }
    }
}

From source file:TableLayout.java

/**
 * Adds the specified component to the layout.
 *///from  w  w w  .  j  a  v a  2 s.  com

public void addLayoutComponent(Component component, Object constraints) {
    synchronized (component.getTreeLock()) {
        int rowCount = rows.size();
        for (int i = 0; i < rowCount; i++) {
            Component[] row = (Component[]) rows.elementAt(i);
            for (int j = 0; j < row.length; j++) {
                if (row[j] == null) {
                    row[j] = component;
                    return;
                }
            }
        }

        Component[] newRow = new Component[columnCount];
        newRow[0] = component;
        rows.addElement(newRow);
    }
}