javax.swing.JTree.getClosestPathForLocation()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(110)

本文整理了Java中javax.swing.JTree.getClosestPathForLocation()方法的一些代码示例,展示了JTree.getClosestPathForLocation()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTree.getClosestPathForLocation()方法的具体详情如下:
包路径:javax.swing.JTree
类名称:JTree
方法名:getClosestPathForLocation

JTree.getClosestPathForLocation介绍

暂无

代码示例

代码示例来源:origin: pmd/pmd

@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());
    }
  }
});

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-vmd-game

private Object getSelectedNodeObj(MouseEvent e){
  TreePath tp = tree.getClosestPathForLocation(e.getX(), e.getY());
  tree.setSelectionPath(tp);
  return tp.getLastPathComponent();
}

代码示例来源:origin: sdedit/sdedit

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;
}

代码示例来源:origin: net.sf.jt400/jt400

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;
}

代码示例来源:origin: triplea-game/triplea

@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);
 }
}

代码示例来源:origin: net.sourceforge.pmd/pmd-core

@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());
    }
  }
});

代码示例来源:origin: org.zaproxy/zap

@Override
  public void mousePressed(MouseEvent e) {
    TreePath path = treeParam.getClosestPathForLocation(e.getX(), e.getY());
    if (path != null && !treeParam.isPathSelected(path)) {
      treeParam.setSelectionPath(path);
    }
  }
});

代码示例来源:origin: org.apache.airavata/airavata-xbaya-gui

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);
  }
}

代码示例来源:origin: infinitest/infinitest

@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));
  }
}

代码示例来源:origin: com.github.insubstantial/substance

@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);
    }
  }
}

代码示例来源:origin: apache/felix

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());
    }
  }
});

代码示例来源:origin: org.java.net.substance/substance

@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);
    }
  }
}

代码示例来源:origin: tinyMediaManager/tinyMediaManager

/**
  * 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);
  }
 }
}

代码示例来源:origin: de.sciss/jtreetable

@Override
public TreePath getClosestPathForLocation(TreeTable treeTable, int x, int y) {
  return tree.getClosestPathForLocation(x-tree.getX(), y-tree.getY());
}

代码示例来源:origin: stackoverflow.com

public void mouseReleased(MouseEvent e) {
  if (e.isPopupTrigger()) {
    TreePath tp = tree.getClosestPathForLocation(e.getX(),e.getY());
    if (tp != null) {
      System.out.println(tp);

代码示例来源:origin: org.java.net.substance/substance

TreePath closestPath = tree.getClosestPathForLocation(e.getX(), e
    .getY());
Rectangle bounds = tree.getPathBounds(closestPath);

代码示例来源:origin: antlr/intellij-plugin-v4

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);
    }
  }
}

代码示例来源:origin: jpcsp/jpcsp

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();
    }
  }
}

代码示例来源:origin: org.netbeans.api/org-openide-explorer

tree.getClosestPathForLocation(p.x, 
p.y);

代码示例来源:origin: abbot/abbot

@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);
  }
});

相关文章

JTree类方法