Java Code Examples for javax.swing.tree.TreeSelectionModel

The following examples show how to use javax.swing.tree.TreeSelectionModel. These examples are extracted from open source projects. 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 Project: ghidra   Source File: RegisterTree.java    License: Apache License 2.0 6 votes vote down vote up
public RegisterTree() {
	super(new RegisterTreeRootNode());
	root = (RegisterTreeRootNode) getModelRoot();

	setEditable(false);

	getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
	setHorizontalScrollPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

	// add change listener to prevent tree from scrolling horizontally since we will
	// never have a horizontal scroll bar.
	JScrollPane scrollPane = getScrollPane();
	final JViewport viewport = scrollPane.getViewport();
	scrollPane.getViewport().addChangeListener(new ChangeListener() {
		@Override
		public void stateChanged(ChangeEvent e) {
			Point viewPosition = viewport.getViewPosition();
			if (viewPosition.x != 0) {
				// if it scrolls horizontally, put it back
				viewPosition.x = 0;
				viewport.setViewPosition(viewPosition);
			}
		}
	});
	setMinimumSize(new Dimension(175, 30));
}
 
Example 2
Source Project: marathonv5   Source File: RTreeTest.java    License: Apache License 2.0 6 votes vote down vote up
public void noNodesSelected() throws Throwable, InvocationTargetException {
    final JTree tree = (JTree) ComponentUtils.findComponent(JTree.class, frame);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    siw(new Runnable() {
        @Override
        public void run() {
            tree.expandRow(0);
        }
    });
    final LoggingRecorder lr = new LoggingRecorder();
    siw(new Runnable() {
        @Override
        public void run() {
            RTree rTree = new RTree(tree, null, null, lr);
            rTree.focusLost(null);
        }
    });
    AssertJUnit.assertEquals(0, lr.getCalls().size());
}
 
Example 3
Source Project: marathonv5   Source File: RTreeTest.java    License: Apache License 2.0 6 votes vote down vote up
public void singleNodeSelected() throws Throwable, InvocationTargetException {
    final JTree tree = (JTree) ComponentUtils.findComponent(JTree.class, frame);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    siw(new Runnable() {
        @Override
        public void run() {
            tree.expandRow(0);
            tree.setSelectionRow(0);
        }
    });
    final LoggingRecorder lr = new LoggingRecorder();
    siw(new Runnable() {
        @Override
        public void run() {
            Rectangle rowBounds = tree.getRowBounds(0);
            RTree rTree = new RTree(tree, null, rowBounds.getLocation(), lr);
            rTree.mouseButton1Pressed(null);
        }
    });
    Call call = lr.getCall();
    AssertJUnit.assertEquals("click", call.getFunction());
    AssertJUnit.assertEquals("/Root Node", call.getCellinfo());
}
 
Example 4
Source Project: marathonv5   Source File: RTreeTest.java    License: Apache License 2.0 6 votes vote down vote up
public void singleNodeWithSpecialChars() throws Throwable, InvocationTargetException {
    final JTree tree = (JTree) ComponentUtils.findComponent(JTree.class, frame);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    siw(new Runnable() {
        @Override
        public void run() {
            DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
            DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
            root.setUserObject("Root Node [] , / Special");
            tree.expandRow(0);
            tree.setSelectionRow(0);
        }
    });
    final LoggingRecorder lr = new LoggingRecorder();
    siw(new Runnable() {
        @Override
        public void run() {
            Rectangle cb = tree.getPathBounds(tree.getPathForRow(0));
            RTree rTree = new RTree(tree, null, new Point(cb.x + 2, cb.y + 2), lr);
            rTree.mouseButton1Pressed(null);
        }
    });
    Call call = lr.getCall();
    AssertJUnit.assertEquals("click", call.getFunction());
    AssertJUnit.assertEquals("/Root Node [] , \\/ Special", call.getCellinfo());
}
 
Example 5
Source Project: consulo   Source File: StructureViewComponent.java    License: Apache License 2.0 6 votes vote down vote up
private void setupTree() {
  myTree.setCellRenderer(new NodeRenderer());
  myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
  myTree.setShowsRootHandles(true);
  registerPsiListener(myProject, this, this::queueUpdate);
  myProject.getMessageBus().connect(this).subscribe(UISettingsListener.TOPIC, o -> rebuild());

  if (showScrollToFromSourceActions()) {
    myAutoScrollToSourceHandler.install(myTree);
    myAutoScrollFromSourceHandler.install();
  }

  TreeUtil.installActions(getTree());

  new TreeSpeedSearch(getTree(), treePath -> {
    Object userObject = TreeUtil.getLastUserObject(treePath);
    return userObject != null ? FileStructurePopup.getSpeedSearchText(userObject) : null;
  });

  addTreeKeyListener();
  addTreeMouseListeners();
  restoreState();
}
 
Example 6
Source Project: pdfxtk   Source File: Overview.java    License: Apache License 2.0 6 votes vote down vote up
ThreadPane(String name_, int tabIdx_) {
     name   = name_;
     tabIdx = tabIdx_;
     setLayout(new BorderLayout());
     setName(name + " (" + msgCount + ")");
     jtree.setRootVisible(false);
     jtree.setShowsRootHandles(true);
     jtree.setCellRenderer(new TreeRenderer());
     jtree.setScrollsOnExpand(true); 
     jtree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
     jtree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
  public void valueChanged(TreeSelectionEvent e) {
    if(e.getNewLeadSelectionPath() == null) return;
    if(e.getNewLeadSelectionPath().getLastPathComponent() instanceof LogMessageNode) {
      LogMessage m = ((LogMessageNode)e.getNewLeadSelectionPath().getLastPathComponent()).m;
      info.setText(Const.LOG_STRINGS[m.priority] + " from " + m.thread + " @ " + new Date(m.time).toString() + "\n" +
		   m.message + "\n" + 
		   m.getException());
    }
  }
});
     add(new JScrollPane(jtree), BorderLayout.CENTER);
   }
 
Example 7
Source Project: uima-uimaj   Source File: MainFrame.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Inits the IR tree.
 */
private void initIRTree() {
  DefaultMutableTreeNode root = new DefaultMutableTreeNode(noIndexReposLabel);
  DefaultTreeModel model = new DefaultTreeModel(root);
  this.indexTree = new JTree(model);
  this.indexTree.setBorder(BorderFactory.createEmptyBorder(2, 4, 2, 2));
  // Only one node can be selected at any one time.
  this.indexTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  this.indexTree.addTreeSelectionListener(new IndexTreeSelectionListener(this));
  // No icons.
  DefaultTreeCellRenderer cellRenderer = new DefaultTreeCellRenderer();
  cellRenderer.setLeafIcon(null);
  // cellRenderer.setIcon(null);
  cellRenderer.setClosedIcon(null);
  cellRenderer.setOpenIcon(null);
  this.indexTree.setCellRenderer(cellRenderer);
}
 
Example 8
Source Project: netbeans   Source File: CheckTreeView.java    License: Apache License 2.0 6 votes vote down vote up
/** Creates a new instance of CheckTreeView */
public CheckTreeView() {
    
    setFocusable( false );
    
    CheckListener l = new CheckListener();
    tree.addMouseListener( l );
    tree.addKeyListener( l );

    CheckRenderer check = new CheckRenderer();
    tree.setCellRenderer( check );
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    
    tree.setShowsRootHandles(false);
    
    InputMap input = tree.getInputMap( JTree.WHEN_FOCUSED );
    if( null != input )
        input.remove( KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0) );
    
    setBorder( UIManager.getBorder("ScrollPane.border") );
}
 
Example 9
private void createSelectionDialog(final byte type) {
	WebServiceClient client = (WebServiceClient) context.getAttribute(PublishWizard.CLIENT);
	jcrBrowserTree = new JcrBrowserTree(type, client);
	jcrBrowserTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
	JPanel selectionPanel = JcrBrowserTreeUtil.createSelectionPanel(jcrBrowserTree, type);

	JDialog dialog = new BaseDialog(selectionPanel, I18NSupport.getString("wizard.publish.file.path.select"),
			true) {
		protected boolean ok() {
			return selection(jcrBrowserTree, type);
		}
	};
	dialog.pack();
	Show.centrateComponent((JDialog) context.getAttribute(PublishWizard.MAIN_FRAME), dialog);
	dialog.setVisible(true);
}
 
Example 10
Source Project: uima-uimaj   Source File: AnnotationFeaturesViewer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Populate.
 *
 * @param analysisEngine the analysis engine
 * @param aeMetaData the ae meta data
 */
public void populate(AnalysisEngine analysisEngine, AnalysisEngineMetaData aeMetaData) {
  tree = generateTreeView(analysisEngine, aeMetaData);

  tree.setDragEnabled(true); // To allow drag to stylemap table.
  tree.setRootVisible(false);
  tree.setShowsRootHandles(true); // Displays node expansion glyphs.

  TreeSelectionModel selectionModel = tree.getSelectionModel();
  selectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

  DefaultTreeCellRenderer cellRenderer = new DefaultTreeCellRenderer();
  cellRenderer.setLeafIcon(null);
  cellRenderer.setClosedIcon(null);
  cellRenderer.setOpenIcon(null);
  tree.setCellRenderer(cellRenderer);

  scrollPane.getViewport().add(tree, null);
}
 
Example 11
Source Project: netbeans   Source File: BrowseFolders.java    License: Apache License 2.0 6 votes vote down vote up
BrowseFolders(SourceGroup[] folders, Class<?> target, String preselectedFileName) {
    initComponents();
    String description = target == DataFolder.class ? "ACSD_BrowseFolders" : "ACSD_BrowseFiles"; // NOI18N
    getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(BrowseFolders.class, description));

    this.folders = folders;
    this.target = target;
    manager = new ExplorerManager();
    AbstractNode rootNode = new AbstractNode(new SourceGroupsChildren(folders));
    manager.setRootContext(rootNode);

    // Create the templates view
    btv = new BeanTreeView();
    btv.setRootVisible(false);
    btv.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    btv.setBorder(SAMPLE_SCROLL_PANE.getBorder());
    expandSelection(preselectedFileName);
    folderPanel.add(btv, BorderLayout.CENTER);
}
 
Example 12
Source Project: netbeans   Source File: ProjectFileExplorer.java    License: Apache License 2.0 6 votes vote down vote up
private void initUserComponents() {
    treeView = new BeanTreeView();
    treeView.setRootVisible(false);
    treeView.setPopupAllowed(false);
    treeView.setDefaultActionAllowed(false);
    treeView.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.insets = new java.awt.Insets(11, 11, 0, 11);
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;
    eventBlocker.setOpaque(false);
    eventBlocker.setVisible(dontCopyCB.isSelected());
    add(eventBlocker, gridBagConstraints);
    add(treeView, gridBagConstraints);
    jLblTreeView.setLabelFor(treeView.getViewport().getView());
    treeView.getAccessibleContext().setAccessibleName(NbBundle.getMessage(ClientExplorerPanel.class, "ACSD_AvailableWebServicesTree")); // NOI18N
    treeView.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ClientExplorerPanel.class, "ACSD_AvailableWebServicesTree")); // NOI18N
    dontCopyCB.setToolTipText(NbBundle.getMessage(ProjectFileExplorer.class, "TXT_DONOTCOPY_TOOLTIP")); // NOI18N
}
 
Example 13
Source Project: netbeans   Source File: DefaultClientSelectionPanel.java    License: Apache License 2.0 6 votes vote down vote up
private void initUserComponents() {
    treeView = new BeanTreeView();
    treeView.setRootVisible(false);
    treeView.setPopupAllowed(false);

    java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.insets = new java.awt.Insets(11, 11, 0, 11);
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;
    add(treeView, gridBagConstraints);
    jLblTreeView.setLabelFor(treeView.getViewport().getView());
    treeView.getAccessibleContext().setAccessibleName(
            NbBundle.getMessage(DefaultClientSelectionPanel.class, "ACSD_AvailableWebServicesTree"));
    treeView.getAccessibleContext().setAccessibleDescription(
            NbBundle.getMessage(DefaultClientSelectionPanel.class, "ACSD_AvailableWebServicesTree"));
    treeView.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
}
 
Example 14
Source Project: consulo   Source File: ChooseActionsDialog.java    License: Apache License 2.0 6 votes vote down vote up
public ChooseActionsDialog(Component parent, Keymap keymap, QuickList[] quicklists) {
  super(parent, true);
  myKeymap = keymap;
  myQuicklists = quicklists;

  myActionsTree = new ActionsTree();
  myActionsTree.reset(keymap, quicklists);
  myActionsTree.getTree().getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);

  new DoubleClickListener() {
    @Override
    protected boolean onDoubleClick(MouseEvent e) {
      doOKAction();
      return true;
    }
  }.installOn(myActionsTree.getTree());


  myTreeExpansionMonitor = TreeExpansionMonitor.install(myActionsTree.getTree());

  setTitle("Add Actions to Quick List");
  init();
}
 
Example 15
Source Project: settlers-remake   Source File: SelectSettlersFolderDialog.java    License: MIT License 6 votes vote down vote up
/**
 * Initialize the Tree with the filesystem
 */
private void initTree() {
	RootTreeNode root = new RootTreeNode(executorService);

	for (File f : File.listRoots()) {
		root.add(new FilesystemTreeNode(f));
	}

	model = new DefaultTreeModel(root);

	// to fire change event when the loading is finished
	root.setModel(model);
	tree = new JTree(model);

	tree.addTreeSelectionListener(selectionListener);
	tree.addTreeExpansionListener(expansionListener);
	tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
	tree.expandRow(0);
	tree.setRootVisible(false);
	tree.setCellRenderer(new FileTreeCellRenderer());
}
 
Example 16
public PlotConfigurationTree(PlotConfiguration plotConfiguration, DataTable dataTable,
		DataTableColumnListTransferHandler aTH) {
	super();
	expandAll();

	// forces the tree to ask the nodes for the correct row heights
	// must also be invoked after LaF changes...
	setRowHeight(0);

	getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
	setExpandsSelectedPaths(true);

	// DnD support
	setDragEnabled(true);
	setDropMode(DropMode.INSERT);

	// Rendering
	setShowsRootHandles(false);
	setBackground(Colors.WHITE);
	setCellRenderer(new PlotConfigurationTreeCellRenderer(aTH));
	putClientProperty("JTree.lineStyle", "Horizontal");

	createNewTreeModel(plotConfiguration);
}
 
Example 17
Source Project: p4ic4idea   Source File: ActiveConnectionPanel.java    License: Apache License 2.0 6 votes vote down vote up
private void setup() {
    root = new JPanel(new BorderLayout());
    JScrollPane scroll = new JBScrollPane();
    root.add(scroll, BorderLayout.CENTER);
    connectionTree = new Tree();
    scroll.setViewportView(connectionTree);

    connectionTree.getEmptyText().setText(P4Bundle.getString("connection.tree.initial"));
    connectionTree.setEditable(false);
    connectionTreeModel = new DefaultTreeModel(treeNode);
    connectionTree.setModel(connectionTreeModel);
    connectionTree.setCellRenderer(new ConnectionTreeCellRenderer());
    connectionTree.setRootVisible(false);
    DefaultTreeSelectionModel selectionModel = new DefaultTreeSelectionModel();
    selectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    connectionTree.setSelectionModel(selectionModel);

    ActionGroup actionButtons = createActionGroup();
    ActionToolbar toolbar =
            ActionManager.getInstance().createActionToolbar("p4.active-connection",
                    actionButtons, false);
    root.add(toolbar.getComponent(), BorderLayout.WEST);

    // TODO add context menu support for each selected node type.
    // TODO add support for navigating to a file if a FilePath is selected.
}
 
Example 18
Source Project: consulo   Source File: AnalyzeDependenciesComponent.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Initialize components
 */
private void init() {
  myTree.setCellRenderer(new ColoredTreeCellRenderer() {
    @Override
    public void customizeCellRenderer(JTree tree,
                                      Object value,
                                      boolean selected,
                                      boolean expanded,
                                      boolean leaf,
                                      int row,
                                      boolean hasFocus) {
      //if(getBackground() == null) {
      //  setBackground(UIUtil.getTreeTextBackground());
      //}
      if (value instanceof MyNode && !(value instanceof MyRootNode)) {
        final MyNode node = (MyNode)value;
        PathNode<?> n = (PathNode<?>)node.getUserObject();
        CellAppearanceEx a = n.getAppearance(selected, node.isDisplayInBold());
        a.customize(this);
      }
    }
  });
  myTree.setShowsRootHandles(false);
  myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  reloadTree();
}
 
Example 19
Source Project: jpexs-decompiler   Source File: TagTree.java    License: GNU General Public License v3.0 6 votes vote down vote up
public List<TreeItem> getSelected() {
    if (!mainPanel.folderPreviewPanel.selectedItems.isEmpty()) {
        return new ArrayList<>(mainPanel.folderPreviewPanel.selectedItems.values());
    }
    TreeSelectionModel tsm = getSelectionModel();
    TreePath[] tps = tsm.getSelectionPaths();
    List<TreeItem> ret = new ArrayList<>();
    if (tps == null) {
        return ret;
    }

    for (TreePath tp : tps) {
        TreeItem treeNode = (TreeItem) tp.getLastPathComponent();
        ret.add(treeNode);
    }
    return ret;
}
 
Example 20
public InspectorTree(final DefaultMutableTreeNode treemodel,
                     String treeName,
                     boolean detailsSubtree,
                     String parentTreeName,
                     boolean rootVisible,
                     boolean legacyMode,
                     Disposable parentDisposable) {
  super(treemodel);
  setUI(new InspectorTreeUI());
  final BasicTreeUI ui = (BasicTreeUI)getUI();
  this.detailsSubtree = detailsSubtree;

  setRootVisible(rootVisible);
  getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  registerShortcuts(parentDisposable);
  if (detailsSubtree) {
    // TODO(devoncarew): This empty text is not showing up for the details area, even when there are no detail nodes.
    getEmptyText().setText(treeName + " subtree of the selected " + parentTreeName);
  }
  else {
    getEmptyText().setText(treeName + " tree for the running app");
  }
}
 
Example 21
public InspectorTree(final DefaultMutableTreeNode treemodel,
                     String treeName,
                     boolean detailsSubtree,
                     String parentTreeName,
                     boolean rootVisible,
                     boolean legacyMode,
                     Disposable parentDisposable) {
  super(treemodel);
  setUI(new InspectorTreeUI());
  final BasicTreeUI ui = (BasicTreeUI)getUI();
  this.detailsSubtree = detailsSubtree;

  setRootVisible(rootVisible);
  getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  registerShortcuts(parentDisposable);
  if (detailsSubtree) {
    // TODO(devoncarew): This empty text is not showing up for the details area, even when there are no detail nodes.
    getEmptyText().setText(treeName + " subtree of the selected " + parentTreeName);
  }
  else {
    getEmptyText().setText(treeName + " tree for the running app");
  }
}
 
Example 22
Source Project: pumpernickel   Source File: AquaLocationSourceList.java    License: MIT License 6 votes vote down vote up
public AquaLocationSourceList(LocationHistory directoryStack,
		GraphicCache graphicCache) {
	super(new DefaultTreeModel(new DefaultMutableTreeNode("root")));

	treeModel = (DefaultTreeModel) getModel();
	root = (DefaultMutableTreeNode) treeModel.getRoot();

	this.directoryStack = directoryStack;
	this.graphicCache = graphicCache;

	treeModel.insertNodeInto(devices, root, 0);
	treeModel.insertNodeInto(places, root, 1);
	addTreeSelectionListener(treeSelectionListener);
	directoryStack.addChangeListener(directoryStackListener);
	setExpandsSelectedPaths(true);
	setCellRenderer(new SourceListLocationRenderer(graphicCache, this));
	getSelectionModel().setSelectionMode(
			TreeSelectionModel.SINGLE_TREE_SELECTION);
	setUI(new SourceListTreeUI(this));

	expandPath(new TreePath(devices.getPath()));
	expandPath(new TreePath(places.getPath()));
}
 
Example 23
Source Project: openAGV   Source File: ComponentsTreeViewManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance.
 *
 * @param treeView The tree view
 * @param userObjectUtil The user object util
 * @param mouseListener The mouse listener
 */
@Inject
public ComponentsTreeViewManager(TreeView treeView,
                                 UserObjectUtil userObjectUtil,
                                 MouseListener mouseListener) {
  super(treeView, userObjectUtil, mouseListener);
  treeView.getTree().getSelectionModel().setSelectionMode(
      TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
}
 
Example 24
Source Project: binnavi   Source File: CTagsTree.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new tree object.
 *
 * @param parent Parent window used for dialogs.
 * @param graph Graph shown in the window.
 * @param manager Provides tag information.
 */
public CTagsTree(final JFrame parent, final ZyGraph graph, final ITagManager manager) {
  m_parent = Preconditions.checkNotNull(parent, "IE02308: Perent argument can not be null");
  m_graph = Preconditions.checkNotNull(graph, "IE01776: Graph can not be null");
  m_tagManager = Preconditions.checkNotNull(manager, "IE01777: Manager argument can not be null");

  m_model = new CTagsTreeModel(this);
  setModel(m_model);
  getModel().addTreeModelListener(new InternalModelListener());
  addMouseListener(m_mouseListener);
  m_graph.addListener(m_graphSelectionListener);
  m_graph.addListener(m_graphVisibilityListener);

  setRootVisible(false);

  m_rootNode = new CRootTagTreeNode(parent, this, graph, m_tagManager);
  m_model.setRoot(m_rootNode);

  setCellRenderer(new CTagTreeCellRenderer()); // ATTENTION: UNDER NO CIRCUMSTANCES MOVE THIS LINE
                                               // ABOVE THE SETROOT LINE

  m_model.nodeStructureChanged(m_rootNode);

  final List<IDropHandler> handlers = new ArrayList<IDropHandler>();

  handlers.add(new CTagSortingHandler());

  new CDefaultTransferHandler(this, DnDConstants.ACTION_COPY_OR_MOVE, handlers);

  final DefaultTreeSelectionModel selectionModel = new DefaultTreeSelectionModel();
  selectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  setSelectionModel(selectionModel);

  final InputMap windowImap = getInputMap(JComponent.WHEN_FOCUSED);

  windowImap.put(HotKeys.DELETE_HK.getKeyStroke(), "DELETE");
  getActionMap().put("DELETE", CActionProxy.proxy(new DeleteAction()));
}
 
Example 25
Source Project: mzmine3   Source File: ProcessingComponent.java    License: GNU General Public License v2.0 5 votes vote down vote up
private @Nullable DefaultMutableTreeNode getSelectedItem(@Nonnull JTree tree) {
  TreeSelectionModel selectionModel = tree.getSelectionModel();
  if (selectionModel == null)
    return null;
  TreePath path = selectionModel.getSelectionPath();
  if (path == null)
    return null;
  return (DefaultMutableTreeNode) path.getLastPathComponent();
}
 
Example 26
/**
    * list all entities in the world.  Double click an item to get its panel.
    * See https://docs.oracle.com/javase/7/docs/api/javax/swing/JTree.html
    */
public void updateEntityTree() {
	// list all objects in scene
    DefaultMutableTreeNode newTop = createTreeNodes(ro);
	JTree newTree = new JTree(newTop);

    newTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    newTree.setShowsRootHandles(true);
    newTree.addTreeSelectionListener(this);
	//tree.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));

	if(oldTree!=null) {
		// preserve the original expansions
		ArrayList<TreePath> expanded = new ArrayList<TreePath>();
		for(int i=0;i<oldTree.getRowCount();++i) {
			if(oldTree.isExpanded(i)) {
				expanded.add(oldTree.getPathForRow(i));
			}
		}
		// restore the expanded paths
		for(TreePath p : expanded) {
			newTree.expandPath(p);
		}
		// restore the selected paths
		TreePath[] paths = oldTree.getSelectionPaths();
		newTree.setSelectionPaths(paths);
	}
	
	if(!newTree.equals(oldTree)) {
		scroll.setViewportView(newTree);
		oldTree=newTree;
		oldTop =newTop;
	}
}
 
Example 27
Source Project: consulo   Source File: AbstractProjectViewPSIPane.java    License: Apache License 2.0 5 votes vote down vote up
private void initTree() {
  myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
  UIUtil.setLineStyleAngled(myTree);
  myTree.setRootVisible(false);
  myTree.setShowsRootHandles(true);
  myTree.expandPath(new TreePath(myTree.getModel().getRoot()));

  EditSourceOnDoubleClickHandler.install(myTree);

  ToolTipManager.sharedInstance().registerComponent(myTree);
  TreeUtil.installActions(myTree);

  new MySpeedSearch(myTree);

  myTree.addKeyListener(new KeyAdapter() {
    @Override
    public void keyPressed(KeyEvent e) {
      if (KeyEvent.VK_ENTER == e.getKeyCode()) {
        TreePath path = getSelectedPath();
        if (path != null && !myTree.getModel().isLeaf(path.getLastPathComponent())) {
          return;
        }

        DataContext dataContext = DataManager.getInstance().getDataContext(myTree);
        OpenSourceUtil.openSourcesFrom(dataContext, ScreenReader.isActive());
      }
      else if (KeyEvent.VK_ESCAPE == e.getKeyCode()) {
        if (e.isConsumed()) return;
        PsiCopyPasteManager copyPasteManager = PsiCopyPasteManager.getInstance();
        boolean[] isCopied = new boolean[1];
        if (copyPasteManager.getElements(isCopied) != null && !isCopied[0]) {
          copyPasteManager.clear();
          e.consume();
        }
      }
    }
  });
  CustomizationUtil.installPopupHandler(myTree, IdeActions.GROUP_PROJECT_VIEW_POPUP, ActionPlaces.PROJECT_VIEW_POPUP);
}
 
Example 28
Source Project: azure-devops-intellij   Source File: TfsTreeForm.java    License: MIT License 5 votes vote down vote up
public TfsTreeForm() {
    DataManager.registerDataProvider(tree, this);
    new TreeSpeedSearch(tree);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent e) {
            selectedItem = doGetSelectedItem();
            pathField.setText(selectedItem != null ? selectedItem.path : null);
            eventDispatcher.getMulticaster().selectionChanged();
        }
    });
    PopupHandler.installPopupHandler(tree, POPUP_ACTION_GROUP, ActionPlaces.REMOTE_HOST_DIALOG_POPUP);
    setMessage(null, false);
}
 
Example 29
Source Project: ghidra   Source File: ProgramDiffPlugin.java    License: Apache License 2.0 5 votes vote down vote up
private OpenVersionedFileDialog getOpenProgramDialog() {

		if (openProgramDialog != null) {
			return openProgramDialog;
		}

		OpenVersionedFileDialog dialog =
			new OpenVersionedFileDialog(tool, "Select Other Program", f -> {
				Class<?> c = f.getDomainObjectClass();
				return Program.class.isAssignableFrom(c);
			});
		dialog.setTreeSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
		dialog.setHelpLocation(new HelpLocation("Diff", "Open_Close_Program_View"));
		return dialog;
	}
 
Example 30
Source Project: consulo   Source File: DualView.java    License: Apache License 2.0 5 votes vote down vote up
private Component createTreeComponent(DualViewColumnInfo[] columns, TreeNode root) {
  myTreeView = new TreeTableView(new ListTreeTableModelOnColumns(root, createTreeColumns(columns))) {
    public TableCellRenderer getCellRenderer(int row, int column) {
      return createWrappedRenderer(super.getCellRenderer(row, column));
    }
  };
  myTreeView.getTree().getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
  JPanel result = new JPanel(new BorderLayout());
  result.add(ScrollPaneFactory.createScrollPane(myTreeView), BorderLayout.CENTER);
  return result;
}