private void syncWithEditor() { ContentPanel selectedContentPanel = tabbedPane.getSelectedCodePanel(); if (selectedContentPanel == null) { return; } JNode node = selectedContentPanel.getNode(); if (node.getParent() == null && treeRoot != null) { // node not register in tree node = treeRoot.searchClassInTree(node); if (node == null) { LOG.error("Class not found in tree"); return; } } TreeNode[] pathNodes = treeModel.getPathToRoot(node); if (pathNodes == null) { return; } TreePath path = new TreePath(pathNodes); tree.setSelectionPath(path); tree.makeVisible(path); tree.scrollPathToVisible(path); tree.requestFocus(); }
/** Makes the object visible in the tree by expanding its parent objects as needed. @param object The object. **/ public void makeVisible (VNode object) { if (object == null) throw new NullPointerException ("object"); TreePath path = getPath (object); if (path != null) tree_.makeVisible (path); }
public void revealFailure(Test failure) { JTree tree= fTreeBrowser.getTree(); TestTreeModel model= (TestTreeModel)tree.getModel(); Vector vpath= new Vector(); int index= model.findTest(failure, (Test)model.getRoot(), vpath); if (index >= 0) { Object[] path= new Object[vpath.size()+1]; vpath.copyInto(path); Object last= path[vpath.size()-1]; path[vpath.size()]= model.getChild(last, index); TreePath selectionPath= new TreePath(path); tree.setSelectionPath(selectionPath); tree.makeVisible(selectionPath); } }
/** * Expands all ascendants of a node in the tree. */ @SuppressWarnings("unchecked") private void expandAscendants(JTree tree, DefaultMutableTreeNode node) { Enumeration<DefaultMutableTreeNode> children = node.children(); while (children.hasMoreElements()) { DefaultMutableTreeNode child = children.nextElement(); if (child.isLeaf()){ tree.makeVisible(new TreePath(child.getPath())); } else{ expandAscendants(tree, child); } } }
private static void expandAll(JTree tree, TreePath parent) { TreeNode node = (TreeNode) parent.getLastPathComponent(); if (node.isLeaf() && tree.isVisible(parent) == false) { tree.makeVisible(parent); } else { for (Enumeration en = node.children(); en.hasMoreElements();) { TreeNode child = (TreeNode) en.nextElement(); expandAll(tree, parent.pathByAddingChild(child)); } } }
/** Expand the given path and makes it visible. * @param path the path */ protected void showPath(TreePath path) { tree.makeVisible(path); Rectangle rect = tree.getPathBounds(path); if (rect != null) { rect.width += rect.x; rect.x = 0; tree.scrollRectToVisible(rect); } tree.setSelectionPath(path); }
/** Expand the given path and makes it visible. * @param path the path */ protected void showPath(TreePath path) { tree.makeVisible(path); Rectangle rect = tree.getPathBounds(path); if (rect != null) { rect.width += rect.x; rect.x = 0; tree.scrollRectToVisible(rect); } tree.setSelectionPath(path); }
@Override public void keyTyped(KeyEvent evt) { char keyChar = evt.getKeyChar(); if (isCharForSearch(evt)) { if (paths == null) { paths = getVisiblePaths(); } searchBuf.append(keyChar); String searchedText = searchBuf.toString().toLowerCase(); String curFileName = null; for (TreePath path : paths) { curFileName = fileChooser.getName(((DirectoryNode) path.getLastPathComponent()).getFile()); if (curFileName != null && curFileName.toLowerCase().startsWith(searchedText)) { tree.makeVisible(path); tree.scrollPathToVisible(path); tree.setSelectionPath(path); break; } } } else { resetBuffer(); } }
/** * Expands entry path and entry itself( when entry is not empty) for specific id * * @param target The target of entry */ private void expand(String target){ debug("expand called"); //find all nodes with certain id Enumeration nodes = findNodes(target).elements(); DefaultMutableTreeNode node = null; while(nodes.hasMoreElements()){ node = (DefaultMutableTreeNode)nodes.nextElement(); debug("expandPath :"+node); if(node.getChildCount() > 0){ DefaultMutableTreeNode child =(DefaultMutableTreeNode) node.getFirstChild(); TreePath path = new TreePath(child.getPath()); tree.makeVisible(path); } else{ TreeNode[] treeNode = node.getPath(); TreePath path = new TreePath(treeNode); //tree.scrollPathToVisible(path); tree.makeVisible(path); } } }
/** Expand the given path and makes it visible. * @param path the path */ protected void showPath(TreePath path) { tree.makeVisible(path); Rectangle rect = tree.getPathBounds(path); if (rect != null) { rect.width += rect.x; rect.x = 0; tree.scrollRectToVisible(rect); } tree.setSelectionPath(path); }
/** * Expands entry path and entry itself( when entry is not empty) for specific id * * @param target The target of entry */ private void expand(String target){ debug("expand called"); //find all nodes with certain id Enumeration nodes = findNodes(target).elements(); DefaultMutableTreeNode node = null; while(nodes.hasMoreElements()){ node = (DefaultMutableTreeNode)nodes.nextElement(); debug("expandPath :"+node); if(node.getChildCount() > 0){ DefaultMutableTreeNode child =(DefaultMutableTreeNode) node.getFirstChild(); TreePath path = new TreePath(child.getPath()); tree.makeVisible(path); } else{ TreeNode[] treeNode = node.getPath(); TreePath path = new TreePath(treeNode); //tree.scrollPathToVisible(path); tree.makeVisible(path); } } }
/** * Expands entry path and entry itself( when entry is not empty) for specific id * * @param target The target of entry */ private void expand(String target){ debug("expand called"); //find all nodes with certain id Enumeration nodes = findNodes(target).elements(); DefaultMutableTreeNode node = null; while(nodes.hasMoreElements()){ node = (DefaultMutableTreeNode)nodes.nextElement(); debug("expandPath :"+node); if(node.getChildCount() > 0){ DefaultMutableTreeNode child =(DefaultMutableTreeNode) node.getFirstChild(); TreePath path = new TreePath(child.getPath()); tree.makeVisible(path); } else{ TreeNode[] treeNode = node.getPath(); TreePath path = new TreePath(treeNode); //tree.scrollPathToVisible(path); tree.makeVisible(path); } } }
public void drop(DropTargetDropEvent dtde) { if (targetPath != null) { try { dtde.acceptDrop(dtde.getDropAction()); DefaultMutableTreeNode target = (DefaultMutableTreeNode) targetPath.getLastPathComponent(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) parentPath.getLastPathComponent(); if (target.getUserObject() instanceof DataNodeDescriptor && parent.getUserObject() instanceof DataMap) { DataNodeDescriptor currentDataNode = (DataNodeDescriptor) target.getUserObject(); DataMap currentDataMap = (DataMap) parent.getUserObject(); LinkDataMapAction action = eventController.getApplication().getActionManager().getAction(LinkDataMapAction.class); action.linkDataMap(currentDataMap, currentDataNode); targetTree.makeVisible(targetPath.pathByAddingChild(target)); dtde.dropComplete(true); } } catch (Exception e) { e.printStackTrace(); dtde.rejectDrop(); } } }
private void selectBox(CssBox box) { TreePath path = getPath(box); if (path != null) { ignoreSelectionEvents = true; try { //TreeSelectionModel model = tree.getSelectionModel(); //TreePath[] paths = new TreePath[] { path }; //model.setSelectionPaths(paths); tree.setSelectionPath(path); //tree.expandPath(path); tree.makeVisible(path); tree.scrollPathToVisible(path); } finally { ignoreSelectionEvents = false; } } }
private void addLayer(LayerContainer layerContainer, TransferSupport support) { Layer transferLayer = layerContainer.getDraggedLayer(); JTree.DropLocation dropLocation = (JTree.DropLocation) support.getDropLocation(); TreePath treePath = dropLocation.getPath(); Layer targetLayer = (Layer) treePath.getLastPathComponent(); List<Layer> targetList = targetLayer.getChildren(); int targetIndex = dropLocation.getChildIndex(); if (targetIndex == -1) { // moving into target layer targetIndex = 0; // insert at the beginning } if (targetList.size() <= targetIndex) { targetList.add(transferLayer); } else { targetList.add(targetIndex, transferLayer); } final TreePath newTreePath = treePath.pathByAddingChild(transferLayer); tree.makeVisible(newTreePath); tree.scrollPathToVisible(newTreePath); }
/** * A utility method used by the event listeners. Given a mouse event, it changes the list selection to the list * item below the mouse. */ private static void updateTreeSelectionForEvent(MouseEvent anEvent, JTree tree, boolean shouldScroll) { Point location = anEvent.getPoint(); if (tree == null) return; int index = tree.getRowForLocation(location.x, location.y); if (index != -1) { TreePath pathForRow = tree.getPathForRow(index); if (tree.getSelectionPath() != pathForRow) { tree.setSelectionRow(index); if (shouldScroll) tree.makeVisible(pathForRow); } } }
private void addLayer(LayerContainer layerContainer, TransferSupport support) { Layer transferLayer = layerContainer.getDraggedLayer(); JTree.DropLocation dropLocation = (JTree.DropLocation) support.getDropLocation(); TreePath treePath = dropLocation.getPath(); Layer targetLayer = (Layer) treePath.getLastPathComponent(); List<Layer> targetList = targetLayer.getChildren(); int targetIndex = dropLocation.getChildIndex(); if (targetIndex == -1) { // moving into target layer targetIndex = 0; // insert at the beginning } if (targetList.size() <= targetIndex) { targetList.add(transferLayer); } else { targetList.add(targetIndex, transferLayer); } final TreePath newTreePath = treePath.pathByAddingChild(transferLayer); tree.makeVisible(newTreePath); tree.scrollPathToVisible(newTreePath); }
private void applyEdit(DirectoryNode node) { TreeNode[] nodes = model.getPathToRoot(node); TreePath editingPath = new TreePath(nodes); tree.setEditable(true); tree.makeVisible(editingPath); tree.scrollPathToVisible(editingPath); tree.setSelectionPath(editingPath); tree.startEditingAtPath(editingPath); JTextField editField = DirectoryCellEditor.getTextField(); editField.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR)); editField.setRequestFocusEnabled(true); editField.requestFocus(); editField.setSelectionStart(0); editField.setSelectionEnd(editField.getText().length()); }
protected void handleUpAction(ActionEvent event) { TreePath paths[] = selectedJTree.getSelectionPaths(); sortTreePaths(paths); for (int i = 0; i < paths.length; i++) { TreePath path = paths[i]; DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode)node.getParent(); int index = parent.getIndex(node); if (index == 0) { continue; } DefaultMutableTreeNode removed = (DefaultMutableTreeNode)parent.getChildAt(index); boolean wasExpanded = selectedJTree.isExpanded(path); selectedJTreeModel.removeNodeFromParent(removed); selectedJTreeModel.insertNodeInto(removed, parent, index - 1); if (wasExpanded && removed.getChildCount() > 0) { DefaultMutableTreeNode firstChild = (DefaultMutableTreeNode)removed.getFirstChild(); selectedJTree.makeVisible(new TreePath(firstChild.getPath())); } } selectedJTree.setSelectionPaths(paths); }
protected void handleDownAction(ActionEvent event) { TreePath[] paths = selectedJTree.getSelectionPaths(); sortTreePaths(paths); for (int i = paths.length - 1; i >= 0; i--) { TreePath path = paths[i]; DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode)node.getParent(); int index = parent.getIndex(node); if ((index + 1) == parent.getChildCount()) { continue; } DefaultMutableTreeNode removed = (DefaultMutableTreeNode)parent.getChildAt(index); boolean wasExpanded = selectedJTree.isExpanded(path); selectedJTreeModel.removeNodeFromParent(removed); selectedJTreeModel.insertNodeInto(removed, parent, index + 1); if (wasExpanded && removed.getChildCount() > 0) { DefaultMutableTreeNode firstChild = (DefaultMutableTreeNode)removed.getFirstChild(); selectedJTree.makeVisible(new TreePath(firstChild.getPath())); } } selectedJTree.setSelectionPaths(paths); }