public boolean shouldSelectCell(EventObject e) { boolean rv = false; // only mouse events if (e instanceof MouseEvent) { MouseEvent me = (MouseEvent) e; TreePath path = tree.getPathForLocation(me.getX(), me.getY()); CategoryNode node = (CategoryNode) path.getLastPathComponent(); rv = node.isLeaf() /*|| !inCheckBoxHitRegion(me)*/; } return rv; }
private void expandSubtree(TreePath path, boolean expand) { if (path == null) { TreePath selectionPath = getSelectionPath(); path = selectionPath == null ? new TreePath(treeModel.getRoot()) : selectionPath; } DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) path.getLastPathComponent(); Enumeration children = currentNode.children(); while (children.hasMoreElements()) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement(); TreePath expandedPath = path.pathByAddingChild(child); expandSubtree(expandedPath, expand); } if (expand) { expandPath(path); } else if (path.getParentPath() != null) { collapsePath(path); } }
private String getRowPathStr(TreePath trp) { String pathStr = ""; if (trp.getPathCount() > 1) { for (int i = 1; i < trp.getPathCount(); i++) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) trp.getPathComponent(i); TreeNodeUserObject userObject = (TreeNodeUserObject) node.getUserObject(); pathStr = pathStr + userObject.getOriginalName() + "/"; } } return pathStr; }
private boolean areSiblingsSelected(TreePath path) { TreePath parent = path.getParentPath(); if (parent == null) { return true; } Object node = path.getLastPathComponent(); Object parentNode = parent.getLastPathComponent(); int childCount = model.getChildCount(parentNode); for (int i = 0; i < childCount; i++) { Object childNode = model.getChild(parentNode, i); if (childNode == node) { continue; } if (!isPathSelected(parent.pathByAddingChild(childNode))) { return false; } } return true; }
setSize(400, 300); DefaultMutableTreeNode top = new DefaultMutableTreeNode( new IconData(ICON_COMPUTER, null, "Computer")); for (int k=0; k<roots.length; k++) node = new DefaultMutableTreeNode(new IconData(ICON_DISK, null, new FileNode(roots[k]))); top.add(node); node.add(new DefaultMutableTreeNode( new Boolean(true) )); m_model = new DefaultTreeModel(top); m_tree.setCellRenderer(renderer); m_tree.addTreeExpansionListener(new DirExpansionListener()); m_tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); return (DefaultMutableTreeNode)(path.getLastPathComponent()); m_model.reload(node); JOptionPane.showMessageDialog(null, "Error reading directory "+m_file.getAbsolutePath(),"Warning", JOptionPane.WARNING_MESSAGE); return null;
int parentIndex = -1; if (tpath != null) { for (parentIndex = tpath.getPathCount() - 1; parentIndex >= 0; parentIndex--) Object p = tpath.getPathComponent(parentIndex); if (p instanceof MondrianGuiDef.Property) { path = p; JOptionPane.showMessageDialog( this, getResourceConverter().getString( "schemaExplorer.propertyNotSelected.alert", parentPathObjs[i] = tpath.getPathComponent(i); TreePath parentPath = new TreePath(parentPathObjs); tree.setSelectionPath(parentPath.pathByAddingChild(formatter)); refreshTree(tree.getSelectionPath()); setTableCellFocus(0);
TreeNode[] path = node.getPath(); TreePath tp = new TreePath(path); CheckedNode cn = new CheckedNode(false, node.getChildCount() > 0, false); nodesCheckingState.put(tp, cn); for (int i = 0 ; i < node.getChildCount() ; i++) { addSubtreeToCheckingStateTracking((DefaultMutableTreeNode) tp.pathByAddingChild(node.getChildAt(i)).getLastPathComponent()); TreePath tp = new TreePath(node.getPath()); CheckedNode cn = nodesCheckingState.get(tp); if (cn == null) { super(); this.setToggleClickCount(0); TreePath parentPath = tp.getParentPath(); DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) parentPath.getLastPathComponent(); parentCheckedNode.allChildrenSelected = true; TreePath childPath = parentPath.pathByAddingChild(parentNode.getChildAt(i)); CheckedNode childCheckedNode = nodesCheckingState.get(childPath); CheckedNode cn = nodesCheckingState.get(tp); cn.isSelected = check; DefaultMutableTreeNode node = (DefaultMutableTreeNode) tp.getLastPathComponent(); for (int i = 0 ; i < node.getChildCount() ; i++) { checkSubTree(tp.pathByAddingChild(node.getChildAt(i)), check);
public boolean inCheckBoxHitRegion(MouseEvent e) { TreePath path = tree.getPathForLocation(e.getX(), e.getY()); if (path == null) { return false; } CategoryNode node = (CategoryNode) path.getLastPathComponent(); boolean rv = false; if (true) { // offset and lastRow DefaultTreeCellEditor // protected members Rectangle bounds = tree.getRowBounds(lastRow); Dimension checkBoxOffset = renderer.getCheckBoxOffset(); bounds.translate(offset + checkBoxOffset.width, checkBoxOffset.height); rv = bounds.contains(e.getPoint()); } return true; }
path = path.getParentPath(); Object obj1[] = path1.getPath(); Object obj2[] = path2.getPath(); for(int i = 0; i<obj2.length; i++){ if(obj1[i]!=obj2[i]) if(path.getParentPath()==null) path = path.getParentPath(); if(temp.getParentPath()!=null) addSelectionPath(temp.getParentPath()); TreePath parent = path.getParentPath(); Object node = path.getLastPathComponent(); Object parentNode = parent.getLastPathComponent(); if(!isPathSelected(parent.pathByAddingChild(childNode)) && !isParameters && !isDescription){ return false; for(int i = 0; i<paths.length; i++){ TreePath path = paths[i]; if(path.getPathCount()==1) super.removeSelectionPaths(new TreePath[]{ path}); else
(DefaultMutableTreeNode)tree.getModel().getRoot(); Enumeration e = root.breadthFirstEnumeration(); while(e.hasMoreElements()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode)e.nextElement(); if(node.isLeaf()) continue; int row = tree.getRowForPath(new TreePath(node.getPath())); (DefaultMutableTreeNode)dest.getLastPathComponent(); (DefaultMutableTreeNode)path.getLastPathComponent(); (DefaultMutableTreeNode)path.getLastPathComponent(); (DefaultMutableTreeNode)path.getLastPathComponent(); new ArrayList<DefaultMutableTreeNode>(); DefaultMutableTreeNode node = (DefaultMutableTreeNode)paths[0].getLastPathComponent(); DefaultMutableTreeNode copy = copy(node); copies.add(copy); for(int i = 1; i < paths.length; i++) { DefaultMutableTreeNode next = (DefaultMutableTreeNode)paths[i].getLastPathComponent(); TreePath dest = dl.getPath(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode)dest.getLastPathComponent();
@Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { TreePath path = tree.getClosestPathForLocation(e.getX(), e.getY()); tree.setSelectionPath(path); JPopupMenu menu = new ASTNodePopupMenu(model, (Node) path.getLastPathComponent()); menu.show(tree, e.getX(), e.getY()); } } });
/** * Fix compatibility issue with right click on Linux. * @param e Mouse event */ private void showPopup(MouseEvent e) { if (e.isPopupTrigger()) { JTree tree = (JTree) e.getSource(); TreePath path = tree.getPathForLocation(e.getX(), e.getY()); if (path == null) { return; } DefaultMutableTreeNode currentTableNode = (DefaultMutableTreeNode) path.getLastPathComponent(); if (currentTableNode.getUserObject() instanceof AbstractNodeModel) { AbstractNodeModel currentTableModel = (AbstractNodeModel) currentTableNode.getUserObject(); if (currentTableModel.isPopupDisplayable()) { currentTableModel.showPopup(currentTableNode, path, e); } } } }
DefaultTreeModel treeModel = (DefaultTreeModel) MediatorGui.treeDatabase().getModel(); DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(newTreeNodeModel); treeModel.insertNodeInto(newNode, tableNode, tableNode.getChildCount()); MediatorGui.treeDatabase().expandPath(new TreePath(tableNode.getPath())); ((AbstractNodeModel) tableNode.getUserObject()).setLoaded(true);
public Collection<Object> extractTargets(MouseEvent e, JTree tree) { int x = e.getX(); int y = e.getY(); TreePath path = tree.getPathForLocation(x, y); if (path == null) { return Collections.emptyList(); } tree.setSelectionPath(path); DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) path.getLastPathComponent(); Object uo = treeNode.getUserObject(); return Arrays.asList(uo, treeNode); }
@Override public void mousePressed(MouseEvent e) { TreePath path = tree.getPathForLocation(e.getX(), e.getY()); if (path != null) { DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) path.getLastPathComponent(); MixedCheckBox checkBox = (MixedCheckBox) currentNode.getUserObject(); // ignore clicks on checkbox's label - enables to select it without changing the state if (e.getX() - tree.getPathBounds(path).getX() > unlabeledMixedCheckBoxWidth) { return; } switch (checkBox.getStatus()) { case CHECKED: resolveNewCheckBoxState(currentNode, UNCHECKED, MIXED); break; case UNCHECKED: resolveNewCheckBoxState(currentNode, CHECKED, MIXED); break; case MIXED: resolveNewCheckBoxState(currentNode, CHECKED, null); break; default: throw new IllegalStateException("The status (" + checkBox.getStatus() + ") is not implemented."); } tree.treeDidChange(); } }
@Override public String getToolTipText(MouseEvent e) { if (getRowForLocation(e.getX(), e.getY()) == -1) { return null; } TreePath curPath = getPathForLocation(e.getX(), e.getY()); if (curPath.getLastPathComponent() instanceof ASTTreeNode) { return ((ASTTreeNode) curPath.getLastPathComponent()).getToolTipText(); } else { return super.getToolTipText(e); } }
protected void addAnnotations(ActionEvent evt) { TreePath tpath = null; tpath = getTreePath(evt); Object path = tree.getSelectionPath().getLastPathComponent(); && !(path instanceof MondrianGuiDef.Role))) JOptionPane.showMessageDialog( this, getResourceConverter().getString( "schemaExplorer.objectNotSelectedForAnnotations.alert", throw new RuntimeException(e); tree.setSelectionPath(tpath.pathByAddingChild(annotations)); refreshTree(tree.getSelectionPath());
protected void addRole(ActionEvent evt) { MondrianGuiDef.Schema schema = (MondrianGuiDef.Schema) tree.getModel().getRoot(); MondrianGuiDef.Role role = new MondrianGuiDef.Role(); role.name = ""; role.schemaGrants = new MondrianGuiDef.SchemaGrant[0]; // add cube to schema role.name = getNewName( getResourceConverter().getString( "schemaExplorer.newRole.title", "New Role"), schema.roles); NodeDef[] temp = schema.roles; schema.roles = new MondrianGuiDef.Role[temp.length + 1]; for (int _i = 0; _i < temp.length; _i++) { schema.roles[_i] = (MondrianGuiDef.Role) temp[_i]; } schema.roles[schema.roles.length - 1] = role; tree.setSelectionPath( (new TreePath(model.getRoot())).pathByAddingChild( role)); refreshTree(tree.getSelectionPath()); setTableCellFocus(0); }
protected void init() { // Create the nodes. DefaultMutableTreeNode top = new DefaultMutableTreeNode("XChart Example Charts"); createNodes(top); tree = new JTree(top); // Create a tree that allows one selection at a time. tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); // Listen for when the selection changes. tree.addTreeSelectionListener(this); // Create the scroll pane and add the tree to it. JScrollPane treeView = new JScrollPane(tree); // Create Chart Panel tabbedPane = new JTabbedPane(); for (int i = 0; i < tree.getRowCount(); i++) { tree.expandRow(i); } // select first leaf DefaultMutableTreeNode firstLeaf = top.getFirstLeaf(); tree.setSelectionPath(new TreePath(firstLeaf.getPath())); // Add the scroll panes to a split pane. splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); splitPane.setTopComponent(treeView); splitPane.setBottomComponent(tabbedPane); Dimension minimumSize = new Dimension(130, 160); treeView.setMinimumSize(minimumSize); splitPane.setPreferredSize(new Dimension(700, 700)); // Add the split pane to this panel. add(splitPane); }