Search in sources :

Example 11 with DefaultTreeCellRenderer

use of javax.swing.tree.DefaultTreeCellRenderer in project vcell by virtualcell.

the class MIRIAMAnnotationEditor method getJTreeMIRIAM.

private JTree getJTreeMIRIAM() {
    if (jTreeMIRIAM == null) {
        try {
            DefaultTreeSelectionModel ivjLocalSelectionModel;
            ivjLocalSelectionModel = new DefaultTreeSelectionModel();
            ivjLocalSelectionModel.setSelectionMode(1);
            jTreeMIRIAM = new JTree();
            jTreeMIRIAM.setName("JTree1");
            jTreeMIRIAM.setToolTipText("");
            jTreeMIRIAM.setBounds(0, 0, 357, 405);
            jTreeMIRIAM.setMinimumSize(new java.awt.Dimension(100, 72));
            jTreeMIRIAM.setSelectionModel(ivjLocalSelectionModel);
            jTreeMIRIAM.setRowHeight(0);
            // Add cellRenderer
            DefaultTreeCellRenderer dtcr = new BioModelCellRenderer(null) {

                @Override
                public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
                    // System.out.println(MIRIAMAnnotationEditor.this.getClass().getName()+".getJTreeMiriam():BioModelCellRenderer  "+value.getClass()+" "+
                    // (value instanceof cbit.vcell.desktop.BioModelNode?
                    // ((cbit.vcell.desktop.BioModelNode)value).getUserObject().getClass():""));
                    JLabel component = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
                    if (value instanceof BioModelNode && ((BioModelNode) value).getUserObject() instanceof Annotation) {
                        component.setToolTipText("(Double-click to edit notes)");
                        Annotation annotation = (Annotation) ((BioModelNode) value).getUserObject();
                        if (annotation.toString() == null || annotation.toString().length() == 0) {
                            component.setText("(Double-click to edit notes)");
                        }
                    }
                    return component;
                }
            };
            jTreeMIRIAM.setCellRenderer(dtcr);
            MouseListener mouseListener = new MouseAdapter() {

                @Override
                public void mouseClicked(MouseEvent e) {
                    // TODO Auto-generated method stub
                    super.mouseClicked(e);
                    TreePath closestMousePath = jTreeMIRIAM.getClosestPathForLocation(e.getPoint().x, e.getPoint().y);
                    showPopup(e, closestMousePath);
                }

                @Override
                public void mouseReleased(MouseEvent e) {
                    // TODO Auto-generated method stub
                    super.mouseReleased(e);
                    TreePath closestMousePath = jTreeMIRIAM.getClosestPathForLocation(e.getPoint().x, e.getPoint().y);
                    showPopup(e, closestMousePath);
                }

                public void mousePressed(MouseEvent e) {
                    TreePath closestMousePath = jTreeMIRIAM.getClosestPathForLocation(e.getPoint().x, e.getPoint().y);
                    jTreeMIRIAM.setSelectionPath(closestMousePath);
                    showPopup(e, closestMousePath);
                    if (e.getClickCount() == 2) {
                        DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTreeMIRIAM.getLastSelectedPathComponent();
                        if (node instanceof LinkNode) {
                            showBrowseToLink((LinkNode) node);
                        } else if (isNodeFreeHandTextEditable(node)) {
                            showEditFreehandText(node);
                        }
                    }
                }
            };
            jTreeMIRIAM.addMouseListener(mouseListener);
        } catch (java.lang.Throwable ivjExc) {
            ivjExc.printStackTrace(System.out);
        }
    }
    return jTreeMIRIAM;
}
Also used : MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) BioModelNode(cbit.vcell.desktop.BioModelNode) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) Annotation(cbit.vcell.desktop.Annotation) JTree(javax.swing.JTree) Dimension(java.awt.Dimension) MouseListener(java.awt.event.MouseListener) DefaultTreeSelectionModel(javax.swing.tree.DefaultTreeSelectionModel) TreePath(javax.swing.tree.TreePath) BioModelCellRenderer(cbit.vcell.desktop.BioModelCellRenderer) LinkNode(cbit.vcell.xml.gui.MiriamTreeModel.LinkNode)

Example 12 with DefaultTreeCellRenderer

use of javax.swing.tree.DefaultTreeCellRenderer in project vcell by virtualcell.

the class BioModelTreePanel method connEtoM2.

/**
 * connEtoM2:  (BioModelTreePanel.initialize() --> JTree2.cellRenderer)
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void connEtoM2() {
    BioModelCellRenderer localValue = null;
    try {
        // Add cellRenderer
        DefaultTreeCellRenderer dtcr = new BioModelCellRenderer(null) {

            @Override
            public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
                JLabel component = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
                if (value instanceof BioModelNode && ((BioModelNode) value).getUserObject() instanceof Annotation) {
                    component.setToolTipText("(Double-click to edit notes)");
                    Annotation annotation = (Annotation) ((BioModelNode) value).getUserObject();
                    if (annotation.toString() == null || annotation.toString().length() == 0) {
                        component.setText("(Double-click to edit notes)");
                    }
                }
                return component;
            }
        };
        getJTree2().setCellRenderer(dtcr);
    // user code begin {2}
    // user code end
    } catch (java.lang.Throwable ivjExc) {
        // user code begin {3}
        // user code end
        handleException(ivjExc);
    }
}
Also used : JTree(javax.swing.JTree) JLabel(javax.swing.JLabel) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer)

Example 13 with DefaultTreeCellRenderer

use of javax.swing.tree.DefaultTreeCellRenderer in project cytoscape-impl by cytoscape.

the class InstallAppsPanel method initComponents.

private void initComponents() {
    searchAppsLabel = new JLabel("Search:");
    installFromFileButton = new JButton("Install from File...");
    filterTextField = new JTextField();
    descriptionSplitPane = new JSplitPane();
    tagsSplitPane = new JSplitPane();
    tagsScrollPane = new JScrollPane();
    tagsTree = new JTree();
    resultsScrollPane = new JScrollPane();
    resultsTree = new JTree();
    descriptionPanel = new JPanel();
    descriptionScrollPane = new JScrollPane();
    descriptionTextPane = new JTextPane();
    viewOnAppStoreButton = new JButton("View on App Store");
    installButton = new JButton("Install");
    downloadSiteLabel = new JLabel("Download Site:");
    downloadSiteComboBox = new JComboBox();
    manageSitesButton = new JButton("Manage Sites...");
    searchAppsLabel.setVisible(!LookAndFeelUtil.isAquaLAF());
    // Aqua LAF only
    filterTextField.putClientProperty("JTextField.variant", "search");
    filterTextField.setToolTipText("To search, start typing");
    installFromFileButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            installFromFileButtonActionPerformed(evt);
        }
    });
    descriptionSplitPane.setBorder(null);
    descriptionSplitPane.setDividerLocation(390);
    tagsSplitPane.setDividerLocation(175);
    tagsSplitPane.setBorder(null);
    DefaultMutableTreeNode treeNode1 = new DefaultMutableTreeNode("root");
    DefaultMutableTreeNode treeNode2 = new DefaultMutableTreeNode("all apps (0)");
    DefaultMutableTreeNode treeNode3 = new DefaultMutableTreeNode("collections (0)");
    DefaultMutableTreeNode treeNode4 = new DefaultMutableTreeNode("apps by tag");
    treeNode1.add(treeNode2);
    treeNode1.add(treeNode3);
    treeNode1.add(treeNode4);
    tagsTree.setModel(new DefaultTreeModel(treeNode1));
    tagsTree.setFocusable(false);
    tagsTree.setRootVisible(false);
    tagsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tagsScrollPane.setViewportView(tagsTree);
    tagsSplitPane.setLeftComponent(tagsScrollPane);
    treeNode1 = new DefaultMutableTreeNode("root");
    resultsTree.setModel(new DefaultTreeModel(treeNode1));
    resultsTree.setFocusable(false);
    resultsTree.setRootVisible(false);
    resultsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    resultsScrollPane.setViewportView(resultsTree);
    tagsSplitPane.setRightComponent(resultsScrollPane);
    descriptionSplitPane.setLeftComponent(tagsSplitPane);
    descriptionTextPane.setContentType("text/html");
    descriptionTextPane.setEditable(false);
    // descriptionTextPane.setText("<html>\n  <head>\n\n  </head>\n  <body>\n    <p style=\"margin-top: 0\">\n      App description is displayed here.\n    </p>\n  </body>\n</html>\n");
    descriptionTextPane.setText("");
    descriptionScrollPane.setViewportView(descriptionTextPane);
    final GroupLayout descriptionPanelLayout = new GroupLayout(descriptionPanel);
    descriptionPanel.setLayout(descriptionPanelLayout);
    descriptionPanelLayout.setHorizontalGroup(descriptionPanelLayout.createParallelGroup(Alignment.LEADING).addComponent(descriptionScrollPane, GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE));
    descriptionPanelLayout.setVerticalGroup(descriptionPanelLayout.createParallelGroup(Alignment.LEADING).addComponent(descriptionScrollPane, GroupLayout.DEFAULT_SIZE, 354, Short.MAX_VALUE));
    descriptionSplitPane.setRightComponent(descriptionPanel);
    viewOnAppStoreButton.setEnabled(false);
    viewOnAppStoreButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            viewOnAppStoreButtonActionPerformed(evt);
        }
    });
    installButton.setEnabled(false);
    installButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            installButtonActionPerformed(evt);
        }
    });
    downloadSiteComboBox.setModel(new DefaultComboBoxModel(new String[] { WebQuerier.DEFAULT_APP_STORE_URL }));
    downloadSiteComboBox.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent evt) {
            downloadSiteComboBoxItemStateChanged(evt);
        }
    });
    downloadSiteComboBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            downloadSiteComboBoxActionPerformed(evt);
        }
    });
    downloadSiteComboBox.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent evt) {
            downloadSiteComboBoxKeyPressed(evt);
        }
    });
    manageSitesButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            manageSitesButtonActionPerformed(evt);
        }
    });
    LookAndFeelUtil.equalizeSize(installFromFileButton, viewOnAppStoreButton, installButton);
    final JSeparator sep = new JSeparator();
    final GroupLayout layout = new GroupLayout(this);
    this.setLayout(layout);
    layout.setAutoCreateContainerGaps(true);
    layout.setAutoCreateGaps(true);
    layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(downloadSiteLabel).addComponent(downloadSiteComboBox, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addComponent(manageSitesButton)).addComponent(sep, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addGroup(layout.createSequentialGroup().addComponent(searchAppsLabel).addComponent(filterTextField, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE)).addComponent(descriptionSplitPane).addGroup(layout.createSequentialGroup().addComponent(installFromFileButton).addPreferredGap(ComponentPlacement.RELATED, 80, Short.MAX_VALUE).addComponent(viewOnAppStoreButton).addComponent(installButton)));
    layout.setVerticalGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(downloadSiteLabel).addComponent(downloadSiteComboBox, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(manageSitesButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addComponent(sep, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(searchAppsLabel).addComponent(filterTextField, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addComponent(descriptionSplitPane, DEFAULT_SIZE, 360, Short.MAX_VALUE).addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(installFromFileButton).addComponent(viewOnAppStoreButton).addComponent(installButton)));
    // Add a key listener to the download site combo box to listen for the enter key event
    final WebQuerier webQuerier = this.appManager.getWebQuerier();
    downloadSiteComboBox.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            final ComboBoxEditor editor = downloadSiteComboBox.getEditor();
            final Object selectedValue = editor.getItem();
            if (e.isActionKey() || e.getKeyCode() == KeyEvent.VK_ENTER) {
                if (downloadSiteComboBox.getModel() instanceof DefaultComboBoxModel && selectedValue != null) {
                    final DefaultComboBoxModel comboBoxModel = (DefaultComboBoxModel) downloadSiteComboBox.getModel();
                    SwingUtilities.invokeLater(new Runnable() {

                        @Override
                        public void run() {
                            boolean selectedAlreadyInList = false;
                            for (int i = 0; i < comboBoxModel.getSize(); i++) {
                                Object listElement = comboBoxModel.getElementAt(i);
                                if (listElement.equals(selectedValue)) {
                                    selectedAlreadyInList = true;
                                    break;
                                }
                            }
                            if (!selectedAlreadyInList) {
                                comboBoxModel.insertElementAt(selectedValue, 1);
                                editor.setItem(selectedValue);
                            }
                        }
                    });
                }
                if (webQuerier.getCurrentAppStoreUrl() != selectedValue.toString()) {
                    webQuerier.setCurrentAppStoreUrl(selectedValue.toString());
                    queryForApps();
                }
            }
        }
    });
    // Make the JTextPane render HTML using the default UI font
    Font font = UIManager.getFont("Label.font");
    String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }";
    ((HTMLDocument) descriptionTextPane.getDocument()).getStyleSheet().addRule(bodyRule);
    // Setup the TreeCellRenderer to make the app tags use the folder icon instead of the default leaf icon,
    // and have it use the opened folder icon when selected
    DefaultTreeCellRenderer tagsTreeCellRenderer = new DefaultTreeCellRenderer() {

        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
            // Make leaves use the open folder icon when selected
            if (selected && leaf)
                this.setIcon(getOpenIcon());
            return this;
        }
    };
    tagsTreeCellRenderer.setLeafIcon(tagsTreeCellRenderer.getDefaultClosedIcon());
    tagsTree.setCellRenderer(tagsTreeCellRenderer);
}
Also used : JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) ComboBoxEditor(javax.swing.ComboBoxEditor) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) JSeparator(javax.swing.JSeparator) Font(java.awt.Font) KeyEvent(java.awt.event.KeyEvent) JTextPane(javax.swing.JTextPane) GroupLayout(javax.swing.GroupLayout) JScrollPane(javax.swing.JScrollPane) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) JTree(javax.swing.JTree) ActionListener(java.awt.event.ActionListener) ItemListener(java.awt.event.ItemListener) JSplitPane(javax.swing.JSplitPane) WebQuerier(org.cytoscape.app.internal.net.WebQuerier)

Example 14 with DefaultTreeCellRenderer

use of javax.swing.tree.DefaultTreeCellRenderer in project chatty by chatty.

the class Tree method createTree.

public static JTree createTree(Map<Page, List<Page>> nodes) {
    // Create nodes structure based on Map
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    for (Page parent : nodes.keySet()) {
        DefaultMutableTreeNode category = new DefaultMutableTreeNode(parent);
        root.add(category);
        List<Page> subNodes = nodes.get(parent);
        for (Page child : subNodes) {
            category.add(new DefaultMutableTreeNode(child));
        }
    }
    // Create and configure tree
    JTree tree = new JTree(root);
    tree.setRootVisible(false);
    tree.setShowsRootHandles(false);
    // Disable icons and use default renderer
    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer() {

        // Border to give text some more space
        private final Border BORDER = BorderFactory.createEmptyBorder(0, 3, 0, 1);

        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            Component c = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
            if (c instanceof JLabel) {
                JLabel label = (JLabel) c;
                label.setBorder(BORDER);
            }
            return c;
        }
    };
    renderer.setLeafIcon(null);
    renderer.setOpenIcon(null);
    tree.setCellRenderer(renderer);
    // Expand all branches
    for (int i = 0; i < tree.getRowCount(); i++) {
        tree.expandRow(i);
    }
    // Select closest node on click, to allow more leniency with selecting
    tree.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            int row = tree.getClosestRowForLocation(e.getX(), e.getY());
            if (row != -1) {
                tree.setSelectionRow(row);
            }
        }
    });
    // Prevent collapsing of nodes completely
    tree.addTreeWillExpandListener(new TreeWillExpandListener() {

        @Override
        public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
        }

        @Override
        public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
            throw new ExpandVetoException(event);
        }
    });
    return tree;
}
Also used : TreeWillExpandListener(javax.swing.event.TreeWillExpandListener) MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) Page(chatty.gui.components.settings.SettingsDialog.Page) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) ExpandVetoException(javax.swing.tree.ExpandVetoException) JTree(javax.swing.JTree) Component(java.awt.Component) Border(javax.swing.border.Border) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent)

Example 15 with DefaultTreeCellRenderer

use of javax.swing.tree.DefaultTreeCellRenderer in project ffx by mjschnie.

the class Hierarchy method initTree.

/**
 * Initialize the Tree representation based on the Root data node
 */
public void initTree() {
    addTreeSelectionListener(this);
    setExpandsSelectedPaths(true);
    setScrollsOnExpand(true);
    // setLargeModel(true);
    setEditable(false);
    putClientProperty("JTree.lineStyle", "Angled");
    setShowsRootHandles(true);
    DefaultTreeCellRenderer tcr = new DefaultTreeCellRenderer();
    tcr.setBackgroundSelectionColor(Color.yellow);
    tcr.setBorderSelectionColor(Color.black);
    tcr.setTextSelectionColor(Color.black);
    setCellRenderer(tcr);
    hierarchyModel = new DefaultTreeModel(root);
    treeSelectionModel = new DefaultTreeSelectionModel();
    setModel(hierarchyModel);
    setSelectionModel(treeSelectionModel);
    setRootVisible(false);
}
Also used : DefaultTreeSelectionModel(javax.swing.tree.DefaultTreeSelectionModel) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer)

Aggregations

DefaultTreeCellRenderer (javax.swing.tree.DefaultTreeCellRenderer)36 JTree (javax.swing.JTree)13 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)13 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)12 TreePath (javax.swing.tree.TreePath)10 MouseAdapter (java.awt.event.MouseAdapter)7 MouseEvent (java.awt.event.MouseEvent)7 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)7 TreeCellRenderer (javax.swing.tree.TreeCellRenderer)7 Dimension (java.awt.Dimension)4 JLabel (javax.swing.JLabel)4 JPanel (javax.swing.JPanel)4 JScrollPane (javax.swing.JScrollPane)4 TreeSelectionListener (javax.swing.event.TreeSelectionListener)4 Topic (com.igormaznitsa.mindmap.model.Topic)3 BorderLayout (java.awt.BorderLayout)3 Component (java.awt.Component)3 ActionEvent (java.awt.event.ActionEvent)3 KeyAdapter (java.awt.event.KeyAdapter)3 KeyEvent (java.awt.event.KeyEvent)3