Example usage for javax.swing.tree DefaultTreeCellRenderer setOpenIcon

List of usage examples for javax.swing.tree DefaultTreeCellRenderer setOpenIcon

Introduction

In this page you can find the example usage for javax.swing.tree DefaultTreeCellRenderer setOpenIcon.

Prototype

public void setOpenIcon(Icon newIcon) 

Source Link

Document

Sets the icon used to represent non-leaf nodes that are expanded.

Usage

From source file:net.sourceforge.squirrel_sql.client.gui.HelpViewerWindow.java

/**
 * Create a tree each node being a link to a document.
 * //from   w ww . j  av a2  s. co m
 * @return The contents tree.
 */
private JScrollPane createContentsTree() throws IOException {

    // i18n[HelpViewerWindow.help=Help]
    final FolderNode root = new FolderNode(s_stringMgr.getString("HelpViewerWindow.help"));
    _tree = new JTree(new DefaultTreeModel(root));
    _tree.setShowsRootHandles(true);
    _tree.addTreeSelectionListener(new ObjectTreeSelectionListener());

    // Renderer for tree.
    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
    SquirrelResources rsrc = _app.getResources();
    renderer.setLeafIcon(rsrc.getIcon(SquirrelResources.IImageNames.HELP_TOPIC));
    renderer.setOpenIcon(rsrc.getIcon(SquirrelResources.IImageNames.HELP_TOC_OPEN));
    renderer.setClosedIcon(rsrc.getIcon(SquirrelResources.IImageNames.HELP_TOC_CLOSED));
    _tree.setCellRenderer(renderer);

    // First put the Welcome to SQuirreL node.
    FileWrapper file = applicationFiles.getWelcomeFile();
    try {
        // i18n[HelpViewerWindow.welcome=Welcome]
        DocumentNode dn = new DocumentNode(s_stringMgr.getString("HelpViewerWindow.welcome"), file);
        root.add(dn);
        _nodes.put(dn.getURL().toString(), dn);
    } catch (MalformedURLException ex) {
        // i18n[HelpViewerWindow.error.loadwelcomefile=Error retrieving Welcome file URL for {0}]
        String msg = s_stringMgr.getString("HelpViewerWindow.error.loadwelcomefile", file.getAbsolutePath());
        s_log.error(msg, ex);
    }

    // Add Help, Licence and Change Log nodes to the tree.
    // i18n[HelpViewerWindow.help=Help]
    final FolderNode helpRoot = new FolderNode(s_stringMgr.getString("HelpViewerWindow.help"));
    root.add(helpRoot);
    _nodes.put(helpRoot.getURL().toString(), helpRoot);
    // i18n[HelpViewerWindow.licences=Licences]
    final FolderNode licenceRoot = new FolderNode(s_stringMgr.getString("HelpViewerWindow.licences"));
    root.add(licenceRoot);
    _nodes.put(licenceRoot.getURL().toString(), licenceRoot);
    // i18n[HelpViewerWindow.changelogs=Change Logs]
    final FolderNode changeLogRoot = new FolderNode(s_stringMgr.getString("HelpViewerWindow.changelogs"));
    root.add(changeLogRoot);
    _nodes.put(changeLogRoot.getURL().toString(), changeLogRoot);

    // Add SQuirreL help to the Help node.
    file = applicationFiles.getQuickStartGuideFile();
    try {
        // i18n[HelpViewerWindow.squirrel=SQuirreL]
        DocumentNode dn = new DocumentNode(s_stringMgr.getString("HelpViewerWindow.squirrel"), file);
        helpRoot.add(dn);
        _homeURL = dn.getURL();
        _nodes.put(_homeURL.toString(), dn);
    } catch (MalformedURLException ex) {
        // i18n[HelpViewerWindow.error.loadwelcomefile=Error retrieving Help file URL for {0}]
        String msg = s_stringMgr.getString("HelpViewerWindow.error.loadhelpfile", file.getAbsolutePath());
        s_log.error(msg, ex);
    }

    // Add SQuirreL Licence to the Licence node.
    file = applicationFiles.getLicenceFile();
    try {
        // i18n[HelpViewerWindow.squirrel=SQuirreL]
        DocumentNode dn = new DocumentNode(s_stringMgr.getString("HelpViewerWindow.squirrel"), file);
        licenceRoot.add(dn);
        _nodes.put(dn.getURL().toString(), dn);
    } catch (MalformedURLException ex) {
        // i18n[HelpViewerWindow.error.loadlicencefile=Error retrieving Licence file URL for {0}]
        String msg = s_stringMgr.getString("HelpViewerWindow.error.loadlicencefile", file.getAbsolutePath());
        s_log.error(msg, ex);
    }

    // Add SQuirreL Change Log to the Licence node.
    file = applicationFiles.getChangeLogFile();
    try {
        // i18n[HelpViewerWindow.squirrel=SQuirreL]
        DocumentNode dn = new DocumentNode(s_stringMgr.getString("HelpViewerWindow.squirrel"), file);
        changeLogRoot.add(dn);
        _nodes.put(dn.getURL().toString(), dn);
    } catch (MalformedURLException ex) {
        // i18n[HelpViewerWindow.error.loadchangelogfile=Error retrieving Change Log file URL for {0}]
        String msg = s_stringMgr.getString("HelpViewerWindow.error.loadchangelogfile", file.getAbsolutePath());
        s_log.error(msg, ex);
    }

    // Add plugin help, licence and change log documents to the tree.
    PluginInfo[] pi = _app.getPluginManager().getPluginInformation();
    for (int i = 0; i < pi.length; ++i) {
        try {
            final FileWrapper dir = pi[i].getPlugin().getPluginAppSettingsFolder();
            final String title = pi[i].getDescriptiveName();

            // Help document.
            try {
                final String fn = pi[i].getHelpFileName();
                if (fn != null && fn.length() > 0) {
                    DocumentNode dn = new DocumentNode(title, fileWrapperFactory.create(dir, fn));
                    helpRoot.add(dn);
                    _nodes.put(dn.getURL().toString(), dn);
                }
            } catch (IOException ex) {
                // i18n[HelpViewerWindow.error.loadpluginhelp=Error generating Help entry for plugin {0}]
                String msg = s_stringMgr.getString("HelpViewerWindow.error.loadpluginhelp",
                        pi[i].getDescriptiveName());
                s_log.error(msg, ex);
            }

            // Licence document.
            try {
                final String fn = pi[i].getLicenceFileName();
                if (fn != null && fn.length() > 0) {
                    DocumentNode dn = new DocumentNode(title, fileWrapperFactory.create(dir, fn));
                    licenceRoot.add(dn);
                    _nodes.put(dn.getURL().toString(), dn);
                }
            } catch (IOException ex) {
                // i18n[HelpViewerWindow.error.loadpluginlicence=Error generating Licence entry for plugin {0}]
                String msg = s_stringMgr.getString("HelpViewerWindow.error.loadpluginlicence",
                        pi[i].getDescriptiveName());
                s_log.error(msg, ex);
            }

            try {
                // Change log.
                final String fn = pi[i].getChangeLogFileName();
                if (fn != null && fn.length() > 0) {
                    DocumentNode dn = new DocumentNode(title, fileWrapperFactory.create(dir, fn));
                    changeLogRoot.add(dn);
                    _nodes.put(dn.getURL().toString(), dn);
                }
            } catch (IOException ex) {
                // i18n[HelpViewerWindow.error.loadchangelog=Error generating Change Log entry for plugin {0}]
                String msg = s_stringMgr.getString("HelpViewerWindow.error.loadchangelog",
                        pi[i].getDescriptiveName());
                s_log.error(msg, ex);
            }
        } catch (IOException ex) {
            // i18n[HelpViewerWindow.error.loadpluginsettings=Error retrieving app settings folder for plugin
            // {0}]
            String msg = s_stringMgr.getString("HelpViewerWindow.error.loadpluginsettings",
                    pi[i].getDescriptiveName());
            s_log.error(msg, ex);
        }
    }

    // FAQ.
    file = applicationFiles.getFAQFile();
    try {
        // i18n[HelpViewerWindow.faq=FAQ]
        DocumentNode dn = new DocumentNode(s_stringMgr.getString("HelpViewerWindow.faq"), file);
        root.add(dn);
        _nodes.put(dn.getURL().toString(), dn);
    } catch (MalformedURLException ex) {
        // i18n[HelpViewerWindow.error.loadfaqfile=Error retrieving FAQ from URL = {0}]
        String msg = s_stringMgr.getString("HelpViewerWindow.error.loadfaqfile", file.getAbsolutePath());
        s_log.error(msg, ex);
    }

    // generate contents file.
    helpRoot.generateContentsFile();
    licenceRoot.generateContentsFile();
    changeLogRoot.generateContentsFile();

    JScrollPane sp = new JScrollPane(_tree);
    sp.setPreferredSize(new Dimension(200, 200));

    return sp;
}

From source file:org.openconcerto.erp.model.FamilleArticleTree.java

public FamilleArticleTree() {

    super();/*from  w ww.j  av a2s  .c  o m*/

    this.setModel(model);

    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
    renderer.setOpenIcon(null);
    renderer.setClosedIcon(null);
    renderer.setLeafIcon(null);
    this.setCellRenderer(renderer);
    loadTree();
    this.addMouseListener(this);
    this.setTableListener();
    this.setDragEnabled(true);
}

From source file:org.openconcerto.erp.model.RubriquePayeTree.java

public RubriquePayeTree() {
    super();//  w w w  .  ja v  a  2 s .co m
    this.setModel(model);
    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
    renderer.setOpenIcon(null);
    renderer.setClosedIcon(null);
    renderer.setLeafIcon(null);
    this.setCellRenderer(renderer);
    DefaultMutableTreeNode currentNode = ((DefaultMutableTreeNode) this.getModel().getRoot()).getNextNode();
    do {
        if (currentNode.getLevel() == 1)
            this.expandPath(new TreePath(currentNode.getPath()));
        currentNode = currentNode.getNextNode();
    } while (currentNode != null);
}

From source file:org.openconcerto.erp.panel.ITreeSelection.java

public ITreeSelection(SQLElement element) {
    super();//from ww w  .  j a v a2s. c o m
    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
    renderer.setOpenIcon(null);
    renderer.setClosedIcon(null);
    renderer.setLeafIcon(null);
    this.setCellRenderer(renderer);

    this.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    this.element = element;

    this.supp = new PropertyChangeSupport(this);

    // Value changed
    this.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent e) {
            ITreeSelection.this.supp.firePropertyChange("value", null, getUncheckedValue());
        }
    });

}

From source file:org.pentaho.ui.xul.swing.tags.SwingTree.java

private void setupTree() {
    XulTreeNode topNode = new XulTreeNode("placeholder", null); //$NON-NLS-1$
    for (XulComponent c : getRootChildren().getChildNodes()) {
        XulTreeItem item = (XulTreeItem) c;
        XulTreeNode node = createNode(item);
        if (node != null) {
            topNode.add(node);//from   ww w .j  av  a 2 s .  c o m
        }
    }
    treeModel = new XulTreeModel(topNode);
    tree.setModel(treeModel);
    tree.setRootVisible(false);
    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
    renderer.setLeafIcon(null);
    renderer.setClosedIcon(null);
    renderer.setOpenIcon(null);
    tree.setCellRenderer(renderer);
    tree.setShowsRootHandles(true);
    this.setExpanded(this.getExpanded());

}

From source file:view.CertificatePropertiesDialog.java

private void setupTree(Certificate[] certificateChain) {
    DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) jTree1.getCellRenderer();
    Icon closedIcon = new ImageIcon(MainWindow.class.getResource("/image/certificate.png"));
    renderer.setLeafIcon(closedIcon);/*from  w w  w  . ja  va2 s.c  o m*/
    renderer.setOpenIcon(closedIcon);
    renderer.setClosedIcon(closedIcon);
    BasicTreeUI treeUI = (BasicTreeUI) jTree1.getUI();
    treeUI.setCollapsedIcon(null);
    treeUI.setExpandedIcon(null);

    if (null != certificateChain) {
        if (certificateChain.length > 0) {
            DefaultMutableTreeNode dmtn[] = new DefaultMutableTreeNode[certificateChain.length];

            boolean needCheck = true;
            for (int i = (certificateChain.length - 1); i >= 0; i--) {
                if (!needCheck) {
                    dmtn[i] = new DefaultMutableTreeNode(getCertificateCN(certificateChain[i]));
                    if (i < (certificateChain.length - 1)) {
                        dmtn[i + 1].add(dmtn[i]);
                    }
                    certChainList.add((X509Certificate) certificateChain[i]);
                    continue;
                }
                if (CCInstance.getInstance().isTrustedCertificate((X509Certificate) certificateChain[i])) {
                    dmtn[i] = new DefaultMutableTreeNode(getCertificateCN(certificateChain[i]));
                    needCheck = false;
                } else if (CCInstance.getInstance()
                        .hasTrustedIssuerCertificate((X509Certificate) certificateChain[i]) != null) {
                    dmtn[i] = new DefaultMutableTreeNode(getCertificateCN(certificateChain[i]));
                } else {
                    dmtn[i] = new DefaultMutableTreeNode("(!)" + getCertificateCN(certificateChain[i]));

                }
                if (i < (certificateChain.length - 1)) {
                    dmtn[i + 1].add(dmtn[i]);
                }
                certChainList.add((X509Certificate) certificateChain[i]);
            }

            TreeModel tm = new DefaultTreeModel(dmtn[certificateChain.length - 1]);
            jTree1.setModel(tm);
            expandTree(jTree1);
        }
    }

    if (null != jTree1.getTreeExpansionListeners()) {
        if (null != jTree1.getTreeExpansionListeners()[0]) {
            jTree1.removeTreeExpansionListener(jTree1.getTreeExpansionListeners()[0]);
        }
    }
}