Java Code Examples for javax.swing.tree.TreePath

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project addis, under directory /application/src/main/java/org/drugis/addis/gui/.

Source file: AddisWindow.java

  22 
vote

public void leftTreeFocus(final Object node){
  TreePath path=d_domainTreeModel.getPathTo(node);
  if (path != null) {
    d_leftPanelTree.setSelectionPath(path);
  }
}
 

Example 2

From project Android-DB-Editor, under directory /src/com/troido/dbeditor/.

Source file: AndroidDBEditor.java

  22 
vote

public JTree createDeviceTree(List<Device> devices){
  DefaultMutableTreeNode top=new DefaultMutableTreeNode("Devices");
  TreePath path=new TreePath(top);
  JTree tree=new JTree(top);
  for (  Device device : devices)   top.add(createNodes(device));
  tree.expandPath(path);
  tree.setRootVisible(false);
  tree.setCellRenderer(new CellRenderer());
  tree.addMouseListener(new TreeMouseListener());
  return tree;
}
 

Example 3

From project Clotho-Core, under directory /ClothoApps/Grapevine/src/org/clothocad/tool/grapevine/.

Source file: BrowseNotes.java

  22 
vote

@Override public void mouseClicked(MouseEvent e){
  if (e.getClickCount() == 2) {
    try {
      TreePath path=collectionTree.getSelectionPath();
      TreeNode node=(TreeNode)path.getLastPathComponent();
      NoteNode cnode=(NoteNode)node;
      cnode.launchViewer();
    }
 catch (    Exception err) {
    }
  }
}
 

Example 4

From project codjo-data-process, under directory /codjo-data-process-gui/src/main/java/net/codjo/dataprocess/gui/util/sqleditor/.

Source file: SqlEditorDetailWindowLogic.java

  22 
vote

@OnMouse(value=SqlEditorDetailWindowGui.TAGS.DB_TREE,eventType=OnMouse.EventType.ALL,popupTriggered=OnMouse.PopupType.TRUE) public void rightButtonOnTree(MouseEvent event,SqlEditorDetailWindowGui gui){
  gui.getDatabasePopupMenu().show(event.getComponent(),event.getX(),event.getY());
  int selRow=gui.getDatabaseTree().getRowForLocation(event.getX(),event.getY());
  if (selRow >= 0) {
    TreePath selPath=gui.getDatabaseTree().getPathForLocation(event.getX(),event.getY());
    gui.getDatabaseTree().setSelectionPath(selPath);
    gui.getDatabasePopupMenu().getMenuItemGenerateInsertInto().setEnabled(selPath.getPath().length == 2);
    gui.getDatabasePopupMenu().getMenuItemGenerateSelectAll().setEnabled(selPath.getPath().length == 2);
    gui.getDatabasePopupMenu().getMenuItemGenerateUpdate().setEnabled(selPath.getPath().length >= 2);
  }
}
 

Example 5

From project codjo-segmentation, under directory /codjo-segmentation-gui/src/main/java/net/codjo/segmentation/gui/settings/.

Source file: AxisTreeLogic.java

  22 
vote

public void updateTree(){
  TreePath path=getGui().getSelectionPath();
  if (path != null && path.getLastPathComponent() instanceof Sleeve) {
    Sleeve sleeve=(Sleeve)path.getLastPathComponent();
    getModel().nodeChanged(sleeve);
  }
}
 

Example 6

From project css-x-fire, under directory /src/com/github/cssxfire/ui/.

Source file: CssToolWindow.java

  22 
vote

public void select(int direction){
  CssTreeNode root=(CssTreeNode)treeModel.getRoot();
  TreePath selectionPath=tree.getSelectionPath();
  CssTreeNode anchor=selectionPath == null ? null : (CssTreeNode)selectionPath.getLastPathComponent();
  CssDeclarationNode declarationNode=TreeUtils.seek(root,anchor,direction);
  if (declarationNode != null) {
    TreePath path=new TreePath(declarationNode.getPath());
    tree.getSelectionModel().setSelectionPath(path);
    navigateTo(path);
  }
}
 

Example 7

From project dawn-isencia, under directory /com.isencia.passerelle.commons/src/main/java/com/isencia/util/swing/components/.

Source file: DynamicTree.java

  22 
vote

/** 
 * Remove the currently selected node. 
 */
public void removeCurrentNode(){
  TreePath currentSelection=tree.getSelectionPath();
  if (currentSelection != null) {
    DefaultMutableTreeNode currentNode=(DefaultMutableTreeNode)(currentSelection.getLastPathComponent());
    MutableTreeNode parent=(MutableTreeNode)(currentNode.getParent());
    if (parent != null) {
      treeModel.removeNodeFromParent(currentNode);
      return;
    }
  }
  toolkit.beep();
}
 

Example 8

From project des, under directory /daemon/lib/apache-log4j-1.2.16/src/main/java/org/apache/log4j/lf5/viewer/categoryexplorer/.

Source file: CategoryExplorerTree.java

  22 
vote

protected void expandRootNode(){
  if (_rootAlreadyExpanded) {
    return;
  }
  _rootAlreadyExpanded=true;
  TreePath path=new TreePath(_model.getRootCategoryNode().getPath());
  expandPath(path);
}
 

Example 9

From project encog-java-workbench, under directory /src/main/java/org/encog/workbench/dialogs/.

Source file: DirChooser.java

  22 
vote

/** 
 * Write the dir selection in the text field.
 */
public void valueChanged(TreeSelectionEvent e){
  TreePath path=e.getPath();
  if (path != null) {
    DefaultMutableTreeNode node=(DefaultMutableTreeNode)path.getLastPathComponent();
    File dir=(File)node.getUserObject();
    dirText.setText(dir.getAbsolutePath());
  }
}
 

Example 10

From project extension_libero_manufacturing, under directory /extension/eevolution/libero/src/main/java/it/cnr/imaa/essi/lablib/gui/checkboxtree/.

Source file: DefaultTreeCheckingModel.java

  22 
vote

/** 
 * Checks the subtree with root path.
 * @param path root of the tree to be checked
 */
public void checkSubTree(final TreePath path){
  addToCheckedPathsSet(path);
  removeFromGreyedPathsSet(path);
  Object node=path.getLastPathComponent();
  int childrenNumber=this.model.getChildCount(node);
  for (int childIndex=0; childIndex < childrenNumber; childIndex++) {
    TreePath childPath=path.pathByAddingChild(this.model.getChild(node,childIndex));
    checkSubTree(childPath);
  }
}
 

Example 11

From project freemind, under directory /freemind/freemind/modes/.

Source file: NodeAdapter.java

  22 
vote

/** 
 * Creates the TreePath recursively 
 */
public TreePath getPath(){
  Vector pathVector=new Vector();
  TreePath treePath;
  this.addToPathVector(pathVector);
  treePath=new TreePath(pathVector.toArray());
  return treePath;
}
 

Example 12

From project Holo-Edit, under directory /holoedit/gui/.

Source file: DynamicTree.java

  22 
vote

/** 
 * Remove the currently selected node. 
 */
public void removeCurrentNode(){
  TreePath currentSelection=tree.getSelectionPath();
  if (currentSelection != null) {
    DefaultMutableTreeNode currentNode=(DefaultMutableTreeNode)(currentSelection.getLastPathComponent());
    MutableTreeNode parent=(MutableTreeNode)(currentNode.getParent());
    if (parent != null) {
      treeModel.removeNodeFromParent(currentNode);
      return;
    }
  }
  toolkit.beep();
}
 

Example 13

From project imageflow, under directory /src/de/danielsenff/imageflow/gui/.

Source file: DelegatesTreeListener.java

  22 
vote

public void mouseClicked(final MouseEvent e){
  if (e.getClickCount() == 2) {
    final JTree tree=(JTree)e.getSource();
    final int selRow=tree.getRowForLocation(e.getX(),e.getY());
    final TreePath selPath=tree.getPathForLocation(e.getX(),e.getY());
    if (selRow != -1 && selPath.getLastPathComponent() instanceof UnitDelegate) {
      final UnitDelegate delegate=((UnitDelegate)selPath.getLastPathComponent());
      Point point=UnitDelegate.POINT;
      GraphControllerManager.getInstance().getController().addNode(delegate,point);
    }
  }
}
 

Example 14

From project ISAcreator, under directory /src/main/java/org/isatools/isacreator/common/filterableTree/.

Source file: FilterableJTree.java

  22 
vote

public Set<String> getExpandedTreePaths(){
  Set<String> expandedPaths=new HashSet<String>();
  TreeNode rootNode=(TreeNode)getModel().getRoot();
  Enumeration children=rootNode.children();
  while (children.hasMoreElements()) {
    DefaultMutableTreeNode childNode=(DefaultMutableTreeNode)children.nextElement();
    TreePath path=new TreePath(childNode.getPath());
    if (isExpanded(path)) {
      expandedPaths.add(childNode.toString());
    }
  }
  return expandedPaths;
}
 

Example 15

From project jASM_16, under directory /src/main/java/de/codesourcery/jasm16/ide/ui/views/.

Source file: SourceEditorView.java

  22 
vote

protected void onCaretUpdate(CaretEvent e){
  final AST ast=getCurrentCompilationUnit() != null ? getCurrentCompilationUnit().getAST() : null;
  if (ast == null) {
    return;
  }
  final ASTNode n=ast.getNodeInRange(e.getDot());
  if (n != null && isASTInspectorVisible()) {
    TreePath path=new TreePath(n.getPathToRoot());
    astTree.setSelectionPath(path);
    astTree.scrollPathToVisible(path);
  }
}
 

Example 16

From project jftp, under directory /src/main/java/com/myjavaworld/jftp/.

Source file: PreferencesDlg.java

  22 
vote

public void valueChanged(TreeSelectionEvent evt){
  TreePath selectedPath=evt.getPath();
  if (selectedPath == null) {
    return;
  }
  IDTreeNode selectedNode=(IDTreeNode)selectedPath.getLastPathComponent();
  String cardName=String.valueOf(selectedNode.getID());
  cardLayout.show(centerPanel,cardName);
}
 

Example 17

From project JGAAP, under directory /src/com/jgaap/ui/.

Source file: JGAAP_UI_MainForm.java

  22 
vote

private void DocumentsPanel_RemoveAuthorButtonActionPerformed(java.awt.event.ActionEvent evt){
  TreePath Path=DocumentsPanel_KnownAuthorsTree.getSelectionPath();
  String AuthorName;
  if (Path.getPathCount() != 1) {
    AuthorName=Path.getPathComponent(1).toString();
    KnownDocumentList=JGAAP_API.getDocumentsByAuthor(AuthorName);
    for (int i=KnownDocumentList.size() - 1; i >= 0; i--) {
      JGAAP_API.removeDocument(KnownDocumentList.get(i));
    }
    UpdateKnownDocumentsTree();
  }
 else {
  }
}
 

Example 18

From project jMemorize, under directory /src/jmemorize/gui/swing/widgets/.

Source file: CategoryTree.java

  22 
vote

/** 
 * @see javax.swing.tree.DefaultTreeCellEditor#isCellEditable
 */
public boolean isCellEditable(EventObject event){
  if (event != null) {
    MouseEvent mEvent=(MouseEvent)event;
    TreePath path=getPathForLocation(mEvent.getX(),mEvent.getY());
    if (path != null) {
      m_editedNode=(DefaultMutableTreeNode)path.getLastPathComponent();
      m_editedCategory=(Category)m_editedNode.getUserObject();
    }
  }
  return super.isCellEditable(event) && m_editedCategory != m_rootCategory;
}
 

Example 19

From project jreepad, under directory /src/jreepad/.

Source file: JreepadView.java

  22 
vote

public void moveCurrentNodeUp(){
  TreePath nodePath=tree.getSelectionPath();
  if (currentNode.equals(root)) {
    notForRootNode();
    return;
  }
  currentNode.moveUp();
  treeModel.reload(currentNode.getParent());
  tree.setSelectionPath(nodePath);
}
 

Example 20

From project LanguageSpecCreator, under directory /src/SpecificationCreation/look/.

Source file: TreeTransferHandler.java

  22 
vote

/** 
 * Transfers the string value of the property.
 * @param c Tree component
 * @return Transferabe
 * @see TransferHandler#createTransferable(JComponent)
 */
public Transferable createTransferable(JComponent c){
  if (c instanceof JTree) {
    JTree tree=(JTree)c;
    TreePath path=tree.getSelectionPath();
    ClassTreeNode node=(ClassTreeNode)path.getLastPathComponent();
    if (node.isCardinal() || node.isMenu() || node.isShaded())     return null;
    return new StringSelection(node.toString());
  }
  JList list=(JList)c;
  return new StringSelection(list.getSelectedValue().toString());
}
 

Example 21

From project LateralGM, under directory /org/lateralgm/main/.

Source file: Listener.java

  22 
vote

public boolean canImport(TransferHandler.TransferSupport support){
  if (!support.isDataFlavorSupported(ResNode.NODE_FLAVOR))   return false;
  for (  DataFlavor f : support.getDataFlavors())   if (f != ResNode.NODE_FLAVOR)   return false;
  TreePath drop=((JTree.DropLocation)support.getDropLocation()).getPath();
  if (drop == null)   return false;
  ResNode dropNode=(ResNode)drop.getLastPathComponent();
  ResNode dragNode=(ResNode)((JTree)support.getComponent()).getLastSelectedPathComponent();
  if (dragNode == dropNode)   return false;
  if (dragNode.isNodeDescendant(dropNode))   return false;
  if (Prefs.groupKind && dropNode.kind != dragNode.kind)   return false;
  if (dropNode.status == ResNode.STATUS_SECONDARY)   return false;
  return true;
}
 

Example 22

From project litle-sdk-for-java, under directory /lib/xerces-2_11_0/samples/dom/traversal/.

Source file: TreeWalkerView.java

  22 
vote

/** 
 * handle a button press: output messages and select node. 
 */
void handleButton(Node node,String function){
  setMessage("treeWalker." + function + " == "+ node);
  if (node == null)   return;
  TreeNode treeNode=jtree.getTreeNode(node);
  if (treeNode == null) {
    setMessage("No JTree TreeNode for Node name:" + node.getNodeName());
    return;
  }
  TreePath path=new TreePath(((DefaultTreeModel)jtree.getModel()).getPathToRoot(treeNode));
  jtree.requestFocus();
  jtree.setSelectionPath(path);
  jtree.scrollPathToVisible(path);
}
 

Example 23

From project log4jna, under directory /thirdparty/log4j/src/main/java/org/apache/log4j/lf5/viewer/categoryexplorer/.

Source file: CategoryExplorerTree.java

  22 
vote

protected void expandRootNode(){
  if (_rootAlreadyExpanded) {
    return;
  }
  _rootAlreadyExpanded=true;
  TreePath path=new TreePath(_model.getRootCategoryNode().getPath());
  expandPath(path);
}
 

Example 24

From project Maimonides, under directory /src/com/codeko/apps/maimonides/cursos/.

Source file: PanelArbolUnidades.java

  22 
vote

public Object getObjetoSeleccionado(){
  TreePath tp=arbol.getSelectionPath();
  Object ret=null;
  if (tp != null) {
    ret=getObjetoArbol(tp);
  }
  return ret;
}
 

Example 25

From project milton, under directory /milton/milton-client-app/src/main/java/bradswebdavclient/.

Source file: BradsWebdavClientView.java

  22 
vote

private void treeMouseClicked(java.awt.event.MouseEvent evt){
  final int clicks=evt.getClickCount();
  TreePath tp=tree.getSelectionPath();
  if (tp != null) {
    if (clicks == 1) {
      selectNode(tp);
    }
 else     if (clicks == 2) {
      selectNode(tp);
    }
  }
}
 

Example 26

From project beanmill_1, under directory /src/main/java/com/traxel/lumbermill/filter/.

Source file: TreeControl.java

  21 
vote

@Override public void mouseClicked(final MouseEvent e){
  final TreePath[] paths;
  final Collection nodes;
  Node node;
  final List actions;
  final Point location;
  POPUP.setVisible(false);
  if (MouseEvent.BUTTON3 == e.getButton()) {
    final TreePath path=TREE_VIEW.getPathForLocation(e.getX(),e.getY());
    TREE_VIEW.setSelectionPath(path);
    paths=TREE_VIEW.getSelectionPaths();
    if ((paths == null) || (paths.length == 0)) {
      return;
    }
    nodes=new ArrayList();
    for (int i=0; i < paths.length; i++) {
      node=(Node)paths[i].getLastPathComponent();
      nodes.add(node);
    }
    actions=SeverityAction.getActions(nodes);
    location=getScreenLocation();
    final Point locP=TREE_PANEL.getLocationOnScreen();
    showPopup(actions,(int)(e.getX() + locP.getX()),(int)(e.getY() + locP.getY() + 5));
  }
}
 

Example 27

From project brix-cms, under directory /brix-core/src/main/java/org/brixcms/web/tree/.

Source file: AbstractTreeModel.java

  21 
vote

private TreePath pathFromNode(AbstractTree tree,TreeNode node){
  List<TreeNode> l=new ArrayList<TreeNode>();
  for (TreeNode n=node; n != null; n=(TreeNode)getParent(tree,n)) {
    l.add(0,n);
  }
  return new TreePath(l.toArray(new TreeNode[l.size()]));
}
 

Example 28

From project ceres, under directory /ceres-ui/src/main/java/com/bc/ceres/swing/.

Source file: TreeCellExtender.java

  21 
vote

@Override protected void paintComponent(Graphics g){
  final int width=getWidth();
  final int height=getHeight();
  if (width <= 0 || height <= 0) {
    return;
  }
  Rectangle bounds=getBounds();
  Color color=g.getColor();
  g.setColor(getBackground());
  g.fillRect(bounds.x,bounds.y,bounds.width,bounds.height);
  g.setColor(color);
  TreePath path=tree.getPathForRow(row);
  TreeCellRenderer renderer=tree.getCellRenderer();
  Component rendererComponent=renderer.getTreeCellRendererComponent(tree,path.getLastPathComponent(),tree.isPathSelected(path),tree.isExpanded(path),true,row,false);
  rendererComponent.setSize(1024,height);
  Graphics g2=g.create(0,0,width,height);
  g2.translate(-offset,0);
  rendererComponent.paint(g2);
  g2.dispose();
}
 

Example 29

From project CloudReports, under directory /src/main/java/cloudreports/gui/.

Source file: CloudTree.java

  21 
vote

/** 
 * Creates a new CloudTree. 
 */
public CloudTree(){
  super(new DefaultMutableTreeNode("CloudReports"));
  DatacenterRegistryDAO drDAO=new DatacenterRegistryDAO();
  String[] datacenterNames=drDAO.getAllDatacentersNames();
  for (  String datacenterName : datacenterNames) {
    providerTreeNode.add(new DefaultMutableTreeNode(datacenterName,false));
  }
  CustomerRegistryDAO crDAO=new CustomerRegistryDAO();
  String[] customerNames=crDAO.getCustomersNames();
  for (  String customerName : customerNames) {
    customersTreeNode.add(new DefaultMutableTreeNode(customerName,false));
  }
  this.expandPath(new TreePath(getCloudTreeNode()));
}
 

Example 30

From project CommunityCase, under directory /src/org/community/intellij/plugins/communitycase/update/.

Source file: SkippedCommits.java

  21 
vote

@Override public Object getData(String dataId){
  if (PlatformDataKeys.PROJECT.is(dataId)) {
    return myProject;
  }
  TreePath selectionPath=myTree.getSelectionPath();
  DefaultMutableTreeNode node=selectionPath == null ? null : (DefaultMutableTreeNode)selectionPath.getLastPathComponent();
  Object o=node == null ? null : node.getUserObject();
  if (o instanceof Commit) {
    Commit c=(Commit)o;
    if (VcsDataKeys.VCS_VIRTUAL_FILE.is(dataId)) {
      return c.root;
    }
    if (VcsDataKeys.VCS_FILE_REVISION.is(dataId)) {
      return new FileRevision(myProject,VcsUtil.getFilePath(c.root.getPath()),c.commitInfo.revision);
    }
  }
  return super.getData(dataId);
}
 

Example 31

From project dawn-common, under directory /org.dawb.hdf5/src/ncsa/hdf/view/.

Source file: DefaultTreeView.java

  21 
vote

/** 
 * Get the TreePath from the parent to the target node.
 * @param parent -- the parent TreePath
 * @param node -- the target node
 * @param depth
 * @return the tree path if target node found, otherwise; returns null;
 */
private static TreePath getTreePath(TreePath parent,TreeNode node,int depth){
  if (node == null || parent == null || depth < 0)   return null;
  TreeNode theNode=(TreeNode)parent.getLastPathComponent();
  if (node == theNode)   return parent;
  if (theNode.getChildCount() >= 0) {
    for (Enumeration<?> e=theNode.children(); e.hasMoreElements(); ) {
      TreeNode n=(TreeNode)e.nextElement();
      TreePath path=parent.pathByAddingChild(n);
      TreePath result=getTreePath(path,node,depth + 1);
      if (result != null) {
        return result;
      }
    }
  }
  return null;
}
 

Example 32

From project ib-ruby, under directory /misc/IBController 2-9-0/src/ibcontroller/.

Source file: ConfigureApiTask.java

  21 
vote

private void completeConfigureItViaEditMenu(){
  Utils.logToConsole("Completing ENABLEAPI configuration");
  JDialog configDialog=TwsListener.getConfigDialog();
  if (configDialog == null) {
    System.err.println("IBControllerServer: could not find the Global Configuration dialog");
    mChannel.writeNack("Global Configuration dialog not found");
    return;
  }
  JTree configTree=Utils.findTree(configDialog);
  if (configTree == null) {
    System.err.println("IBControllerServer: could not find the config tree in the Global Configuration dialog");
    mChannel.writeNack("config tree not found");
    return;
  }
  TreePath tp=new TreePath(configTree.getModel().getRoot());
  Object node=Utils.findChildNode(configTree.getModel(),configTree.getModel().getRoot(),"API");
  tp=tp.pathByAddingChild(node);
  node=Utils.findChildNode(configTree.getModel(),node,"Settings");
  if (!(node == null))   tp=tp.pathByAddingChild(node);
  Utils.logToConsole("getExpandsSelectedPaths = " + configTree.getExpandsSelectedPaths());
  Utils.logToConsole("Selection path = " + tp.toString());
  configTree.setSelectionPath(tp);
  JCheckBox cb=Utils.findCheckBox(configDialog,"Enable ActiveX and Socket Clients");
  if (cb == null) {
    System.err.println("IBControllerServer: Could not find Enable ActiveX checkbox inside API menu.");
    mChannel.writeNack("Enable ActiveX checkbox not found");
    return;
  }
  if (!cb.isSelected()) {
    cb.doClick();
    Utils.clickButton(configDialog,"OK");
    Utils.logToConsole("TWS has been configured to accept API connections.");
    mChannel.writeAck("configured");
  }
 else {
    Utils.logToConsole("TWS is already configured to accept API connections.");
    mChannel.writeAck("already configured");
  }
  configDialog.setVisible(false);
}
 

Example 33

From project JaamSim, under directory /com/sandwell/JavaSimulation3D/.

Source file: EntityPallet.java

  21 
vote

public void dragGestureRecognized(DragGestureEvent event){
  TreePath path=tree.getSelectionPath();
  if (path != null) {
    if (path.getLastPathComponent() instanceof DefaultMutableTreeNode) {
      DefaultMutableTreeNode treeNode=(DefaultMutableTreeNode)path.getLastPathComponent();
      if (treeNode.getUserObject() instanceof ObjectType) {
        ObjectType type=(ObjectType)treeNode.getUserObject();
        Cursor cursor=null;
        if (event.getDragAction() == DnDConstants.ACTION_COPY) {
          cursor=DragSource.DefaultCopyDrop;
        }
        event.startDrag(cursor,new TransferableObjectType(type));
      }
    }
  }
}
 

Example 34

From project jenkins-control-plugin, under directory /src/main/java/org/codinjutsu/tools/jenkins/view/.

Source file: JobSearchComponent.java

  21 
vote

private void findOccurrence(String text,SearchMovement searchMovement){
  DefaultMutableTreeNode currentNode=getStartingNode(searchMovement);
  boolean foundNode=false;
  while (currentNode != null) {
    Object userObject=currentNode.getUserObject();
    if (userObject instanceof Jenkins) {
      break;
    }
    Job job=(Job)userObject;
    if (StringUtils.startsWithIgnoreCase(job.getName(),text) && !foundNode) {
      lastSelectedNode=currentNode;
      TreePath pathToSelect=new TreePath(currentNode.getPath());
      jobTree.setSelectionPath(pathToSelect);
      jobTree.scrollPathToVisible(pathToSelect);
      foundNode=true;
    }
    currentNode=searchMovement.get(currentNode);
  }
  updateFeebackComponent(foundNode);
}
 

Example 35

From project jsmaa, under directory /main/src/main/java/fi/smaa/jsmaa/gui/.

Source file: Focuser.java

  21 
vote

public static void focus(JTree tree,TreeModel model,Object o){
  TreePath tp=null;
  if (o == model.getRoot()) {
    tp=new TreePath(new Object[]{o});
  }
 else   if (model.getIndexOfChild(model.getRoot(),o) != -1) {
    tp=new TreePath(new Object[]{model.getRoot(),o});
  }
 else {
    for (int i=0; i < model.getChildCount(model.getRoot()); i++) {
      Object parent=model.getChild(model.getRoot(),i);
      if (model.getIndexOfChild(parent,o) != -1) {
        tp=new TreePath(new Object[]{model.getRoot(),parent,o});
        break;
      }
    }
  }
  tree.setSelectionPath(tp);
  expandTree(tree);
}
 

Example 36

From project knime-scripting, under directory /scriptingcore/src/de/mpicbg/tds/knime/knutils/scripting/templatewizard/.

Source file: ScriptTemplateWizard.java

  21 
vote

public ScriptTemplateWizard(ScriptingNodeDialog parent,List<ScriptTemplate> templates){
  this.templates=templates;
  this.parentDialog=parent;
  initComponents();
  categoryTreeModel=new DefaultTreeModel(new DefaultMutableTreeNode());
  categoryTree.setRootVisible(false);
  categoryTree.setModel(categoryTreeModel);
  repopulateTemplateTree(null);
  descContainerSplitPanel.setDividerLocation(0.0);
  categoryTree.addTreeSelectionListener(new TreeSelectionListener(){
    public void valueChanged(    TreeSelectionEvent evt){
      TreePath selectionPath=categoryTree.getSelectionPath();
      if (selectionPath == null) {
        setCurrentTemplate(null);
        return;
      }
      Object selectedPathElement=selectionPath.getLastPathComponent();
      if (selectedPathElement == null) {
        setCurrentTemplate(null);
        return;
      }
      Object userObject=((DefaultMutableTreeNode)selectedPathElement).getUserObject();
      if (userObject instanceof ScriptTemplate) {
        ScriptTemplate scriptTemplate=(ScriptTemplate)userObject;
        setCurrentTemplate(scriptTemplate);
      }
 else {
        setCurrentTemplate(null);
      }
    }
  }
);
}
 

Example 37

From project java-psd-library, under directory /psd-tool/src/psdtool/.

Source file: TreeLayerModel.java

  19 
vote

public void setPsd(Psd psd){
  this.psd=psd;
  if (!listeners.isEmpty()) {
    TreeModelEvent event=new TreeModelEvent(this,new TreePath(psd));
    for (    TreeModelListener l : listeners) {
      l.treeStructureChanged(event);
    }
  }
}