示例#1
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));
   }
 }
示例#2
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();
    }
  }