Search in sources :

Example 1 with DefaultTreeCellRenderer

use of javax.swing.tree.DefaultTreeCellRenderer in project hackpad by dropbox.

the class RunProxy method resetTree.

/**
     * Initializes a tree for this tree table.
     */
public JTree resetTree(TreeTableModel treeTableModel) {
    tree = new TreeTableCellRenderer(treeTableModel);
    // Install a tableModel representing the visible rows in the tree.
    super.setModel(new TreeTableModelAdapter(treeTableModel, tree));
    // Force the JTable and JTree to share their row selection models.
    ListToTreeSelectionModelWrapper selectionWrapper = new ListToTreeSelectionModelWrapper();
    tree.setSelectionModel(selectionWrapper);
    setSelectionModel(selectionWrapper.getListSelectionModel());
    // Make the tree and table row heights the same.
    if (tree.getRowHeight() < 1) {
        // Metal looks better like this.
        setRowHeight(18);
    }
    // Install the tree editor renderer and editor.
    setDefaultRenderer(TreeTableModel.class, tree);
    setDefaultEditor(TreeTableModel.class, new TreeTableCellEditor());
    setShowGrid(true);
    setIntercellSpacing(new Dimension(1, 1));
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    DefaultTreeCellRenderer r = (DefaultTreeCellRenderer) tree.getCellRenderer();
    r.setOpenIcon(null);
    r.setClosedIcon(null);
    r.setLeafIcon(null);
    return tree;
}
Also used : Dimension(java.awt.Dimension) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) TreeTableModelAdapter(org.mozilla.javascript.tools.debugger.treetable.TreeTableModelAdapter)

Example 2 with DefaultTreeCellRenderer

use of javax.swing.tree.DefaultTreeCellRenderer in project pcgen by PCGen.

the class PreferencesPluginsPanel method getCenter.

@Override
protected JComponent getCenter() {
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Root");
    DefaultMutableTreeNode characterNode;
    DefaultMutableTreeNode pcGenNode;
    DefaultMutableTreeNode appearanceNode;
    DefaultMutableTreeNode gameModeNode;
    panelList = new ArrayList<>(15);
    // Build the settings panel
    settingsPanel = new JPanel();
    settingsPanel.setLayout(new CardLayout());
    settingsPanel.setPreferredSize(new Dimension(780, 420));
    // Build the selection tree
    characterNode = new DefaultMutableTreeNode(in_character);
    settingsPanel.add(buildEmptyPanel("", LanguageBundle.getString("in_Prefs_charTip")), in_character);
    characterStatsPanel = new CharacterStatsPanel(this);
    addPanelToTree(characterNode, characterStatsPanel);
    hitPointsPanel = new HitPointsPanel();
    addPanelToTree(characterNode, hitPointsPanel);
    houseRulesPanel = new HouseRulesPanel();
    addPanelToTree(characterNode, houseRulesPanel);
    monsterPanel = new MonsterPanel();
    addPanelToTree(characterNode, monsterPanel);
    defaultsPanel = new DefaultsPanel();
    addPanelToTree(characterNode, defaultsPanel);
    rootNode.add(characterNode);
    appearanceNode = new DefaultMutableTreeNode(in_appearance);
    settingsPanel.add(buildEmptyPanel("", LanguageBundle.getString("in_Prefs_appearanceTip")), in_appearance);
    colorsPanel = new ColorsPanel();
    addPanelToTree(appearanceNode, colorsPanel);
    displayOptionsPanel = new DisplayOptionsPanel();
    addPanelToTree(appearanceNode, displayOptionsPanel);
    levelUpPanel = new LevelUpPanel();
    addPanelToTree(appearanceNode, levelUpPanel);
    lookAndFeelPanel = new LookAndFeelPanel(this);
    addPanelToTree(appearanceNode, lookAndFeelPanel);
    //		tabsPanel = new TabsPanel();
    //		addPanelToTree(appearanceNode, tabsPanel);
    rootNode.add(appearanceNode);
    pcGenNode = new DefaultMutableTreeNode(Constants.APPLICATION_NAME);
    settingsPanel.add(buildEmptyPanel("", LanguageBundle.getString("in_Prefs_pcgenTip")), Constants.APPLICATION_NAME);
    equipmentPanel = new EquipmentPanel();
    addPanelToTree(pcGenNode, equipmentPanel);
    languagePanel = new LanguagePanel();
    addPanelToTree(pcGenNode, languagePanel);
    locationPanel = new LocationPanel();
    addPanelToTree(pcGenNode, locationPanel);
    inputPanel = new InputPanel();
    addPanelToTree(pcGenNode, inputPanel);
    outputPanel = new OutputPanel();
    addPanelToTree(pcGenNode, outputPanel);
    sourcesPanel = new SourcesPanel();
    addPanelToTree(pcGenNode, sourcesPanel);
    rootNode.add(pcGenNode);
    String in_gamemode = LanguageBundle.getString("in_mnuSettingsCampaign");
    gameModeNode = new DefaultMutableTreeNode(in_gamemode);
    settingsPanel.add(buildEmptyPanel("", LanguageBundle.getString("in_mnuSettingsCampaignTip")), in_gamemode);
    copySettingsPanel = new CopySettingsPanel();
    addPanelToTree(gameModeNode, copySettingsPanel);
    rootNode.add(gameModeNode);
    DefaultMutableTreeNode pluginNode = new DefaultMutableTreeNode(//$NON-NLS-1$
    LanguageBundle.getString("in_Prefs_plugins"));
    addPluginPanes(rootNode, pluginNode);
    settingsModel = new DefaultTreeModel(rootNode);
    settingsTree = new JTree(settingsModel);
    settingsTree.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 0));
    settingsTree.setRootVisible(false);
    settingsTree.setShowsRootHandles(true);
    settingsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    settingsScroll = new JScrollPane(settingsTree, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    // Turn off the icons
    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
    renderer.setLeafIcon(null);
    renderer.setOpenIcon(null);
    renderer.setClosedIcon(null);
    settingsTree.setCellRenderer(renderer);
    // Expand all of the branch nodes
    settingsTree.expandPath(new TreePath(characterNode.getPath()));
    settingsTree.expandPath(new TreePath(pcGenNode.getPath()));
    settingsTree.expandPath(new TreePath(appearanceNode.getPath()));
    settingsTree.expandPath(new TreePath(gameModeNode.getPath()));
    settingsTree.expandPath(new TreePath(pluginNode.getPath()));
    // Add the listener which switches panels when a node of the tree is selected
    settingsTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) settingsTree.getLastSelectedPathComponent();
            if (node == null) {
                return;
            }
            CardLayout cl = (CardLayout) (settingsPanel.getLayout());
            cl.show(settingsPanel, String.valueOf(node));
        }
    });
    // Build the split pane
    splitPane = new FlippingSplitPane(JSplitPane.HORIZONTAL_SPLIT, settingsScroll, settingsPanel, "Prefs");
    splitPane.setOneTouchExpandable(true);
    splitPane.setDividerSize(10);
    return splitPane;
}
Also used : JPanel(javax.swing.JPanel) LocationPanel(pcgen.gui2.prefs.LocationPanel) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) SourcesPanel(pcgen.gui2.prefs.SourcesPanel) OutputPanel(pcgen.gui2.prefs.OutputPanel) TreeSelectionListener(javax.swing.event.TreeSelectionListener) HitPointsPanel(pcgen.gui2.prefs.HitPointsPanel) CopySettingsPanel(pcgen.gui2.prefs.CopySettingsPanel) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) HouseRulesPanel(pcgen.gui2.prefs.HouseRulesPanel) DisplayOptionsPanel(pcgen.gui2.prefs.DisplayOptionsPanel) LevelUpPanel(pcgen.gui2.prefs.LevelUpPanel) ColorsPanel(pcgen.gui2.prefs.ColorsPanel) LanguagePanel(pcgen.gui2.prefs.LanguagePanel) EquipmentPanel(pcgen.gui2.prefs.EquipmentPanel) JScrollPane(javax.swing.JScrollPane) CardLayout(java.awt.CardLayout) CharacterStatsPanel(pcgen.gui2.prefs.CharacterStatsPanel) InputPanel(pcgen.gui2.prefs.InputPanel) Dimension(java.awt.Dimension) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) FlippingSplitPane(pcgen.gui2.tools.FlippingSplitPane) JTree(javax.swing.JTree) DefaultsPanel(pcgen.gui2.prefs.DefaultsPanel) TreePath(javax.swing.tree.TreePath) MonsterPanel(pcgen.gui2.prefs.MonsterPanel) LookAndFeelPanel(pcgen.gui2.prefs.LookAndFeelPanel) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 3 with DefaultTreeCellRenderer

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

the class TreeTableTree method updateUI.

public void updateUI() {
    super.updateUI();
    TreeCellRenderer tcr = super.getCellRenderer();
    if (tcr instanceof DefaultTreeCellRenderer) {
        DefaultTreeCellRenderer dtcr = (DefaultTreeCellRenderer) tcr;
        dtcr.setTextSelectionColor(UIUtil.getTableSelectionForeground());
        dtcr.setBackgroundSelectionColor(UIUtil.getTableSelectionBackground());
    }
}
Also used : TreeCellRenderer(javax.swing.tree.TreeCellRenderer) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer)

Example 4 with DefaultTreeCellRenderer

use of javax.swing.tree.DefaultTreeCellRenderer in project android by JetBrains.

the class AndroidModelView method updateContents.

private void updateContents() {
    myTree.setRootVisible(true);
    if (GradleSyncState.getInstance(myProject).isSyncInProgress()) {
        myTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Gradle project sync in progress ...")));
        return;
    } else {
        myTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Loading ...")));
    }
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(myProject.getName());
        String projectPath = myProject.getBasePath();
        for (Module module : ModuleManager.getInstance(myProject).getModules()) {
            AndroidModuleModel androidModel = AndroidModuleModel.get(module);
            if (androidModel != null) {
                DefaultMutableTreeNode moduleNode = new ModuleNodeBuilder(module.getName(), androidModel, projectPath).getNode();
                rootNode.add(moduleNode);
            }
        // TODO: Also add NativeAndroidGradleModel to the view.
        }
        UIUtil.invokeLaterIfNeeded(() -> {
            DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
            renderer.setOpenIcon(AllIcons.Nodes.NewFolder);
            renderer.setClosedIcon(AllIcons.Nodes.NewFolder);
            renderer.setLeafIcon(AllIcons.ObjectBrowser.ShowModules);
            myTree.setCellRenderer(renderer);
            DefaultTreeModel model = new DefaultTreeModel(rootNode);
            myTree.setRootVisible(false);
            myTree.setModel(model);
        });
    });
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) Module(com.intellij.openapi.module.Module) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer)

Example 5 with DefaultTreeCellRenderer

use of javax.swing.tree.DefaultTreeCellRenderer in project android by JetBrains.

the class InternalAndroidModelView method updateContents.

private void updateContents() {
    myTree.setRootVisible(true);
    if (GradleSyncState.getInstance(myProject).isSyncInProgress()) {
        myTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Gradle project sync in progress ...")));
        return;
    } else {
        myTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Loading ...")));
    }
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(myProject.getName());
        for (Module module : ModuleManager.getInstance(myProject).getModules()) {
            AndroidModuleModel androidModel = AndroidModuleModel.get(module);
            if (androidModel != null) {
                DefaultMutableTreeNode moduleNode = new DefaultMutableTreeNode(module.getName());
                AndroidProject androidProject = androidModel.waitForAndGetProxyAndroidProject();
                addProxyObject(moduleNode, androidProject);
                rootNode.add(moduleNode);
            }
            NdkModuleModel ndkModuleModel = NdkModuleModel.get(module);
            if (ndkModuleModel != null) {
                String nodeName = androidModel == null ? module.getName() : module.getName() + " (native)";
                DefaultMutableTreeNode nativeModuleNode = new DefaultMutableTreeNode(nodeName);
                NativeAndroidProject nativeAndroidProject = ndkModuleModel.waitForAndGetProxyAndroidProject();
                addProxyObject(nativeModuleNode, nativeAndroidProject);
                rootNode.add(nativeModuleNode);
            }
        }
        invokeLaterIfNeeded(() -> {
            DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
            renderer.setOpenIcon(AllIcons.Nodes.NewFolder);
            renderer.setClosedIcon(AllIcons.Nodes.NewFolder);
            renderer.setLeafIcon(AllIcons.ObjectBrowser.ShowModules);
            myTree.setCellRenderer(renderer);
            DefaultTreeModel model = new DefaultTreeModel(rootNode);
            myTree.setRootVisible(false);
            myTree.setModel(model);
        });
    });
}
Also used : NativeAndroidProject(com.android.builder.model.NativeAndroidProject) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) NativeAndroidProject(com.android.builder.model.NativeAndroidProject) AndroidProject(com.android.builder.model.AndroidProject) Module(com.intellij.openapi.module.Module) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer)

Aggregations

DefaultTreeCellRenderer (javax.swing.tree.DefaultTreeCellRenderer)40 JTree (javax.swing.JTree)15 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)15 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)13 TreePath (javax.swing.tree.TreePath)11 MouseAdapter (java.awt.event.MouseAdapter)9 MouseEvent (java.awt.event.MouseEvent)9 Dimension (java.awt.Dimension)7 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)7 TreeCellRenderer (javax.swing.tree.TreeCellRenderer)7 JLabel (javax.swing.JLabel)6 JPanel (javax.swing.JPanel)5 JScrollPane (javax.swing.JScrollPane)5 BorderLayout (java.awt.BorderLayout)4 Component (java.awt.Component)4 TreeSelectionListener (javax.swing.event.TreeSelectionListener)4 DefaultTreeSelectionModel (javax.swing.tree.DefaultTreeSelectionModel)4 Topic (com.igormaznitsa.mindmap.model.Topic)3 Font (java.awt.Font)3 ActionEvent (java.awt.event.ActionEvent)3