List of usage examples for javax.swing.tree TreePath TreePath
public TreePath(Object lastPathComponent)
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** Handles the selection of the nodes in the tree.*/ private void handleTreeSelection() { delayedHandlingTreeSelection = false; TreeImageDisplay[] nodes = model.getSelectedDisplays(); if (((rightClickButton && !ctrl) || rightClickPad) && model.isMultiSelection()) { setFoundNode(nodes);//from w ww . j a v a 2s . co m return; } if (ctrl && leftMouseButton) { TreePath[] paths = treeDisplay.getSelectionPaths(); List<TreePath> added = new ArrayList<TreePath>(); TreePath[] all = null; if (paths != null) { all = new TreePath[paths.length]; for (int i = 0; i < paths.length; i++) { all[i] = new TreePath(paths[i].getPath()); } } //treeDisplay.removeTreeSelectionListener(selectionListener); if (all != null) treeDisplay.setSelectionPaths(all); //treeDisplay.addTreeSelectionListener(selectionListener); if (all != null) { for (int i = 0; i < all.length; i++) added.add(all[i]); } controller.onClick(added); return; } if (event == null) return; TreePath[] paths = event.getPaths(); List<TreePath> added = new ArrayList<TreePath>(); for (int i = 0; i < paths.length; i++) { if (rightClickPad) { if (!event.isAddedPath(paths[i])) { added.add(paths[i]); } } else { if (event.isAddedPath(paths[i])) { added.add(paths[i]); } } } //if (!ctrl) controller.onClick(added); }
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Helper method to create the trees hosting the display. * // w w w. j a va 2s . co m * @param exp The logged in experimenter. */ private void createTrees(ExperimenterData exp) { treeDisplay = new DnDTree(model.getUserID(), TreeViewerAgent.isAdministrator()); treeDisplay.addPropertyChangeListener(this); String key = "meta pressed A"; if (UIUtilities.isWindowsOS()) key = "ctrl pressed A"; KeyStroke ks = KeyStroke.getKeyStroke(key); treeDisplay.getInputMap().put(ks, "none"); treeDisplay.setVisible(true); treeDisplay.setRootVisible(false); ToolTipManager.sharedInstance().registerComponent(treeDisplay); treeDisplay.setCellRenderer(new TreeCellRenderer(model.getUserID())); treeDisplay.setShowsRootHandles(true); TreeImageSet root = new TreeImageSet(""); treeDisplay.setModel(new DefaultTreeModel(root)); if (model.getBrowserType() != Browser.ADMIN_EXPLORER) { TreeImageDisplay node = buildTreeNodes(exp); if (node != null) treeDisplay.collapsePath(new TreePath(node.getPath())); } //Add Listeners //treeDisplay.requestFocus(); treeDisplay.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { mousePressedTime = e.getWhen(); rightClickPad = UIUtilities.isMacOS() && SwingUtilities.isLeftMouseButton(e) && e.isControlDown(); rightClickButton = SwingUtilities.isRightMouseButton(e); ctrl = e.isControlDown(); if (UIUtilities.isMacOS()) ctrl = e.isMetaDown(); leftMouseButton = SwingUtilities.isLeftMouseButton(e); if (UIUtilities.isMacOS() || UIUtilities.isLinuxOS()) onClick(e, false); } public void mouseReleased(MouseEvent e) { leftMouseButton = SwingUtilities.isLeftMouseButton(e); if (UIUtilities.isWindowsOS()) onClick(e, true); } // public void mouseMoved(MouseEvent e) { rollOver(e); } }); treeDisplay.addMouseMotionListener(new MouseMotionAdapter() { public void mouseMoved(MouseEvent e) { rollOver(e); } }); treeDisplay.addTreeExpansionListener(listener); selectionListener = new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { event = e; eventHandledTime = System.currentTimeMillis(); if (delayedHandlingTreeSelection) /* mouse click delayed handling until this event occurred */ handleTreeSelection(); switch (keyEvent) { case KeyEvent.VK_DOWN: case KeyEvent.VK_UP: TreePath[] paths = treeDisplay.getSelectionPaths(); if (paths != null) controller.onClick(Arrays.asList(paths)); else controller.onClick(new ArrayList<TreePath>()); break; } } }; treeDisplay.addTreeSelectionListener(selectionListener); //remove standard behaviour treeDisplay.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { ctrl = false; switch (e.getKeyCode()) { case KeyEvent.VK_ENTER: ViewCmd cmd = new ViewCmd(model.getParentModel(), true); cmd.execute(); break; case KeyEvent.VK_DELETE: switch (model.getState()) { case Browser.LOADING_DATA: case Browser.LOADING_LEAVES: //case Browser.COUNTING_ITEMS: break; default: model.delete(); } break; case KeyEvent.VK_CONTROL: if (!UIUtilities.isMacOS()) ctrl = true; break; case KeyEvent.VK_META: if (UIUtilities.isMacOS()) ctrl = true; break; case KeyEvent.VK_A: if (UIUtilities.isWindowsOS() && e.isControlDown() || !UIUtilities.isWindowsOS() && e.isMetaDown()) { handleMultiSelection(); } break; case KeyEvent.VK_DOWN: case KeyEvent.VK_UP: case KeyEvent.VK_RIGHT: keyEvent = e.getKeyCode(); break; case KeyEvent.VK_LEFT: TreePath[] paths = treeDisplay.getSelectionPaths(); TreeImageDisplay node; Object o; for (int i = 0; i < paths.length; i++) { o = paths[i].getLastPathComponent(); if (o instanceof TreeImageDisplay) { node = (TreeImageDisplay) o; if (node.isExpanded()) node.setExpanded(false); } } } } public void keyReleased(KeyEvent e) { ctrl = false; keyEvent = -1; } }); }
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Selects the specified node.//from w w w . j a v a 2s. c o m * * @param node The node to select. */ void selectFoundNode(TreeImageDisplay node) { TreePath path = new TreePath(node.getPath()); treeDisplay.setSelectionPath(path); TreeCellRenderer renderer = (TreeCellRenderer) treeDisplay.getCellRenderer(); //treeDisplay.requestFocus(); renderer.getTreeCellRendererComponent(treeDisplay, node, treeDisplay.isPathSelected(path), false, true, 0, false); }
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Collapses the specified node. To avoid loop, we first need to * remove the <code>TreeExpansionListener</code>. * /*from w w w. j a v a 2 s.c o m*/ * @param node The node to collapse. */ void collapsePath(DefaultMutableTreeNode node) { //First remove listener otherwise an event is fired. treeDisplay.removeTreeExpansionListener(listener); treeDisplay.collapsePath(new TreePath(node.getPath())); treeDisplay.addTreeExpansionListener(listener); }
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Removes the specified set of nodes from the tree. * //from w ww.ja va2 s. c o m * @param nodes The collection of nodes to remove. * @param parentDisplay The selected parent. */ void removeNodes(List nodes, TreeImageDisplay parentDisplay) { if (parentDisplay == null) parentDisplay = getTreeRoot(); Iterator i = nodes.iterator(); TreeImageDisplay node; TreeImageDisplay parent; DefaultTreeModel dtm = (DefaultTreeModel) treeDisplay.getModel(); while (i.hasNext()) { node = (TreeImageDisplay) i.next(); parent = node.getParentDisplay(); if (parent.isChildrenLoaded()) { parent.removeChildDisplay(node); parent.remove(node); dtm.reload(parent); if (parent.equals(parentDisplay)) treeDisplay.setSelectionPath(new TreePath(parent.getPath())); } } }
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Adds the newly created node to the tree. * /*from w ww. java 2 s .c om*/ * @param nodes The collection of the parent nodes. * @param newNode The node to add to the parent. * @param parentDisplay The selected parent. */ void createNodes(List nodes, TreeImageDisplay newNode, TreeImageDisplay parentDisplay) { if (parentDisplay == null) parentDisplay = getTreeRoot(); Iterator i = nodes.iterator(); TreeImageDisplay parent; List list; Iterator j; DefaultTreeModel dtm = (DefaultTreeModel) treeDisplay.getModel(); //buildEmptyNode(newNode); boolean toLoad = false; TreeImageDisplay n; while (i.hasNext()) { parent = (TreeImageDisplay) i.next(); //problem will come when we have images if (parent.isChildrenLoaded()) { parent.addChildDisplay(newNode); list = prepareSortedList(sorter.sort(parent.getChildrenDisplay())); parent.removeAllChildren(); j = list.iterator(); while (j.hasNext()) { n = (TreeImageDisplay) j.next(); if (!n.isChildrenLoaded()) { n.removeAllChildren(); buildEmptyNode(n); } dtm.insertNodeInto(n, parent, parent.getChildCount()); } dtm.reload(parent); expandNode(parent); if (parent.equals(parentDisplay)) treeDisplay.setSelectionPath(new TreePath(newNode.getPath())); } else { //Only the currently selected one will be loaded. if (parent.equals(parentDisplay)) toLoad = true; } } //should be leaves. Need to review that code. if (toLoad) { //TO BE MODIFIED //if (parentDisplay.getParentDisplay() == null) //root // controller.loadData(); //else controller.loadLeaves(); } }
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Sets the nodes selecting via other views. * // www. ja v a 2 s . c o m * @param newSelection The collection of nodes to select. */ void setFoundNode(TreeImageDisplay[] newSelection) { if (newSelection == null) { model.setSelectedDisplay(null, true); treeDisplay.clearSelection(); controller.getAction(BrowserControl.DELETE).setEnabled(false); } else { TreePath[] paths = new TreePath[newSelection.length]; for (int i = 0; i < newSelection.length; i++) { paths[i] = new TreePath(newSelection[i].getPath()); } treeDisplay.setSelectionPaths(paths); } treeDisplay.repaint(); }
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Reloads the specified node./*from ww w. j a v a2s . c o m*/ * * @param node The node to reload. */ void reloadContainer(TreeImageDisplay node) { if (node == null) return; node.removeAllChildren(); node.removeAllChildrenDisplay(); node.setChildrenLoaded(Boolean.FALSE); buildEmptyNode(node); treeDisplay.collapsePath(new TreePath(node.getPath())); treeDisplay.expandPath(new TreePath(node.getPath())); DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel(); tm.reload(node); }
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Expands the specified node. To avoid loop, we first need to * remove the <code>TreeExpansionListener</code>. * /*from w w w . j av a2s .co m*/ * @param node The node to expand. */ void expandNode(TreeImageDisplay node, boolean withListener) { //First remove listener otherwise an event is fired. if (node == null) return; node.setExpanded(true); if (withListener) { treeDisplay.expandPath(new TreePath(node.getPath())); } else { treeDisplay.removeTreeExpansionListener(listener); treeDisplay.expandPath(new TreePath(node.getPath())); treeDisplay.addTreeExpansionListener(listener); } }
From source file:org.openmicroscopy.shoola.agents.treeviewer.util.MoveGroupSelectionDialog.java
/** * Creates a new container corresponding to {@link #containerType}. * //from w w w . ja va 2 s .com * @param name The name of the container. */ private void create(String name) { if (containerType == null) return; if (ProjectData.class.equals(containerType)) { toCreate = new ProjectData(); ((ProjectData) toCreate).setName(name); } else if (ScreenData.class.equals(containerType)) { toCreate = new ScreenData(); ((ScreenData) toCreate).setName(name); } else if (DatasetData.class.equals(containerType)) { toCreate = new DatasetData(); ((DatasetData) toCreate).setName(name); } DefaultTreeModel dtm = (DefaultTreeModel) treeDisplay.getModel(); TreeImageDisplay root = (TreeImageDisplay) dtm.getRoot(); TreeImageSet node = new TreeImageSet(toCreate); node.setDisplayItems(false); dtm.insertNodeInto(node, root, root.getChildCount()); node = (TreeImageSet) root.getChildAt(root.getChildCount() - 1); treeDisplay.setSelectionPath(new TreePath(node.getPath())); if (noDisplay) { noDisplay = false; Container c = getContentPane(); c.remove(body); c.remove(1); c.add(new JScrollPane(treeDisplay), BorderLayout.CENTER); c.add(buildToolBar(), BorderLayout.SOUTH); validate(); repaint(); } }