javax.swing.event.TreeSelectionListener Java Examples

The following examples show how to use javax.swing.event.TreeSelectionListener. 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: TreePainter.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Installs custom {@link TreeSelectionListener} for complex selections update.
 */
protected void installTreeSelectionListeners ()
{
    treeSelectionListener = new TreeSelectionListener ()
    {
        @Override
        public void valueChanged ( @NotNull final TreeSelectionEvent e )
        {
            // Ensure component is still available
            // This might happen if painter is replaced from another TreeSelectionListener
            if ( component != null )
            {
                // Optimized selection repaint
                repaintSelection ();
            }
        }
    };
    component.addTreeSelectionListener ( treeSelectionListener );
}
 
Example #2
Source File: HintsPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public HintsPanel(HintMetadata preselected, @NullAllowed final CustomizerContext<?, ?> cc, ClassPathBasedHintWrapper cpBased) {
    this.cpBased = cpBased;
    this.queryStatus = cc == null ? QueryStatus.NEVER : QueryStatus.SHOW_QUERIES;
    this.showHeavyInspections = true;
    init(null, true, false, false, false, cc == null, false, cc != null);
    select(preselected);
    configurationsPanel.setVisible(false);
    
    if (cc != null) {
        errorTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
            @Override public void valueChanged(TreeSelectionEvent e) {
                HintMetadata hm = getSelectedHint();

                if (hm != null) {
                    cc.setSelectedId(AnalyzerImpl.ID_JAVA_HINTS_PREFIX + hm.id);
                }
            }
        });
    }
}
 
Example #3
Source File: ScopeChooserConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void initTree() {
  myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(TreeSelectionEvent e) {
      final TreePath path = e.getOldLeadSelectionPath();
      if (path != null) {
        final MyNode node = (MyNode)path.getLastPathComponent();
        final NamedConfigurable namedConfigurable = node.getConfigurable();
        if (namedConfigurable instanceof ScopeConfigurable) {
          ((ScopeConfigurable)namedConfigurable).cancelCurrentProgress();
        }
      }
    }
  });
  super.initTree();
  myTree.setShowsRootHandles(false);
  new TreeSpeedSearch(myTree, new Convertor<TreePath, String>() {
    @Override
    public String convert(final TreePath treePath) {
      return ((MyNode)treePath.getLastPathComponent()).getDisplayName();
    }
  }, true);

  myTree.getEmptyText().setText(IdeBundle.message("scopes.no.scoped"));
}
 
Example #4
Source File: ToolSelectDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected ToolSelectDialog(@Nullable Project project, @Nullable String actionIdToSelect, BaseToolsPanel toolsPanel) {
  super(project);
  myToolsPanel = toolsPanel;
  myToolsPanel.reset();
  setOKActionEnabled(myToolsPanel.getSingleSelectedTool() != null);
  myToolsPanel.addSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(TreeSelectionEvent e) {
      setOKActionEnabled(myToolsPanel.getSingleSelectedTool() != null);
    }
  });
  init();
  pack();
  if (actionIdToSelect != null) {
    myToolsPanel.selectTool(actionIdToSelect);
  }
  setTitle(ToolsBundle.message("tools.dialog.title"));
}
 
Example #5
Source File: ClassMemberList.java    From Cafebabe with GNU General Public License v3.0 6 votes vote down vote up
public ClassMemberList() {
	MethodEditorPanel editor = new MethodEditorPanel(this);
	this.setRootVisible(false);
	this.setShowsRootHandles(false);
	this.setFocusable(false);
	this.setCellRenderer(new MethodListCellRenderer());
	this.addTreeSelectionListener(new TreeSelectionListener() {
		@Override
		public void valueChanged(TreeSelectionEvent e) {
			MethodListNode node = (MethodListNode) getLastSelectedPathComponent();
			if (node != null && node.getMethod() != null) {
				Cafebabe.gui.smallEditorPanel.setViewportView(editor);
				editor.editMethod(node.getMethod());
			}
		}
	});
	this.model = new DefaultTreeModel(root = new MethodListNode(null, null));
	this.setModel(model);
	this.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
}
 
Example #6
Source File: AbstractTableView.java    From ramus with GNU General Public License v3.0 6 votes vote down vote up
protected void createInnerComponent() {
    panel.removeAll();
    Attribute[] attributes = getAttributes();
    RootCreater rootCreater = getRootCreater();

    component = new RowTreeTableComponent(engine, qualifier, accessRules,
            rootCreater, attributes, framework);

    rowSet = component.getRowSet();
    table = component.getTable();

    table.getTreeSelectionModel().addTreeSelectionListener(
            new TreeSelectionListener() {
                @Override
                public void valueChanged(TreeSelectionEvent e) {
                    refreshActions();
                }
            });
    refreshActions();
    panel.add(component, BorderLayout.CENTER);
    panel.revalidate();
    panel.repaint();
}
 
Example #7
Source File: ClassTree.java    From JByteMod-Beta with GNU General Public License v2.0 6 votes vote down vote up
public ClassTree(JByteMod jam) {
  this.jbm = jam;
  this.setRootVisible(false);
  this.setShowsRootHandles(true);
  this.setCellRenderer(new TreeCellRenderer());
  this.addTreeSelectionListener(new TreeSelectionListener() {
    public void valueChanged(TreeSelectionEvent e) {
      SortedTreeNode node = (SortedTreeNode) ClassTree.this.getLastSelectedPathComponent();
      if (node == null)
        return;
      if (node.getCn() != null && node.getMn() != null) {
        jam.selectMethod(node.getCn(), node.getMn());
      } else if (node.getCn() != null) {
        jam.selectClass(node.getCn());
      } else {

      }
    }
  });
  this.model = new DefaultTreeModel(new SortedTreeNode(""));
  this.setModel(model);
  this.setTransferHandler(new JarDropHandler(this, 0));
  this.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
}
 
Example #8
Source File: JPanelForTree.java    From freeinternals with Apache License 2.0 6 votes vote down vote up
/**
 * Create a panel tool bar to contain a {@code JTree} object.
 *
 * @param jTree The tree to be contained
 * @param frame The parent window
 */
public JPanelForTree(final JTree jTree, final JFrame frame) {
    if (jTree == null) {
        throw new IllegalArgumentException("[tree] cannot be null.");
    }

    this.tree = jTree;
    this.topLevelFrame = frame;
    this.tree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(final javax.swing.event.TreeSelectionEvent evt) {
            treeSelectionChanged(evt);
        }
    });

    this.toolbar = new JToolBar();
    this.toolbarbtnDetails = new JButton("Details");
    this.initToolbar();

    this.layoutComponents();
}
 
Example #9
Source File: AppleDiskTab.java    From DiskBrowser with GNU General Public License v3.0 6 votes vote down vote up
private void setSelectionListener (JTree tree)
// ---------------------------------------------------------------------------------//
{
  tree.addTreeSelectionListener (new TreeSelectionListener ()
  {
    @Override
    public void valueChanged (TreeSelectionEvent e)
    {
      // A null happens when there is a click in the DiskLayoutPanel, in order
      // to turn off the currently selected file
      AppleFileSource afs = (AppleFileSource) getSelectedObject ();
      if (afs != null)
        eventHandler.fireFileSelectionEvent (afs);
    }
  });
}
 
Example #10
Source File: Overview.java    From pdfxtk with 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 #11
Source File: TreeToolbarDecorator.java    From consulo with Apache License 2.0 6 votes vote down vote up
TreeToolbarDecorator(JTree tree, @Nullable final ElementProducer<?> producer) {
  myTree = tree;
  myProducer = producer;
  myAddActionEnabled = myRemoveActionEnabled = myUpActionEnabled = myDownActionEnabled = myTree.getModel() instanceof EditableTreeModel;
  if (myTree.getModel() instanceof EditableTreeModel) {
    createDefaultTreeActions();
  }
  myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(TreeSelectionEvent e) {
      updateButtons();
    }
  });
  myTree.addPropertyChangeListener("enabled", new PropertyChangeListener() {
    @Override
    public void propertyChange(PropertyChangeEvent evt) {
      updateButtons();
    }
  });
}
 
Example #12
Source File: ClassTree.java    From Cafebabe with GNU General Public License v3.0 6 votes vote down vote up
public ClassTree(ClassMemberList ml) {
	ClassEditorPanel editor = new ClassEditorPanel(this);
	this.setRootVisible(false);
	this.setShowsRootHandles(true);
	this.setFocusable(false);
	this.setCellRenderer(new ClassTreeCellRenderer());
	this.setSelectionStyle(TreeSelectionStyle.group);

	this.addTreeSelectionListener(new TreeSelectionListener() {
		@Override
		public void valueChanged(TreeSelectionEvent e) {
			SortedTreeClassNode node = (SortedTreeClassNode) getLastSelectedPathComponent();
			if (node != null && node.getClazz() != null) {
				ml.setMethods(node.getClazz());
				Cafebabe.gui.smallEditorPanel.setViewportView(editor);
				editor.editClass(node.getClazz());
			}
		}
	});
	this.model = new DefaultTreeModel(root = new SortedTreeClassNode(""));
	this.setModel(model);
	this.setTransferHandler(new JarDropHandler(this, 0));
	this.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
}
 
Example #13
Source File: HintUpdateSupply.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void installTreeListener(@Nonnull final JTree tree) {
  tree.addTreeSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(final TreeSelectionEvent e) {
      if (!isHintVisible(HintUpdateSupply.this.myHint) || isSelectedByMouse(tree)) return;

      TreePath path = tree.getSelectionPath();
      if (path != null) {
        final PsiElement psiElement = getPsiElementForHint(path.getLastPathComponent());
        if (psiElement != null && psiElement.isValid()) {
          updateHint(psiElement);
        }
      }
    }
  });
}
 
Example #14
Source File: HistoryWindow.java    From Spark with Apache License 2.0 6 votes vote down vote up
private TreeSelectionListener onTreeSelected() {
	return e -> {

           TreePath tp = e.getNewLeadSelectionPath();
           if (tp == null)
               return;

           Object node = tp.getLastPathComponent();
           if (!(node instanceof HistoryTreeNode))
               return;

           HistoryTreeNode entry = (HistoryTreeNode) node;
           HistoryEntry historyEntry = entry.getHistoryEntry();

           String historyText = (historyEntry == null || historyEntry
                   .isEmpty()) ? EMPTY : historyEntry.getHistory();

           historyContentText.setText(historyText);
       };
}
 
Example #15
Source File: SMTestRunnerResultsForm.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void addEventsListener(final EventsListener listener) {
  myEventListeners.add(listener);
  addTestsTreeSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(final TreeSelectionEvent e) {
      //We should fire event only if it was generated by this component,
      //e.g. it is focused. Otherwise it is side effect of selecting proxy in
      //try by other component
      //if (myTreeView.isFocusOwner()) {
      @Nullable final SMTestProxy selectedProxy = (SMTestProxy)getTreeView().getSelectedTest();
      listener.onSelected(selectedProxy, SMTestRunnerResultsForm.this, SMTestRunnerResultsForm.this);
      //}
    }
  });
}
 
Example #16
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 #17
Source File: Container.java    From dctb-utfpr-2018-1 with Apache License 2.0 5 votes vote down vote up
private void createJTree() {
    DefaultMutableTreeNode root
            = new DefaultMutableTreeNode("Ordem");
    DefaultMutableTreeNode types = new DefaultMutableTreeNode("tipos");
    root.add(types);

    DefaultMutableTreeNode fpTypes
            = new DefaultMutableTreeNode("Alb");
    types.add(fpTypes);
    fpTypes.add(new DefaultMutableTreeNode("A"));
    fpTypes.add(new DefaultMutableTreeNode("B"));

    DefaultMutableTreeNode intTypes
            = new DefaultMutableTreeNode("Num");
    types.add(intTypes);
    intTypes.add(new DefaultMutableTreeNode("1"));
    intTypes.add(new DefaultMutableTreeNode("2"));
    intTypes.add(new DefaultMutableTreeNode("3"));
    intTypes.add(new DefaultMutableTreeNode("4"));

    types.add(new DefaultMutableTreeNode("Rom"));
    types.add(new DefaultMutableTreeNode("Sem"));

    JTree tree = new JTree(root);

    tree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent tse) {
            titulo.setText("a seleção é: "
                    + tse.getPath().getLastPathComponent());
        }
    });

    bottom.add(tree);
}
 
Example #18
Source File: MppFilePanel.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param file MPP file to be displayed in this view.
 */
public MppFilePanel(File file)
{
   m_treeModel = new PoiTreeModel();
   m_treeController = new PoiTreeController(m_treeModel);
   m_treeView = new PoiTreeView(m_treeModel);
   m_treeView.setShowsRootHandles(true);

   m_hexDumpModel = new HexDumpModel();
   m_hexDumpController = new HexDumpController(m_hexDumpModel);
   setLayout(new GridLayout(0, 1, 0, 0));
   m_hexDumpView = new HexDumpView(m_hexDumpModel);

   JSplitPane splitPane = new JSplitPane();
   splitPane.setDividerLocation(0.3);
   add(splitPane);

   JScrollPane scrollPane = new JScrollPane(m_treeView);
   splitPane.setLeftComponent(scrollPane);

   final JTabbedPane tabbedPane = new JTabbedPane(SwingConstants.TOP);
   splitPane.setRightComponent(tabbedPane);
   tabbedPane.add("Hex Dump", m_hexDumpView);

   m_treeView.addTreeSelectionListener(new TreeSelectionListener()
   {
      @Override public void valueChanged(TreeSelectionEvent e)
      {
         TreePath path = e.getPath();
         Object component = path.getLastPathComponent();
         if (component instanceof DocumentEntry)
         {
            m_hexDumpController.viewDocument((DocumentEntry) component);
         }
      }
   });

   m_treeController.loadFile(file);
}
 
Example #19
Source File: GraphicalTreeRenderer.java    From jsqsh with Apache License 2.0 5 votes vote down vote up
/**
 * A way to set a will expand listener, this was added as a hack to 
 * interface with the tree command.  This too will be nullified after
 * the footer has been called.
 * @param twel
 */
public void setTreeListeners(TreeWillExpandListener twel, 
        TreeSelectionListener tsl) {
    
    this.twel = twel;
    
    this.tsl = tsl;
}
 
Example #20
Source File: MainWindow.java    From clarity-examples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void initialize() {
    frmNetpropertyViewer = new JFrame();
    frmNetpropertyViewer.setMinimumSize(new Dimension(700, 300));
    frmNetpropertyViewer.setIconImage(Toolkit.getDefaultToolkit().getImage(MainWindow.class.getResource("/images/dota_2_icon.png")));
    frmNetpropertyViewer.setTitle("DT inspector");
    frmNetpropertyViewer.setBounds(100, 100, 800, 450);
    frmNetpropertyViewer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JSplitPane splitPane = new JSplitPane();
    frmNetpropertyViewer.getContentPane().add(splitPane, BorderLayout.CENTER);

    scrollPaneLeft = new JScrollPane();
    splitPane.setLeftComponent(scrollPaneLeft);

    classTree = new JTree();
    classTree.setRootVisible(false);
    classTree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent e) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent();
            TreePayload p = (TreePayload) node.getUserObject();
            DTClass cls = p.getDtClass();
            if (cls instanceof S1DTClass) {
                table.setModel(new TableModelS1((S1DTClass) cls));
            } else {
                table.setModel(new TableModelS2((S2DTClass) cls));
            }
        }
    });
    scrollPaneLeft.setViewportView(classTree);

    scrollPaneRight = new JScrollPane();
    splitPane.setRightComponent(scrollPaneRight);
    
    table = new JTable();
    table.setColumnSelectionAllowed(true);
    table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    table.setAutoCreateRowSorter(true);
    scrollPaneRight.setViewportView(table);
    splitPane.setDividerLocation(200);
}
 
Example #21
Source File: GroupedBandChoosingStrategy.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public JPanel createCheckersPane() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    Map<String, Integer> groupNodeMap = initGrouping(root);
    List<TreePath> selectedPaths = new ArrayList<>();
    addBandCheckBoxes(root, selectedPaths, groupNodeMap);
    addTiePointGridCheckBoxes(root, selectedPaths, groupNodeMap);
    removeEmptyGroups(root, groupNodeMap);

    TreeModel treeModel = new DefaultTreeModel(root);

    checkBoxTree = new CheckBoxTree(treeModel);
    checkBoxTree.getCheckBoxTreeSelectionModel().setSelectionPaths(selectedPaths.toArray(new TreePath[selectedPaths.size()]));
    checkBoxTree.setRootVisible(false);
    checkBoxTree.setShowsRootHandles(true);
    checkBoxTree.getCheckBoxTreeSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
        @Override
        public void valueChanged(TreeSelectionEvent e) {
            updateCheckBoxStates();
        }
    });
    final DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) checkBoxTree.getActualCellRenderer();
    renderer.setFont(SMALL_ITALIC_FONT);
    renderer.setLeafIcon(null);
    renderer.setOpenIcon(null);
    renderer.setClosedIcon(null);
    Color color = new Color(240, 240, 240);
    checkBoxTree.setBackground(color);
    renderer.setBackgroundSelectionColor(color);
    renderer.setBackgroundNonSelectionColor(color);
    renderer.setBorderSelectionColor(color);
    renderer.setTextSelectionColor(Color.BLACK);

    GridBagConstraints gbc2 = GridBagUtils.createConstraints("insets.left=4,anchor=WEST,fill=BOTH");
    final JPanel checkersPane = GridBagUtils.createPanel();
    GridBagUtils.addToPanel(checkersPane, checkBoxTree, gbc2, "weightx=1.0,weighty=1.0");
    return checkersPane;
}
 
Example #22
Source File: TaskTreeTab.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Component createTreePanel() {
    treeComponent = new TaskTreeComponent(gradlePluginLord, new TaskTreeComponent.Interaction() {
        public void rightClick(JTree tree, int x, int y) {
            enableThingsAppropriately();
            popupMenu.show(tree, x, y);
        }

        public void taskInvoked(TaskView task, boolean isCtrlKeyDown) {
            if (isCtrlKeyDown) {
                gradlePluginLord.addExecutionRequestToQueue(task, false, "-a");
            } else {
                gradlePluginLord.addExecutionRequestToQueue(task, false);
            }
        }

        public void projectInvoked(ProjectView project) {
            executeDefaultTasksInProject(project);
        }
    });

    treeComponent.getTree().addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent e) {
            enableThingsAppropriately();
        }
    });

    defaultTreeBackground = treeComponent.getTree().getBackground();

    treeScrollPane = new JScrollPane();

    treeComponent.getTree().setBackground(workingBackgroundColor);  //change the color to better indicate that
    showTextInViewport("Has not built projects/tasks yet.");

    return treeScrollPane;
}
 
Example #23
Source File: TaskTreeTab.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Component createTreePanel() {
    treeComponent = new TaskTreeComponent(gradlePluginLord, new TaskTreeComponent.Interaction() {
        public void rightClick(JTree tree, int x, int y) {
            enableThingsAppropriately();
            popupMenu.show(tree, x, y);
        }

        public void taskInvoked(TaskView task, boolean isCtrlKeyDown) {
            if (isCtrlKeyDown) {
                gradlePluginLord.addExecutionRequestToQueue(task, false, "-a");
            } else {
                gradlePluginLord.addExecutionRequestToQueue(task, false);
            }
        }

        public void projectInvoked(ProjectView project) {
            executeDefaultTasksInProject(project);
        }
    });

    treeComponent.getTree().addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent e) {
            enableThingsAppropriately();
        }
    });

    defaultTreeBackground = treeComponent.getTree().getBackground();

    treeScrollPane = new JScrollPane();

    treeComponent.getTree().setBackground(workingBackgroundColor);  //change the color to better indicate that
    showTextInViewport("Has not built projects/tasks yet.");

    return treeScrollPane;
}
 
Example #24
Source File: FilteringTreeBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
public FilteringTreeBuilder(Tree tree, ElementFilter filter, AbstractTreeStructure structure, @Nullable Comparator<? super NodeDescriptor> comparator) {
  super(tree, (DefaultTreeModel)tree.getModel(), structure instanceof FilteringTreeStructure ? structure : new FilteringTreeStructure(filter, structure), comparator);

  myTree = tree;
  initRootNode();

  if (filter instanceof ElementFilter.Active) {
    ((ElementFilter.Active)filter).addListener(new ElementFilter.Listener() {
      @Nonnull
      @Override
      public Promise<?> update(final Object preferredSelection, final boolean adjustSelection, final boolean now) {
        return refilter(preferredSelection, adjustSelection, now);
      }
    }, this);
  }

  myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(TreeSelectionEvent e) {
      TreePath newPath = e.getNewLeadSelectionPath();
      if (newPath != null) {
        Object element = getElementFor(newPath.getLastPathComponent());
        if (element != null) {
          myLastSuccessfulSelect = element;
        }
      }
    }
  });
}
 
Example #25
Source File: DirectoryChooserModuleTreeView.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void onSelectionChange(final Runnable runnable) {
  myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(TreeSelectionEvent e) {
      runnable.run();
    }
  });
}
 
Example #26
Source File: MethodsCountPanel.java    From android-classyshark with Apache License 2.0 5 votes vote down vote up
private void setup() {
    this.setLayout(new BorderLayout());
    treeModel = new DefaultTreeModel(new DefaultMutableTreeNode(null));
    jTree = new JTree(treeModel);
    jTree.setRootVisible(false);
    jTree.setCellRenderer(new CellRenderer());
    theme.applyTo(jTree);

    DefaultTreeCellRenderer cellRenderer = (DefaultTreeCellRenderer) jTree.getCellRenderer();

    cellRenderer.setFont(new Font("Monospaced", Font.PLAIN, 20));
    jTree.setCellRenderer(cellRenderer);
    jTree.addTreeSelectionListener(new TreeSelectionListener() {
        @Override
        public void valueChanged(TreeSelectionEvent e) {
            Object selection = jTree.getLastSelectedPathComponent();
            DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode)selection;
            ClassNode node = (ClassNode) defaultMutableTreeNode.getUserObject();
            viewerController.onSelectedMethodCount(node);
        }
    });

    JScrollPane jScrollPane = new JScrollPane(jTree);
    this.setBorder(new EmptyBorder(0,0,0,0));
    this.add(jScrollPane, BorderLayout.CENTER);
    theme.applyTo(jScrollPane);

    jTree.setDragEnabled(true);
    jTree.setTransferHandler(new FileTransferHandler(viewerController));
}
 
Example #27
Source File: WebTree.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets whether or not tree should automatically scroll to selected {@link MutableTreeNode}s.
 *
 * @param scroll whether or not tree should automatically scroll to selected {@link MutableTreeNode}s
 */
public void setScrollToSelection ( final boolean scroll )
{
    if ( scroll )
    {
        if ( !isScrollToSelection () )
        {
            scrollToSelectionListener = new TreeSelectionListener ()
            {
                @Override
                public void valueChanged ( final TreeSelectionEvent e )
                {
                    scrollToSelection ();
                }
            };
            addTreeSelectionListener ( scrollToSelectionListener );
        }
    }
    else
    {
        if ( isScrollToSelection () )
        {
            removeTreeSelectionListener ( scrollToSelectionListener );
            scrollToSelectionListener = null;
        }
    }
}
 
Example #28
Source File: ChangesTreeList.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void addSelectionListener(final Runnable runnable) {
  myGenericSelectionListener = runnable;
  addTreeSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(TreeSelectionEvent e) {
      myGenericSelectionListener.run();
    }
  });
}
 
Example #29
Source File: TaskTreeTab.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Component createTreePanel() {
    treeComponent = new TaskTreeComponent(gradlePluginLord, new TaskTreeComponent.Interaction() {
        public void rightClick(JTree tree, int x, int y) {
            enableThingsAppropriately();
            popupMenu.show(tree, x, y);
        }

        public void taskInvoked(TaskView task, boolean isCtrlKeyDown) {
            if (isCtrlKeyDown) {
                gradlePluginLord.addExecutionRequestToQueue(task, false, "-a");
            } else {
                gradlePluginLord.addExecutionRequestToQueue(task, false);
            }
        }

        public void projectInvoked(ProjectView project) {
            executeDefaultTasksInProject(project);
        }
    });

    treeComponent.getTree().addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent e) {
            enableThingsAppropriately();
        }
    });

    defaultTreeBackground = treeComponent.getTree().getBackground();

    treeScrollPane = new JScrollPane();

    treeComponent.getTree().setBackground(workingBackgroundColor);  //change the color to better indicate that
    showTextInViewport("Has not built projects/tasks yet.");

    return treeScrollPane;
}
 
Example #30
Source File: MakeLayoutPane.java    From DroidUIBuilder with Apache License 2.0 5 votes vote down vote up
private JTree initTreeLayoutExplore()
{
	final JTree treeLayoutExplore = new JTree(AndroidEditor.instance().getLayoutTreeModel());
	treeLayoutExplore.setShowsRootHandles(true);
	treeLayoutExplore.addTreeSelectionListener(new TreeSelectionListener(){
		public void valueChanged(TreeSelectionEvent arg0){
			Widget w = (Widget) treeLayoutExplore.getLastSelectedPathComponent();
			AndroidEditor.instance().select(w);
		}
	});
	treeLayoutExplore.setBorder(BorderFactory.createTitledBorder("Layout Explorer"));
	treeLayoutExplore.setMinimumSize(new Dimension(200, 400));
	return treeLayoutExplore;
}