There are 20 code examples for javax.swing.tree.TreePath.

The API names are highlighted below. You can use suckoo button to vote the code example(s) you like. The best code example will be ranked first next time. Thanks a lot for your feedback.

Project Name: druid Package: org.dlib.gui.treetable

Source Code: TreeTableCellEditor.java (Click to view .java file)

Method Code:
vote
like

public boolean isCellEditable(EventObject e){
  if (table.getSelectedRowCount() > 1)   return false;
  if (e == null) {
    TreePath path=tree.getSelectionPath();
    TreeViewModel model=(TreeViewModel)tree.getModel();
    if (model.isEditable(path.getLastPathComponent())) {
      tree.startEditingAtSelectedPath();
      return true;
    }
  }
 else   if (e instanceof MouseEvent) {
    MouseEvent me=(MouseEvent)e;
    int newX=getLocalX(me.getX());
    MouseEvent newME=new MouseEvent(tree,me.getID(),me.getWhen(),me.getModifiers(),newX,me.getY(),me.getClickCount(),me.isPopupTrigger());
    tree.dispatchEvent(newME);
    TreePath path=tree.getPathForLocation(newX,me.getY());
    if (path == null)     return false;
    return me.getClickCount() >= 2;
  }
  return false;
}
 

Project Name: druid Package: org.dlib.gui.treetable

Source Code: TreeViewProxy.java (Click to view .java file)

Method Code:
vote
like

public void expandPath(TreePath path){
  table.getTreeView().expandPath(path);
}
 

Project Name: druid Package: org.dlib.gui.treetable

Source Code: TreeTable.java (Click to view .java file)

Method Code:
vote
like

public void setSelectionPaths(TreePath[] paths){
  if (paths == null || paths.length == 0) {
    clearSelection();
    return;
  }
  ArrayList<Integer> alRows=new ArrayList<Integer>();
  for (  TreePath path : paths) {
    int row=treeView.getRowForPath(path);
    if (row != -1)     alRows.add(row);
  }
  if (alRows.size() == 0) {
    clearSelection();
    return;
  }
  int rows[]=new int[alRows.size()];
  for (int i=0; i < alRows.size(); i++)   rows[i]=alRows.get(i);
  setRowSelection(rows);
}
 

Project Name: druid Package: org.dlib.gui.treetable

Source Code: TreeTable.java (Click to view .java file)

Method Code:
vote
like

public void setSelectionPaths(TreePath[] paths){
  if (paths == null || paths.length == 0) {
    clearSelection();
    return;
  }
  ArrayList<Integer> alRows=new ArrayList<Integer>();
  for (  TreePath path : paths) {
    int row=treeView.getRowForPath(path);
    if (row != -1)     alRows.add(row);
  }
  if (alRows.size() == 0) {
    clearSelection();
    return;
  }
  int rows[]=new int[alRows.size()];
  for (int i=0; i < alRows.size(); i++)   rows[i]=alRows.get(i);
  setRowSelection(rows);
}
 

Project Name: druid Package: org.dlib.gui.treetable

Source Code: InternalModelListener.java (Click to view .java file)

Method Code:
vote
like

public void treeNodesInserted(final TreeModelEvent e){
  TreeView tree=table.getTreeView();
  InternalTableModel model=(InternalTableModel)table.getModel();
  TreePath parent=e.getTreePath();
  if (!tree.isRootVisible())   tree.expandRoot();
  for (  Object child : e.getChildren()) {
    TreePath path=parent.pathByAddingChild(child);
    int row=tree.getRowForPath(path);
    model.fireTableRowInserted(row);
  }
}
 

Project Name: druid Package: org.dlib.gui.treeview

Source Code: TreeDropTargetListener.java (Click to view .java file)

Method Code:
vote
like

private AcceptType discoverAcceptType(Point p,int dropAction,Map<DataFlavor,Object> data){
  AcceptType result=AcceptType.INSIDE;
  if (p.y - currRect.y <= currRect.height / 4)   result=AcceptType.BEFORE;
 else   if (p.y - currRect.y >= 3 * currRect.height / 4)   result=AcceptType.AFTER;
  if (dropHandler.acceptDrop(data,currPath,result,dropAction))   return result;
 else   if (result == AcceptType.INSIDE) {
    if (p.y - currRect.y <= currRect.height / 2)     result=AcceptType.BEFORE;
 else     result=AcceptType.AFTER;
    if (dropHandler.acceptDrop(data,currPath,result,dropAction))     return result;
  }
 else   if (result == AcceptType.BEFORE || result == AcceptType.AFTER) {
    result=AcceptType.INSIDE;
    if (dropHandler.acceptDrop(data,currPath,result,dropAction))     return result;
  }
  return AcceptType.NONE;
}
 

Project Name: druid Package: org.dlib.gui.treeview

Source Code: InternalCellRenderer.java (Click to view .java file)

Method Code:
vote
like

/** 
 * This method is required for the TreeCellEditor to show proper icons 
 */
public Icon getClosedIcon(){
  TreePath path=treeView.getSelectionPath();
  if (path == null)   return null;
  Object obj=path.getLastPathComponent();
  Component c=treeCellRend.getTreeCellRendererComponent(treeView,obj,true,treeView.isExpanded(path),false,treeView.getRowForPath(path),true);
  return ((JLabel)c).getIcon();
}
 

Project Name: druid Package: org.dlib.gui.treeview

Source Code: TreeViewNode.java (Click to view .java file)

Method Code:
vote
like

public void makeVisible(){
  TreePath p=new TreePath(getPath());
  tree().scrollPathToVisible(p);
}
 

Project Name: druid Package: org.dlib.gui.treeview

Source Code: InternalMouseListener.java (Click to view .java file)

Method Code:
vote
like

public void mousePressed(MouseEvent e){
  if (!tree.isFocusOwner())   tree.requestFocusInWindow();
  if (e.isMetaDown()) {
    TreePath path=tree.getPathForLocation(e.getX(),e.getY());
    Object obj=null;
    if (path != null) {
      obj=path.getLastPathComponent();
      tree.setSelectionPath(path);
    }
 else {
      tree.clearSelection();
    }
    if (tree.getPopupGen() == null)     return;
    JPopupMenu popup=tree.getPopupGen().generate(obj);
    if (popup == null)     return;
    if (popup.getComponentCount() != 0)     popup.show(tree,e.getX(),e.getY());
  }
 else {
    tree.setSuperEditable(false);
    Object selObj=tree.getLastSelectedPathComponent();
    if (selObj == null)     return;
    if (e.getClickCount() == 2 && editable) {
      boolean canEdit=true;
      if (tree.getModel() instanceof TreeViewModel) {
        TreeViewModel model=(TreeViewModel)tree.getModel();
        canEdit=model.isEditable(selObj);
      }
      if (canEdit)       tree.startEditingAtSelectedPath();
    }
  }
}
 

Project Name: druid Package: org.dlib.gui.treeview

Source Code: AbstractTVDropManager.java (Click to view .java file)

Method Code:
vote
like

private boolean checkTreePaths(TreePath paths[]){
  for (  TreePath path1 : paths)   for (  TreePath path2 : paths)   if (!path1.equals(path2))   if (path1.isDescendant(path2))   return false;
  return true;
}
 

Project Name: druid Package: org.dlib.gui.treeview

Source Code: AbstractTVDropManager.java (Click to view .java file)

Method Code:
vote
like

private boolean checkTreePaths(TreePath paths[]){
  for (  TreePath path1 : paths)   for (  TreePath path2 : paths)   if (!path1.equals(path2))   if (path1.isDescendant(path2))   return false;
  return true;
}
 

Project Name: druid Package: org.dlib.gui.treeview

Source Code: TreeViewPathTransfer.java (Click to view .java file)

Method Code:
vote
like

public TreePath[] getDragPaths(){
  return dragPaths;
}
 

Project Name: druid Package: org.dlib.gui.treeview

Source Code: TreeView.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Enable the drag action in a drag'n'drop.
 * @param actions a bitwise mask of DndConstants values, like ACTION_MOVE, ACTION_COPY, ACTION_LINK
 * @param listener listener to be notified when the drop action ends on success 
 */
public void setDragPathEnabled(int actions,final DragSourceListener listener){
  DragGestureListener dgl=new DragGestureListener(){
    public void dragGestureRecognized(    DragGestureEvent e){
      TreePath paths[]=getSelectionPaths();
      if (paths != null)       e.startDrag(null,new TreeViewPathTransfer(TreeView.this,paths),listener);
    }
  }
;
  DragSource dragSource=DragSource.getDefaultDragSource();
  dragSource.createDefaultDragGestureRecognizer(this,actions,dgl);
}
 

Project Name: druid Package: org.dlib.gui.treeview

Source Code: TreeView.java (Click to view .java file)

Method Code:
vote
like

public void dragGestureRecognized(DragGestureEvent e){
  TreePath paths[]=getSelectionPaths();
  if (paths != null)   e.startDrag(null,new TreeViewPathTransfer(TreeView.this,paths),listener);
}
 

Project Name: druid Package: org.dlib.gui.treeview

Source Code: TreeView.java (Click to view .java file)

Method Code:
vote
like

public void startEditingAtSelectedPath(){
  TreePath path=getSelectionPath();
  if (path == null)   return;
  setSuperEditable(true);
  startEditingAtPath(path);
  String text=path.getLastPathComponent().toString();
  Component c=getCellEditor().getTreeCellEditorComponent(this,text,false,false,false,0);
  if (c instanceof Container) {
    c=((Container)c).getComponent(0);
    if (c instanceof JTextField) {
      JTextField txt=(JTextField)c;
      Caret car=txt.getCaret();
      Document doc=txt.getDocument();
      car.setDot(0);
      car.moveDot(doc.getLength());
    }
  }
}
 

Project Name: rmoffice Package: net.sf.rmoffice.ui

Source Code: RMFrame.java (Click to view .java file)

Method Code:
vote
like

/** 
 */
private void addCurrentSelectedISkill(boolean withModifiedName){
  TreePath selectionPath=skillsSelectionTree.getSelectionPath();
  if (selectionPath != null) {
    Object lastPathComponent=selectionPath.getLastPathComponent();
    if (lastPathComponent != null && lastPathComponent instanceof SkillTreeNode) {
      SkillTreeNode node=(SkillTreeNode)lastPathComponent;
      if (node.getUserObject() instanceof ISkill) {
        ISkill skill=(ISkill)node.getUserObject();
        if (withModifiedName) {
          ModifySkillDialog dialog=new ModifySkillDialog(skill,null);
          JOptionPane pane=new JOptionPane(dialog,JideOptionPane.QUESTION_MESSAGE,JideOptionPane.OK_CANCEL_OPTION);
          JDialog d=pane.createDialog(RMFrame.this,RESOURCE.getString("ui.skills.btEditBeforeAdd.title"));
          pane.selectInitialValue();
          d.setVisible(true);
          d.dispose();
          Object result=pane.getValue();
          if (result != null && result instanceof Integer && ((Integer)result).intValue() == JOptionPane.OK_OPTION) {
            skillModel.addSkill(skill,dialog.getSkillName(),dialog.getSkillType());
          }
        }
 else         if (!sheet.hasSkillRank(skill)) {
          skillModel.addSkill(skill);
        }
      }
    }
  }
}
 

Project Name: weka Package: weka.gui

Source Code: PropertySelectorDialog.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Create the property selection dialog.
 * @param parentFrame the parent frame of the dialog
 * @param rootObject the object containing properties to select from
 */
public PropertySelectorDialog(Frame parentFrame,Object rootObject){
  super(parentFrame,"Select a property",ModalityType.DOCUMENT_MODAL);
  m_CancelBut.addActionListener(new ActionListener(){
    public void actionPerformed(    ActionEvent e){
      m_Result=CANCEL_OPTION;
      setVisible(false);
    }
  }
);
  m_SelectBut.addActionListener(new ActionListener(){
    public void actionPerformed(    ActionEvent e){
      TreePath tPath=m_Tree.getSelectionPath();
      if (tPath == null) {
        m_Result=CANCEL_OPTION;
      }
 else {
        m_ResultPath=tPath.getPath();
        if ((m_ResultPath == null) || (m_ResultPath.length < 2)) {
          m_Result=CANCEL_OPTION;
        }
 else {
          m_Result=APPROVE_OPTION;
        }
      }
      setVisible(false);
    }
  }
);
  m_RootObject=rootObject;
  m_Root=new DefaultMutableTreeNode(new PropertyNode(m_RootObject));
  createNodes(m_Root);
  Container c=getContentPane();
  c.setLayout(new BorderLayout());
  Box b1=new Box(BoxLayout.X_AXIS);
  b1.add(m_SelectBut);
  b1.add(Box.createHorizontalStrut(10));
  b1.add(m_CancelBut);
  c.add(b1,BorderLayout.SOUTH);
  m_Tree=new JTree(m_Root);
  m_Tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  c.add(new JScrollPane(m_Tree),BorderLayout.CENTER);
  pack();
}
 

Project Name: weka Package: weka.gui

Source Code: PropertySelectorDialog.java (Click to view .java file)

Method Code:
vote
like

public void actionPerformed(ActionEvent e){
  TreePath tPath=m_Tree.getSelectionPath();
  if (tPath == null) {
    m_Result=CANCEL_OPTION;
  }
 else {
    m_ResultPath=tPath.getPath();
    if ((m_ResultPath == null) || (m_ResultPath.length < 2)) {
      m_Result=CANCEL_OPTION;
    }
 else {
      m_Result=APPROVE_OPTION;
    }
  }
  setVisible(false);
}
 

Project Name: weka Package: weka.gui

Source Code: GenericObjectEditor.java (Click to view .java file)

Method Code:
vote
like

/** 
 * creates a classname from the given path.
 * @param path	the path to generate the classname from
 * @return		the generated classname
 */
protected String getClassnameFromPath(TreePath path){
  StringBuffer classname=new StringBuffer();
  int start=0;
  if (m_ObjectNames.size() > 1)   start=1;
  for (int i=start; i < path.getPathCount(); i++) {
    if (i > start)     classname.append(".");
    classname.append((String)((GOETreeNode)path.getPathComponent(i)).getUserObject());
  }
  return classname.toString();
}
 

Project Name: weka Package: weka.gui.beans

Source Code: KnowledgeFlowApp.java (Click to view .java file)

Method Code:
vote
like

public void mouseClicked(MouseEvent e){
  if (((e.getModifiers() & InputEvent.BUTTON1_MASK) != InputEvent.BUTTON1_MASK) || e.isAltDown()) {
    boolean clearSelection=true;
    if (clearSelection) {
      m_toolBarBean=null;
      m_mode=NONE;
      KnowledgeFlowApp.this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
      m_componentTree.clearSelection();
    }
  }
  TreePath p=m_componentTree.getSelectionPath();
  if (p != null) {
    if (p.getLastPathComponent() instanceof DefaultMutableTreeNode) {
      DefaultMutableTreeNode tNode=(DefaultMutableTreeNode)p.getLastPathComponent();
      if (tNode.isLeaf()) {
        Object userObject=tNode.getUserObject();
        if (userObject instanceof JTreeLeafDetails) {
          if ((e.getModifiers() & InputEvent.SHIFT_MASK) != 0 && ((JTreeLeafDetails)userObject).isMetaBean()) {
            if (m_firstUserComponentOpp) {
              installWindowListenerForSavingUserStuff();
              m_firstUserComponentOpp=false;
            }
            Vector toRemove=((JTreeLeafDetails)userObject).getMetaBean();
            DefaultTreeModel model=(DefaultTreeModel)m_componentTree.getModel();
            MutableTreeNode userRoot=(MutableTreeNode)tNode.getParent();
            model.removeNodeFromParent(tNode);
            m_userComponents.remove(toRemove);
            if (m_userComponents.size() == 0) {
              model.removeNodeFromParent(userRoot);
              m_userCompNode=null;
            }
          }
 else {
            ((JTreeLeafDetails)userObject).instantiateBean();
          }
        }
      }
    }
  }
}