Example usage for javax.swing.event TreeSelectionListener TreeSelectionListener

List of usage examples for javax.swing.event TreeSelectionListener TreeSelectionListener

Introduction

In this page you can find the example usage for javax.swing.event TreeSelectionListener TreeSelectionListener.

Prototype

TreeSelectionListener

Source Link

Usage

From source file:org.piraso.ui.base.RequestTreeTopComponent.java

public RequestTreeTopComponent() {
    setName(Bundle.CTL_RequestTreeTopComponent());
    setToolTipText(Bundle.HINT_RequestTreeTopComponent());

    initComponents();/*  w  w  w. j av  a 2  s .  c  om*/

    InstanceContent content = new InstanceContent();
    associateLookup(new AbstractLookup(content));

    this.entryContent = new SingleClassInstanceContent<Entry>(content);

    jTree.setFont(FontProviderManager.INSTANCE.getEditorDefaultFont());
    jTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    jTree.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            int selRow = jTree.getRowForLocation(e.getX(), e.getY());
            TreePath selPath = jTree.getPathForLocation(e.getX(), e.getY());
            if (selRow != -1 && selPath != null) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) selPath.getLastPathComponent();
                Child child = null;
                if (Child.class.isInstance(node.getUserObject())) {
                    child = (Child) node.getUserObject();
                }

                if (child != null && e.getClickCount() == 1) {
                    child.select();
                }
            }
        }
    });

    jTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
        @Override
        public void valueChanged(TreeSelectionEvent e) {
            if (e.getPath() != null && e.getPath().getLastPathComponent() != null) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent();
                if (node.getUserObject() != null && Child.class.isInstance(node.getUserObject())) {
                    Child child = (Child) node.getUserObject();
                    child.showRequestView();
                }
            }
        }
    });
}

From source file:org.sintef.thingml.FilePanel.java

public FilePanel(final ThingMLPanel editor, final ThingMLFrame frame, File rootF) {
    this.setLayout(new BorderLayout());
    add(new JScrollPane(tree), BorderLayout.CENTER);

    File root = rootF;//w  w w  .  j  a v a2  s  .  co  m
    if (root == null) {
        JFileChooser filechooser = new JFileChooser();
        filechooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        filechooser.setDialogTitle("Select base directory for ThingML files");

        File dir = ThingMLSettings.getInstance().get_default_work_dir();

        if (dir != null) {
            filechooser.setSelectedFile(dir);
        }

        int returnVal = filechooser.showOpenDialog(null);
        if (filechooser.getSelectedFile() != null && returnVal == JFileChooser.APPROVE_OPTION) {
            ThingMLSettings.getInstance().store_default_work_dir(filechooser.getSelectedFile());
            root = filechooser.getSelectedFile();
        } else {
            System.exit(0);
        }
    }

    FileFilter fileFilter = new FileFilter() {
        @Override
        public boolean accept(File f) {
            return f.getName().endsWith(".thingml");
        }
    };

    final File root2 = root;

    try {
        simpleFileManager = new SimpleFileManager(root, fileFilter);
    } catch (IOException e) {
        e.printStackTrace();
    }
    tree.setModel(new DefaultTreeModel(simpleFileManager.getDirectoryTree()));
    simpleFileManager.startMonitoring();
    FileMonitor fileMonitor = simpleFileManager.getFileMonitor();
    fileMonitor.addClient(this);

    tree.addTreeSelectionListener(new TreeSelectionListener() {
        @Override
        public void valueChanged(TreeSelectionEvent e) {
            TreePath path = e.getNewLeadSelectionPath();
            String file = path.getLastPathComponent().toString();
            while (path.getParentPath() != null) {
                path = path.getParentPath();
                file = path.getLastPathComponent() + "/" + file;
            }
            if (file.indexOf("/") > -1) {
                File fileF = new File(root2 + "/" + file.substring(file.indexOf("/")));
                if (fileF.isFile()) {
                    try {
                        final InputStream input = new FileInputStream(fileF.getAbsolutePath());
                        final java.util.List<String> packLines = IOUtils.readLines(input);
                        String content = "";
                        for (String line : packLines) {
                            content += line + "\n";
                        }
                        input.close();
                        editor.loadText(content, fileF);
                        frame.setTitle("ThingML Editor : "
                                + e.getNewLeadSelectionPath().getLastPathComponent().toString());
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
        }
    });
}

From source file:org.sonar.scanner.protocol.viewer.ScannerReportViewerApp.java

/**
 * Initialize the contents of the frame.
 *///w w w  . j  av  a2s. c  o  m
private void initialize() {
    try {
        for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (Exception e) {
        // If Nimbus is not available, you can set the GUI to another look and feel.
    }
    frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    splitPane = new JSplitPane();
    frame.getContentPane().add(splitPane, BorderLayout.CENTER);

    tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    tabbedPane.setPreferredSize(new Dimension(500, 7));
    splitPane.setRightComponent(tabbedPane);

    componentDetailsTab = new JScrollPane();
    tabbedPane.addTab("Component details", null, componentDetailsTab, null);

    componentEditor = new JEditorPane();
    componentDetailsTab.setViewportView(componentEditor);

    sourceTab = new JScrollPane();
    tabbedPane.addTab("Source", null, sourceTab, null);

    sourceEditor = createSourceEditor();
    sourceEditor.setEditable(false);
    sourceTab.setViewportView(sourceEditor);

    textLineNumber = createTextLineNumber();
    sourceTab.setRowHeaderView(textLineNumber);

    highlightingTab = new JScrollPane();
    tabbedPane.addTab("Highlighting", null, highlightingTab, null);

    highlightingEditor = new JEditorPane();
    highlightingTab.setViewportView(highlightingEditor);

    symbolTab = new JScrollPane();
    tabbedPane.addTab("Symbol references", null, symbolTab, null);

    symbolEditor = new JEditorPane();
    symbolTab.setViewportView(symbolEditor);

    coverageTab = new JScrollPane();
    tabbedPane.addTab("Coverage", null, coverageTab, null);

    coverageEditor = new JEditorPane();
    coverageTab.setViewportView(coverageEditor);

    duplicationTab = new JScrollPane();
    tabbedPane.addTab("Duplications", null, duplicationTab, null);

    duplicationEditor = new JEditorPane();
    duplicationTab.setViewportView(duplicationEditor);

    testsTab = new JScrollPane();
    tabbedPane.addTab("Tests", null, testsTab, null);

    testsEditor = new JEditorPane();
    testsTab.setViewportView(testsEditor);

    issuesTab = new JScrollPane();
    tabbedPane.addTab("Issues", null, issuesTab, null);

    issuesEditor = new JEditorPane();
    issuesTab.setViewportView(issuesEditor);

    measuresTab = new JScrollPane();
    tabbedPane.addTab("Measures", null, measuresTab, null);

    measuresEditor = new JEditorPane();
    measuresTab.setViewportView(measuresEditor);

    scmTab = new JScrollPane();
    tabbedPane.addTab("SCM", null, scmTab, null);

    scmEditor = new JEditorPane();
    scmTab.setViewportView(scmEditor);

    activeRuleTab = new JScrollPane();
    tabbedPane.addTab("ActiveRules", null, activeRuleTab, null);

    activeRuleEditor = new JEditorPane();
    activeRuleTab.setViewportView(activeRuleEditor);

    treeScrollPane = new JScrollPane();
    treeScrollPane.setPreferredSize(new Dimension(200, 400));
    splitPane.setLeftComponent(treeScrollPane);

    componentTree = new JTree();
    componentTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("empty") {
        {
        }
    }));
    treeScrollPane.setViewportView(componentTree);
    componentTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    componentTree.addTreeSelectionListener(new TreeSelectionListener() {
        @Override
        public void valueChanged(TreeSelectionEvent e) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) componentTree.getLastSelectedPathComponent();

            if (node == null) {
                // Nothing is selected.
                return;
            }

            frame.setCursor(new Cursor(Cursor.WAIT_CURSOR));
            updateDetails((Component) node.getUserObject());
            frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

        }

    });
    frame.pack();
}

From source file:org.tinymediamanager.ui.tvshows.TvShowPanel.java

/**
 * Instantiates a new tv show panel./*from www  . j  a va2 s  .com*/
 */
public TvShowPanel() {
    super();

    treeModel = new TvShowTreeModel(tvShowList.getTvShows());
    tvShowSeasonSelectionModel = new TvShowSeasonSelectionModel();
    tvShowEpisodeSelectionModel = new TvShowEpisodeSelectionModel();

    // build menu
    menu = new JMenu(BUNDLE.getString("tmm.tvshows")); //$NON-NLS-1$
    JFrame mainFrame = MainWindow.getFrame();
    JMenuBar menuBar = mainFrame.getJMenuBar();
    menuBar.add(menu);

    setLayout(new FormLayout(
            new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("850px:grow"),
                    FormFactory.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC, RowSpec.decode("default:grow"), }));

    JSplitPane splitPane = new JSplitPane();
    splitPane.setContinuousLayout(true);
    add(splitPane, "2, 2, fill, fill");

    JPanel panelTvShowTree = new JPanel();
    splitPane.setLeftComponent(panelTvShowTree);
    panelTvShowTree.setLayout(new FormLayout(
            new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
                    FormFactory.UNRELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
                    FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, },
            new RowSpec[] { FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                    RowSpec.decode("3px:grow"), FormFactory.RELATED_GAP_ROWSPEC,
                    FormFactory.DEFAULT_ROWSPEC, }));

    textField = EnhancedTextField.createSearchTextField();
    panelTvShowTree.add(textField, "4, 1, right, bottom");
    textField.setColumns(12);
    textField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void insertUpdate(final DocumentEvent e) {
            applyFilter();
        }

        @Override
        public void removeUpdate(final DocumentEvent e) {
            applyFilter();
        }

        @Override
        public void changedUpdate(final DocumentEvent e) {
            applyFilter();
        }

        public void applyFilter() {
            TvShowTreeModel filteredModel = (TvShowTreeModel) tree.getModel();
            if (StringUtils.isNotBlank(textField.getText())) {
                filteredModel.setFilter(SearchOptions.TEXT, textField.getText());
            } else {
                filteredModel.removeFilter(SearchOptions.TEXT);
            }

            filteredModel.filter(tree);
        }
    });

    final JToggleButton btnFilter = new JToggleButton(IconManager.FILTER);
    btnFilter.setToolTipText(BUNDLE.getString("movieextendedsearch.options")); //$NON-NLS-1$
    panelTvShowTree.add(btnFilter, "6, 1, default, bottom");

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    panelTvShowTree.add(scrollPane, "2, 3, 5, 1, fill, fill");

    JToolBar toolBar = new JToolBar();
    toolBar.setRollover(true);
    toolBar.setFloatable(false);
    toolBar.setOpaque(false);
    panelTvShowTree.add(toolBar, "2, 1");

    // toolBar.add(actionUpdateDatasources);
    final JSplitButton buttonUpdateDatasource = new JSplitButton(IconManager.REFRESH);
    // temp fix for size of the button
    buttonUpdateDatasource.setText("   ");
    buttonUpdateDatasource.setHorizontalAlignment(JButton.LEFT);
    // buttonScrape.setMargin(new Insets(2, 2, 2, 24));
    buttonUpdateDatasource.setSplitWidth(18);
    buttonUpdateDatasource.setToolTipText(BUNDLE.getString("update.datasource")); //$NON-NLS-1$
    buttonUpdateDatasource.addSplitButtonActionListener(new SplitButtonActionListener() {
        public void buttonClicked(ActionEvent e) {
            actionUpdateDatasources.actionPerformed(e);
        }

        public void splitButtonClicked(ActionEvent e) {
            // build the popupmenu on the fly
            buttonUpdateDatasource.getPopupMenu().removeAll();
            buttonUpdateDatasource.getPopupMenu().add(new JMenuItem(actionUpdateDatasources2));
            buttonUpdateDatasource.getPopupMenu().addSeparator();
            for (String ds : TvShowModuleManager.SETTINGS.getTvShowDataSource()) {
                buttonUpdateDatasource.getPopupMenu()
                        .add(new JMenuItem(new TvShowUpdateSingleDatasourceAction(ds)));
            }
            buttonUpdateDatasource.getPopupMenu().addSeparator();
            buttonUpdateDatasource.getPopupMenu().add(new JMenuItem(actionUpdateTvShow));
            buttonUpdateDatasource.getPopupMenu().pack();
        }
    });

    JPopupMenu popup = new JPopupMenu("popup");
    buttonUpdateDatasource.setPopupMenu(popup);
    toolBar.add(buttonUpdateDatasource);

    JSplitButton buttonScrape = new JSplitButton(IconManager.SEARCH);
    // temp fix for size of the button
    buttonScrape.setText("   ");
    buttonScrape.setHorizontalAlignment(JButton.LEFT);
    buttonScrape.setSplitWidth(18);
    buttonScrape.setToolTipText(BUNDLE.getString("tvshow.scrape.selected")); //$NON-NLS-1$

    // register for listener
    buttonScrape.addSplitButtonActionListener(new SplitButtonActionListener() {
        @Override
        public void buttonClicked(ActionEvent e) {
            actionScrape.actionPerformed(e);
        }

        @Override
        public void splitButtonClicked(ActionEvent e) {
        }
    });

    popup = new JPopupMenu("popup");
    JMenuItem item = new JMenuItem(actionScrape2);
    popup.add(item);
    // item = new JMenuItem(actionScrapeUnscraped);
    // popup.add(item);
    item = new JMenuItem(actionScrapeSelected);
    popup.add(item);
    item = new JMenuItem(actionScrapeNewItems);
    popup.add(item);
    buttonScrape.setPopupMenu(popup);
    toolBar.add(buttonScrape);
    toolBar.add(actionEdit);

    JButton btnMediaInformation = new JButton();
    btnMediaInformation.setAction(actionMediaInformation);
    toolBar.add(btnMediaInformation);

    // install drawing of full with
    tree = new ZebraJTree(treeModel) {
        private static final long serialVersionUID = 2422163883324014637L;

        @Override
        public void paintComponent(Graphics g) {
            width = this.getWidth();
            super.paintComponent(g);
        }
    };
    tvShowSelectionModel = new TvShowSelectionModel(tree);

    TreeUI ui = new TreeUI() {
        @Override
        protected void paintRow(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds,
                TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf) {
            bounds.width = width - bounds.x;
            super.paintRow(g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf);
        }
    };
    tree.setUI(ui);

    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    tree.setCellRenderer(new TvShowTreeCellRenderer());
    tree.setRowHeight(0);
    scrollPane.setViewportView(tree);

    JPanel panelHeader = new JPanel() {
        private static final long serialVersionUID = -6914183798172482157L;

        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            JTattooUtilities.fillHorGradient(g, AbstractLookAndFeel.getTheme().getColHeaderColors(), 0, 0,
                    getWidth(), getHeight());
        }
    };
    scrollPane.setColumnHeaderView(panelHeader);
    panelHeader.setLayout(new FormLayout(
            new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
                    FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("center:20px"),
                    ColumnSpec.decode("center:20px"), ColumnSpec.decode("center:20px") },
            new RowSpec[] { FormFactory.DEFAULT_ROWSPEC, }));

    JLabel lblTvShowsColumn = new JLabel(BUNDLE.getString("metatag.tvshow")); //$NON-NLS-1$
    lblTvShowsColumn.setHorizontalAlignment(JLabel.CENTER);
    panelHeader.add(lblTvShowsColumn, "2, 1");

    JLabel lblNfoColumn = new JLabel("");
    lblNfoColumn.setHorizontalAlignment(JLabel.CENTER);
    lblNfoColumn.setIcon(IconManager.INFO);
    lblNfoColumn.setToolTipText(BUNDLE.getString("metatag.nfo"));//$NON-NLS-1$
    panelHeader.add(lblNfoColumn, "4, 1");

    JLabel lblImageColumn = new JLabel("");
    lblImageColumn.setHorizontalAlignment(JLabel.CENTER);
    lblImageColumn.setIcon(IconManager.IMAGE);
    lblImageColumn.setToolTipText(BUNDLE.getString("metatag.images"));//$NON-NLS-1$
    panelHeader.add(lblImageColumn, "5, 1");

    JLabel lblSubtitleColumn = new JLabel("");
    lblSubtitleColumn.setHorizontalAlignment(JLabel.CENTER);
    lblSubtitleColumn.setIcon(IconManager.SUBTITLE);
    lblSubtitleColumn.setToolTipText(BUNDLE.getString("metatag.subtitles"));//$NON-NLS-1$
    panelHeader.add(lblSubtitleColumn, "6, 1");

    JPanel panel = new JPanel();
    panelTvShowTree.add(panel, "2, 5, 3, 1, fill, fill");
    panel.setLayout(new FormLayout(
            new ColumnSpec[] { FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
                    FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
                    FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
                    FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, },
            new RowSpec[] { FormFactory.LINE_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, }));

    JLabel lblTvShowsT = new JLabel(BUNDLE.getString("metatag.tvshows") + ":"); //$NON-NLS-1$
    panel.add(lblTvShowsT, "1, 2, fill, fill");

    lblTvShows = new JLabel("");
    panel.add(lblTvShows, "3, 2");

    JLabel labelSlash = new JLabel("/");
    panel.add(labelSlash, "5, 2");

    JLabel lblEpisodesT = new JLabel(BUNDLE.getString("metatag.episodes") + ":"); //$NON-NLS-1$
    panel.add(lblEpisodesT, "7, 2");

    lblEpisodes = new JLabel("");
    panel.add(lblEpisodes, "9, 2");

    JLayeredPane layeredPaneRight = new JLayeredPane();
    layeredPaneRight.setLayout(
            new FormLayout(new ColumnSpec[] { ColumnSpec.decode("default"), ColumnSpec.decode("default:grow") },
                    new RowSpec[] { RowSpec.decode("default"), RowSpec.decode("default:grow") }));
    panelRight = new JPanel();
    layeredPaneRight.add(panelRight, "1, 1, 2, 2, fill, fill");
    layeredPaneRight.setLayer(panelRight, 0);

    // glass pane
    final TvShowExtendedSearchPanel panelExtendedSearch = new TvShowExtendedSearchPanel(treeModel, tree);
    panelExtendedSearch.setVisible(false);
    // panelMovieList.add(panelExtendedSearch, "2, 5, 2, 1, fill, fill");
    btnFilter.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            if (panelExtendedSearch.isVisible() == true) {
                panelExtendedSearch.setVisible(false);
            } else {
                panelExtendedSearch.setVisible(true);
            }
        }
    });
    // add a propertychangelistener which reacts on setting a filter
    tree.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if ("filterChanged".equals(evt.getPropertyName())) {
                if (Boolean.TRUE.equals(evt.getNewValue())) {
                    btnFilter.setIcon(IconManager.FILTER_ACTIVE);
                    btnFilter.setToolTipText(BUNDLE.getString("movieextendedsearch.options.active")); //$NON-NLS-1$
                } else {
                    btnFilter.setIcon(IconManager.FILTER);
                    btnFilter.setToolTipText(BUNDLE.getString("movieextendedsearch.options")); //$NON-NLS-1$
                }
            }
        }
    });
    layeredPaneRight.add(panelExtendedSearch, "1, 1, fill, fill");
    layeredPaneRight.setLayer(panelExtendedSearch, 1);

    splitPane.setRightComponent(layeredPaneRight);
    panelRight.setLayout(new CardLayout(0, 0));

    JPanel panelTvShow = new TvShowInformationPanel(tvShowSelectionModel);
    panelRight.add(panelTvShow, "tvShow");

    JPanel panelTvShowSeason = new TvShowSeasonInformationPanel(tvShowSeasonSelectionModel);
    panelRight.add(panelTvShowSeason, "tvShowSeason");

    JPanel panelTvShowEpisode = new TvShowEpisodeInformationPanel(tvShowEpisodeSelectionModel);
    panelRight.add(panelTvShowEpisode, "tvShowEpisode");

    tree.addTreeSelectionListener(new TreeSelectionListener() {
        @Override
        public void valueChanged(TreeSelectionEvent e) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
            if (node != null) {
                // click on a tv show
                if (node.getUserObject() instanceof TvShow) {
                    TvShow tvShow = (TvShow) node.getUserObject();
                    tvShowSelectionModel.setSelectedTvShow(tvShow);
                    CardLayout cl = (CardLayout) (panelRight.getLayout());
                    cl.show(panelRight, "tvShow");
                }

                // click on a season
                if (node.getUserObject() instanceof TvShowSeason) {
                    TvShowSeason tvShowSeason = (TvShowSeason) node.getUserObject();
                    tvShowSeasonSelectionModel.setSelectedTvShowSeason(tvShowSeason);
                    CardLayout cl = (CardLayout) (panelRight.getLayout());
                    cl.show(panelRight, "tvShowSeason");
                }

                // click on an episode
                if (node.getUserObject() instanceof TvShowEpisode) {
                    TvShowEpisode tvShowEpisode = (TvShowEpisode) node.getUserObject();
                    tvShowEpisodeSelectionModel.setSelectedTvShowEpisode(tvShowEpisode);
                    CardLayout cl = (CardLayout) (panelRight.getLayout());
                    cl.show(panelRight, "tvShowEpisode");
                }
            } else {
                // check if there is at least one tv show in the model
                TvShowRootTreeNode root = (TvShowRootTreeNode) tree.getModel().getRoot();
                if (root.getChildCount() == 0) {
                    // sets an inital show
                    tvShowSelectionModel.setSelectedTvShow(null);
                }
            }
        }
    });

    addComponentListener(new ComponentAdapter() {
        @Override
        public void componentHidden(ComponentEvent e) {
            menu.setVisible(false);
            super.componentHidden(e);
        }

        @Override
        public void componentShown(ComponentEvent e) {
            menu.setVisible(true);
            super.componentHidden(e);
        }
    });

    // further initializations
    init();
    initDataBindings();

    // selecting first TV show at startup
    if (tvShowList.getTvShows() != null && tvShowList.getTvShows().size() > 0) {
        DefaultMutableTreeNode firstLeaf = (DefaultMutableTreeNode) ((DefaultMutableTreeNode) tree.getModel()
                .getRoot()).getFirstChild();
        tree.setSelectionPath(new TreePath(((DefaultMutableTreeNode) firstLeaf.getParent()).getPath()));
        tree.setSelectionPath(new TreePath(firstLeaf.getPath()));
    }
}

From source file:plugin.notes.gui.NotesView.java

private void initTree() {
    dataDir.listFiles();//from  w ww  . ja va 2s.c  om
    root = new NotesTreeNode(dataDir.getName(), dataDir, notesTree);

    TreeModel model = new DefaultTreeModel(root);
    notesTree.setModel(model);
    notesTree.addTreeSelectionListener(new TreeSelectionListener() {
        @Override
        public void valueChanged(TreeSelectionEvent evt) {
            notesTreeActionPerformed();
        }
    });
    notesTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    notesTree.setEditable(true);
    model.addTreeModelListener(new TreeModelListener() {
        @Override
        public void treeNodesChanged(TreeModelEvent e) {
            notesTreeNodesChanged();
        }

        @Override
        public void treeNodesInserted(TreeModelEvent e) {
            // TODO:  Method does nothing?
        }

        @Override
        public void treeNodesRemoved(TreeModelEvent e) {
            // TODO:  Method does nothing?
        }

        @Override
        public void treeStructureChanged(TreeModelEvent e) {
            // TODO:  Method does nothing?
        }
    });
}

From source file:se.nawroth.asciidoc.browser.AsciidocBrowserApplication.java

public AsciidocBrowserApplication(final String[] args) {
    super("Asciidoc Browser");
    setIconImage(Icons.APPLICATION.image());

    setSize(1200, 1024);/*from w ww  .jav  a 2s. co m*/

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(final WindowEvent e) {
            actionExit();
        }
    });

    JPanel buttonPanel = new JPanel();
    backButton = new JButton("");
    backButton.setIcon(Icons.BACK.icon());
    backButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            actionBack();
        }
    });
    buttonPanel.setLayout(new MigLayout("", "[1px][][][][]", "[1px]"));

    JButton btnOptionsbutton = new JButton("");
    btnOptionsbutton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            settingsDialog.setVisible(true);
        }
    });
    btnOptionsbutton.setIcon(Icons.OPTIONS.icon());
    buttonPanel.add(btnOptionsbutton, "flowx,cell 0 0");
    backButton.setEnabled(false);
    buttonPanel.add(backButton, "cell 0 0,grow");
    forwardButton = new JButton("");
    forwardButton.setIcon(Icons.FORWARD.icon());
    forwardButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            actionForward();
        }
    });
    forwardButton.setEnabled(false);
    buttonPanel.add(forwardButton, "cell 0 0,grow");
    getContentPane().setLayout(new MigLayout("", "[793.00px,grow]", "[44px][930px]"));
    getContentPane().add(buttonPanel, "cell 0 0,growx,aligny top");
    locationTextField = new JTextField(65);
    locationTextField.setText("");
    locationTextField.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent e) {
            int keyCode = e.getKeyCode();
            if (keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_TAB) {
                actionGo();
                refreshDocumentTree();
            }
        }
    });
    locationTextField.setTransferHandler(
            new TextFieldTransferHandler(locationTextField.getTransferHandler(), new Runnable() {
                @Override
                public void run() {
                    locationTextField.setText("");
                }
            }, new Runnable() {

                @Override
                public void run() {
                    actionGo();
                    refreshDocumentTree();
                }
            }));

    homebutton = new JButton("");
    homebutton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            locationTextField.setText(Settings.getHome());
            actionGo();
            refreshDocumentTree();
        }
    });

    refreshButton = new JButton("");
    refreshButton.setToolTipText("Refresh");
    refreshButton.setEnabled(false);
    refreshButton.setIcon(Icons.REFRESH.icon());
    refreshButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            actionGo();
            refreshPreview();
        }
    });
    buttonPanel.add(refreshButton, "cell 1 0");

    homebutton.setIcon(Icons.HOME.icon());
    buttonPanel.add(homebutton, "cell 2 0");
    buttonPanel.add(locationTextField, "cell 3 0,grow");

    treeSourceSplitPane = new JSplitPane();
    treeSourceSplitPane.setResizeWeight(0.3);
    getContentPane().add(treeSourceSplitPane, "cell 0 1,grow");

    treeScrollPane = new JScrollPane();
    treeScrollPane.setMinimumSize(new Dimension(200, 200));
    treeSourceSplitPane.setLeftComponent(treeScrollPane);

    documentTree = new DocumentTree(documentModel);
    documentTree.setCellRenderer(new TooltipsTreeCellRenderer());
    ToolTipManager.sharedInstance().registerComponent(documentTree);
    ToolTipManager.sharedInstance().setInitialDelay(INITIAL_TOOLTIP_DELAY);
    ToolTipManager.sharedInstance().setReshowDelay(0);
    documentTree.addTreeSelectionListener(new TreeSelectionListener() {
        @Override
        public void valueChanged(final TreeSelectionEvent tse) {
            TreePath newLeadSelectionPath = tse.getNewLeadSelectionPath();
            if (newLeadSelectionPath != null && !newLeadSelectionPath.equals(currentSelectionPath)) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) newLeadSelectionPath
                        .getLastPathComponent();
                FileWrapper file = (FileWrapper) node.getUserObject();
                showFile(file, true);
                refreshPreview();
            }
        }
    });
    treeScrollPane.setViewportView(documentTree);

    sourceEditorPane = new JEditorPane();
    sourceEditorPane.setContentType("text/html");
    sourceEditorPane.setEditable(false);
    sourceEditorPane.addHyperlinkListener(new HandleHyperlinkUpdate());
    JScrollPane fileScrollPane = new JScrollPane(sourceEditorPane);
    fileScrollPane.setMinimumSize(new Dimension(600, 600));

    documentTabbedPane = new JTabbedPane(SwingConstants.BOTTOM);
    documentTabbedPane.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(final ChangeEvent ce) {
            refreshPreview();
        }
    });
    sourceLogSplitPane = new JSplitPane();
    sourceLogSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
    treeSourceSplitPane.setRightComponent(sourceLogSplitPane);
    sourceLogSplitPane.setTopComponent(documentTabbedPane);
    documentTabbedPane.add(fileScrollPane);
    documentTabbedPane.setTitleAt(0, "Source");

    browserPane = new BrowserPane();

    previewScrollPane = new JScrollPane(browserPane);
    documentTabbedPane.addTab("Preview", null, previewScrollPane, null);

    console = new JConsole();
    System.setErr(console.getErr());
    System.setOut(console.getOut());
    sourceLogSplitPane.setBottomComponent(console);

    executor = new AsciidocExecutor();
}

From source file:tk.tomby.tedit.plugins.explorer.Explorer.java

/**
 * Creates a new Explorer object./*from   w ww .  j  a  v  a 2  s .c  o m*/
 */
public Explorer() {
    super("Explorer");

    File rootDir = new File(PreferenceManager.getString("explorer.directory", System.getProperty("user.home")));

    JPanel internalPanel = new JPanel();
    internalPanel.setLayout(new BorderLayout());

    topPanel = new TopPanel(rootDir.getAbsolutePath());
    topPanel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            JComboBox combo = (JComboBox) evt.getSource();
            TaskManager.execute(new ReadDirectoryWorker(combo));
        }
    });

    internalPanel.add(BorderLayout.NORTH, topPanel);

    DefaultMutableTreeNode directoryRoot = new DefaultMutableTreeNode(rootDir);

    directoryTreeModel = new ShortedTreeModel(directoryRoot, new ToStringComparator());
    directoryTree = new JTree(directoryTreeModel);
    directoryTree.setCellRenderer(new DirectoryCellRenderer());
    directoryTree.setRootVisible(true);
    directoryTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    directoryTree.setEnabled(true);
    directoryTree.setEditable(false);
    directoryTree.setShowsRootHandles(true);
    directoryTree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent evt) {
            TreePath path = evt.getPath();
            TreePath leadPath = evt.getNewLeadSelectionPath();

            if ((path != null) && (leadPath != null)) {
                TaskManager.execute(new RefreshWorker(leadPath, false));
            }
        }
    });
    directoryTree.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent evt) {
            if (evt.getClickCount() == 2) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) directoryTree
                        .getLastSelectedPathComponent();

                if (!node.isRoot()) {
                    File dir = (File) node.getUserObject();

                    topPanel.setDirectory(dir.getAbsolutePath());
                }
            }
        }
    });

    JScrollPane directoryScroll = new JScrollPane(directoryTree);
    directoryScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    directoryScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    directoryScroll.getViewport().setScrollMode(JViewport.BLIT_SCROLL_MODE);

    fileListModel = new ShortedListModel(new ToStringComparator());
    fileList = new JList(fileListModel);
    fileList.setDragEnabled(true);
    fileList.setCellRenderer(new FileCellRenderer());
    fileList.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent evt) {
            if (evt.getClickCount() == 2) {
                final int index = fileList.locationToIndex(evt.getPoint());

                TaskManager.execute(new Runnable() {
                    public void run() {
                        File file = (File) fileListModel.getElementAt(index);

                        if (log.isDebugEnabled()) {
                            log.debug(file);
                        }

                        IBuffer buffer = new BufferFactory().createBuffer();
                        buffer.open(file);

                        WorkspaceManager.addBuffer(buffer);
                    }
                });
            }
        }
    });

    JScrollPane filesScroll = new JScrollPane(fileList);
    filesScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    filesScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    filesScroll.getViewport().setScrollMode(JViewport.BLIT_SCROLL_MODE);

    splitPane = new StrippedSplitPane(JSplitPane.VERTICAL_SPLIT, directoryScroll, filesScroll);
    splitPane.setBorder(BorderFactory.createEmptyBorder());
    splitPane.setOneTouchExpandable(false);
    splitPane.setDividerSize(5);
    splitPane.setDividerLocation(PreferenceManager.getInt("explorer.divider", 0));

    List<MutableTreeNode> dirs = openDirectory(rootDir);
    directoryTreeModel.insertAllInto(dirs, directoryRoot);

    List<File> files = getFiles(rootDir);
    fileListModel.addAll(files);

    directoryTree.expandRow(0);

    internalPanel.add(splitPane, BorderLayout.CENTER);

    setContent(internalPanel);
}

From source file:tufts.vue.OutlineViewTree.java

/** Creates a new instance of OverviewTree */
public OutlineViewTree() {
    setModel(null);//from ww  w.  j a v a  2s. com
    setEditable(true);
    setFocusable(true);
    getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    setCellRenderer(new OutlineViewTreeRenderer());
    //setCellRenderer(new DefaultTreeCellRenderer());
    setCellEditor(new OutlineViewTreeEditor());
    setInvokesStopCellEditing(true); // so focus-loss during edit triggers a save instead of abort edit

    setRowHeight(-1); // ahah: must do this to force variable row height

    //tree selection listener to keep track of the selected node 
    addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent e) {
            ArrayList selectedComponents = new ArrayList();
            TreePath[] paths = getSelectionPaths();

            //if there is no selected nodes
            if (paths == null) {
                valueChangedState = false;
                selectionFromVUE = false;

                return;
            }

            for (int i = 0; i < paths.length; i++) {
                DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) paths[i].getLastPathComponent();
                Object o = treeNode.getUserObject();
                if (DEBUG.FOCUS)
                    System.out.println(this + " valueChanged in treeNode[" + treeNode + "] userObject="
                            + o.getClass() + "[" + o + "]");
                tufts.oki.hierarchy.HierarchyNode hierarchyNode = (tufts.oki.hierarchy.HierarchyNode) o;

                LWComponent component = hierarchyNode.getLWComponent();

                //if it is not LWMap, add to the selected components list
                if (!(component instanceof LWMap)) {
                    selectedComponents.add(component);
                }
            }

            if (!selectionFromVUE) {
                valueChangedState = true;

                //                         if(selectedComponents.size() != 0)
                //                           VUE.getSelection().setTo(selectedComponents.iterator());
                //                         else
                //                           VUE.getSelection().clear();
            }

            valueChangedState = false;
            selectionFromVUE = false;
        }
    });
}

From source file:ui.panel.UILicenseAdd.java

private JPanel createPnlFeature() {
    JPanel panel = p.createPanel(Layouts.gridbag);

    GridBagConstraints g = new GridBagConstraints();
    lblSelectFeature = l.createLabel("Select Features", SwingConstants.LEFT);
    g.gridx = 0;/*  w  w w .j  a va 2  s  . co  m*/
    g.gridy = 0;
    g.gridwidth = 2;
    g.insets = new Insets(5, 5, 5, 5);
    panel.add(lblSelectFeature, g);

    lblServiceApi = l.createLabel("Service APIs Used", SwingConstants.LEFT);
    g.gridx = 4;
    g.gridy = 0;
    g.gridwidth = 2;
    g.insets = new Insets(5, 5, 5, 5);
    panel.add(lblServiceApi, g);
    getFeaturesData();
    DefaultMutableTreeNode root = new MyDataNode("Features", "Features");
    for (String key : Data.featureList.keySet()) {
        try {
            DefaultMutableTreeNode element = new MyDataNode(key, Data.fieldNames.get(key));

            JSONArray features = Data.featureList.get(key);
            ArrayList<DefaultMutableTreeNode> arrayFeatureCheckBox = new ArrayList<DefaultMutableTreeNode>();

            for (int i = 0; i < features.length(); i++) {
                JSONObject feature = features.getJSONObject(i);
                DefaultMutableTreeNode featureElement = new MyDataNode((String) feature.get("name"),
                        Data.fieldNames.get(feature.get("name")));
                element.add(featureElement);
                arrayFeatureCheckBox.add(featureElement);
            }

            root.add(element);

        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

    tree = new JTree(root);
    tree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            TreePath path = tree.getSelectionModel().getSelectionPath();
            model.removeAllElements();
            String item = tree.getSelectionModel().getSelectionPath().getLastPathComponent().toString();
            MyDataNode node = (MyDataNode) tree.getSelectionModel().getSelectionPath().getLastPathComponent();
            String selected = node.getValue();
            servicesList = new HashMap<String, String>();
            try {
                if (selected.equalsIgnoreCase("Features")) {
                    for (String key : Data.featureList.keySet()) {
                        JSONArray featureArray = Data.featureList.get(key);

                        for (int i = 0; i < featureArray.length(); i++) {
                            JSONArray servicesArray = featureArray.getJSONObject(i).getJSONArray("services");

                            for (int x = 0; x < servicesArray.length(); x++) {
                                servicesList.put(Integer.toString(servicesArray.getJSONObject(x).getInt("id")),
                                        servicesArray.getJSONObject(x).getString("name"));
                            }
                        }
                    }
                } else if (path.getPathCount() == 2) {
                    for (String key : Data.featureList.keySet()) {
                        if (key.equals(selected)) {
                            JSONArray featureArray = Data.featureList.get(key);

                            for (int i = 0; i < featureArray.length(); i++) {
                                JSONArray servicesArray = featureArray.getJSONObject(i)
                                        .getJSONArray("services");

                                for (int x = 0; x < servicesArray.length(); x++) {
                                    servicesList.put(
                                            Integer.toString(servicesArray.getJSONObject(x).getInt("id")),
                                            servicesArray.getJSONObject(x).getString("name"));
                                }
                            }
                        } else {
                            continue;
                        }
                    }
                } else {
                    MyDataNode nodePath = (MyDataNode) path.getPathComponent(1);
                    for (String key : Data.featureList.keySet()) {
                        if (key.equals(nodePath.getValue())) {

                            JSONArray featureArray = Data.featureList.get(key);
                            for (int i = 0; i < featureArray.length(); i++) {
                                System.out.println(
                                        featureArray.getJSONObject(i).getString("name") + ":" + selected);
                                if (featureArray.getJSONObject(i).getString("name").equals(selected)) {
                                    JSONArray servicesArray = featureArray.getJSONObject(i)
                                            .getJSONArray("services");
                                    System.out.println(servicesArray);
                                    for (int x = 0; x < servicesArray.length(); x++) {
                                        servicesList.put(
                                                Integer.toString(servicesArray.getJSONObject(x).getInt("id")),
                                                servicesArray.getJSONObject(x).getString("name"));
                                    }
                                } else {
                                    continue;
                                }
                            }
                        } else {
                            continue;
                        }
                    }
                }
            } catch (JSONException ex) {
                ex.printStackTrace();
            }
            for (String serviceKey : servicesList.keySet()) {
                model.addElement(servicesList.get(serviceKey));
            }
            listServiceUsed.setModel(model);
        }
    });
    checkTreeManager = new CheckTreeManager(tree);

    spTreeCheckBox = new JScrollPane(tree);
    spTreeCheckBox.setPreferredSize(new Dimension(300, 300));
    g.gridx = 0;
    g.gridy = 1;
    g.gridwidth = 3;
    g.anchor = g.LINE_START;
    g.insets = new Insets(5, 5, 5, 5);
    panel.add(spTreeCheckBox, g);

    model = new DefaultListModel<>();
    model.addElement("");
    listServiceUsed = new JList<String>(model);
    spList = new JScrollPane(listServiceUsed);
    spList.setPreferredSize(new Dimension(300, 300));
    g.gridx = 4;
    g.gridy = 1;
    g.gridwidth = 3;
    g.anchor = g.LINE_START;
    panel.add(spList, g);

    return panel;
}

From source file:VASSAL.launch.ModuleManagerWindow.java

protected void buildTree() {
    recentModuleConfig = new StringArrayConfigurer("RecentModules", null);
    Prefs.getGlobalPrefs().addOption(null, recentModuleConfig);
    final List<String> missingModules = new ArrayList<String>();
    final List<ModuleInfo> moduleList = new ArrayList<ModuleInfo>();
    for (String s : recentModuleConfig.getStringArray()) {
        final ModuleInfo module = new ModuleInfo(s);
        if (module.getFile().exists() && module.isValid()) {
            moduleList.add(module);//from  w w w.  j  a v a  2s  . c om
        } else {
            missingModules.add(s);
        }
    }

    for (String s : missingModules) {
        logger.info(Resources.getString("ModuleManager.removing_module", s));
        moduleList.remove(s);
        recentModuleConfig.removeValue(s);
    }

    Collections.sort(moduleList, new Comparator<ModuleInfo>() {
        public int compare(ModuleInfo f1, ModuleInfo f2) {
            return f1.compareTo(f2);
        }
    });

    rootNode = new MyTreeNode(new RootInfo());

    for (ModuleInfo moduleInfo : moduleList) {
        final MyTreeNode moduleNode = new MyTreeNode(moduleInfo);
        for (ExtensionInfo ext : moduleInfo.getExtensions()) {
            final MyTreeNode extensionNode = new MyTreeNode(ext);
            moduleNode.add(extensionNode);
        }

        final ArrayList<File> missingFolders = new ArrayList<File>();

        for (File f : moduleInfo.getFolders()) {
            if (f.exists() && f.isDirectory()) {
                final GameFolderInfo folderInfo = new GameFolderInfo(f, moduleInfo);
                final MyTreeNode folderNode = new MyTreeNode(folderInfo);
                moduleNode.add(folderNode);
                final ArrayList<File> l = new ArrayList<File>();

                final File[] files = f.listFiles();
                if (files == null)
                    continue;

                for (File f1 : files) {
                    if (f1.isFile()) {
                        l.add(f1);
                    }
                }
                Collections.sort(l);

                for (File f2 : l) {
                    final SaveFileInfo fileInfo = new SaveFileInfo(f2, folderInfo);
                    if (fileInfo.isValid() && fileInfo.belongsToModule()) {
                        final MyTreeNode fileNode = new MyTreeNode(fileInfo);
                        folderNode.add(fileNode);
                    }
                }
            } else {
                missingFolders.add(f);
            }
        }

        for (File mf : missingFolders) {
            logger.info(Resources.getString("ModuleManager.removing_folder", mf.getPath()));
            moduleInfo.removeFolder(mf);
        }

        rootNode.add(moduleNode);
    }

    updateModuleList();

    treeModel = new MyTreeTableModel(rootNode);
    tree = new MyTree(treeModel);

    tree.setRootVisible(false);
    tree.setEditable(false);

    tree.setTreeCellRenderer(new MyTreeCellRenderer());

    tree.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                final TreePath path = tree.getPathForLocation(e.getPoint().x, e.getPoint().y);

                // do nothing if not on a node, or if this node was expanded
                // or collapsed during the past doubleClickInterval milliseconds
                if (path == null || (lastExpansionPath == path
                        && e.getWhen() - lastExpansionTime <= doubleClickInterval))
                    return;

                selectedNode = (MyTreeNode) path.getLastPathComponent();

                final int row = tree.getRowForPath(path);
                if (row < 0)
                    return;

                final AbstractInfo target = (AbstractInfo) selectedNode.getUserObject();

                // launch module or load save, otherwise expand or collapse node
                if (target instanceof ModuleInfo) {
                    final ModuleInfo modInfo = (ModuleInfo) target;
                    if (modInfo.isModuleTooNew()) {
                        ErrorDialog.show("Error.module_too_new", modInfo.getFile().getPath(),
                                modInfo.getVassalVersion(), Info.getVersion());
                        return;
                    } else {
                        ((ModuleInfo) target).play();
                    }
                } else if (target instanceof SaveFileInfo) {
                    ((SaveFileInfo) target).play();
                } else if (tree.isExpanded(row)) {
                    tree.collapseRow(row);
                } else {
                    tree.expandRow(row);
                }
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            final TreePath path = tree.getPathForLocation(e.getPoint().x, e.getPoint().y);
            if (path == null)
                return;

            selectedNode = (MyTreeNode) path.getLastPathComponent();

            if (e.isMetaDown()) {
                final int row = tree.getRowForPath(path);
                if (row >= 0) {
                    tree.clearSelection();
                    tree.addRowSelectionInterval(row, row);
                    final AbstractInfo target = (AbstractInfo) selectedNode.getUserObject();
                    target.buildPopup(row).show(tree, e.getX(), e.getY());
                }
            }
        }
    });

    // We capture the time and location of clicks which would cause
    // expansion in order to distinguish these from clicks which
    // might launch a module or game.
    tree.addTreeWillExpandListener(new TreeWillExpandListener() {
        public void treeWillCollapse(TreeExpansionEvent e) {
            lastExpansionTime = System.currentTimeMillis();
            lastExpansionPath = e.getPath();
        }

        public void treeWillExpand(TreeExpansionEvent e) {
            lastExpansionTime = System.currentTimeMillis();
            lastExpansionPath = e.getPath();
        }
    });

    // This ensures that double-clicks always start the module but
    // doesn't prevent single-clicks on the handles from working.
    tree.setToggleClickCount(3);

    tree.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    tree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent e) {
            final MyTreeNode node = (MyTreeNode) e.getPath().getLastPathComponent();
            final AbstractInfo target = node.getNodeInfo();
            if (target instanceof ModuleInfo) {
                setSelectedModule(target.getFile());
            } else {
                if (node.getParent() != null) {
                    setSelectedModule(node.getParentModuleFile());
                }
            }
        }
    });

    // FIXME: Width handling needs improvement. Also save in prefs
    tree.getColumnModel().getColumn(KEY_COLUMN).setMinWidth(250);

    tree.getColumnModel().getColumn(VERSION_COLUMN).setCellRenderer(new VersionCellRenderer());
    tree.getColumnModel().getColumn(VERSION_COLUMN).setMinWidth(100);

    tree.getColumnModel().getColumn(VASSAL_COLUMN).setCellRenderer(new VersionCellRenderer());
    tree.getColumnModel().getColumn(VASSAL_COLUMN).setMinWidth(100);

    tree.getColumnModel().getColumn(SPARE_COLUMN).setMinWidth(10);
    tree.getColumnModel().getColumn(SPARE_COLUMN).setPreferredWidth(600);

    // FIXME: How to set alignment of individual header components?
    tree.getTableHeader().setAlignmentX(JComponent.CENTER_ALIGNMENT);

}