Java Code Examples for javax.swing.tree.TreePath#getPath()

The following examples show how to use javax.swing.tree.TreePath#getPath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ObjectTreeInternalFrame.java    From bigtable-sql with Apache License 2.0 6 votes vote down vote up
public void valueChanged(TreeSelectionEvent evt)
{
   final TreePath selPath = evt.getNewLeadSelectionPath();
   if (selPath != null)
   {
      StringBuffer buf = new StringBuffer();
      Object[] fullPath = selPath.getPath();
      for (int i = 0; i < fullPath.length; ++i)
      {
         if (fullPath[i] instanceof ObjectTreeNode)
         {
            ObjectTreeNode node = (ObjectTreeNode)fullPath[i];
            buf.append('/').append(node.toString());
         }
      }
      //JASON: have a main application status bar setStatusBarMessage(buf.toString());
   }
}
 
Example 2
Source File: GuildManagePanel.java    From gameserver with Apache License 2.0 6 votes vote down vote up
@Override
public void valueChanged(TreeSelectionEvent e) {
	TreePath path = e.getPath();
	if ( path.getPathCount() > 1 ) {
		DBObjectTreeTableNode node = (DBObjectTreeTableNode)path.getPath()[1];
		Object nodeKey = node.getKey();
		if ( nodeKey instanceof UserId ) {
			UserId userId = (UserId)node.getKey();
			User user = ((MongoUserManager)(UserManager.getInstance())).
					constructUserObject((DBObject)node.getUserObject());
			if ( userId != null ) {
				delGuildAction.setEnabled(true);
				return;
			}
		}
	} else {
		delGuildAction.setEnabled(false);
	}
}
 
Example 3
Source File: TreePanel.java    From nmonvisualizer with Apache License 2.0 6 votes vote down vote up
private TreePath rebuildPath(TreePath oldPath) {
    Object[] oldPaths = oldPath.getPath();
    DefaultMutableTreeNode[] newPath = new DefaultMutableTreeNode[oldPaths.length];

    DefaultMutableTreeNode parent = ((DefaultMutableTreeNode) tree.getModel().getRoot());

    newPath[0] = parent;
    int pathIdx = 1;

    while ((parent != null) && (pathIdx < newPath.length)) {
        List<javax.swing.tree.TreeNode> children = java.util.Collections
                .list((java.util.Enumeration<javax.swing.tree.TreeNode>) parent.children());

        for (javax.swing.tree.TreeNode c : children) {
            DefaultMutableTreeNode child = (DefaultMutableTreeNode) c;
            if (((DefaultMutableTreeNode) oldPaths[pathIdx]).getUserObject().equals(child.getUserObject())) {
                newPath[pathIdx] = child;
                ++pathIdx;
                parent = child;
                break;
            }
        }
    }

    return new TreePath(newPath);
}
 
Example 4
Source File: CustomizationUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static ActionUrl getActionUrl(final TreePath treePath, int actionType) {
  ActionUrl url = new ActionUrl();
  for (int i = 0; i < treePath.getPath().length - 1; i++) {
    Object o = ((DefaultMutableTreeNode)treePath.getPath()[i]).getUserObject();
    if (o instanceof Group) {
      url.getGroupPath().add(((Group)o).getName());
    }

  }

  final DefaultMutableTreeNode component = ((DefaultMutableTreeNode)treePath.getLastPathComponent());
  url.setComponent(component.getUserObject());
  DefaultMutableTreeNode node = component;
  final TreeNode parent = node.getParent();
  url.setAbsolutePosition(parent != null ? parent.getIndex(node) : 0);
  url.setActionType(actionType);
  return url;
}
 
Example 5
Source File: View.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
public static List<List<String>> getExpandedNodes(JTree tree) {
    List<List<String>> expandedNodes = new ArrayList<>();
    int rowCount = tree.getRowCount();
    for (int i = 0; i < rowCount; i++) {
        try {
            TreePath path = tree.getPathForRow(i);
            if (tree.isExpanded(path)) {
                List<String> pathAsStringList = new ArrayList<>();
                for (Object pathCompnent : path.getPath()) {
                    pathAsStringList.add(pathCompnent.toString());
                }
                expandedNodes.add(pathAsStringList);
            }
        } catch (IndexOutOfBoundsException | NullPointerException ex) {
            // TreeNode was removed, ignore
        }
    }
    return expandedNodes;
}
 
Example 6
Source File: LayerTreeTransferHandler.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
private static boolean isValidDrag(TransferSupport support, LayerContainer layerContainer) {
    JTree.DropLocation dropLocation = (JTree.DropLocation) support.getDropLocation();
    TreePath treePath = dropLocation.getPath();

    final Object[] path = treePath.getPath();
    for (Object o : path) {
        final Layer layer = (Layer) o;
        if (layer == layerContainer.getDraggedLayer()) {
            return false;
        }
    }

    Layer targetLayer = (Layer) treePath.getLastPathComponent();
    int targetIndex = dropLocation.getChildIndex();
    if (targetIndex == -1) { //  -1 indicates move into other layer
        return targetLayer.isCollectionLayer();
    }

    return true;
}
 
Example 7
Source File: JPlotterPanel.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
private void jPlotterDeletePlotButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPlotterDeletePlotButtonActionPerformed
   
   // Make a cache so that object deletion does not mess up the selections array
   // we're working on.
   Object[] cache = new Object[selectedPathsVector.size()];
   selectedPathsVector.copyInto(cache);
   for(int i=0;i<cache.length; i++){
      TreePath nextPath = (TreePath)cache[i]; // Since the array shrinks!
      Object[] pathObjects = nextPath.getPath();
      int depth =pathObjects.length-1;
      DefaultMutableTreeNode node = (DefaultMutableTreeNode)pathObjects[depth];
      if (node instanceof PlotNode){
         Plot figToDelete = ((Plot)node.getUserObject());
         plotterModel.deletePlot(figToDelete);
      } else if (node instanceof PlotCurveNode){
         PlotCurve cvToDelete = ((PlotCurve)node.getUserObject());
         plotterModel.deleteCurve(cvToDelete);
      } else
         JOptionPane.showMessageDialog(this, "Don't know what to delete!");
      
   }
}
 
Example 8
Source File: GltfBrowserPanel.java    From JglTF with MIT License 5 votes vote down vote up
/**
 * Returns the tree path of the parent of the given tree path. 
 * 
 * @param treePath The tree path
 * @return The parent tree path
 */
private static TreePath getParentPath(TreePath treePath)
{
    Object[] array = treePath.getPath();
    if (array.length == 0)
    {
        return treePath;
    }
    return new TreePath(Arrays.copyOf(array,  array.length-1));
}
 
Example 9
Source File: TreeTableModelAdapter.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private TreePath getCurrentPath(TreePath oldPath) {
    if (oldPath == null || oldPath.getPathCount() < 1) return null;
    if (!treeTableModel.getRoot().equals(oldPath.getPathComponent(0))) return null;
    
    TreePath p = getRootPath();
    Object[] op = oldPath.getPath();
    CCTNode n = (CCTNode)treeTableModel.getRoot();
    
    for (int i = 1; i < op.length; i++) {
        // #241115
        CCTNode[] children = n.getChildren();
        if (children == null) return null;
        
        CCTNode nn = null;
        
        for (CCTNode c : children)
            if (c.equals(op[i])) {
                nn = c;
                break;
            }
        
        if (nn == null) return null;
        
        n = nn;
        p = p.pathByAddingChild(n);
    }
    
    return p;
}
 
Example 10
Source File: ProfilerTreeTable.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private static TreePath getSimilarPath(TreePath oldPath, TreeModel currentModel) {
        if (oldPath == null || oldPath.getPathCount() < 1) return null;

//        TreeModel currentModel = getModel();
        Object currentRoot = currentModel.getRoot();
        if (!currentRoot.equals(oldPath.getPathComponent(0))) return null;

        TreePath p = new TreePath(currentRoot);
        Object[] op = oldPath.getPath();
        Object n = currentRoot;

        for (int i = 1; i < op.length; i++) {
            Object nn = null;

            for (int ii = 0; ii < currentModel.getChildCount(n); ii++) {
                Object c = currentModel.getChild(n, ii);
                if (c.equals(op[i])) {
                    nn = c;
                    break;
                }
            }

            if (nn == null) return null;

            n = nn;
            p = p.pathByAddingChild(n);
        }
//        System.err.println(">>> Similar path for " + oldPath + " is " + p);
        return p;
    }
 
Example 11
Source File: Main.java    From freeinternals with Apache License 2.0 5 votes vote down vote up
private void zftree_DoubleClick(final TreePath tp) {
    final DefaultMutableTreeNode node = (DefaultMutableTreeNode) this.zftree.getLastSelectedPathComponent();
    if (node == null) {
        return;
    }
    if (node.isLeaf() == false) {
        return;
    }

    final Object objLast = tp.getLastPathComponent();
    if (objLast == null) {
        return;
    }

    if (objLast.toString().endsWith(ClassFile.EXTENTION_CLASS) == false) {
        return;
    }

    final Object[] objArray = tp.getPath();
    if (objArray.length < 2) {
        return;
    }

    final Object userObj = node.getUserObject();
    if (!(userObj instanceof JTreeNodeZipFile)) {
        return;
    }

    final ZipEntry ze = ((JTreeNodeZipFile) userObj).getNodeObject();
    if (ze == null) {
        JOptionPane.showMessageDialog(
                this,
                "Node Object [zip entry] is emtpy.",
                this.getTitle(),
                JOptionPane.WARNING_MESSAGE);
    } else {
        this.showClassWindow(ze);
    }
}
 
Example 12
Source File: BrowserUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static String pathFromRoot(TreePath path) {
    int m = ((HeapWalkerNode)path.getLastPathComponent()).getMode();
    Object[] nodes = path.getPath();
    StringBuilder b = new StringBuilder();
    int s = nodes.length;
    for (int i = 0; i < s; i++) {
        HeapWalkerNode n = (HeapWalkerNode)nodes[i];
        if (m == HeapWalkerNode.MODE_FIELDS) fieldFromRoot(n, b, i, s);
        else referenceFromRoot(n, b, i, s);
        b.append("\n"); // NOI18N
    }
    return b.toString().replace("].[", ""); // NOI18N
}
 
Example 13
Source File: FavoritesTreeViewPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
static FavoritesListNode getListNodeFromPath(TreePath path) {
  if (path != null && path.getPathCount() > 1) {
    final Object o = path.getPath()[1];
    if (o instanceof DefaultMutableTreeNode) {
      final Object obj = ((DefaultMutableTreeNode)o).getUserObject();
      if (obj instanceof FavoritesTreeNodeDescriptor) {
        final AbstractTreeNode node = ((FavoritesTreeNodeDescriptor)obj).getElement();
        if (node instanceof FavoritesListNode) {
          return (FavoritesListNode)node;
        }
      }
    }
  }
  return null;
}
 
Example 14
Source File: BindingCustomizer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public String pathToString(TreePath path) {
    StringBuilder sb = new StringBuilder();
    Object[] items = path.getPath();
    for (int i=1; i<items.length; i++) {
        sb.append(items[i]).append('.');
    }
    if (sb.length() > 0) {
        sb.deleteCharAt(sb.length()-1);
    }
    String value = sb.toString().trim();
    return "null".equals(value) ? "null" : designSupport.elWrap(sb.toString()); // NOI18N
}
 
Example 15
Source File: APKRepatcher.java    From APKRepatcher with MIT License 5 votes vote down vote up
public static String createFilePath(TreePath treePath) {
	StringBuilder sb = new StringBuilder();
	Object[] nodes = treePath.getPath();
	for (int i = 0; i < nodes.length; i++) {
		sb.append(File.separatorChar).append(nodes[i].toString());
	}
	return sb.toString();
}
 
Example 16
Source File: DefaultContextMenu.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void recordAction(int action) {
    TreePath[] selectionPaths = assertionTree.getSelectionPaths();
    for (TreePath path : selectionPaths) {
        Object[] objects = path.getPath();
        final StringBuffer sb = new StringBuffer();
        RComponent forComponent = rcomponent;
        for (int j = 1; j < objects.length; j++) {
            final AssertionTreeNode node = (AssertionTreeNode) objects[j];
            if (node.getObject() instanceof RComponent) {
                forComponent = (RComponent) node.getObject();
                sb.setLength(0);
                continue;
            }
            sb.append(node.getProperty());
            if (j < objects.length - 1) {
                if (!((AssertionTreeNode) objects[j + 1]).getProperty().startsWith("[")) {
                    sb.append(".");
                }
            } else {
                String property = sb.toString();
                Object value = null;
                if (property.equals("Content")) {
                    value = forComponent.getContent();
                } else {
                    if (property.equals("Text")) {
                        value = forComponent.getText();
                    } else {
                        value = forComponent.getAttribute(property);
                    }
                }
                getRecorder().recordAction(forComponent, action == ASSERT_ACTION ? "assert" : "wait", property, value);
            }
        }
    }
}
 
Example 17
Source File: FilterTreeModel.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public void addFilter(Filter filter, TreePath selectionPath) {
    if (selectionPath != null) {
        Object[] path = selectionPath.getPath();
        if (path.length >= 2) {
            Group group = (Group) path[1];
            filter.getTags().add(group.name);
        }
    }
    filterSet.addFilter(filter);
}
 
Example 18
Source File: UserManagePanel.java    From gameserver with Apache License 2.0 5 votes vote down vote up
@Override
public void valueChanged(TreeSelectionEvent e) {
	TreePath path = e.getPath();
	if ( path.getPathCount() > 1 ) {
		DBObjectTreeTableNode node = (DBObjectTreeTableNode)path.getPath()[1];
		Object nodeKey = node.getKey();
		if ( nodeKey instanceof UserId ) {
			UserId userId = (UserId)node.getKey();
			User user = ((MongoUserManager)(UserManager.getInstance())).
					constructUserObject((DBObject)node.getUserObject());
			if ( userId != null ) {
				bagAction.setUser(user);
				bagAction.setEnabled(true);
				delAction.setUserId(userId);
				delAction.setEnabled(true);
				sendGiftAction.setUserId(userId);
				sendGiftAction.setEnabled(true);
				loginStatusAction.setEnabled(false);
				deleteAccountButton.setEnabled(false);
				chargeAction.setUserId(userId);
				chargeAction.setEnabled(true);
				pushAction.setUser(user);
				pushAction.setEnabled(true);
				return;
			}
		}
	} else {
		bagAction.setEnabled(false);
		delAction.setEnabled(false);
		sendGiftAction.setEnabled(false);
		loginStatusAction.setEnabled(false);
	}
}
 
Example 19
Source File: InspectorWindow.java    From megan-ce with GNU General Public License v3.0 5 votes vote down vote up
/**
 * returns the match head node in a path
 *
 * @param path
 * @return read head node or null
 */
private MatchHeadLineNode getMatchHeadLineNodeFromPath(TreePath path) {
    Object[] components = path.getPath();
    for (Object component : components) {
        if (component instanceof MatchHeadLineNode)
            return (MatchHeadLineNode) component;
    }
    return null;
}
 
Example 20
Source File: GhidraScriptComponentProvider.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private String[] getCategoryPath(GTreeNode node) {
	TreePath treePath = node.getTreePath();
	Object[] path = treePath.getPath();
	String[] categoryPath = new String[path.length - 1];
	for (int i = 0; i < categoryPath.length; i++) {
		categoryPath[i] = ((GTreeNode) path[i + 1]).getName();
	}
	return categoryPath;
}