Search in sources :

Example 21 with DefaultTreeCellRenderer

use of javax.swing.tree.DefaultTreeCellRenderer in project groovy-core by groovy.

the class ClosureRenderer method render.

private Component render() {
    if (children.isEmpty() || defaultRenderer) {
        defaultRenderer = true;
        children.clear();
        if (table != null) {
            TableCellRenderer tcr;
            if (tableHeader) {
                tcr = table.getTableHeader().getDefaultRenderer();
            } else {
                tcr = table.getDefaultRenderer(table.getColumnClass(column));
            }
            children.add(tcr.getTableCellRendererComponent(table, value, selected, focused, row, column));
        } else if (tree != null) {
            TreeCellRenderer tcr;
            tcr = new DefaultTreeCellRenderer();
            children.add(tcr.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, focused));
        } else if (list != null) {
            ListCellRenderer lcr = (ListCellRenderer) UIManager.get("List.cellRenderer");
            if (lcr == null) {
                lcr = new DefaultListCellRenderer();
            }
            children.add(lcr.getListCellRendererComponent(list, value, row, selected, focused));
        }
    }
    Object o = update.call();
    if (o instanceof Component) {
        return (Component) o;
    } else {
        return (Component) children.get(0);
    }
}
Also used : TreeCellRenderer(javax.swing.tree.TreeCellRenderer) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer)

Example 22 with DefaultTreeCellRenderer

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

the class SiteMapPanel method getTreeSite.

/**
 * This method initializes treeSite
 *
 * @return javax.swing.JTree
 */
public JTree getTreeSite() {
    if (treeSite == null) {
        treeSite = new JTree(new DefaultTreeModel(new DefaultMutableTreeNode()));
        treeSite.setShowsRootHandles(true);
        treeSite.setName("treeSite");
        treeSite.setToggleClickCount(1);
        // Force macOS L&F to query the row height from SiteMapTreeCellRenderer to hide the
        // filtered nodes.
        // Other L&Fs hide the filtered nodes by default.
        LookAndFeel laf = UIManager.getLookAndFeel();
        if (laf != null && Constant.isMacOsX() && UIManager.getSystemLookAndFeelClassName().equals(laf.getClass().getName())) {
            treeSite.setRowHeight(0);
        }
        treeSite.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {

            @Override
            public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
                SiteNode node = (SiteNode) treeSite.getLastSelectedPathComponent();
                if (node == null) {
                    return;
                }
                if (!node.isRoot()) {
                    HttpMessage msg = null;
                    try {
                        msg = node.getHistoryReference().getHttpMessage();
                    } catch (Exception e1) {
                        // ZAP: Log exceptions
                        log.warn(e1.getMessage(), e1);
                        return;
                    }
                    getView().displayMessage(msg);
                    // ZAP: Call SiteMapListenners
                    for (SiteMapListener listener : listeners) {
                        listener.nodeSelected(node);
                    }
                } else {
                    // ZAP: clear the views when the root is selected
                    getView().displayMessage(null);
                }
            }
        });
        treeSite.setComponentPopupMenu(new SitesCustomPopupMenu());
        // ZAP: Add custom tree cell renderer.
        DefaultTreeCellRenderer renderer = new SiteMapTreeCellRenderer(listeners);
        treeSite.setCellRenderer(renderer);
        String deleteSiteNode = "zap.delete.sitenode";
        treeSite.getInputMap().put(getView().getDefaultDeleteKeyStroke(), deleteSiteNode);
        treeSite.getActionMap().put(deleteSiteNode, new AbstractAction() {

            private static final long serialVersionUID = 1L;

            @Override
            public void actionPerformed(ActionEvent e) {
                ExtensionHistory extHistory = Control.getSingleton().getExtensionLoader().getExtension(ExtensionHistory.class);
                if (extHistory == null || treeSite.getSelectionCount() == 0) {
                    return;
                }
                int result = View.getSingleton().showConfirmDialog(Constant.messages.getString("sites.purge.warning"));
                if (result != JOptionPane.YES_OPTION) {
                    return;
                }
                SiteMap siteMap = Model.getSingleton().getSession().getSiteTree();
                for (TreePath path : treeSite.getSelectionPaths()) {
                    extHistory.purge(siteMap, (SiteNode) path.getLastPathComponent());
                }
            }
        });
    }
    return treeSite;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ActionEvent(java.awt.event.ActionEvent) ExtensionHistory(org.parosproxy.paros.extension.history.ExtensionHistory) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) LookAndFeel(javax.swing.LookAndFeel) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) DatabaseException(org.parosproxy.paros.db.DatabaseException) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) SiteMap(org.parosproxy.paros.model.SiteMap) SiteMapTreeCellRenderer(org.zaproxy.zap.view.SiteMapTreeCellRenderer) HttpMessage(org.parosproxy.paros.network.HttpMessage) SiteMapListener(org.zaproxy.zap.view.SiteMapListener) AbstractAction(javax.swing.AbstractAction) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 23 with DefaultTreeCellRenderer

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

the class AbstractParamContainerPanel method getTreeParam.

/**
 * This method initializes treeParam
 *
 * @return javax.swing.JTree
 */
private JTree getTreeParam() {
    if (treeParam == null) {
        treeParam = new JTree();
        treeParam.setModel(getTreeModel());
        treeParam.setShowsRootHandles(true);
        treeParam.setRootVisible(true);
        treeParam.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {

            @Override
            public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) getTreeParam().getLastSelectedPathComponent();
                if (node == null) {
                    return;
                }
                String name = (String) node.getUserObject();
                if (getParamPanel(name) == null) {
                    if (node.getChildCount() == 0) {
                        return;
                    }
                    name = (String) ((DefaultMutableTreeNode) node.getFirstChild()).getUserObject();
                }
                showParamPanel(name);
            }
        });
        DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
        renderer.setLeafIcon(null);
        renderer.setOpenIcon(null);
        renderer.setClosedIcon(null);
        treeParam.setCellRenderer(renderer);
        treeParam.setRowHeight(DisplayUtils.getScaledSize(18));
        treeParam.addMouseListener(new MouseAdapter() {

            @Override
            public void mousePressed(MouseEvent e) {
                TreePath path = treeParam.getClosestPathForLocation(e.getX(), e.getY());
                if (path != null && !treeParam.isPathSelected(path)) {
                    treeParam.setSelectionPath(path);
                }
            }
        });
    }
    return treeParam;
}
Also used : JTree(javax.swing.JTree) MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) MouseAdapter(java.awt.event.MouseAdapter) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer)

Example 24 with DefaultTreeCellRenderer

use of javax.swing.tree.DefaultTreeCellRenderer in project groovy by apache.

the class ClosureRenderer method render.

private Component render() {
    if (children.isEmpty() || defaultRenderer) {
        defaultRenderer = true;
        children.clear();
        if (table != null) {
            TableCellRenderer tcr;
            if (tableHeader) {
                tcr = table.getTableHeader().getDefaultRenderer();
            } else {
                tcr = table.getDefaultRenderer(table.getColumnClass(column));
            }
            children.add(tcr.getTableCellRendererComponent(table, value, selected, focused, row, column));
        } else if (tree != null) {
            TreeCellRenderer tcr;
            tcr = new DefaultTreeCellRenderer();
            children.add(tcr.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, focused));
        } else if (list != null) {
            ListCellRenderer lcr = (ListCellRenderer) UIManager.get("List.cellRenderer");
            if (lcr == null) {
                lcr = new DefaultListCellRenderer();
            }
            children.add(lcr.getListCellRendererComponent(list, value, row, selected, focused));
        }
    }
    Object o = update.call();
    if (o instanceof Component) {
        return (Component) o;
    } else {
        return (Component) children.get(0);
    }
}
Also used : TreeCellRenderer(javax.swing.tree.TreeCellRenderer) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer)

Example 25 with DefaultTreeCellRenderer

use of javax.swing.tree.DefaultTreeCellRenderer in project intellij-community by JetBrains.

the class PackageChooserDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    myModel = new DefaultTreeModel(new DefaultMutableTreeNode());
    createTreeModel();
    myTree = new Tree(myModel);
    UIUtil.setLineStyleAngled(myTree);
    myTree.setCellRenderer(new DefaultTreeCellRenderer() {

        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
            setIcon(PlatformIcons.PACKAGE_ICON);
            if (value instanceof DefaultMutableTreeNode) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
                Object object = node.getUserObject();
                if (object instanceof PsiPackage) {
                    String name = ((PsiPackage) object).getName();
                    if (name != null && name.length() > 0) {
                        setText(name);
                    } else {
                        setText(IdeBundle.message("node.default"));
                    }
                }
            }
            return this;
        }
    });
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree);
    scrollPane.setPreferredSize(JBUI.size(500, 300));
    new TreeSpeedSearch(myTree, new Convertor<TreePath, String>() {

        public String convert(TreePath path) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
            Object object = node.getUserObject();
            if (object instanceof PsiPackage)
                return ((PsiPackage) object).getName();
            else
                return "";
        }
    });
    myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

        public void valueChanged(TreeSelectionEvent e) {
            PsiPackage selection = getTreeSelection();
            if (selection != null) {
                String name = selection.getQualifiedName();
                setTitle(myTitle + " - " + ("".equals(name) ? IdeBundle.message("node.default.package") : name));
            } else {
                setTitle(myTitle);
            }
            updatePathFromTree();
        }
    });
    panel.add(scrollPane, BorderLayout.CENTER);
    DefaultActionGroup group = createActionGroup(myTree);
    final JPanel northPanel = new JPanel(new BorderLayout());
    panel.add(northPanel, BorderLayout.NORTH);
    ActionToolbar toolBar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true);
    northPanel.add(toolBar.getComponent(), BorderLayout.WEST);
    setupPathComponent(northPanel);
    return panel;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeSpeedSearch(com.intellij.ui.TreeSpeedSearch) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) TreePath(javax.swing.tree.TreePath) Tree(com.intellij.ui.treeStructure.Tree) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

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