javax.swing.tree.TreePath.getLastPathComponent()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(200)

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

TreePath.getLastPathComponent介绍

暂无

代码示例

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

public boolean shouldSelectCell(EventObject e) {
 boolean rv = false;  // only mouse events
 if (e instanceof MouseEvent) {
  MouseEvent me = (MouseEvent) e;
  TreePath path = tree.getPathForLocation(me.getX(),
    me.getY());
  CategoryNode node = (CategoryNode)
    path.getLastPathComponent();
  rv = node.isLeaf() /*|| !inCheckBoxHitRegion(me)*/;
 }
 return rv;
}

代码示例来源:origin: kiegroup/optaplanner

@Override
public void mousePressed(MouseEvent e) {
  TreePath path = tree.getPathForLocation(e.getX(), e.getY());
  if (path != null) {
    DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) path.getLastPathComponent();
    MixedCheckBox checkBox = (MixedCheckBox) currentNode.getUserObject();
    // ignore clicks on checkbox's label - enables to select it without changing the state
    if (e.getX() - tree.getPathBounds(path).getX() > unlabeledMixedCheckBoxWidth) {
      return;
    }
    switch (checkBox.getStatus()) {
      case CHECKED:
        resolveNewCheckBoxState(currentNode, UNCHECKED, MIXED);
        break;
      case UNCHECKED:
        resolveNewCheckBoxState(currentNode, CHECKED, MIXED);
        break;
      case MIXED:
        resolveNewCheckBoxState(currentNode, CHECKED, null);
        break;
      default:
        throw new IllegalStateException("The status (" + checkBox.getStatus() + ") is not implemented.");
    }
    tree.treeDidChange();
  }
}

代码示例来源:origin: kiegroup/optaplanner

private CheckBoxTree createCheckBoxTree() {
  final CheckBoxTree resultCheckBoxTree = new CheckBoxTree(initBenchmarkHierarchy(true));
  resultCheckBoxTree.addTreeSelectionListener(e -> {
    TreePath treeSelectionPath = e.getNewLeadSelectionPath();
    if (treeSelectionPath != null) {
      DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) treeSelectionPath.getLastPathComponent();
      MixedCheckBox checkBox = (MixedCheckBox) treeNode.getUserObject();
      detailTextArea.setText(checkBox.getDetail());
      detailTextArea.setCaretPosition(0);
      renameNodeButton.setEnabled(checkBox.getBenchmarkResult() instanceof PlannerBenchmarkResult
          || checkBox.getBenchmarkResult() instanceof SolverBenchmarkResult);
    }
  });
  resultCheckBoxTree.addMouseListener(new MouseAdapter() {
    @Override
    public void mousePressed(MouseEvent e) {
      // Enable button if checked singleBenchmarkResults exist
      generateReportButton.setEnabled(!resultCheckBoxTree.getSelectedSingleBenchmarkNodes().isEmpty());
    }
  });
  checkBoxTree = resultCheckBoxTree;
  return resultCheckBoxTree;
}

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

Object node = path.getLastPathComponent(); 
Object parentNode = parent.getLastPathComponent(); 
  Object node = temp.getLastPathComponent(); 
  Object peekNode = peekPath.getLastPathComponent(); 
  int childCount = model.getChildCount(node); 
  selectionModel = new CheckTreeSelectionModel(tree.getModel()); 
TreePath path = tree.getPathForLocation(me.getX(), me.getY()); 
if(me.getX()/1.2>tree.getPathBounds(path).x+hotspot)

代码示例来源:origin: pentaho/mondrian

.getLastPathComponent()))
lastSelected = e.getPath().getLastPathComponent();
Object o = tpath.getLastPathComponent();
Object po = null;
String elementName = "";
if (parentTpath != null) {
  po = parentTpath.getLastPathComponent();
  Class parentClassName = po.getClass();
  try {
  pNames = DEF_JOIN;
  if (parentName.equalsIgnoreCase("Join")) {
    Object parentJoin = parentTpath.getLastPathComponent();
    int indexOfChild = tree.getModel().getIndexOfChild(
      parentJoin, o);
    switch (indexOfChild) {

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

nodesCheckingState = new HashMap<TreePath, CheckedNode>();
checkedPaths = new HashSet<TreePath>();
DefaultMutableTreeNode node = (DefaultMutableTreeNode)getModel().getRoot();
if (node == null) {
  return;
nodesCheckingState.put(tp, cn);
for (int i = 0 ; i < node.getChildCount() ; i++) {              
  addSubtreeToCheckingStateTracking((DefaultMutableTreeNode) tp.pathByAddingChild(node.getChildAt(i)).getLastPathComponent());
    TreePath tp = selfPointer.getPathForLocation(arg0.getX(), arg0.getY());
    if (tp == null) {
      return;
DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) parentPath.getLastPathComponent();     
parentCheckedNode.allChildrenSelected = true;
parentCheckedNode.isSelected = false;
CheckedNode cn = nodesCheckingState.get(tp);
cn.isSelected = check;
DefaultMutableTreeNode node = (DefaultMutableTreeNode) tp.getLastPathComponent();
for (int i = 0 ; i < node.getChildCount() ; i++) {              
  checkSubTree(tp.pathByAddingChild(node.getChildAt(i)), check);

代码示例来源:origin: pentaho/mondrian

public Object getParentObject() {
  TreePath tPath = tree.getSelectionPath();
  if ((tPath != null) && (tPath.getParentPath() != null)) {
    return tPath.getParentPath().getLastPathComponent();
  }
  return null;
}

代码示例来源:origin: org.jrobin/jrobin

private RrdNode getSelectedRrdNode() {
  TreePath path = mainTree.getSelectionPath();
  if (path != null) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
    Object obj = node.getUserObject();
    if (obj instanceof RrdNode) {
      return (RrdNode) obj;
    }
  }
  return null;
}

代码示例来源:origin: pentaho/mondrian

protected void arrowButtonDownAction(ActionEvent evt) {
  TreePath tpath = tree.getSelectionPath();
  if (tpath != null) {
    Object current = tpath.getLastPathComponent();
    Object child = tree.getModel().getChild(current, 0);
    if (child != null) {
      Object[] treeObjs = new Object[30];
      int objCnt = 2;
      while (parentpath != null) {
        Object po = parentpath.getLastPathComponent();
        treeObjs[objCnt] = po;
        objCnt += 1;

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

(DefaultMutableTreeNode)dest.getLastPathComponent();
TreePath path = tree.getPathForRow(selRows[0]);
DefaultMutableTreeNode firstNode =
  (DefaultMutableTreeNode)path.getLastPathComponent();
if(firstNode.getChildCount() > 0 &&
    target.getLevel() < firstNode.getLevel()) {
TreePath path = tree.getPathForRow(selRows[0]);
DefaultMutableTreeNode first =
  (DefaultMutableTreeNode)path.getLastPathComponent();
int childCount = first.getChildCount();
  path = tree.getPathForRow(selRows[i]);
  DefaultMutableTreeNode next =
    (DefaultMutableTreeNode)path.getLastPathComponent();
  if(first.isNodeChild(next)) {
    new ArrayList<DefaultMutableTreeNode>();
  DefaultMutableTreeNode node =
    (DefaultMutableTreeNode)paths[0].getLastPathComponent();
  DefaultMutableTreeNode copy = copy(node);
  copies.add(copy);
  for(int i = 1; i < paths.length; i++) {
    DefaultMutableTreeNode next =
      (DefaultMutableTreeNode)paths[i].getLastPathComponent();
TreePath dest = dl.getPath();
DefaultMutableTreeNode parent =

代码示例来源:origin: kaikramer/keystore-explorer

private X509Certificate getSelectedCertificate() {
  TreePath[] selections = jtrHierarchy.getSelectionPaths();
  if (selections == null) {
    return null;
  }
  return (X509Certificate) ((DefaultMutableTreeNode) selections[0].getLastPathComponent()).getUserObject();
}

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

@Override
public String getToolTipText(MouseEvent e) {
  if (getRowForLocation(e.getX(), e.getY()) == -1) {
    return null;
  }
  TreePath curPath = getPathForLocation(e.getX(), e.getY());
  if (curPath.getLastPathComponent() instanceof ASTTreeNode) {
    return ((ASTTreeNode) curPath.getLastPathComponent()).getToolTipText();
  } else {
    return super.getToolTipText(e);
  }
}

代码示例来源:origin: ron190/jsql-injection

/**
 * Fix compatibility issue with right click on Linux.
 * @param e Mouse event
 */
private void showPopup(MouseEvent e) {
  if (e.isPopupTrigger()) {
    JTree tree = (JTree) e.getSource();
    TreePath path = tree.getPathForLocation(e.getX(), e.getY());
    if (path == null) {
      return;
    }
    DefaultMutableTreeNode currentTableNode = (DefaultMutableTreeNode) path.getLastPathComponent();
    if (currentTableNode.getUserObject() instanceof AbstractNodeModel) {
      AbstractNodeModel currentTableModel = (AbstractNodeModel) currentTableNode.getUserObject();
      if (currentTableModel.isPopupDisplayable()) {
        currentTableModel.showPopup(currentTableNode, path, e);
      }
    }
  }
}

代码示例来源:origin: kiegroup/optaplanner

@Override
  public void actionPerformed(ActionEvent e) {
    if (checkBoxTree.getSelectionPath() != null) {
      DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) checkBoxTree.getSelectionPath().getLastPathComponent();
      MixedCheckBox mixedCheckBox = (MixedCheckBox) selectedNode.getUserObject();
      if (mixedCheckBox.getBenchmarkResult() instanceof PlannerBenchmarkResult
          || mixedCheckBox.getBenchmarkResult() instanceof SolverBenchmarkResult) {
        RenameNodeDialog renameNodeDialog = new RenameNodeDialog(selectedNode);
        renameNodeDialog.pack();
        renameNodeDialog.setLocationRelativeTo(BenchmarkAggregatorFrame.this);
        renameNodeDialog.setVisible(true);
      }
    }
  }
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-languages

public void mouseClicked (MouseEvent ev) {
  if (ev.getClickCount () != 2) return;
  TreePath path = tree.getPathForLocation 
    (ev.getX (), ev.getY ());
  if (path == null) return;
  Object node = path.getLastPathComponent ();
  LanguagesNavigatorModel model = (LanguagesNavigatorModel) tree.getModel ();
  model.show (node);
}

代码示例来源:origin: pentaho/mondrian

TreePath parentpath = tpath.getParentPath();
if (parentpath != null) {
  Object parent = parentpath.getLastPathComponent();
  if (parent instanceof MondrianGuiDef.Join) {
    int indexOfChild = tree.getModel().getIndexOfChild(
      parent, value);
    switch (indexOfChild) {

代码示例来源:origin: pentaho/mondrian

protected void addAnnotations(ActionEvent evt) {
  TreePath tpath = null;
  tpath = getTreePath(evt);
  Object path = tree.getSelectionPath().getLastPathComponent();
  refreshTree(tree.getSelectionPath());

代码示例来源:origin: org.fusesource.rrd4j/rrd4j

private RrdNode getSelectedRrdNode() {
  TreePath path = mainTree.getSelectionPath();
  if (path != null) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
    Object obj = node.getUserObject();
    if (obj instanceof RrdNode) {
      return (RrdNode) obj;
    }
  }
  return null;
}

代码示例来源:origin: pentaho/mondrian

TreePath tpath = tree.getSelectionPath();
if (tpath != null) {
  Object value = tpath.getLastPathComponent();
  TreePath parentpath = tpath.getParentPath();
  if (parentpath != null) {
    Object parent = parentpath.getLastPathComponent();
    if (parent instanceof MondrianGuiDef.Hierarchy) {
      ((MondrianGuiDef.Hierarchy) parent).relation = relationObj;
    } else if (parent instanceof MondrianGuiDef.Join) {
      int indexOfChild =
        tree.getModel().getIndexOfChild(parent, value);
      switch (indexOfChild) {
      case 0:

代码示例来源: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());
    }
  }
});

相关文章