@Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { TreePath path = tree.getClosestPathForLocation(e.getX(), e.getY()); tree.setSelectionPath(path); JPopupMenu menu = new ASTNodePopupMenu(model, (Node) path.getLastPathComponent()); menu.show(tree, e.getX(), e.getY()); } } });
private Object getSelectedNodeObj(MouseEvent e){ TreePath tp = tree.getClosestPathForLocation(e.getX(), e.getY()); tree.setSelectionPath(tp); return tp.getLastPathComponent(); }
public TreePath getPathFor(MouseEvent e) { int x = e.getX(); int y = e.getY(); TreePath path = navigationTree.getClosestPathForLocation(x,y); Rectangle rect = navigationTree.getPathBounds(path); if (rect.contains(x, y)) { return path; } return null; }
public VObject getObjectAt (Point point) { VObject object = null; TreePath treePath = tree_.getClosestPathForLocation (point.x, point.y); Rectangle pathBounds = tree_.getPathBounds (treePath); if (pathBounds.contains (point)) object = (VObject) treePath.getLastPathComponent (); return object; }
@Override public void mouseClicked(final MouseEvent me) { if (SwingUtilities.isRightMouseButton(me)) { currentPopupNode = (HistoryNode) tree.getClosestPathForLocation(me.getX(), me.getY()).getLastPathComponent(); HistoryPanel.this.popup.show(me.getComponent(), me.getX(), me.getY()); } else if (mouseWasOverPanel) { final TreePath clickedPath = new TreePath( ((HistoryNode) tree.getClosestPathForLocation(me.getX(), me.getY()).getLastPathComponent()).getPath()); adaptStayExpandedPathsOnClickedPath(clickedPath); } }
@Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { TreePath path = tree.getClosestPathForLocation(e.getX(), e.getY()); tree.setSelectionPath(path); JPopupMenu menu = new ASTNodePopupMenu(model, (Node) path.getLastPathComponent()); menu.show(tree, e.getX(), e.getY()); } } });
@Override public void mousePressed(MouseEvent e) { TreePath path = treeParam.getClosestPathForLocation(e.getX(), e.getY()); if (path != null && !treeParam.isPathSelected(path)) { treeParam.setSelectionPath(path); } } });
private void showPopupIfNecessary(MouseEvent event) { Point point = event.getPoint(); TreePath path = this.tree.getClosestPathForLocation(point.x, point.y); this.tree.setSelectionPath(path); if (path.getPathCount() >= 2) { this.popup.show(event.getComponent(), point.x, point.y); } }
@Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() != 2) { return; } JTree tree = (JTree) e.getSource(); TreePath path = tree.getClosestPathForLocation(e.getX(), e.getY()); Object treeNode = path.getLastPathComponent(); if (treeNode instanceof TestEvent) { TestEvent event = (TestEvent) treeNode; navigator.open(classFor(event)).line(lineFor(event)); } }
@Override public void mousePressed(MouseEvent e) { if (!tree.isEnabled()) return; TreePath closestPath = tree.getClosestPathForLocation(e.getX(), e .getY()); if (closestPath == null) return; Rectangle bounds = tree.getPathBounds(closestPath); // Process events outside the immediate bounds - fix for defect // 19 on substance-netbeans. This properly handles Ctrl and Shift // selections on trees. if ((e.getY() >= bounds.y) && (e.getY() < (bounds.y + bounds.height)) && ((e.getX() < bounds.x) || (e.getX() > (bounds.x + bounds.width)))) { // tree.setSelectionPath(closestPath); // fix - don't select a node if the click was on the // expand control if (isLocationInExpandControl(closestPath, e.getX(), e.getY())) return; selectPathForEvent(closestPath, e); } } }
public void mouseClicked(MouseEvent e){ if (SwingUtilities.isRightMouseButton(e)){ TreePath path = tree.getClosestPathForLocation(e.getX(), e.getY()); tree.setSelectionPath(path); tree.scrollPathToVisible(path); popup.show(tree, e.getX(), e.getY()); } } });
@Override public void mousePressed(MouseEvent e) { if (!tree.isEnabled()) return; TreePath closestPath = tree.getClosestPathForLocation(e.getX(), e .getY()); if (closestPath == null) return; Rectangle bounds = tree.getPathBounds(closestPath); // Process events outside the immediate bounds - fix for defect // 19 on substance-netbeans. This properly handles Ctrl and Shift // selections on trees. if ((e.getY() >= bounds.y) && (e.getY() < (bounds.y + bounds.height)) && ((e.getX() < bounds.x) || (e.getX() > (bounds.x + bounds.width)))) { // tree.setSelectionPath(closestPath); // fix - don't select a node if the click was on the // expand control if (isLocationInExpandControl(closestPath, e.getX(), e.getY())) return; selectPathForEvent(closestPath, e); } } }
/** * Listener for selecting the entire rows. * * @param e * the e * @author Kirill Grouchnikov */ @Override public void mousePressed(MouseEvent e) { if (!tree.isEnabled()) return; TreePath closestPath = tree.getClosestPathForLocation(e.getX(), e.getY()); if (closestPath == null) return; Rectangle bounds = tree.getPathBounds(closestPath); // Process events outside the immediate bounds - // This properly handles Ctrl and Shift // selections on trees. if ((e.getY() >= bounds.y) && (e.getY() < (bounds.y + bounds.height)) && ((e.getX() < bounds.x) || (e.getX() > (bounds.x + bounds.width)))) { // fix - don't select a node if the click was on the // expand control if (isLocationInExpandControl(closestPath, e.getX(), e.getY())) { return; } selectPathForEvent(closestPath, e); } } }
@Override public TreePath getClosestPathForLocation(TreeTable treeTable, int x, int y) { return tree.getClosestPathForLocation(x-tree.getX(), y-tree.getY()); }
public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { TreePath tp = tree.getClosestPathForLocation(e.getX(),e.getY()); if (tp != null) { System.out.println(tp);
TreePath closestPath = tree.getClosestPathForLocation(e.getX(), e .getY()); Rectangle bounds = tree.getPathBounds(closestPath);
private void onClick(MouseEvent e) { if (highlightSource) { TreePath path = myTree.getClosestPathForLocation(e.getX(), e.getY()); if (path == null) { return; } DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Tree tree = (Tree) node.getUserObject(); int startIndex; int stopIndex; if (tree instanceof ParserRuleContext) { startIndex = ((ParserRuleContext) tree).getStart().getStartIndex(); stopIndex = ((ParserRuleContext) tree).getStop().getStopIndex(); } else if (tree instanceof TerminalNode) { startIndex = ((TerminalNode) tree).getSymbol().getStartIndex(); stopIndex = ((TerminalNode) tree).getSymbol().getStopIndex(); } else { return; } Editor editor = previewPanel.inputPanel.getInputEditor(); editor.getSelectionModel().removeSelection(); editor.getSelectionModel().setSelection(startIndex, stopIndex + 1); } } }
private void showJTree (JScrollPane view, Point pt) { JTree tree = (JTree) view.getViewport().getView(); Point p = SwingUtilities.convertPoint(view, pt.x, pt.y, tree); int row = tree.getClosestRowForLocation(p.x, p.y); TreePath path = tree.getClosestPathForLocation(p.x, p.y); Rectangle bds = tree.getPathBounds(path); if (bds == null || !bds.contains(p)) { hide(); return; } if (setCompAndRow (tree, row)) { Rectangle visible = getShowingRect (view); Rectangle[] rects = getRects (bds, visible); if (rects.length > 0) { ensureOldPopupsHidden(); painter.configure(path.getLastPathComponent(), view, tree, path, row); showPopups (rects, bds, visible, tree, view); } else { hide(); } } }
@Override public JTreeLocation call() { JTree tree = (JTree)c; if (tree.getRowCount() == 0) return new JTreeLocation(p); Rectangle rect = tree.getRowBounds(tree.getRowCount()-1); int maxY = rect.y + rect.height; if (p.y > maxY) return new JTreeLocation(p); // TODO: ignore clicks to the left of the expansion control, or maybe // embed them in the location. TreePath path = tree.getClosestPathForLocation(p.x, p.y); TreePath stringPath = pathToStringPath(tree, path); if (stringPath != null) { // if the root is hidden, drop it from the path if (!tree.isRootVisible()) { Object[] objs = stringPath.getPath(); Object[] subs = new Object[objs.length-1]; System.arraycopy(objs, 1, subs, 0, subs.length); stringPath = new TreePath(subs); } return new JTreeLocation(stringPath); } int row = tree.getClosestRowForLocation(p.x, p.y); if (row != -1) { return new JTreeLocation(row); } return new JTreeLocation(p); } });