Example usage for javax.swing.tree TreeSelectionModel SINGLE_TREE_SELECTION

List of usage examples for javax.swing.tree TreeSelectionModel SINGLE_TREE_SELECTION

Introduction

In this page you can find the example usage for javax.swing.tree TreeSelectionModel SINGLE_TREE_SELECTION.

Prototype

int SINGLE_TREE_SELECTION

To view the source code for javax.swing.tree TreeSelectionModel SINGLE_TREE_SELECTION.

Click Source Link

Document

Selection can only contain one path at a time.

Usage

From source file:com.yosanai.java.aws.console.panel.InstancesPanel.java

/** Creates new form InstancesPanel */
public InstancesPanel() {
    initComponents();/*from  ww w . j a  v a 2 s. c o  m*/
    DefaultTreeModel treeModel = (DefaultTreeModel) trInstances.getModel();
    DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) treeModel.getRoot();
    rootNode.setAllowsChildren(true);
    rootNode.setUserObject("Instances");
    instancesTableModel = (DefaultTableModel) tblInstances.getModel();
    instanceTableModel = new ObjectEditorTableModel();
    instanceTableModel.setEditable(false);
    instanceTableModel.setExpandAllProperties(true);
    trInstances.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
}

From source file:com.edduarte.protbox.ui.windows.RestoreFileWindow.java

private RestoreFileWindow(final PReg registry) {
    super();// w w w.  jav a 2  s . c o m
    setLayout(null);

    final JTextField searchField = new JTextField();
    searchField.setLayout(null);
    searchField.setBounds(2, 2, 301, 26);
    searchField.setBorder(new LineBorder(Color.lightGray));
    searchField.setFont(Constants.FONT);
    add(searchField);

    final JLabel noBackupFilesLabel = new JLabel("<html>No backups files were found!<br><br>"
            + "<font color=\"gray\">If you think there is a problem with the<br>"
            + "backup system, please create an issue here:<br>"
            + "<a href=\"#\">https://github.com/com.edduarte/protbox/issues</a></font></html>");
    noBackupFilesLabel.setLayout(null);
    noBackupFilesLabel.setBounds(20, 50, 300, 300);
    noBackupFilesLabel.setFont(Constants.FONT.deriveFont(14f));
    noBackupFilesLabel.addMouseListener((OnMouseClick) e -> {
        String urlPath = "https://github.com/com.edduarte/protbox/issues";

        try {

            if (Desktop.isDesktopSupported()) {
                Desktop.getDesktop().browse(new URI(urlPath));

            } else {
                if (SystemUtils.IS_OS_WINDOWS) {
                    Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + urlPath);

                } else {
                    java.util.List<String> browsers = Lists.newArrayList("firefox", "opera", "safari",
                            "mozilla", "chrome");

                    for (String browser : browsers) {
                        if (Runtime.getRuntime().exec(new String[] { "which", browser }).waitFor() == 0) {

                            Runtime.getRuntime().exec(new String[] { browser, urlPath });
                            break;
                        }
                    }
                }
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    });

    DefaultMutableTreeNode rootTreeNode = registry.buildEntryTree();
    final JTree tree = new JTree(rootTreeNode);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    if (rootTreeNode.getChildCount() == 0) {
        searchField.setEnabled(false);
        add(noBackupFilesLabel);
    }
    expandTree(tree);
    tree.setLayout(null);
    tree.setRootVisible(false);
    tree.setEditable(false);
    tree.setCellRenderer(new SearchableTreeCellRenderer(searchField));
    searchField.addKeyListener((OnKeyReleased) e -> {

        // update and expand tree
        DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
        model.nodeStructureChanged((TreeNode) model.getRoot());
        expandTree(tree);
    });
    final JScrollPane scroll = new JScrollPane(tree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scroll.setBorder(new DropShadowBorder());
    scroll.setBorder(new LineBorder(Color.lightGray));
    scroll.setBounds(2, 30, 334, 360);
    add(scroll);

    JLabel close = new JLabel(new ImageIcon(Constants.getAsset("close.png")));
    close.setLayout(null);
    close.setBounds(312, 7, 18, 18);
    close.setFont(Constants.FONT);
    close.setForeground(Color.gray);
    close.addMouseListener((OnMouseClick) e -> dispose());
    add(close);

    final JLabel permanentDeleteButton = new JLabel(new ImageIcon(Constants.getAsset("permanent.png")));
    permanentDeleteButton.setLayout(null);
    permanentDeleteButton.setBounds(91, 390, 40, 39);
    permanentDeleteButton.setBackground(Color.black);
    permanentDeleteButton.setEnabled(false);
    permanentDeleteButton.addMouseListener((OnMouseClick) e -> {
        if (permanentDeleteButton.isEnabled()) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
            PbxEntry entry = (PbxEntry) node.getUserObject();

            if (JOptionPane.showConfirmDialog(null,
                    "Are you sure you wish to permanently delete '" + entry.realName()
                            + "'?\nThis file and its "
                            + "backup copies will be deleted immediately. You cannot undo this action.",
                    "Confirm Cancel", JOptionPane.YES_NO_OPTION,
                    JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) {

                registry.permanentDelete(entry);
                dispose();
                RestoreFileWindow.getInstance(registry);

            } else {
                setVisible(true);
            }
        }
    });
    add(permanentDeleteButton);

    final JLabel configBackupsButton = new JLabel(new ImageIcon(Constants.getAsset("config.png")));
    configBackupsButton.setLayout(null);
    configBackupsButton.setBounds(134, 390, 40, 39);
    configBackupsButton.setBackground(Color.black);
    configBackupsButton.setEnabled(false);
    configBackupsButton.addMouseListener((OnMouseClick) e -> {
        if (configBackupsButton.isEnabled()) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
            PbxEntry entry = (PbxEntry) node.getUserObject();
            if (entry instanceof PbxFile) {
                PbxFile pbxFile = (PbxFile) entry;

                JFrame frame = new JFrame("Choose backup policy");
                Object option = JOptionPane.showInputDialog(frame,
                        "Choose below the backup policy for this file:", "Choose backup",
                        JOptionPane.QUESTION_MESSAGE, null, PbxFile.BackupPolicy.values(),
                        pbxFile.getBackupPolicy());

                if (option == null) {
                    setVisible(true);
                    return;
                }
                PbxFile.BackupPolicy pickedPolicy = PbxFile.BackupPolicy.valueOf(option.toString());
                pbxFile.setBackupPolicy(pickedPolicy);
            }
            setVisible(true);
        }
    });
    add(configBackupsButton);

    final JLabel restoreBackupButton = new JLabel(new ImageIcon(Constants.getAsset("restore.png")));
    restoreBackupButton.setLayout(null);
    restoreBackupButton.setBounds(3, 390, 85, 39);
    restoreBackupButton.setBackground(Color.black);
    restoreBackupButton.setEnabled(false);
    restoreBackupButton.addMouseListener((OnMouseClick) e -> {
        if (restoreBackupButton.isEnabled()) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
            PbxEntry entry = (PbxEntry) node.getUserObject();
            if (entry instanceof PbxFolder) {
                registry.restoreFolderFromEntry((PbxFolder) entry);

            } else if (entry instanceof PbxFile) {
                PbxFile pbxFile = (PbxFile) entry;
                java.util.List<String> snapshots = pbxFile.snapshotsToString();
                if (snapshots.isEmpty()) {
                    setVisible(true);
                    return;
                }

                JFrame frame = new JFrame("Choose backup");
                Object option = JOptionPane.showInputDialog(frame,
                        "Choose below what backup snapshot would you like restore:", "Choose backup",
                        JOptionPane.QUESTION_MESSAGE, null, snapshots.toArray(), snapshots.get(0));

                if (option == null) {
                    setVisible(true);
                    return;
                }
                int pickedIndex = snapshots.indexOf(option.toString());
                registry.restoreFileFromEntry((PbxFile) entry, pickedIndex);
            }
            dispose();
        }
    });
    add(restoreBackupButton);

    tree.addMouseListener((OnMouseClick) e -> {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
        if (node != null) {
            PbxEntry entry = (PbxEntry) node.getUserObject();
            if ((entry instanceof PbxFolder && entry.areNativeFilesDeleted())) {
                permanentDeleteButton.setEnabled(true);
                restoreBackupButton.setEnabled(true);
                configBackupsButton.setEnabled(false);

            } else if (entry instanceof PbxFile) {
                permanentDeleteButton.setEnabled(true);
                restoreBackupButton.setEnabled(true);
                configBackupsButton.setEnabled(true);

            } else {
                permanentDeleteButton.setEnabled(false);
                restoreBackupButton.setEnabled(false);
                configBackupsButton.setEnabled(false);
            }
        }
    });

    final JLabel cancel = new JLabel(new ImageIcon(Constants.getAsset("cancel.png")));
    cancel.setLayout(null);
    cancel.setBounds(229, 390, 122, 39);
    cancel.setBackground(Color.black);
    cancel.addMouseListener((OnMouseClick) e -> dispose());
    add(cancel);

    addWindowFocusListener(new WindowFocusListener() {
        private boolean gained = false;

        @Override
        public void windowGainedFocus(WindowEvent e) {
            gained = true;
        }

        @Override
        public void windowLostFocus(WindowEvent e) {
            if (gained) {
                dispose();
            }
        }
    });

    setSize(340, 432);
    setUndecorated(true);
    getContentPane().setBackground(Color.white);
    setResizable(false);
    getRootPane().setBorder(BorderFactory.createLineBorder(new Color(100, 100, 100)));
    Utils.setComponentLocationOnCenter(this);
    setVisible(true);
}

From source file:com.mindcognition.mindraider.ui.swing.trash.TrashJPanel.java

/**
 * Constructor./*from w  w  w  .  java 2 s  . c o  m*/
 */
private TrashJPanel() {
    treeNodeToResourceUriMap = new HashMap();

    rootNode = new DefaultMutableTreeNode(Messages.getString("TrashJPanel.notebookArchive"));
    treeModel = new DefaultTreeModel(rootNode);
    treeModel.addTreeModelListener(new MyTreeModelListener());

    tree = new JTree(treeModel);
    tree.setEditable(false);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.addTreeExpansionListener(this);
    tree.addTreeWillExpandListener(this);
    tree.setShowsRootHandles(true);
    tree.putClientProperty("JTree.lineStyle", "Angled");

    // tree rendered
    // TODO implement own renderer in order to tooltips
    tree.setCellRenderer(new TrashTreeCellRenderer(IconsRegistry.getImageIcon("trashFull.png"),
            IconsRegistry.getImageIcon("explorerNotebookIcon.png")));

    setLayout(new BorderLayout());

    // control panel
    JToolBar tp = new JToolBar();
    tp.setLayout(new GridLayout(1, 6));
    undoButton = new JButton("", IconsRegistry.getImageIcon("trashUndo.png"));
    undoButton.setEnabled(false);
    undoButton.setToolTipText("Restore Outline");
    undoButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
            if (node == null) {
                return;
            }
            new RestoreNotebookJDialog((String) treeNodeToResourceUriMap.get(node), "Restore Outline",
                    "Restore", true);
        }
    });
    tp.add(undoButton);

    deleteButton = new JButton("", IconsRegistry.getImageIcon("explorerDeleteSmall.png"));
    deleteButton.setToolTipText("Delete Outline");
    deleteButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
            if (node == null) {
                return;
            }

            int result = JOptionPane.showConfirmDialog(MindRaider.mainJFrame,
                    "Do you really want to DELETE this Outline?", "Delete Outline", JOptionPane.YES_NO_OPTION);
            if (result == JOptionPane.YES_OPTION) {
                MindRaider.labelCustodian.deleteOutline((String) treeNodeToResourceUriMap.get(node));
                refresh();
                ExplorerJPanel.getInstance().refresh();
            }
        }
    });
    tp.add(deleteButton);

    emptyButton = new JButton("", IconsRegistry.getImageIcon("trashEmpty.png"));

    emptyButton.setToolTipText(Messages.getString("TrashJPanel.emptyArchive"));
    emptyButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            int result = JOptionPane.showConfirmDialog(MindRaider.mainJFrame,
                    "Do you really want to DELETE all discarded Outlines?", "Empty Trash",
                    JOptionPane.YES_NO_OPTION);
            if (result == JOptionPane.YES_OPTION) {
                final SwingWorker worker = new SwingWorker() {

                    public Object construct() {
                        ProgressDialogJFrame progressDialogJFrame = new ProgressDialogJFrame("Empty Trash",
                                "<html><br>&nbsp;&nbsp;<b>Deleting:</b>&nbsp;&nbsp;</html>");
                        try {
                            ResourceDescriptor[] resourceDescriptors = MindRaider.labelCustodian
                                    .getDiscardedOutlineDescriptors();
                            if (resourceDescriptors != null) {
                                for (int i = 0; i < resourceDescriptors.length; i++) {
                                    MindRaider.labelCustodian.deleteOutline(resourceDescriptors[i].getUri());
                                }
                                refresh();
                            }
                        } finally {
                            if (progressDialogJFrame != null) {
                                progressDialogJFrame.dispose();
                            }
                        }
                        return null;
                    }
                };
                worker.start();
            }
        }
    });
    tp.add(emptyButton);

    add(tp, BorderLayout.NORTH);

    // add the tree
    JScrollPane scrollPane = new JScrollPane(tree);
    add(scrollPane);
    // build the whole tree
    buildTree();
    // click handler
    tree.addTreeSelectionListener(new TreeSelectionListener() {

        public void valueChanged(TreeSelectionEvent e) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
            if (node == null) {
                return;
            }
            logger.debug("Tree selection path: " + node.getPath()[node.getLevel()]);

            enableDisableToolbarButtons(node.getLevel());
        }
    });
}

From source file:ldap.LdapClient.java

public LdapClient() throws Exception {
    try {//from w  w w.ja  v  a 2  s  .  co m
        resources = ResourceBundle.getBundle("ldap/LdapClient", SessionManager.getSession().getLocale());
    } catch (MissingResourceException e) {
        throw new ServletException("resource bundle not found", e);
    }

    frame = new SFrame("LDAP Client");

    SContainer contentPane = frame.getContentPane();
    tabbedPane = new STabbedPane();
    contentPane.setLayout(null);

    settingsForm = new SForm(new SGridLayout(2));
    tabbedPane.add(settingsForm, resources.getString("provider"));

    urlTextField = new STextField();
    urlTextField.setColumns(columns);
    urlTextField.setText((String) SessionManager.getSession().getProperty("java.naming.provider.url"));
    settingsForm.add(new SLabel(resources.getString("provider.url")));
    settingsForm.add(urlTextField);

    basednTextField = new STextField();
    basednTextField.setColumns(columns);
    basednTextField.setText((String) SessionManager.getSession().getProperty("java.naming.provider.basedn"));
    settingsForm.add(new SLabel(resources.getString("provider.basedn")));
    settingsForm.add(basednTextField);

    binddnTextField = new STextField();
    binddnTextField.setColumns(columns);
    binddnTextField.setText((String) SessionManager.getSession().getProperty("java.naming.security.principal"));
    settingsForm.add(new SLabel(resources.getString("provider.binddn")));
    settingsForm.add(binddnTextField);

    passwordTextField = new SPasswordField();
    passwordTextField.setColumns(columns);
    passwordTextField
            .setText((String) SessionManager.getSession().getProperty("java.naming.security.credentials"));
    settingsForm.add(new SLabel(resources.getString("provider.password")));
    settingsForm.add(passwordTextField);

    connectButton = new SButton(resources.getString("provider.connect"));
    disconnectButton = new SButton(resources.getString("provider.disconnect"));
    disconnectButton.setVisible(false);
    settingsForm.add(connectButton);
    settingsForm.add(disconnectButton);

    mainPanel = new SPanel();

    try {
        mainPanel.setLayout(new STemplateLayout(getClass().getResource("ldapclientlayout.html")));
    } catch (Exception e) {
        logger.warn("no template", e);
        mainPanel.setLayout(new SFlowLayout());
    }

    tabbedPane.add(mainPanel, resources.getString("browser"));

    createTreeModel(null);
    tree = new STree(treeModel);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.addTreeSelectionListener(this);

    SessionManager.getSession().setProperty("tree", tree);

    editPanel = new EditObjectPanel();
    mainPanel.add(tree, "tree");
    mainPanel.add(editPanel, "editor");

    addPanel = new AddObjectPanel();
    tabbedPane.add(addPanel, resources.getString("add"));

    contentPane.add(tabbedPane);

    connectButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            Session session = SessionManager.getSession();

            String url = urlTextField.getText();
            if (url != null && url.length() > 0)
                session.setProperty("java.naming.provider.url", url);

            String basedn = basednTextField.getText();
            if (basedn != null && basedn.length() > 0)
                session.setProperty("java.naming.provider.basedn", basedn);

            String binddn = binddnTextField.getText();
            if (binddn != null && binddn.length() > 0)
                session.setProperty("java.naming.security.principal", binddn);

            String password = passwordTextField.getText();
            if (password != null && password.length() > 0)
                session.setProperty("java.naming.security.credentials", password);

            try {
                context = new InitialDirContext(new Hashtable(session.getProperties()));
                createTreeModel(context);
                tree.setModel(treeModel);
                tabbedPane.setSelectedIndex(1);

                urlTextField.setVisible(true);
                basednTextField.setVisible(true);
                binddnTextField.setVisible(true);
                passwordTextField.setVisible(true);

                connectButton.setVisible(true);
                disconnectButton.setVisible(false);
                passwordTextField.setText(null);
            } catch (NamingException e) {
                passwordTextField.setText(null);
                logger.warn("no initial context", e);
            }
        }
    });

    disconnectButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            createTreeModel(null);
            tree.setModel(treeModel);

            urlTextField.setVisible(false);
            basednTextField.setVisible(false);
            binddnTextField.setVisible(false);
            passwordTextField.setVisible(false);

            connectButton.setVisible(false);
            disconnectButton.setVisible(true);
            passwordTextField.setText(null);
        }
    });

    frame.show();
}

From source file:com.qspin.qtaste.ui.TestCaseTree.java

public TestCaseTree(TestCasePane testCasePn) {
    super();//w  w w.  jav  a  2s . c o m
    mTestCaseTree = this;
    this.setCellRenderer(new TestCaseTreeCellRenderer());

    testCasePane = testCasePn;
    testCasePane.setTestCaseTree(this);
    ToolTipManager.sharedInstance().registerComponent(this);

    FileNode rootFileNode = createRootFileNode();

    TCTreeNode rootNode = new TCTreeNode(rootFileNode, true);
    DefaultTreeModel tm = new DefaultTreeModel(rootNode);
    setModel(tm);
    generateScriptsTree(rootFileNode);
    TCTreeListener listener = new TCTreeListener();
    this.addMouseListener(listener);
    addTreeWillExpandListener(listener);
    addTreeSelectionListener(listener);
    TreeSelectionModel selModel = this.getSelectionModel();
    selModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    // drag drop initialization
    ds = new DragSource();
    dt = new DropTarget();

    ds.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY, this);
    try {
        dt.setComponent(this);
        dt.addDropTargetListener(this);
    } catch (java.util.TooManyListenersException e) {
        logger.error(e.getMessage());
    }

}

From source file:de.codesourcery.eve.skills.ui.components.impl.ItemChooserComponent.java

@Override
protected JPanel createPanelHook() {

    tree.setRootVisible(false);//w w  w .j a v a  2s. c om
    tree.setCellRenderer(treeRenderer);

    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    tree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() != 2 || e.isPopupTrigger()) {
                return;
            }

            final TreePath path = tree.getClosestPathForLocation(e.getX(), e.getY());
            final ITreeNode node = (ITreeNode) path.getLastPathComponent();

            if (node.getValue() instanceof InventoryType) {
                final InventoryType selectedItem = (InventoryType) node.getValue();
                selectedItemsModel.addItem(selectedItem);
                if (selectionMode == SelectionMode.SINGLE_SELECTION) {
                    okButtonClicked();
                } else if (selectionMode == SelectionMode.MULTIPLE_SELECTION) {
                    // ok
                } else {
                    throw new RuntimeException("Unhandled mode " + selectionMode);
                }
            }
        }
    });

    tree.addTreeWillExpandListener(new TreeWillExpandListener() {

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

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

    final JScrollPane pane = new JScrollPane(tree);
    pane.setPreferredSize(new Dimension(400, 400));

    final JPanel result = new JPanel();
    result.setLayout(new GridBagLayout());

    switch (selectionMode) {
    case SINGLE_SELECTION:
        result.add(pane, constraints().useRemainingSpace().resizeBoth().end());
        break;
    case MULTIPLE_SELECTION:
        result.add(pane, constraints(0, 0).useRelativeWidth().resizeBoth().end());
        result.add(createListViewPanel(), constraints(1, 0).useRemainingWidth().resizeBoth().end());
        break;
    default:
        throw new RuntimeException("Unhandled selection mode" + selectionMode);
    }

    return result;
}

From source file:com.moss.bdbadmin.client.ui.BdbAdminClient.java

public BdbAdminClient(HttpClient httpClient, JFrame window, File configPath, ProxyFactory proxyFactory) {

    this.httpClient = httpClient;
    this.ancestor = window;
    this.configPath = configPath;
    this.proxyFactory = proxyFactory;

    try {//from  www . j ava2  s.c om
        configJaxbContext = JAXBContext.newInstance(ServiceConfig.class);
    } catch (JAXBException ex) {
        throw new RuntimeException(ex);
    }

    JMenuItem newServiceItem = new JMenuItem("New Service");
    newServiceItem.setAction(new NewServiceAction());

    JMenu fileMenu = new JMenu("File");
    fileMenu.add(newServiceItem);

    JMenuBar menuBar = new JMenuBar();
    menuBar.add(fileMenu);

    window.setJMenuBar(menuBar);
    window.setIconImage(new ImageIcon(this.getClass().getClassLoader().getResource("service.gif")).getImage());

    this.root = new DefaultMutableTreeNode();
    this.model = new DefaultTreeModel(root);
    getTree().setModel(model);
    getTree().setShowsRootHandles(true);
    getTree().setRootVisible(false);
    getTree().setCellRenderer(new Renderer());
    getTree().getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    getTree().getSelectionModel().addTreeSelectionListener(new SelectionListener());
    getTree().addMouseListener(new ContextMenuHandler());

    addAncestorListener(new AncestorListener() {
        public void ancestorAdded(AncestorEvent event) {
            loadConfig();
        }

        public void ancestorMoved(AncestorEvent event) {
        }

        public void ancestorRemoved(AncestorEvent event) {
        }
    });
}

From source file:mobac.gui.components.JMapSourceTree.java

public JMapSourceTree(Vector<MapSource> enabledOrderedMapSources) {
    super();//  www. j av  a  2  s  .c  o m
    // Setting a cell renderer which will provide proper icons behavior
    setCellRenderer(new CustomIconRenderer());
    initialize(enabledOrderedMapSources);
    setRootVisible(false);
    getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    setExpandsSelectedPaths(true);
    setToggleClickCount(1);
    setToolTipText(I18nUtils.localizedStringForKey("lp_map_source_tree_tips"));
}

From source file:hr.fer.zemris.vhdllab.view.explorer.ProjectExplorerView.java

@Override
protected JComponent createControl() {
    CommandManager commandManager = getActiveWindow().getCommandManager();
    commandManager.createCommandGroup("hierarchyMenu", new String[] { hierarchyXUsesYCommand.getId(),
            hierarchyXUsedByYCommand.getId(), hierarchyFlatCommand.getId() });
    CommandGroup commandGroup = commandManager.createCommandGroup("treePopupMenu",
            new String[] { "newMenu", "separator", openCommand.getId(), "separator", compileCommand.getId(),
                    simulateCommand.getId(), viewVhdlCommand.getId(), "separator", deleteCommand.getId(),
                    "separator", "hierarchyMenu" });
    popupMenu = commandGroup.createPopupMenu();

    root = new DefaultMutableTreeNode("vhdllab-root");
    model = new DefaultTreeModel(root);
    model.addTreeModelListener(new TreeModelAdapter() {
        @Override//from w w w  . j  a  v a2 s.co m
        public void treeNodesInserted(TreeModelEvent e) {
            Object[] children = e.getChildren();
            if (children.length > 0) {
                Object child = children[children.length - 1];
                TreePath path = e.getTreePath().pathByAddingChild(child);
                tree.setSelectionPath(path);
            }
        }
    });
    tree = new JTree(model);
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    // tree is expanded manually in OpenFileOrShowPopupMenuListener
    tree.setToggleClickCount(0);
    tree.setCellRenderer(new WorkspaceCellRenderer());
    tree.addMouseListener(new OpenFileOrShowPopupMenuListener());
    tree.addTreeSelectionListener(new CommandGuard());
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    JPanel hierarchyPanel = new JPanel();
    hierarchyPanel.add(createHierarchyButton(hierarchyXUsesYCommand));
    hierarchyPanel.add(createHierarchyButton(hierarchyXUsedByYCommand));
    hierarchyPanel.add(createHierarchyButton(hierarchyFlatCommand));
    JPanel borderHierarchyPanel = new JPanel(new BorderLayout());
    borderHierarchyPanel.add(hierarchyPanel, BorderLayout.WEST);

    JPanel control = new JPanel(new BorderLayout());
    control.add(borderHierarchyPanel, BorderLayout.NORTH);
    control.add(new JScrollPane(tree), BorderLayout.CENTER);

    return control;
}

From source file:e3fraud.gui.MainWindow.java

public MainWindow() {
    super(new BorderLayout(5, 5));

    extended = false;/*ww  w  .ja  v  a  2s.  co m*/

    //Create the log first, because the action listeners
    //need to refer to it.
    log = new JTextArea(10, 50);
    log.setMargin(new Insets(5, 5, 5, 5));
    log.setEditable(false);
    logScrollPane = new JScrollPane(log);
    DefaultCaret caret = (DefaultCaret) log.getCaret();
    caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

    //        create the progress bar
    progressBar = new JProgressBar(0, 100);
    progressBar.setValue(progressBar.getMinimum());
    progressBar.setVisible(false);
    progressBar.setStringPainted(true);
    //Create the settings pane
    generationSettingLabel = new JLabel("Generate:");
    SpinnerModel collusionsSpinnerModel = new SpinnerNumberModel(1, 0, 3, 1);
    collusionSettingsPanel = new JPanel(new FlowLayout()) {
        @Override
        public Dimension getMaximumSize() {
            return getPreferredSize();
        }
    };
    // collusionSettingsPanel.setLayout(new BoxLayout(collusionSettingsPanel, BoxLayout.X_AXIS));
    collusionsButton = new JSpinner(collusionsSpinnerModel);
    collusionsLabel = new JLabel("collusion(s)");
    collusionSettingsPanel.add(collusionsButton);
    collusionSettingsPanel.add(collusionsLabel);

    rankingSettingLabel = new JLabel("Rank by:");
    lossButton = new JRadioButton("loss");
    lossButton.setToolTipText("Sort sub-ideal models based on loss for Target of Assessment (high -> low)");
    gainButton = new JRadioButton("gain");
    gainButton.setToolTipText(
            "Sort sub-ideal models based on gain of any actor except Target of Assessment (high -> low)");
    lossGainButton = new JRadioButton("loss + gain");
    lossGainButton.setToolTipText(
            "Sort sub-ideal models based on loss for Target of Assessment and, if equal, on gain of any actor except Target of Assessment");
    //gainLossButton = new JRadioButton("gain + loss");
    lossGainButton.setSelected(true);
    rankingGroup = new ButtonGroup();
    rankingGroup.add(lossButton);
    rankingGroup.add(gainButton);
    rankingGroup.add(lossGainButton);
    //rankingGroup.add(gainLossButton);
    groupingSettingLabel = new JLabel("Group by:");
    groupingButton = new JCheckBox("collusion");
    groupingButton.setToolTipText(
            "Groups sub-ideal models based on the pair of actors colluding before ranking them");
    groupingButton.setSelected(false);
    refreshButton = new JButton("Refresh");
    refreshButton.addActionListener(this);

    settingsPanel = new JPanel();
    settingsPanel.setLayout(new BoxLayout(settingsPanel, BoxLayout.PAGE_AXIS));
    settingsPanel.add(Box.createRigidArea(new Dimension(0, 5)));
    settingsPanel.add(generationSettingLabel);
    collusionSettingsPanel.setAlignmentX(LEFT_ALIGNMENT);
    settingsPanel.add(Box.createRigidArea(new Dimension(0, 5)));
    settingsPanel.add(collusionSettingsPanel);
    settingsPanel.add(Box.createRigidArea(new Dimension(0, 5)));
    rankingSettingLabel.setAlignmentY(TOP_ALIGNMENT);
    settingsPanel.add(rankingSettingLabel);
    settingsPanel.add(lossButton);
    settingsPanel.add(gainButton);
    settingsPanel.add(lossGainButton);
    //settingsPanel.add(gainLossButton);
    settingsPanel.add(Box.createRigidArea(new Dimension(0, 5)));
    settingsPanel.add(groupingSettingLabel);
    settingsPanel.add(groupingButton);
    settingsPanel.add(Box.createRigidArea(new Dimension(0, 5)));
    settingsPanel.add(refreshButton);
    settingsPanel.add(Box.createRigidArea(new Dimension(0, 20)));
    progressBar.setPreferredSize(
            new Dimension(settingsPanel.getSize().width, progressBar.getPreferredSize().height));
    settingsPanel.add(progressBar);

    //Create the result tree
    root = new DefaultMutableTreeNode("No models to display");
    treeModel = new DefaultTreeModel(root);
    tree = new JTree(treeModel);
    //tree.setUI(new CustomTreeUI());
    tree.setCellRenderer(new CustomTreeCellRenderer(tree));
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setLargeModel(true);
    resultScrollPane = new JScrollPane(tree);
    tree.addTreeSelectionListener(treeSelectionListener);

    //tree.setShowsRootHandles(true);
    //Create a file chooser for saving
    sfc = new JFileChooser();
    FileFilter jpegFilter = new FileNameExtensionFilter("JPEG image", new String[] { "jpg", "jpeg" });
    sfc.addChoosableFileFilter(jpegFilter);
    sfc.setFileFilter(jpegFilter);

    //Create a file chooser for loading
    fc = new JFileChooser();
    FileFilter rdfFilter = new FileNameExtensionFilter("RDF file", "RDF");
    fc.addChoosableFileFilter(rdfFilter);
    fc.setFileFilter(rdfFilter);

    //Create the open button.  
    openButton = new JButton("Load model", createImageIcon("images/Open24.png"));
    openButton.addActionListener(this);
    openButton.setToolTipText("Load a e3value model");

    //Create the ideal graph button. 
    idealGraphButton = new JButton("Show ideal graph", createImageIcon("images/Plot.png"));
    idealGraphButton.setToolTipText("Display ideal profitability graph");
    idealGraphButton.addActionListener(this);

    Dimension thinButtonDimension = new Dimension(15, 420);

    //Create the expand subideal graph button. 
    expandButton = new JButton(">");
    expandButton.setPreferredSize(thinButtonDimension);
    expandButton.setMargin(new Insets(0, 0, 0, 0));
    expandButton.setToolTipText("Expand to show non-ideal profitability graph for selected model");
    expandButton.addActionListener(this);

    //Create the collapse sub-ideal graph button. 
    collapseButton = new JButton("<");
    collapseButton.setPreferredSize(thinButtonDimension);
    collapseButton.setMargin(new Insets(0, 0, 0, 0));
    collapseButton.setToolTipText("Collapse non-ideal profitability graph for selected model");
    collapseButton.addActionListener(this);

    //Create the generation button. 
    generateButton = new JButton("Generate sub-ideal models", createImageIcon("images/generate.png"));
    generateButton.addActionListener(this);
    generateButton.setToolTipText("Generate sub-ideal models for the e3value model currently loaded");

    //Create the chart panel
    chartPane = new JPanel();
    chartPane.setLayout(new FlowLayout(FlowLayout.LEFT));
    chartPane.add(expandButton);

    //For layout purposes, put the buttons in a separate panel
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    buttonPanel.add(openButton);
    buttonPanel.add(Box.createRigidArea(new Dimension(20, 0)));
    buttonPanel.add(generateButton);
    buttonPanel.add(Box.createRigidArea(new Dimension(10, 0)));
    buttonPanel.add(idealGraphButton);

    //Add the buttons, the ranking options, the result list and the log to this panel.
    add(buttonPanel, BorderLayout.PAGE_START);
    add(settingsPanel, BorderLayout.LINE_START);
    add(resultScrollPane, BorderLayout.CENTER);

    add(logScrollPane, BorderLayout.PAGE_END);
    add(chartPane, BorderLayout.LINE_END);
    //and make a nice border around it
    setBorder(BorderFactory.createEmptyBorder(5, 10, 10, 10));
}