Exemplo n.º 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));
   }
 }
Exemplo n.º 2
0
 @Nullable
 public static Object getTagAtForRenderer(
     CheckboxTree.CheckboxTreeCellRenderer renderer, MouseEvent e) {
   JTree tree = (JTree) e.getSource();
   Object tag = null;
   final TreePath path = tree.getPathForLocation(e.getX(), e.getY());
   if (path != null) {
     final Rectangle rectangle = tree.getPathBounds(path);
     assert rectangle != null;
     int dx = e.getX() - rectangle.x;
     final TreeNode treeNode = (TreeNode) path.getLastPathComponent();
     final int row = tree.getRowForLocation(e.getX(), e.getY());
     tree.getCellRenderer()
         .getTreeCellRendererComponent(tree, treeNode, false, false, true, row, true);
     if (treeNode instanceof RepositoryNode) {
       RepositoryNode repositoryNode = (RepositoryNode) treeNode;
       int checkBoxWidth =
           repositoryNode.isCheckboxVisible() ? renderer.getCheckbox().getWidth() : 0;
       tag = renderer.getTextRenderer().getFragmentTagAt(dx - checkBoxWidth);
     } else {
       tag = renderer.getTextRenderer().getFragmentTagAt(dx);
     }
   }
   return tag;
 }
Exemplo n.º 3
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.º 4
0
 public static RelativePoint getPointForPath(JTree aTree, TreePath path) {
   final Rectangle rowBounds = aTree.getPathBounds(path);
   rowBounds.x += 20;
   return getPointForBounds(aTree, rowBounds);
 }