Java Code Examples for javax.swing.JTree#getRowForLocation()

The following examples show how to use javax.swing.JTree#getRowForLocation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CheckBoxTreeNodeSelectionListener.java    From rest-client with Apache License 2.0 6 votes vote down vote up
@Override
public void mouseClicked(MouseEvent event)
{
    JTree tree = (JTree) event.getSource();
    int x = event.getX();
    int y = event.getY();
    int row = tree.getRowForLocation(x, y);
    TreePath path = tree.getPathForRow(row);
    if (null == path)
    {
        return;
    }

    CheckBoxTreeNode node = (CheckBoxTreeNode) path.getLastPathComponent();
    if (null == node)
    {
        return;
    }

    boolean selected = !node.isSelected();
    node.setSelected(selected);
    ((DefaultTreeModel) tree.getModel()).nodeStructureChanged(node);
}
 
Example 2
Source File: IMContactDoubleClicker.java    From SmartIM with Apache License 2.0 6 votes vote down vote up
@Override
public void mouseClicked(MouseEvent e) {
    super.mouseClicked(e);
    JTree tree = (JTree)e.getSource();
    int selRow = tree.getRowForLocation(e.getX(), e.getY());
    TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
    if (selRow != -1 && selPath != null) {
        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)selPath.getLastPathComponent();
        if (selectedNode.getChildCount() > 0) {
            if (tree.isExpanded(selPath)) {
                tree.collapsePath(selPath);
            } else {
                tree.expandPath(selPath);
            }
            return;
        }
        if (imPanel != null && e.getClickCount() == 2) {
            imPanel.onDoubleClick(((DefaultMutableTreeNode)selectedNode).getUserObject());
        }
    }
}
 
Example 3
Source File: CheckNodeListener.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void mousePressed(MouseEvent event) {
    JTree tree = (JTree) event.getSource();
    int x = event.getX();
    int y = event.getY();

    int row = tree.getRowForLocation(x, y);
    TreePath path = tree.getPathForRow(row);

    // if path exists and mouse is clicked exactly once
    if (path == null) {
        return;
    }
    CheckNode node = (CheckNode) path.getLastPathComponent();

    if ( !SwingUtilities.isRightMouseButton(event)) {
        return;
    }
    Object o = node.getUserObject();

}
 
Example 4
Source File: RevertDeletedAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void mouseClicked(MouseEvent e) {
    JTree tree = (JTree) e.getSource();
    Point p = e.getPoint();
    int row = tree.getRowForLocation(e.getX(), e.getY());
    TreePath path = tree.getPathForRow(row);
    
    // if path exists and mouse is clicked exactly once
    if (path != null) {
        FileNode node = (FileNode) path.getLastPathComponent();
        Rectangle chRect = DeletedListRenderer.getCheckBoxRectangle();
        Rectangle rowRect = tree.getPathBounds(path);
        chRect.setLocation(chRect.x + rowRect.x, chRect.y + rowRect.y);
        if (e.getClickCount() == 1 && chRect.contains(p)) {
            boolean isSelected = !(node.isSelected());
            node.setSelected(isSelected);
            ((DefaultTreeModel) tree.getModel()).nodeChanged(node);
            if (row == 0) {
                tree.revalidate();
            }
            tree.repaint();
        }
    }
}
 
Example 5
Source File: CatalogPanel.java    From DiskBrowser with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void mousePressed (MouseEvent e)
// -------------------------------------------------------------------------------//
{
  JTree tree = (JTree) e.getSource ();
  int selRow = tree.getRowForLocation (e.getX (), e.getY ());
  if (selRow < 0)
    return;

  TreePath tp = tree.getPathForLocation (e.getX (), e.getY ());
  DefaultMutableTreeNode selectedNode =
      (DefaultMutableTreeNode) tp.getLastPathComponent ();
  FileNode node = (FileNode) selectedNode.getUserObject ();
  if (node.file.isDirectory ())
  {
    //        lister.catalogLister.setNode (selectedNode);
  }
  else if (e.getClickCount () == 2)
    addDiskPanel (node.getFormattedDisk (), true);
}
 
Example 6
Source File: CheckBoxTreeNodeSelectionListener.java    From SmartIM with Apache License 2.0 5 votes vote down vote up
@Override
public void mouseClicked(MouseEvent event) {
    JTree tree = (JTree)event.getSource();
    int x = event.getX();
    int y = event.getY();
    int row = tree.getRowForLocation(x, y);
    TreePath path = tree.getPathForRow(row);
    if (path != null) {
        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)path.getLastPathComponent();
        if (selectedNode != null && selectedNode.getChildCount() > 0 && event.getClickCount() > 1) {
            // if (tree.isExpanded(path)) {
            // tree.collapsePath(path);
            // }
            // else {
            // tree.expandPath(path);
            // }
            return;
        } else if (selectedNode instanceof CheckBoxTreeNode && event.getClickCount() == 1) {
            CheckBoxTreeNode node = (CheckBoxTreeNode)selectedNode;
            if (node != null) {
                boolean isSelected = !node.isSelected();
                node.setSelected(isSelected);
                ((DefaultTreeModel)tree.getModel()).nodeStructureChanged(node);
            }
        }
    }
}
 
Example 7
Source File: CheckListener.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void mouseClicked(MouseEvent e) {
    // todo (#pf): we need to solve problem between click and double
    // click - click should be possible only on the check box area
    // and double click should be bordered by title text.
    // we need a test how to detect where the mouse pointer is
    JTree tree = (JTree) e.getSource();
    Point p = e.getPoint();
    int x = e.getX();
    int y = e.getY();
    int row = tree.getRowForLocation(x, y);
    TreePath path = tree.getPathForRow(row);

    // if path exists and mouse is clicked exactly once
    if (path == null) {
        return;
    }

    Node node = Visualizer.findNode(path.getLastPathComponent());
    if (node == null) {
        return;
    }

    Rectangle chRect = CheckRenderer.getCheckBoxRectangle();
    Rectangle rowRect = tree.getPathBounds(path);
    chRect.setLocation(chRect.x + rowRect.x, chRect.y + rowRect.y);
    if (e.getClickCount() == 1 && chRect.contains(p)) {
        boolean isSelected = model.isNodeSelected(node);
        model.setNodeSelected(node, !isSelected);
        tree.repaint();
    }
}
 
Example 8
Source File: CheckNodeListener.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void mousePressed(MouseEvent event) {
    JTree tree = (JTree) event.getSource();
    int x = event.getX();
    int y = event.getY();

    int row = tree.getRowForLocation(x, y);
    TreePath path = tree.getPathForRow(row);

    // if path exists and mouse is clicked exactly once
    if (path == null) {
        return;
    }
    CheckNode node = (CheckNode) path.getLastPathComponent();

    if ( !SwingUtilities.isRightMouseButton(event)) {
        return;
    }
    Object o = node.getUserObject();

    if ( !(o instanceof TreeElement)) {
        return;
    }
    o = ((TreeElement) o).getUserObject();

    if (o instanceof RefactoringElement) {
        showPopup(((RefactoringElement) o).getLookup().lookupAll(Action.class), tree, x, y);
    }
}
 
Example 9
Source File: CheckListener.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void mouseClicked(MouseEvent e) {
    // todo (#pf): we need to solve problem between click and double
    // click - click should be possible only on the check box area
    // and double click should be bordered by title text.
    // we need a test how to detect where the mouse pointer is
    JTree tree = (JTree) e.getSource();
    Point p = e.getPoint();
    int x = e.getX();
    int y = e.getY();
    int row = tree.getRowForLocation(x, y);
    TreePath path = tree.getPathForRow(row);

    // if path exists and mouse is clicked exactly once
    if( null == path )
        return;
    
    Node node = Visualizer.findNode( path.getLastPathComponent() );
    if( null == node )
        return;
    
    Rectangle chRect = CheckRenderer.getCheckBoxRectangle();
    Rectangle rowRect = tree.getPathBounds(path);
    chRect.setLocation(chRect.x + rowRect.x, chRect.y + rowRect.y);
    if (e.getClickCount() == 1 && chRect.contains(p)) {
        boolean isSelected = settings.isNodeVisible( node );
        settings.setNodeVisible( node, !isSelected );
        tree.repaint();
    }
}