Java Code Examples for javax.swing.event.TreeSelectionEvent#getSource()

The following examples show how to use javax.swing.event.TreeSelectionEvent#getSource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ObjectSelector.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
@Override
public void valueChanged( TreeSelectionEvent e ) {
	JTree tree = (JTree) e.getSource();
	DefaultMutableTreeNode node = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
	if(node == null) {
		// This occurs when we set no selected entity (null) and then
		// force the tree to have a null selected node
		return;
	}

	Object userObj = node.getUserObject();
	if (userObj instanceof Entity) {
		FrameBox.setSelectedEntity((Entity)userObj, false);
	}
	else {
		FrameBox.setSelectedEntity(null, false);
	}
}
 
Example 2
Source File: ElementSelectionListener.java    From niftyeditor with Apache License 2.0 6 votes vote down vote up
@Override
public void valueChanged(TreeSelectionEvent e) {
    TreePath path = e.getNewLeadSelectionPath();
    if (path != null) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
        if (!node.isRoot()) {
            try {
                SelectCommand command = CommandProcessor.getInstance().getCommand(SelectCommand.class);
                command.setElement((GElement) node.getUserObject());
                CommandProcessor.getInstance().excuteCommand(command);
            } catch (Exception ex) {
                Logger.getLogger(ElementSelectionListener.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        final JTree temp = (JTree) e.getSource();

        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                temp.updateUI();
            }
        });
    }
}
 
Example 3
Source File: DasaTreeListener.java    From Astrosoft with GNU General Public License v2.0 6 votes vote down vote up
public void valueChanged(TreeSelectionEvent e) {
	JTree tree = (JTree) e.getSource();

	DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
	
	if (node != null){
	
		boolean isRoot = node.isRoot();
		Dasa dasa = (Dasa) node.getUserObject();
		
		//Add sub dasas only if not present already.
		if (!isRoot && node.isLeaf()){
			
			
			for(Dasa d : dasa.subDasas()){
				node.add(new DefaultMutableTreeNode(d, true));
			}
			DefaultTreeModel model = (DefaultTreeModel)tree.getModel();
			model.reload(node);
		}
		handler.nodeSelected(node, e.getNewLeadSelectionPath());
			
	}
	//tree.collapsePath(e.getOldLeadSelectionPath());
}
 
Example 4
Source File: DirectoryChooserUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/************ imple of TreeSelectionListener *******/

@Override
public void valueChanged(TreeSelectionEvent e) {
    showPopupCompletion = false;
    FileSystemView fsv = fileChooser.getFileSystemView();
    JTree tree = (JTree) e.getSource();
    TreePath path = tree.getSelectionPath();
    TreePath curSel = e.getNewLeadSelectionPath();
    curSelPath = (curSel != null) ? new WeakReference<TreePath>(curSel) : null;
    
    if(path != null) {
        
        DirectoryNode node = (DirectoryNode)path.getLastPathComponent();
        File file = node.getFile();
        
        if(file != null) {
            setSelected(getSelectedNodes(tree.getSelectionPaths()));
            newFolderAction.setEnabled(false);
            
            if(!node.isLeaf()) {
                newFolderAction.enable(file);
                setDirectorySelected(true);
            }
        }
    }
}
 
Example 5
Source File: ProjectTree.java    From KodeBeagle with Apache License 2.0 5 votes vote down vote up
public final TreeSelectionListener getTreeSelectionListener(final TreeNode root) {
    return new TreeSelectionListener() {
        @Override
        public void valueChanged(final TreeSelectionEvent treeSelectionEvent) {
            JTree jtree = (JTree) treeSelectionEvent.getSource();
            DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)
                    jtree.getLastSelectedPathComponent();
            if (selectedNode != null && selectedNode.isLeaf() && root.getChildCount() > 0) {
                final CodeInfo codeInfo = (CodeInfo) selectedNode.getUserObject();
                ProgressManager.getInstance().run(new FetchFileContentTask(
                        windowObjects.getProject(), codeInfo));
            }
        }
    };
}
 
Example 6
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override public void valueChanged(TreeSelectionEvent e) {
  DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent();
  if (!node.isLeaf()) {
    return;
  }
  File parent = (File) node.getUserObject();
  if (!parent.isDirectory()) {
    return;
  }

  JTree tree = (JTree) e.getSource();
  DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
  new BackgroundTask(fileSystemView, parent) {
    @Override protected void process(List<File> chunks) {
      if (isCancelled()) {
        return;
      }
      if (!tree.isDisplayable()) {
        cancel(true);
        return;
      }
      chunks.stream().map(DefaultMutableTreeNode::new)
          .forEach(child -> model.insertNodeInto(child, node, node.getChildCount()));
      // model.reload(node);
    }
  }.execute();
}
 
Example 7
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override public void valueChanged(TreeSelectionEvent e) {
  DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent();
  if (!node.isLeaf()) {
    return;
  }
  File parent = (File) node.getUserObject();
  if (!parent.isDirectory()) {
    return;
  }

  JTree tree = (JTree) e.getSource();
  // if (frame == null) {
  //   frame = (JFrame) SwingUtilities.getWindowAncestor(tree);
  //   frame.setGlassPane(new LockingGlassPane());
  // }
  // frame.getGlassPane().setVisible(true);

  DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
  new BackgroundTask(fileSystemView, parent) {
    @Override protected void process(List<File> chunks) {
      if (isCancelled()) {
        return;
      }
      if (!tree.isDisplayable()) {
        cancel(true);
        return;
      }
      chunks.stream().map(DefaultMutableTreeNode::new)
          .forEach(child -> model.insertNodeInto(child, node, node.getChildCount()));
      // model.reload(parent); // = model.nodeStructureChanged(parent);
      // tree.expandPath(path);
    }
  }.execute();
}
 
Example 8
Source File: MainPanel.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void valueChanged(TreeSelectionEvent e) {
    Object source = e.getSource();
    TreeItem treeItem = (TreeItem) e.getPath().getLastPathComponent();

    if (!(treeItem instanceof SWFList)) {
        SWF swf = treeItem.getSwf();
        if (swfs.isEmpty()) {
            // show welcome panel after closing swfs
            updateUi();
        } else {
            if (swf == null && swfs.get(0) != null) {
                swf = swfs.get(0).get(0);
            }

            if (swf != null) {
                updateUi(swf);
            }
        }
    } else {
        updateUi();
    }

    reload(false);

    if (source == dumpTree) {
        Tag t = null;
        if (treeItem instanceof DumpInfo) {
            DumpInfo di = (DumpInfo) treeItem;
            t = di.getTag();
        }

        showPreview(t, dumpPreviewPanel);
    }
}
 
Example 9
Source File: SelectionController.java    From nextreports-designer with Apache License 2.0 4 votes vote down vote up
public void valueChanged(TreeSelectionEvent event) {
    if (ignoreEvent) {
        return;
    }

    JTree tree = (JTree) event.getSource();
    TreePath[] paths = tree.getSelectionPaths();
    if (paths == null) {
        return;
    }

    SelectionModel selectionModel = Globals.getReportGrid().getSelectionModel();
    selectionModel.clearSelection();
    List<Cell> selectedCells = new ArrayList<Cell>();
    List<Integer> selectedRows = new ArrayList<Integer>();
    for (TreePath path : paths) {
        StructureTreeNode node = (StructureTreeNode) path.getLastPathComponent();
        Object userObject = node.getUserObject();                  
        if (userObject instanceof ReportGridCell) {
        	// cell layout properties
            boolean filter = Globals.getReportDesignerPanel().getStructurePanel().getStructureTreeModel().isActivatedFilter();
            if ((filter && node.isVisible()) || !filter) {
                selectedCells.add((Cell) userObject);
            }
        } else if (userObject instanceof Integer) { 
        	// row layout properties
        	Integer i = (Integer)userObject;
        	String bandName = ((Band)((StructureTreeNode)node.getParent()).getUserObject()).getName();
        	int gridRow = LayoutHelper.getReportLayout().getGridRow(bandName, i);
        	selectedRows.add(gridRow);            	
        } else if (node.isRoot()) {
            // report layout properties
            selectionModel.addRootSelection();
            return;   
        } else {
            // other nodes in tree (band)
            selectionModel.emptySelection(); 
            return;
        }
    }

    if (selectedCells.size() > 0) {
        ignoreEvent = true;
        selectionModel.addSelectionCells(selectedCells);
        ignoreEvent = false;
    } else if (selectedRows.size() > 0) {
    	ignoreEvent = true;
        selectionModel.addSelectionRows(selectedRows);   // used by PropertyPanel to select properties                                
        ignoreEvent = false;        
    } else {
        selectionModel.clearSelection();
    }
    Globals.getReportLayoutPanel().getReportGridPanel().repaintHeaders();
}
 
Example 10
Source File: PrideXMLDisplay.java    From PDV with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Tree valueChanged
 * @param evt TreeSelectionEvent
 */
private void valueChanged(TreeSelectionEvent evt) {

    JTree tree = (JTree)evt.getSource();
    DefaultMutableTreeNode selectionNode = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();

    TreeNode parentNode = selectionNode.getParent();

    String nodeName = selectionNode.toString().split("\\(")[0];

    if(titleToPrideXmlReader.containsKey(nodeName)){
        currentPrideXmlReader = titleToPrideXmlReader.get(nodeName);
        currentProtein = selectionNode.getFirstChild().toString().split("\\(")[0];

        currentFileCount = parentNode.getIndex(selectionNode) + 1;

        currentProteinCount = 1;

        updatePSMJTable();

        updateDetails();

        updateSpectrumTable();

    } else if(!nodeName.equals("Files")){
        if(currentPrideXmlReader != titleToPrideXmlReader.get(parentNode.toString().split("\\(")[0])){
            currentPrideXmlReader = titleToPrideXmlReader.get(parentNode.toString().split("\\(")[0]);
            updateDetails();

            updateSpectrumTable();
        }

        currentProtein = nodeName;

        TreeNode grandNode = parentNode.getParent();

        currentFileCount = grandNode.getIndex(parentNode) + 1;

        currentProteinCount = parentNode.getIndex(selectionNode) + 1;

        updatePSMJTable();
    }

    tree.requestFocus();
}