Java Code Examples for javax.swing.JTree#putClientProperty()

The following examples show how to use javax.swing.JTree#putClientProperty() . 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: ProfilerTreeTable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
static void restoreExpandedNodes(JTree tree, UIState uiState) {
        try {
            tree.putClientProperty(UIUtils.PROP_EXPANSION_TRANSACTION, Boolean.TRUE);
            Enumeration<TreePath> paths = uiState.getExpandedPaths();
            if (paths != null) while (paths.hasMoreElements()) {
                TreePath tp = paths.nextElement();
//                System.err.println(">>> Restoring expanded " + tp);
                tree.expandPath(getSimilarPath(tp, tree.getModel()));
            }
        } catch (Exception e) {
            System.err.println(">>> Exception in ProfilerTreeTable.restoreExpandedNodes: " + e.getMessage());
            e.printStackTrace();
        } finally {
            tree.putClientProperty(UIUtils.PROP_EXPANSION_TRANSACTION, null);
        }
    }
 
Example 2
Source File: ConstructorPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void initTree() {
    JTree tree = new JTree(getRootNode());
    tree.setCellRenderer(new CheckBoxTreeRenderer());
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.putClientProperty("JTree.lineStyle", "Angled");  //NOI18N
    NodeSelectionListener listener = new NodeSelectionListener(tree);
    tree.addMouseListener(listener);
    tree.addKeyListener(listener);
    tree.expandRow(0);
    tree.setShowsRootHandles(true);
    tree.setSelectionRow(0);

    initTree(tree);

    scrollPane.add(tree);
    scrollPane.setViewportView(tree);
}
 
Example 3
Source File: ClassHierarchyPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public ClassHierarchyPanel(boolean isView) {
    initComponents();
    if (!isView) {
        toolBar.remove(0);
        toolBar.remove(0);
        subtypeButton.setFocusable(true);
        supertypeButton.setFocusable(true);
    }
    setName(NbBundle.getMessage(getClass(), "CTL_ClassHierarchyTopComponent")); // NOI18N
    setToolTipText(NbBundle.getMessage(getClass(), "HINT_ClassHierarchyTopComponent")); // NOI18N
    tree = new JTree();
    treeModel = new DefaultTreeModel(new DefaultMutableTreeNode());
    tree.setModel(treeModel);
    tree.setToggleClickCount(0);
    tree.setCellRenderer(new TreeRenderer());
    tree.putClientProperty("JTree.lineStyle", "Angled");  //NOI18N
    tree.expandRow(0);
    tree.setShowsRootHandles(true);
    tree.setSelectionRow(0);
    tree.setRootVisible(false);
    hierarchyPane.add(tree);
    hierarchyPane.setViewportView(tree);
    tree.addMouseListener(mouseListener);
}
 
Example 4
Source File: ProfilerTreeTable.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
static void restoreExpandedNodes(JTree tree, UIState uiState) {
        try {
            tree.putClientProperty(UIUtils.PROP_EXPANSION_TRANSACTION, Boolean.TRUE);
            Enumeration<TreePath> paths = uiState.getExpandedPaths();
            if (paths != null) while (paths.hasMoreElements()) {
                TreePath tp = paths.nextElement();
//                System.err.println(">>> Restoring expanded " + tp);
                tree.expandPath(getSimilarPath(tp, tree.getModel()));
            }
        } catch (Exception e) {
            System.err.println(">>> Exception in ProfilerTreeTable.restoreExpandedNodes: " + e.getMessage());
            e.printStackTrace();
        } finally {
            tree.putClientProperty(UIUtils.PROP_EXPANSION_TRANSACTION, null);
        }
    }
 
Example 5
Source File: DatasetTreeView.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
DatasetTreeView() {
  // the catalog tree
  tree = new JTree() {
    public JToolTip createToolTip() {
      return new MultilineTooltip();
    }
  };
  tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode(null, false)));
  tree.setCellRenderer(new MyTreeCellRenderer());

  tree.addMouseListener(new MouseAdapter() {
    public void mousePressed(MouseEvent e) {
      int selRow = tree.getRowForLocation(e.getX(), e.getY());
      if (selRow != -1) {
        TreeNode node = (TreeNode) tree.getLastSelectedPathComponent();
        if (node instanceof VariableNode) {
          Variable v = ((VariableNode) node).var;
          firePropertyChangeEvent(new PropertyChangeEvent(this, "Selection", null, v));
        }
      }
    }
  });

  tree.putClientProperty("JTree.lineStyle", "Angled");
  tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  tree.setToggleClickCount(1);
  ToolTipManager.sharedInstance().registerComponent(tree);

  // layout
  setLayout(new BorderLayout());
  add(new JScrollPane(tree), BorderLayout.CENTER);
}
 
Example 6
Source File: TreeSelectionRenderer.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
public final void editLaF(JTree tree) {
    UIDefaults paneDefaults = new UIDefaults();
    paneDefaults.put("Tree.selectionBackground", null);
    tree.putClientProperty("Nimbus.Overrides", paneDefaults);
    tree.putClientProperty("Nimbus.Overrides.InheritDefaults", false);
    tree.setBackground(Color.WHITE);
}
 
Example 7
Source File: CheckTree.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a new CheckBox tree.
 *
 * @param rootNode Node that is the root of this tree.
 */
public CheckTree(CheckNode rootNode) {
    tree = new JTree(rootNode);
    tree.setCellRenderer(new CheckRenderer());
    tree.setRowHeight(18);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setToggleClickCount(1000);
    tree.putClientProperty("JTree.lineStyle", "Angled");
    tree.addMouseListener(new NodeSelectionListener(tree));

    setLayout(new BorderLayout());
    add(tree, BorderLayout.CENTER);
}
 
Example 8
Source File: LogParserView.java    From yGuard with MIT License 4 votes vote down vote up
static void setParser( final JTree tree, final YGuardLogParser parser ) {
  tree.setModel(parser.getTreeModel());
  tree.putClientProperty("PARSER", parser);
}
 
Example 9
Source File: TreeDemo.java    From OpenDA with GNU Lesser General Public License v3.0 4 votes vote down vote up
public TreeDemo() {
    super(new GridLayout(1,0));

    //Create the nodes.
    DefaultMutableTreeNode top =
        new DefaultMutableTreeNode("The Java Series");
    createNodes(top);

    //Create a tree that allows one selection at a time.
    tree = new JTree(top);
    tree.getSelectionModel().setSelectionMode
            (TreeSelectionModel.SINGLE_TREE_SELECTION);

    //Listen for when the selection changes.
    tree.addTreeSelectionListener(this);

    if (playWithLineStyle) {
        System.out.println("line style = " + lineStyle);
        tree.putClientProperty("JTree.lineStyle", lineStyle);
    }

    //Create the scroll pane and add the tree to it. 
    JScrollPane treeView = new JScrollPane(tree);

    //Create the HTML viewing pane.
    htmlPane = new JEditorPane();
    htmlPane.setEditable(false);
    initHelp();
    JScrollPane htmlView = new JScrollPane(htmlPane);

    //Add the scroll panes to a split pane.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setTopComponent(treeView);
    splitPane.setBottomComponent(htmlView);

    Dimension minimumSize = new Dimension(100, 50);
    htmlView.setMinimumSize(minimumSize);
    treeView.setMinimumSize(minimumSize);
    splitPane.setDividerLocation(100); 
    splitPane.setPreferredSize(new Dimension(500, 300));

    //Add the split pane to this panel.
    add(splitPane);
}
 
Example 10
Source File: TreeDemo.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public TreeDemo() {
    super(new GridLayout(1, 0));

    // Create the nodes.
    DefaultMutableTreeNode top = new DefaultMutableTreeNode("The Java Series");
    createNodes(top);

    // Create a tree that allows one selection at a time.
    tree = new JTree(top);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    // Listen for when the selection changes.
    tree.addTreeSelectionListener(this);

    if (playWithLineStyle) {
        System.out.println("line style = " + lineStyle);
        tree.putClientProperty("JTree.lineStyle", lineStyle);
    }

    // Create the scroll pane and add the tree to it.
    JScrollPane treeView = new JScrollPane(tree);

    // Create the HTML viewing pane.
    htmlPane = new JEditorPane();
    htmlPane.setEditable(false);
    initHelp();
    JScrollPane htmlView = new JScrollPane(htmlPane);

    // Add the scroll panes to a split pane.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setTopComponent(treeView);
    splitPane.setBottomComponent(htmlView);

    Dimension minimumSize = new Dimension(100, 50);
    htmlView.setMinimumSize(minimumSize);
    treeView.setMinimumSize(minimumSize);
    splitPane.setDividerLocation(100);
    splitPane.setPreferredSize(new Dimension(500, 300));

    // Add the split pane to this panel.
    add(splitPane);
}
 
Example 11
Source File: CorefEditor.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * This method intiates the GUI for co-reference editor
 */
@Override
protected void initGUI() {

  //get a pointer to the textual view used for highlights
  Iterator<DocumentView> centralViewsIter = owner.getCentralViews().iterator();
  while (textView == null && centralViewsIter.hasNext()) {
    DocumentView aView = centralViewsIter.next();
    if (aView instanceof TextualDocumentView)
      textView = (TextualDocumentView) aView;
  }
  textPane = (JTextArea) ( (JScrollPane) textView.getGUI()).getViewport().
             getView();
  highlighter = textPane.getHighlighter();
  chainToolTipAction = new ChainToolTipAction();
  chainToolTipTimer = new javax.swing.Timer(500, chainToolTipAction);
  chainToolTipTimer.setRepeats(false);
  newCorefAction = new NewCorefAction();
  newCorefActionTimer = new javax.swing.Timer(500, newCorefAction);
  newCorefActionTimer.setRepeats(false);

  colorGenerator = new ColorGenerator();

  // main Panel
  mainPanel = new JPanel();
  mainPanel.setLayout(new BorderLayout());

  // topPanel
  topPanel = new JPanel();
  topPanel.setLayout(new BorderLayout());

  // subPanel
  subPanel = new JPanel();
  subPanel.setLayout(new FlowLayout(FlowLayout.LEFT));

  // showAnnotations Button
  showAnnotations = new JToggleButton("Show");
  showAnnotations.addActionListener(this);

  // annotSets
  annotSets = new JComboBox<String>();
  annotSets.addActionListener(this);

  // get all the annotationSets
  Map<String,AnnotationSet> annotSetsMap = document.getNamedAnnotationSets();
  annotSetsModel = new DefaultComboBoxModel<String>();
  if (annotSetsMap != null) {
    String [] array = annotSetsMap.keySet().toArray(new String[annotSetsMap.keySet().size()]);
    for(int i=0;i<array.length;i++) {
      annotSetsMap.get(array[i]).addAnnotationSetListener(this);
    }
    annotSetsModel = new DefaultComboBoxModel<String>(array);
  }
  document.getAnnotations().addAnnotationSetListener(this);
  annotSetsModel.insertElementAt(DEFAULT_ANNOTSET_NAME, 0);
  annotSets.setModel(annotSetsModel);

  // annotTypes
  annotTypesModel = new DefaultComboBoxModel<String>();
  annotTypes = new JComboBox<String>(annotTypesModel);
  annotTypes.addActionListener(this);
  subPanel.add(new JLabel("Sets : "));
  subPanel.add(annotSets);
  JPanel tempPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
  tempPanel.add(new JLabel("Types : "));
  tempPanel.add(annotTypes);
  tempPanel.add(showAnnotations);
  // intialises the Data
  initData();

  // and creating the tree
  corefTree = new JTree(rootNode);
  corefTree.putClientProperty("JTree.lineStyle", "None");
  corefTree.setRowHeight(corefTree.getRowHeight() * 2);
  corefTree.setLargeModel(true);
  corefTree.setAutoscrolls(true);

  //corefTree.setRootVisible(false);
  //corefTree.setShowsRootHandles(false);
  corefTree.addMouseListener(new CorefTreeMouseListener());
  corefTree.setCellRenderer(new CorefTreeCellRenderer());

  mainPanel.add(topPanel, BorderLayout.NORTH);
  mainPanel.add(new JScrollPane(corefTree), BorderLayout.CENTER);
  topPanel.add(subPanel, BorderLayout.CENTER);
  topPanel.add(tempPanel, BorderLayout.SOUTH);

  // get the highlighter
  textPaneMouseListener = new TextPaneMouseListener();
  annotSets.setSelectedIndex(0);

  // finally show the tree
  //annotSetSelectionChanged();

  document.addDocumentListener(this);
  document.getFeatures().addFeatureMapListener(this);
}
 
Example 12
Source File: BookBrowser.java    From audiveris with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Creates a new {@code BookBrowser} object.
 *
 * @param book the related book
 */
public BookBrowser (Book book)
{
    this.book = book;

    component = new JPanel();

    // Set up the tree
    model = new Model(book);

    ///model.addTreeModelListener(new ModelListener()); // Debug
    /** The tree entity */
    JTree tree = new JTree(model);

    // Build left-side view
    JScrollPane treeView = new JScrollPane(tree);

    // Build right-side view
    htmlPane = new JEditorPane("text/html", "");
    htmlPane.setEditable(false);

    JScrollPane htmlView = new JScrollPane(htmlPane);

    // Allow only single selections
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    // Display lines to explicit relationships
    tree.putClientProperty("JTree.lineStyle", "Angled");

    // Wire the two views together. Use a selection listener
    // created with an anonymous inner-class adapter.
    // Listen for when the selection changes.
    tree.addTreeSelectionListener(new SelectionListener());

    // To be notified of expansion / collapse actions (debug ...)
    ///tree.addTreeExpansionListener(new ExpansionListener());
    // Build split-pane view
    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, treeView, htmlView);
    splitPane.setName("treeHtmlSplitPane");
    splitPane.setContinuousLayout(true);
    splitPane.setBorder(null);
    splitPane.setDividerSize(2);

    // Add GUI components
    component.setLayout(new BorderLayout());
    component.add("Center", splitPane);
}
 
Example 13
Source File: ScoreTree.java    From libreveris with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Creates a new ScoreTree object.
 *
 * @param score the related score
 */
public ScoreTree (Score score)
{
    this.score = score;

    component = new JPanel();

    // Set up the tree
    model = new Model(score);

    ///model.addTreeModelListener(new ModelListener()); // Debug

    /** The tree entity */
    JTree tree = new JTree(model);

    // Build left-side view
    JScrollPane treeView = new JScrollPane(tree);

    // Build right-side view
    htmlPane = new JEditorPane("text/html", "");
    htmlPane.setEditable(false);

    JScrollPane htmlView = new JScrollPane(htmlPane);

    // Allow only single selections
    tree.getSelectionModel().setSelectionMode(
            TreeSelectionModel.SINGLE_TREE_SELECTION);

    // Display lines to explicit relationships
    tree.putClientProperty("JTree.lineStyle", "Angled");

    // Wire the two views together. Use a selection listener
    // created with an anonymous inner-class adapter.
    // Listen for when the selection changes.
    tree.addTreeSelectionListener(new SelectionListener());

    // To be notified of expansion / collapse actions (debug ...)
    ///tree.addTreeExpansionListener(new ExpansionListener());

    // Build split-pane view
    JSplitPane splitPane = new JSplitPane(
            JSplitPane.HORIZONTAL_SPLIT,
            treeView,
            htmlView);
    splitPane.setName("treeHtmlSplitPane");
    splitPane.setContinuousLayout(true);
    splitPane.setBorder(null);
    splitPane.setDividerSize(2);

    // Add GUI components
    component.setLayout(new BorderLayout());
    component.add("Center", splitPane);
}