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;
}
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;
}
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());
}
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));
}
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;
}
Aggregations