List of usage examples for javax.swing.tree TreePath equals
public boolean equals(Object o)
From source file:Main.java
/** * @return true, if path1 is a descendant of path2. Else, returns false. *///w w w.j a va 2 s . c o m public static boolean isDescendant(TreePath path1, TreePath path2) { int count1 = path1.getPathCount(); int count2 = path2.getPathCount(); if (count1 <= count2) return false; while (count1 != count2) { path1 = path1.getParentPath(); count1--; } return path1.equals(path2); }
From source file:Main.java
private void myPopupEvent(MouseEvent e) { int x = e.getX(); int y = e.getY(); JTree tree = (JTree) e.getSource(); TreePath path = tree.getPathForLocation(x, y); if (path == null) return;/*from www . ja va2 s . c o m*/ DefaultMutableTreeNode rightClickedNode = (DefaultMutableTreeNode) path.getLastPathComponent(); TreePath[] selectionPaths = tree.getSelectionPaths(); boolean isSelected = false; if (selectionPaths != null) { for (TreePath selectionPath : selectionPaths) { if (selectionPath.equals(path)) { isSelected = true; } } } if (!isSelected) { tree.setSelectionPath(path); } if (rightClickedNode.isLeaf()) { JPopupMenu popup = new JPopupMenu(); final JMenuItem refreshMenuItem = new JMenuItem("refresh"); refreshMenuItem.addActionListener(ev -> System.out.println("refresh!")); popup.add(refreshMenuItem); popup.show(tree, x, y); } }
From source file:com.mgmtp.jfunk.core.ui.JFunkFrame.java
private void buildTree() { tree = new JTree(new ScriptsTreeModel(roots)); tree.setCellRenderer(new ScriptsTreeCellRenderer()); tree.setRootVisible(false);//from w w w. j av a2 s .co m tree.setShowsRootHandles(true); tree.addKeyListener(new KeyAdapter() { @Override public void keyPressed(final KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { runScripts(); } } }); tree.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(final MouseEvent e) { if (!e.isPopupTrigger() && e.getClickCount() == 2) { if (tree.getModel().isLeaf(tree.getSelectionPath().getLastPathComponent())) { runScripts(); } } } @Override public void mousePressed(final MouseEvent e) { if (e.isPopupTrigger()) { TreePath selPath = tree.getPathForLocation(e.getX(), e.getY()); TreePath[] paths = tree.getSelectionPaths(); boolean newPath = true; for (TreePath path : paths) { if (selPath.equals(path)) { newPath = false; break; } } if (newPath) { tree.setSelectionPath(selPath); } popup.show((Component) e.getSource(), e.getX(), e.getY()); } } @Override public void mouseReleased(final MouseEvent e) { if (e.isPopupTrigger()) { TreePath selPath = tree.getPathForLocation(e.getX(), e.getY()); TreePath[] paths = tree.getSelectionPaths(); boolean newPath = true; for (TreePath path : paths) { if (selPath.equals(path)) { newPath = false; break; } } if (newPath) { tree.setSelectionPath(selPath); } popup.show((Component) e.getSource(), e.getX(), e.getY()); } } }); }
From source file:edu.ku.brc.specify.tasks.subpane.security.NavigationTreeContextMenuMgr.java
/** * @param clickedElement/*from w w w. j av a 2 s. co m*/ */ private void updateSelection(TreePath clickedElement) { // Find out if the clicked on element is already selected boolean clickedElementSelected = false; TreePath[] selection = getTree().getSelectionPaths(); if (clickedElement != null && selection != null) { // Determine if it one of the selected paths for (int index = 0; index < selection.length; ++index) { if (clickedElement.equals(selection[index])) { clickedElementSelected = true; break; } } } // Select the clicked on element or clear all selections if (!clickedElementSelected) { if (clickedElement != null) { // Clicked on unselected item - make it the selection getTree().setSelectionPath(clickedElement); } else { // clicked over nothing clear the selection getTree().clearSelection(); } } }
From source file:com.mgmtp.perfload.loadprofiles.ui.AppFrame.java
private void expandTree() { List<TreePath> paths = treeModel.getPaths(); for (TreePath path : paths) { if (path.equals(activeLeafPath)) { tree.setSelectionPath(path); tree.scrollPathToVisible(path); }//from w w w .j a v a 2 s.co m tree.expandPath(path.getParentPath()); } }
From source file:org.apache.cayenne.modeler.ProjectTreeView.java
private void initController() { treeSelectionListener = new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { TreePath[] paths = getSelectionPaths(); if (paths != null) { if (paths.length > 1) { ConfigurationNode projectParentPath = null; ConfigurationNode[] projectPaths = new ConfigurationNode[paths.length]; boolean commonParentPath = true; for (int i = 0; i < paths.length; i++) { projectPaths[i] = createProjectPath(paths[i]); TreePath parentPath = paths[i].getParentPath(); if (i > 0 && parentPath != null && !parentPath.equals(paths[i - 1].getParentPath())) { commonParentPath = false; }/*from w ww . j av a2 s. c o m*/ } if (commonParentPath) { TreePath parentPath = paths[0].getParentPath(); projectParentPath = createProjectPath(parentPath); } mediator.fireMultipleObjectsDisplayEvent( new MultipleObjectsDisplayEvent(this, projectPaths, projectParentPath)); } else if (paths.length == 1) { processSelection(paths[0]); } } } /** * Converts TreePath to Object */ private ConfigurationNode createProjectPath(TreePath treePath) { Object[] path = treePath.getPath(); ConfigurationNode projectPath = (ConfigurationNode) ((DefaultMutableTreeNode) path[path.length - 1]) .getUserObject(); return projectPath; } }; treeWillExpandListener = new TreeWillExpandListener() { @Override public void treeWillExpand(TreeExpansionEvent e) throws ExpandVetoException { TreePath path = e.getPath(); if (!isPathSelected(path) && !isSelectionEmpty()) { setSelectionPath(path); } } @Override public void treeWillCollapse(TreeExpansionEvent e) throws ExpandVetoException { TreePath path = e.getPath(); if (!isPathSelected(path) && !isSelectionEmpty()) { setSelectionPath(path); } } }; addTreeSelectionListener(treeSelectionListener); addTreeWillExpandListener(treeWillExpandListener); addMouseListener(new PopupHandler()); mediator.addDomainListener(this); mediator.addDomainDisplayListener(this); mediator.addDataNodeListener(this); mediator.addDataNodeDisplayListener(this); mediator.addDataMapListener(this); mediator.addDataMapDisplayListener(this); mediator.addObjEntityListener(this); mediator.addObjEntityDisplayListener(this); mediator.addDbEntityListener(this); mediator.addDbEntityDisplayListener(this); mediator.addEmbeddableDisplayListener(this); mediator.addEmbeddableListener(this); mediator.addProcedureListener(this); mediator.addProcedureDisplayListener(this); mediator.addQueryListener(this); mediator.addQueryDisplayListener(this); mediator.addMultipleObjectsDisplayListener(this); mediator.getApplication().getActionManager().setupCutCopyPaste(this, CutAction.class, CopyAction.class); }
From source file:org.languagetool.gui.ConfigurationDialog.java
@NotNull private MouseAdapter getMouseAdapter() { return new MouseAdapter() { private void handlePopupEvent(MouseEvent e) { JTree tree = (JTree) e.getSource(); TreePath path = tree.getPathForLocation(e.getX(), e.getY()); if (path == null) { return; }//from www.j a v a 2s . c o m DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); TreePath[] paths = tree.getSelectionPaths(); boolean isSelected = false; if (paths != null) { for (TreePath selectionPath : paths) { if (selectionPath.equals(path)) { isSelected = true; } } } if (!isSelected) { tree.setSelectionPath(path); } if (node.isLeaf()) { JPopupMenu popup = new JPopupMenu(); JMenuItem aboutRuleMenuItem = new JMenuItem(messages.getString("guiAboutRuleMenu")); aboutRuleMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { RuleNode node = (RuleNode) tree.getSelectionPath().getLastPathComponent(); Rule rule = node.getRule(); Language lang = config.getLanguage(); if (lang == null) { lang = Languages.getLanguageForLocale(Locale.getDefault()); } Tools.showRuleInfoDialog(tree, messages.getString("guiAboutRuleTitle"), rule.getDescription(), rule, rule.getUrl(), messages, lang.getShortCodeWithCountryAndVariant()); } }); popup.add(aboutRuleMenuItem); popup.show(tree, e.getX(), e.getY()); } } @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { handlePopupEvent(e); } } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { handlePopupEvent(e); } } }; }
From source file:org.parosproxy.paros.view.SiteMapPanel.java
/** * This method initializes treeSite//from w w w . ja v a 2 s .c o m * * @return JTree */ public JTree getTreeSite() { if (treeSite == null) { treeSite = new JTree(); treeSite.setShowsRootHandles(true); treeSite.setName("treeSite"); treeSite.setToggleClickCount(1); treeSite.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0) { // ZAP: Select site list item on right click TreePath tp = treeSite.getPathForLocation(e.getPoint().x, e.getPoint().y); if (tp != null) { boolean select = true; // Only select a new item if the current item is not // already selected - this is to allow multiple items // to be selected if (treeSite.getSelectionPaths() != null) { for (TreePath t : treeSite.getSelectionPaths()) { if (t.equals(tp)) { select = false; break; } } } if (select) { treeSite.getSelectionModel().setSelectionPath(tp); } } View.getSingleton().getPopupMenu().show(e.getComponent(), e.getX(), e.getY()); } } }); treeSite.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { HttpMessage msg = null; SiteNode node = (SiteNode) treeSite.getLastSelectedPathComponent(); if (node == null) { return; } if (!node.isRoot()) { try { msg = node.getHistoryReference().getHttpMessage(); } catch (Exception e1) { // ZAP: Log exceptions log.warn(e1.getMessage(), e1); return; } HttpPanel reqPanel = getView().getRequestPanel(); HttpPanel resPanel = getView().getResponsePanel(); reqPanel.setMessage(msg, true); resPanel.setMessage(msg, false); // ZAP: Call SiteMapListenners for (SiteMapListener listener : listenners) { listener.nodeSelected(node); } } } }); } return treeSite; }
From source file:se.nawroth.asciidoc.browser.AsciidocBrowserApplication.java
public AsciidocBrowserApplication(final String[] args) { super("Asciidoc Browser"); setIconImage(Icons.APPLICATION.image()); setSize(1200, 1024);//from www. j av a 2s . co m addWindowListener(new WindowAdapter() { @Override public void windowClosing(final WindowEvent e) { actionExit(); } }); JPanel buttonPanel = new JPanel(); backButton = new JButton(""); backButton.setIcon(Icons.BACK.icon()); backButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { actionBack(); } }); buttonPanel.setLayout(new MigLayout("", "[1px][][][][]", "[1px]")); JButton btnOptionsbutton = new JButton(""); btnOptionsbutton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { settingsDialog.setVisible(true); } }); btnOptionsbutton.setIcon(Icons.OPTIONS.icon()); buttonPanel.add(btnOptionsbutton, "flowx,cell 0 0"); backButton.setEnabled(false); buttonPanel.add(backButton, "cell 0 0,grow"); forwardButton = new JButton(""); forwardButton.setIcon(Icons.FORWARD.icon()); forwardButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { actionForward(); } }); forwardButton.setEnabled(false); buttonPanel.add(forwardButton, "cell 0 0,grow"); getContentPane().setLayout(new MigLayout("", "[793.00px,grow]", "[44px][930px]")); getContentPane().add(buttonPanel, "cell 0 0,growx,aligny top"); locationTextField = new JTextField(65); locationTextField.setText(""); locationTextField.addKeyListener(new KeyAdapter() { @Override public void keyReleased(final KeyEvent e) { int keyCode = e.getKeyCode(); if (keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_TAB) { actionGo(); refreshDocumentTree(); } } }); locationTextField.setTransferHandler( new TextFieldTransferHandler(locationTextField.getTransferHandler(), new Runnable() { @Override public void run() { locationTextField.setText(""); } }, new Runnable() { @Override public void run() { actionGo(); refreshDocumentTree(); } })); homebutton = new JButton(""); homebutton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { locationTextField.setText(Settings.getHome()); actionGo(); refreshDocumentTree(); } }); refreshButton = new JButton(""); refreshButton.setToolTipText("Refresh"); refreshButton.setEnabled(false); refreshButton.setIcon(Icons.REFRESH.icon()); refreshButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { actionGo(); refreshPreview(); } }); buttonPanel.add(refreshButton, "cell 1 0"); homebutton.setIcon(Icons.HOME.icon()); buttonPanel.add(homebutton, "cell 2 0"); buttonPanel.add(locationTextField, "cell 3 0,grow"); treeSourceSplitPane = new JSplitPane(); treeSourceSplitPane.setResizeWeight(0.3); getContentPane().add(treeSourceSplitPane, "cell 0 1,grow"); treeScrollPane = new JScrollPane(); treeScrollPane.setMinimumSize(new Dimension(200, 200)); treeSourceSplitPane.setLeftComponent(treeScrollPane); documentTree = new DocumentTree(documentModel); documentTree.setCellRenderer(new TooltipsTreeCellRenderer()); ToolTipManager.sharedInstance().registerComponent(documentTree); ToolTipManager.sharedInstance().setInitialDelay(INITIAL_TOOLTIP_DELAY); ToolTipManager.sharedInstance().setReshowDelay(0); documentTree.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(final TreeSelectionEvent tse) { TreePath newLeadSelectionPath = tse.getNewLeadSelectionPath(); if (newLeadSelectionPath != null && !newLeadSelectionPath.equals(currentSelectionPath)) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) newLeadSelectionPath .getLastPathComponent(); FileWrapper file = (FileWrapper) node.getUserObject(); showFile(file, true); refreshPreview(); } } }); treeScrollPane.setViewportView(documentTree); sourceEditorPane = new JEditorPane(); sourceEditorPane.setContentType("text/html"); sourceEditorPane.setEditable(false); sourceEditorPane.addHyperlinkListener(new HandleHyperlinkUpdate()); JScrollPane fileScrollPane = new JScrollPane(sourceEditorPane); fileScrollPane.setMinimumSize(new Dimension(600, 600)); documentTabbedPane = new JTabbedPane(SwingConstants.BOTTOM); documentTabbedPane.addChangeListener(new ChangeListener() { @Override public void stateChanged(final ChangeEvent ce) { refreshPreview(); } }); sourceLogSplitPane = new JSplitPane(); sourceLogSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); treeSourceSplitPane.setRightComponent(sourceLogSplitPane); sourceLogSplitPane.setTopComponent(documentTabbedPane); documentTabbedPane.add(fileScrollPane); documentTabbedPane.setTitleAt(0, "Source"); browserPane = new BrowserPane(); previewScrollPane = new JScrollPane(browserPane); documentTabbedPane.addTab("Preview", null, previewScrollPane, null); console = new JConsole(); System.setErr(console.getErr()); System.setOut(console.getOut()); sourceLogSplitPane.setBottomComponent(console); executor = new AsciidocExecutor(); }