Search in sources :

Example 96 with TreeNode

use of javax.swing.tree.TreeNode in project ffx by mjschnie.

the class Joint method getTorsionTorsions.

/**
 * <p>
 * getTorsionTorsions</p>
 *
 * @return a {@link ffx.potential.bonded.MSNode} object.
 */
public MSNode getTorsionTorsions() {
    for (Enumeration e = children(); e.hasMoreElements(); ) {
        MSNode m = (MSNode) e.nextElement();
        TreeNode node = m.getChildAt(0);
        if (node instanceof TorsionTorsion) {
            return m;
        }
    }
    return null;
}
Also used : Enumeration(java.util.Enumeration) TreeNode(javax.swing.tree.TreeNode)

Example 97 with TreeNode

use of javax.swing.tree.TreeNode in project ffx by mjschnie.

the class Joint method getBonds.

/**
 * <p>
 * getBonds</p>
 *
 * @return a {@link ffx.potential.bonded.MSNode} object.
 */
public MSNode getBonds() {
    for (Enumeration e = children(); e.hasMoreElements(); ) {
        MSNode m = (MSNode) e.nextElement();
        TreeNode node = m.getChildAt(0);
        if (node instanceof Bond) {
            return m;
        }
    }
    return null;
}
Also used : Enumeration(java.util.Enumeration) TreeNode(javax.swing.tree.TreeNode)

Example 98 with TreeNode

use of javax.swing.tree.TreeNode in project ffx by mjschnie.

the class ExtUtils method printTreeFromNode.

public static void printTreeFromNode(MSNode target) {
    StringBuilder sb = new StringBuilder();
    sb.append(format(" Tree Hierarchy for %s\n", target.getName()));
    sb.append(format(" ===================%s\n", StringUtils.repeat("=", target.getName().length())));
    TreeNode root = target;
    while (root.getParent() != null) {
        root = root.getParent();
    }
    Enumeration<?> fromRoot = target.pathFromAncestorEnumeration(root);
    List<MSNode> toLeaves = target.getDescendants(MSNode.class);
    boolean init = false;
    for (MSNode node : toLeaves) {
        if (!init) {
            sb.append(format(" %s> %s\n", StringUtils.repeat(">", node.getLevel()), node.getName()));
            init = true;
            continue;
        }
        if (!node.getName().isEmpty()) {
            sb.append(format(" └%s> %s\n", StringUtils.repeat("-", node.getLevel()), node.getName()));
        }
    }
    logger.info(sb.toString());
}
Also used : MSNode(ffx.potential.bonded.MSNode) TreeNode(javax.swing.tree.TreeNode)

Example 99 with TreeNode

use of javax.swing.tree.TreeNode in project airavata by apache.

the class ComponentSelector method expandTreeLeaf.

private void expandTreeLeaf(ComponentTreeNode selectedNode, List<? extends Component> components) {
    ComponentReference componentReference = selectedNode.getComponentReference();
    ComponentTreeNode newNode = new ComponentTreeNode(componentReference.getName());
    ComponentTreeNode parent = (ComponentTreeNode) selectedNode.getParent();
    int index = this.treeModel.getIndexOfChild(parent, selectedNode);
    this.treeModel.removeNodeFromParent(selectedNode);
    this.treeModel.insertNodeInto(newNode, parent, index);
    for (Component component : components) {
        WSComponent wsComponent = (WSComponent) component;
        String operationName = wsComponent.getOperationName();
        ComponentOperationReference reference = new ComponentOperationReference(operationName, wsComponent);
        ComponentTreeNode child = new ComponentTreeNode(reference);
        this.treeModel.addNodeInto(child, newNode);
    }
    // expand
    TreeNode[] path = newNode.getPath();
    this.tree.expandPath(new TreePath(path));
}
Also used : ComponentOperationReference(org.apache.airavata.workflow.model.component.ComponentOperationReference) TreePath(javax.swing.tree.TreePath) TreeNode(javax.swing.tree.TreeNode) ComponentReference(org.apache.airavata.workflow.model.component.ComponentReference) WSComponent(org.apache.airavata.workflow.model.component.ws.WSComponent) WSComponent(org.apache.airavata.workflow.model.component.ws.WSComponent) Component(org.apache.airavata.workflow.model.component.Component) XBayaComponent(org.apache.airavata.xbaya.ui.widgets.XBayaComponent) Point(java.awt.Point)

Example 100 with TreeNode

use of javax.swing.tree.TreeNode in project xsimilarity by iamxiatian.

the class SememeTreeUI method createPanel.

public static JPanel createPanel() {
    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());
    try {
        final DefaultMutableTreeNode root = load();
        final JTree jtree = new JTree(root);
        JScrollPane treeScrollPane = new JScrollPane(jtree);
        // mainPanel.add(treeScrollPane, BorderLayout.SOUTH);
        JPanel queryPanel = new JPanel();
        // TODO加入查询义原路径的处理
        final JTextField queryField = new JTextField();
        queryField.setColumns(50);
        queryPanel.add(new JLabel("输入义原:"));
        queryPanel.add(queryField);
        JButton queryButton = new JButton("查询");
        queryPanel.add(queryButton);
        mainPanel.add(queryPanel, BorderLayout.NORTH);
        final JTextArea editor = new JTextArea();
        editor.setLineWrap(true);
        editor.setForeground(Color.RED);
        editor.setRows(3);
        JScrollPane editorScrollPane = new JScrollPane(editor);
        JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, editorScrollPane, treeScrollPane);
        splitPane.setDividerSize(2);
        mainPanel.add(splitPane, BorderLayout.CENTER);
        // mainPanel.add(editorScrollPane, BorderLayout.CENTER);
        queryButton.addActionListener(new ActionListener() {

            /**
             * 递归查询符合条件的结果,并把所有结果存入selectedNodes中
             *
             * @param node
             * @param selectedNodes
             */
            private void query(DefaultMutableTreeNode node, Collection<DefaultMutableTreeNode> selectedNodes) {
                String queryString = queryField.getText();
                String text = node.getUserObject().toString();
                if (text.startsWith(queryString) || text.endsWith(queryString)) {
                    selectedNodes.add(node);
                }
                if (node.getChildCount() == 0)
                    return;
                for (DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getFirstChild(); child != null; child = child.getNextSibling()) {
                    query(child, selectedNodes);
                }
            }

            /**
             * 关闭所有树的节点
             *
             * @param parent
             */
            @SuppressWarnings("unchecked")
            private void collapseAll(TreePath parent) {
                TreeNode node = (TreeNode) parent.getLastPathComponent();
                if (node.getChildCount() > 0) {
                    for (Enumeration<TreeNode> e = node.children(); e.hasMoreElements(); ) {
                        TreeNode child = e.nextElement();
                        TreePath path = parent.pathByAddingChild(child);
                        collapseAll(path);
                    }
                }
                jtree.collapsePath(parent);
            }

            @Override
            public void actionPerformed(ActionEvent e) {
                String queryString = queryField.getText();
                if (queryString.trim().equals("")) {
                    editor.setText("请输入查询义原");
                    return;
                }
                Collection<DefaultMutableTreeNode> selectedNodes = new ArrayList<DefaultMutableTreeNode>();
                query(root, selectedNodes);
                if (selectedNodes.size() == 0) {
                    editor.setText("查询结果:无匹配记录");
                    return;
                }
                jtree.setSelectionPath(null);
                collapseAll(new TreePath(((DefaultTreeModel) jtree.getModel()).getPathToRoot(root)));
                StringBuilder sb = new StringBuilder("共有" + selectedNodes.size() + "条匹配义原:\n");
                for (DefaultMutableTreeNode node : selectedNodes) {
                    TreePath path = new TreePath(((DefaultTreeModel) jtree.getModel()).getPathToRoot(node));
                    jtree.expandPath(path);
                    jtree.addSelectionPath(path);
                    Object[] objs = path.getPath();
                    for (int i = objs.length - 1; i > 0; i--) {
                        if (i < objs.length - 1) {
                            sb.append(" -> ");
                        }
                        sb.append(objs[i].toString());
                    }
                    sb.append("\n\n");
                }
                editor.setText(sb.toString());
                editor.setCaretPosition(0);
            }
        });
    } catch (IOException e) {
        e.printStackTrace();
    }
    return mainPanel;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) Enumeration(java.util.Enumeration) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) IOException(java.io.IOException) JTextField(javax.swing.JTextField) JTree(javax.swing.JTree) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) TreePath(javax.swing.tree.TreePath) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Collection(java.util.Collection) JSplitPane(javax.swing.JSplitPane)

Aggregations

TreeNode (javax.swing.tree.TreeNode)313 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)146 TreePath (javax.swing.tree.TreePath)125 FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)31 Enumeration (java.util.Enumeration)30 PanelEquationTree (gov.sandia.n2a.ui.eq.PanelEquationTree)28 MPart (gov.sandia.n2a.eqset.MPart)27 ArrayList (java.util.ArrayList)27 NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)25 JTree (javax.swing.JTree)23 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)23 Nullable (org.jetbrains.annotations.Nullable)23 MutableTreeNode (javax.swing.tree.MutableTreeNode)19 CannotRedoException (javax.swing.undo.CannotRedoException)18 NodePart (gov.sandia.n2a.ui.eq.tree.NodePart)16 CannotUndoException (javax.swing.undo.CannotUndoException)14 NodeVariable (gov.sandia.n2a.ui.eq.tree.NodeVariable)12 MouseEvent (java.awt.event.MouseEvent)11 NotNull (org.jetbrains.annotations.NotNull)11 PanelEquations (gov.sandia.n2a.ui.eq.PanelEquations)10