public void mouseClicked(MouseEvent e) {
      int selRow = tree.getRowForLocation(e.getX(), e.getY());
      TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());

      if (e.getClickCount() == 2) {
        myDoubleClick(selRow, selPath);
      }
    }
Exemplo n.º 2
0
 /**
  * Handles mouse moved events.
  *
  * @param e the mouse event
  */
 public void mouseMoved(MouseEvent e) {
   TreePath path = tree.getPathForLocation(e.getX(), e.getY());
   if (path == null) return;
   if (e.getX() > tree.getPathBounds(path).x + hotspot - 3
       || e.getX() < tree.getPathBounds(path).x + 2) tree.setCursor(Cursor.getDefaultCursor());
   else {
     tree.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
   }
 }
 @Override
 public boolean isCellEditable(EventObject e) {
   if (e instanceof MouseEvent && e.getSource() instanceof JTree) {
     MouseEvent me = (MouseEvent) e;
     JTree tree = (JTree) e.getSource();
     TreePath path = tree.getPathForLocation(me.getX(), me.getY());
     Rectangle r = tree.getPathBounds(path);
     if (r == null) {
       return false;
     }
     Dimension d = getPreferredSize();
     r.setSize(new Dimension(d.width, r.height));
     if (r.contains(me.getX(), me.getY())) {
       if (str == null && System.getProperty("java.version").startsWith("1.7.0")) {
         setBounds(new Rectangle(0, 0, d.width, r.height));
       }
       // System.out.println(getBounds());
       return true;
     }
   }
   return false;
 }
Exemplo n.º 4
0
    // {{{ mousePressed() method
    @Override
    public void mousePressed(MouseEvent evt) {
      if (evt.isConsumed()) return;

      TreePath path1 = resultTree.getPathForLocation(evt.getX(), evt.getY());
      if (path1 == null) return;

      resultTree.setSelectionPath(path1);
      if (GUIUtilities.isPopupTrigger(evt)) showPopupMenu(evt);
      else {
        goToSelectedNode(M_OPEN);
      }
    } // }}}
Exemplo n.º 5
0
  /**
   * Handles mouse click events.
   *
   * @param e the mouse event
   */
  public void mouseClicked(MouseEvent e) {
    TreePath path = tree.getPathForLocation(e.getX(), e.getY());
    if (path == null) return;
    if (e.getX() > tree.getPathBounds(path).x + hotspot) return;

    boolean selected = selectionModel.isAncestorSelected(path);
    try {
      ignoreEvents = true;
      if (selected) {
        selectionModel.removeSelectionPath(path);
      } else {
        selectionModel.addSelectionPath(path);
      }
    } finally {
      ignoreEvents = false;
      tree.treeDidChange();
    }
  }
Exemplo n.º 6
0
    public void mouseReleased(MouseEvent e) {
      if (e.isPopupTrigger()) {
        DefaultTreeModel model = (DefaultTreeModel) m_tree.getModel();
        TreePath path = m_tree.getSelectionPath();
        if (path != null) {
          DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();

          if (node == model.getRoot()) {
            mi_add.setEnabled(true);
            mi_edit.setEnabled(false);
            mi_delete.setEnabled(false);
          } else {
            mi_add.setEnabled(true);
            mi_edit.setEnabled(true);
            mi_delete.setEnabled(true);
          }

          Rectangle rectangle = m_tree.getPathBounds(path);
          if (rectangle.contains(e.getPoint())) m_popupMenu.show(m_tree, e.getX(), e.getY());
        }
      }
    }
Exemplo n.º 7
0
    // {{{ showPopupMenu method
    private void showPopupMenu(MouseEvent evt) {
      TreePath path = resultTree.getSelectionPath();
      DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();

      popupMenu = new JPopupMenu();
      Object userObj = node.getUserObject();
      if (userObj instanceof HyperSearchFileNode || userObj instanceof HyperSearchResult) {
        popupMenu.add(new GoToNodeAction("hypersearch-results.open", M_OPEN));
        popupMenu.add(new GoToNodeAction("hypersearch-results.open-view", M_OPEN_NEW_VIEW));
        popupMenu.add(
            new GoToNodeAction("hypersearch-results.open-plain-view", M_OPEN_NEW_PLAIN_VIEW));
        popupMenu.add(new GoToNodeAction("hypersearch-results.open-split", M_OPEN_NEW_SPLIT));
      }
      if (!(userObj instanceof HyperSearchFolderNode)) popupMenu.add(new RemoveTreeNodeAction());
      popupMenu.add(new ExpandChildTreeNodesAction());
      if (userObj instanceof HyperSearchFolderNode || userObj instanceof HyperSearchOperationNode) {
        popupMenu.add(new CollapseChildTreeNodesAction());
        if (userObj instanceof HyperSearchFolderNode) popupMenu.add(new NewSearchAction());
      }
      if (userObj instanceof HyperSearchOperationNode) {
        popupMenu.add(new JPopupMenu.Separator());
        HyperSearchOperationNode resultNode = (HyperSearchOperationNode) userObj;
        JCheckBoxMenuItem chkItem =
            new JCheckBoxMenuItem(
                jEdit.getProperty("hypersearch-results.tree-view"),
                resultNode.isTreeViewDisplayed());
        chkItem.addActionListener(new TreeDisplayAction());
        popupMenu.add(chkItem);

        popupMenu.add(new RedoSearchAction((HyperSearchOperationNode) userObj));
      }
      popupMenu.add(new CopyToClipboardAction());

      GUIUtilities.showPopupMenu(popupMenu, evt.getComponent(), evt.getX(), evt.getY());
      evt.consume();
    } // }}}