Example usage for java.awt Component getParent

List of usage examples for java.awt Component getParent

Introduction

In this page you can find the example usage for java.awt Component getParent.

Prototype

public Container getParent() 

Source Link

Document

Gets the parent of this component.

Usage

From source file:edu.ku.brc.specify.utilapps.ERDVisualizer.java

public void calcLoc(final Point p, final Component src, final Component stop) {
    if (src != stop) {
        Point sp = src.getLocation();
        p.translate(sp.x, sp.y);/*  w  ww.  jav  a2s  .  co  m*/
        calcLoc(p, src.getParent(), stop);
    }
}

From source file:org.eclipse.jubula.rc.swing.components.AUTSwingHierarchy.java

/**
 * {@inheritDoc}//  w w w .ja va 2 s  .  com
 */
protected List getComponentContext(Object component) {
    Component comp = (Component) component;
    List context = new ArrayList();
    if (comp.getParent() != null) {
        SwingHierarchyContainer parent = getHierarchyContainer(comp.getParent());
        if (parent != null) {
            SwingHierarchyContainer[] comps = parent.getComponents();
            for (int i = 0; i < comps.length; i++) {
                Component child = comps[i].getComponentID().getRealComponent();
                if (!child.equals(comp)) {
                    String toAdd = child.getClass().getName() + Constants.CLASS_NUMBER_SEPERATOR + 1;
                    while (context.contains(toAdd)) {
                        int lastCount = Integer
                                .valueOf(toAdd
                                        .substring(toAdd.lastIndexOf(Constants.CLASS_NUMBER_SEPERATOR) + 1))
                                .intValue();
                        toAdd = child.getClass().getName() + Constants.CLASS_NUMBER_SEPERATOR + (lastCount + 1);
                    }
                    context.add(toAdd);
                }
            }
        }
    }
    return context;
}

From source file:edu.purdue.cc.bionet.ui.ClusteringDisplayPanel.java

/**
 * The actionPerformed method of the ActionListener interface. Performs 
 * cluster recalculation when the 'recalculate' button is clicked.
 * /*from  w  w w.  j  a  v a2 s.  c  o  m*/
 * @param e The event which triggered this action.
 */
public void actionPerformed(ActionEvent e) {
    Logger logger = Logger.getLogger(getClass());
    Language language = Settings.getLanguage();
    Object source = e.getSource();
    if (source == this.recomputeMenuItem) {
        // don't change the groups, just trigger the clusterer
        this.setSampleGroups(this.getSampleGroups());
    } else if (source == this.chooseSampleGroupsMenuItem) {
        // Choose sample groups.
        Component frame = this;
        while (!(frame instanceof Frame) && frame != null) {
            frame = frame.getParent();
        }
        Collection<SampleGroup> groups = SampleGroupDialog.showInputDialog((Frame) frame,
                Settings.getLanguage().get("Choose groups"), this.samples);
        if (groups != null) {

            if (this.getSampleGroups() != null) {
                for (SampleGroup group : this.getSampleGroups()) {
                    logger.debug(group.toString());
                    for (Sample sample : group) {
                        logger.debug("\t" + sample.toString());
                    }
                }
            }
            this.setSampleGroups(groups);
        }
    } else if (source == this.removeSampleGroupsMenuItem) {
        Collection<SampleGroup> groups = new ArrayList<SampleGroup>();
        groups.add(new SampleGroup("", this.samples));
        this.setSampleGroups(groups);
    }
}

From source file:edu.purdue.cc.bionet.ui.ClusteringDisplayPanel.java

public void setSampleGroups(Collection<SampleGroup> sampleGroups) {
    Component frame = this;
    while (!(frame instanceof Frame) && frame != null) {
        frame = frame.getParent();
    }//  ww  w  .j  ava  2s  . co m
    ClusterSelectionDialog dialog = new ClusterSelectionDialog((Frame) frame,
            Settings.getLanguage().get("Choose Clustering Method"), this.getSampleGroups() != null);

    if (dialog.getReturnValue() == null) {
        return;
    }
    super.setSampleGroups(sampleGroups);
    Collection<Molecule> molecules;
    try {
        ClusterSelectorTreePanel clusterPanel = (ClusterSelectorTreePanel) this.selectorPanel.getComponent(0);
        molecules = clusterPanel.getCheckedMolecules();
    } catch (ArrayIndexOutOfBoundsException e) {
        molecules = this.molecules;
    } catch (ClassCastException e) {
        molecules = this.molecules;
        Logger.getLogger(this.getClass()).error(e, e);
    }
    // clear the panels and set new layouts based on the new groups.
    this.selectorPanel.removeAll();
    this.clusterGraphPanel.removeAll();
    int rows = (int) Math.ceil(Math.sqrt(sampleGroups.size()));
    int cols = (int) Math.ceil(sampleGroups.size() / rows);
    GridLayout layout = (GridLayout) this.selectorPanel.getLayout();
    layout.setRows(rows);
    layout.setColumns(cols);
    layout = (GridLayout) this.clusterGraphPanel.getLayout();
    layout.setRows(rows);
    layout.setColumns(cols);

    // start the clusterer(s) in parallel.
    Map<Thread, RunnableClusterer> clusterers = new HashMap<Thread, RunnableClusterer>();
    for (SampleGroup group : sampleGroups) {
        RunnableClusterer clusterer = new RunnableClusterer(dialog.getReturnValue());
        SampleGroup filteredGroup = new SampleGroup(group);
        filteredGroup.retainAll(this.sampleSelectorTree.getSamples());
        clusterer.setDataset(this.getDataset(molecules, filteredGroup));
        Thread thread = new Thread(clusterer);
        thread.start();
        clusterers.put(thread, clusterer);
    }

    // iterate through each group and join the threads
    Iterator<SampleGroup> groupIter = sampleGroups.iterator();
    Collection<ClusterSelectorTreePanel> clusterTreeList = new ArrayList<ClusterSelectorTreePanel>();
    this.clusterGraphPanel.removeAll();
    for (Map.Entry<Thread, RunnableClusterer> clusterer : clusterers.entrySet()) {
        try {
            clusterer.getKey().join();
            Dataset[] result = clusterer.getValue().getResult();
            Collection<Collection<Molecule>> clusters = new TreeSet<Collection<Molecule>>(
                    new DatasetComparator());
            Collection<Molecule> unclustered = new ArrayList<Molecule>(this.molecules);
            for (Dataset dataset : result) {
                Collection<Molecule> cluster = this.getMoleculesForDataset(dataset);
                clusters.add(cluster);
                unclustered.removeAll(cluster);
            }

            // create a new clustertree and add the appropriate listeners
            ClusterSelectorTreePanel clusterTree = new ClusterSelectorTreePanel(clusters);
            if (unclustered.size() > 0) {
                clusterTree.add(unclustered,
                        String.format(Settings.getLanguage().get("Unclustered") + " (%d)", unclustered.size()),
                        false);
            }
            for (ClusterSelectorTreePanel tree : clusterTreeList) {
                tree.addTreeCheckingListener(clusterTree);
                clusterTree.addTreeCheckingListener(tree);
            }
            clusterTreeList.add(clusterTree);

            this.selectorPanel.add(clusterTree);
            ClusterGraph graph = new ClusterGraph(this.sampleSelectorTree, clusterTree, groupIter.next());
            this.clusterGraphPanel.add(graph);
            graph.setMeanGraph(clusterTree.getRoot());
        } catch (InterruptedException e) {
            Logger.getLogger(this.getClass()).debug(e, e);
        }
    }
    this.removeSampleGroupsMenuItem.setEnabled(sampleGroups.size() > 1);
    this.validate();
}

From source file:edu.ku.brc.af.ui.forms.validation.ValComboBox.java

/**
 * @return/*from   w  ww .  j av  a2s .c  om*/
 */
private MultiView getMultiView() {
    Component comp = getParent();
    do {
        if (comp instanceof MultiView) {
            return (MultiView) comp;
        }
        if (comp != null) {
            comp = comp.getParent();
        } else {
            break;
        }
    } while (true);

    return null;
}

From source file:edu.purdue.cc.bionet.ui.DistributionAnalysisDisplayPanel.java

/**
 * The actionPerformed method of the ActionListener interface.
 * // ww w.ja  v  a 2  s  .  co  m
 * @see ActionListener#actionPerformed( ActionEvent )
 * @param e The event which triggered this action.
 */
public void actionPerformed(ActionEvent e) {
    Logger logger = Logger.getLogger(getClass());
    Language language = Settings.getLanguage();
    Object source = e.getSource();
    if (source == this.chooseSampleGroupsMenuItem) {
        // Choose sample groups.
        Component frame = this;
        while (!(frame instanceof Frame) && frame != null) {
            frame = frame.getParent();
        }
        Collection<SampleGroup> groups = SampleGroupDialog.showInputDialog((Frame) frame,
                Settings.getLanguage().get("Choose groups"), this.samples);
        if (groups != null) {

            if (this.getSampleGroups() != null) {
                for (SampleGroup group : this.getSampleGroups()) {
                    logger.debug(group.toString());
                    for (Sample sample : group) {
                        logger.debug("\t" + sample.toString());
                    }
                }
            }
            this.setSampleGroups(groups);
        }
    } else if (source == this.removeSampleGroupsMenuItem) {
        Collection<SampleGroup> groups = new ArrayList<SampleGroup>();
        groups.add(new SampleGroup("", this.samples));
        this.setSampleGroups(groups);
    } else if (source == this.hideOutliersViewMenuItem) {
        this.deselectOutliers();
    }
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.FormPane.java

/**
 * For a given Object (usually from a MouseEvent) it determines if a selection of a control or label happened.
 * It also requests focus for the COntrol of the label.
 * @param obj the UI Object/*from  w  w  w.ja  v a  2s.c  om*/
 * @return the parent InputPanel
 */
protected InputPanel getInputPanel(final Object obj) {
    Component comp = ((Component) obj).getParent();
    while (comp != null && !(comp instanceof InputPanel)) {
        comp = comp.getParent();
    }

    InputPanel inputPanel = comp instanceof InputPanel ? (InputPanel) comp : null;
    if (inputPanel != null) {
        if (obj instanceof JLabel) {
            inputPanel.getComp().requestFocus();
        }
    }
    return inputPanel;
}

From source file:org.eclipse.jubula.rc.swing.components.AUTSwingHierarchy.java

/**
 * Add the new component to the hierarchy.
 * /*from   ww  w.ja v a2s  .  com*/
 * @param toAdd The component to add to the hierarchy.
 */
private void addComponent(Component toAdd) {
    ClassLoader originalCL = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
    try {
        // Don't add an invisible component
        if (!toAdd.isShowing()) {
            return;
        }
        Container container = toAdd.getParent();
        if (log.isDebugEnabled()) {
            log.debug("component '" + toAdd //$NON-NLS-1$
                    + "' added to '" + container + "'"); //$NON-NLS-1$ //$NON-NLS-2$                  
        }
        // get the hierarchy container for container, must be there!
        SwingHierarchyContainer hierarchyContainer = null;
        if (toAdd instanceof Window) {
            hierarchyContainer = getHierarchyContainer(toAdd);
        } else {
            hierarchyContainer = getHierarchyContainer(container);
        }

        if (hierarchyContainer == null) {
            // Parent container not managed at this time.
            // Do not clutter up the hierarchy with orphan components.
            return;
        }
        // create new hierarchy container for child, name, update hashtable, put
        // them together,
        if (getHierarchyContainer(toAdd) != null) {
            return;
        }
        // create new hierarchy container for child, name, update hashtable, put
        // them together,
        SwingHierarchyContainer hierarchyChild = new SwingHierarchyContainer(new SwingComponent(toAdd));
        hierarchyContainer.add(hierarchyChild);
        hierarchyChild.setParent(hierarchyContainer);
        name(hierarchyChild);
        addToHierachyMap(hierarchyChild);
        if (toAdd instanceof Container) {
            Container cont = (Container) toAdd;
            // call addTohierachyDown()
            addToHierarchyDown(hierarchyChild, cont);
        }
    } finally {
        Thread.currentThread().setContextClassLoader(originalCL);
    }
}

From source file:org.docx4all.ui.main.WordMLEditor.java

public Frame getWindowFrame() {
    if (_applet == null) {
        return getMainFrame();
    }//from  ww  w. ja va2 s  .  c  om

    Component c = _applet;
    while (c != null && !(c instanceof Frame)) {
        c = c.getParent();
    }

    return (Frame) c;
}

From source file:brainflow.app.toplevel.BrainFlow.java

private boolean parentIsImageView(Component c) {
    if (c instanceof ImageView) {
        return true;
    }//from   w  ww.ja  v a  2s.  c o  m

    while (c != null) {
        Container comp = c.getParent();
        if (comp instanceof ImageView) {
            return true;
        }

        c = c.getParent();
    }

    return false;

}