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:org.zaproxy.zap.view.NodeSelectDialog.java

private JTree getTreeSite() {
    if (treeSite == null) {
        this.siteTree = this.emptySiteTree();
        treeSite = new JTree(this.siteTree);
        treeSite.setShowsRootHandles(true);
        treeSite.setName("nodeSelectTree");
        treeSite.setToggleClickCount(1);
        treeSite.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
        treeSite.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {

            @Override/*  w  w  w.  j a va 2 s .  c om*/
            public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
                SiteNode node = (SiteNode) treeSite.getLastSelectedPathComponent();
                getSelectButton().setEnabled(node != null && (node.getParent() != null || allowRoot));
            }
        });
        treeSite.addMouseListener(new java.awt.event.MouseAdapter() {
            @Override
            public void mousePressed(java.awt.event.MouseEvent e) {
            }

            @Override
            public void mouseReleased(java.awt.event.MouseEvent e) {
                mouseClicked(e);
            }

            @Override
            public void mouseClicked(java.awt.event.MouseEvent e) {
                // right mouse button action
                if (treeSite.getLastSelectedPathComponent() != null) {
                    // They selected a site node, deselect any context
                    getTreeContext().clearSelection();
                }
                if (e.getClickCount() > 1) {
                    // Its a double click - close the dialog to select this node
                    nodeSelected();
                }
            }
        });

        treeSite.setCellRenderer(new SiteMapTreeCellRenderer(new ArrayList<SiteMapListener>()));
    }
    return treeSite;
}

From source file:org.zaproxy.zap.view.NodeSelectDialog.java

private JTree getTreeContext() {
    if (treeContext == null) {
        this.contextTree = this.emptyContextTree();
        treeContext = new JTree(this.contextTree);
        treeContext.setShowsRootHandles(true);
        treeContext.setName("nodeContextTree");
        treeContext.setToggleClickCount(1);
        treeContext.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
        treeContext.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {

            @Override/*w  ww . j  a  v  a  2s  .  c  o  m*/
            public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
                SiteNode node = (SiteNode) treeContext.getLastSelectedPathComponent();
                getSelectButton().setEnabled(node != null && (node.getParent() != null || allowRoot));
            }
        });
        treeContext.addMouseListener(new java.awt.event.MouseAdapter() {
            @Override
            public void mousePressed(java.awt.event.MouseEvent e) {
            }

            @Override
            public void mouseReleased(java.awt.event.MouseEvent e) {
                mouseClicked(e);
            }

            @Override
            public void mouseClicked(java.awt.event.MouseEvent e) {
                // right mouse button action
                if (treeContext.getLastSelectedPathComponent() != null) {
                    // They selected a context node, deselect any site node
                    getTreeSite().clearSelection();
                }
                if (e.getClickCount() > 1) {
                    // Its a double click - close the dialog to select this node
                    contextSelected();
                }
            }
        });

        treeContext.setCellRenderer(new ContextsTreeCellRenderer());
    }
    return treeContext;
}

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

private void initTree() {
    dataDir.listFiles();/*from w w  w  . ja v a  2 s  .c o  m*/
    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:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java

/** Creates new form MainWindow */
private MainWindow() {
    this.ranges = new ArrayList<javax.swing.JCheckBox>();
    List<String> names = null;
    try {//w  w  w.j  av a  2s .c o  m
        names = PluginController4user.getInstance().getPluginNames();
        for (String name : names) {
            JCheckBox newJCB = new JCheckBox(name);
            if (PluginController4user.getInstance().isLocalPlugin(name)) {
                newJCB.setSelected(true);
            }
            this.ranges.add(newJCB);
        }
    } catch (RemoteException ex) {
        Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
    }

    initComponents();

    javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
    jPanel6.setLayout(jPanel6Layout);
    SequentialGroup groupBoxesH = jPanel6Layout.createSequentialGroup().addComponent(jLabel2);
    ParallelGroup groupBoxesV = jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
            .addComponent(jLabel2);

    for (JCheckBox cbox : this.ranges) {
        groupBoxesH.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(cbox);
        groupBoxesV.addComponent(cbox);
    }

    Group groupH = jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(groupBoxesH.addContainerGap(10, Short.MAX_VALUE));

    Group groupV = jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
            jPanel6Layout.createSequentialGroup().addGroup(groupBoxesV).addContainerGap(5, Short.MAX_VALUE));

    jPanel6Layout.setHorizontalGroup(groupH);
    jPanel6Layout.setVerticalGroup(groupV);

    Image image = Toolkit.getDefaultToolkit()
            .getImage(Main.class.getResource("/pt/ua/dicoogle/gfx/trayicon.gif"));
    this.setIconImage(image);

    clientCore = ClientCore.getInstance();

    if (!clientCore.isAdmin()) {
        jMenu10.setVisible(false);
        jMenuItemShutdown.setVisible(false);
        jMenuDirScan2.setVisible(false);

        //jPanel8.setVisible(false);
        jButtonServices.setVisible(false);
        jButtonPreferences.setVisible(false);
        jButtonLogs.setVisible(false);
    }

    if (!clientCore.isUser()) {
        jPanel5.setVisible(false);
        jButtonClientPreferences.setVisible(false);
    } else {
        searchTree = Result2Tree.getInstance();
    }

    if (Main.isFixedClient()) {
        jMenuItemShutdown.setVisible(false);

    } else {
        jMenuItem7.setVisible(false);
    }

    jLabelResults.setText("Enter your terms and hit the button.");
    SelectDefaultSearch.setSelected(true);
    SelectAdvancedSearch.setSelected(false);
    jPanel2.setVisible(false);
    ModalSelectNone.setSelected(false);
    ModalSelectAll.setSelected(true);
    ModalCR.setSelected(true);
    ModalCT.setSelected(true);
    ModalDX.setSelected(true);
    ModalES.setSelected(true);
    ModalMG.setSelected(true);
    ModalMR.setSelected(true);
    ModalNM.setSelected(true);
    ModalOT.setSelected(true);
    ModalPT.setSelected(true);
    ModalRF.setSelected(true);
    ModalSC.setSelected(true);
    ModalUS.setSelected(true);
    ModalXA.setSelected(true);

    StudyDateRangeInitialBoundary.setEnabled(false);
    StudyDateRangeTerminalBoundary.setEnabled(false);
    DateRange.setSelected(false);
    ExactDate.setSelected(true);

    StudyDateRangeInitialBoundaryActivation.setEnabled(false);
    StudyDateRangeTerminalBoundaryActivation.setEnabled(false);
    StudyDateRangeInitialBoundary.setEnabled(false);
    StudyDateRangeTerminalBoundary.setEnabled(false);

    //tree view init
    jTreeResults.setModel(new DefaultTreeModel(Result2Tree.getInstance().getTop()));
    jTreeResults.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    jButtonDownload.setEnabled(false);
    jButtonView.setEnabled(false);
    jButtonDump.setEnabled(false);
    this.resizeWindow();
    registerForMacOSXEvents();
    centerWindow();

    //////////////////////////////////////////////////////////////
    /**
     * This search is needed to autocomplete
     */
    /*
    QueryResults q = new QueryResults("*:*");
            
            
    List<String> items = q.getFields();
            
            
            
    boolean strictMatching = false;
    AutoCompleteDecorator.decorate(jTextFieldQuery, items, strictMatching);
     *
     */

}

From source file:qic.ui.EditorPanel.java

private void setupFileTree() {
    TreeModel model = new FileTreeModel(new File("."));
    fileTree = new JTree(model);
    fileTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    fileTree.addTreeSelectionListener(tse -> {
        File file = (File) fileTree.getLastSelectedPathComponent();
        if (isFileEditable(file)) {
            saveCurrentScriptToFile();/* w w w.  j a  v a2  s . c om*/
            currentScript = file;
            loadFileToTextArea(file);
        }
    });
    fileTree.setSelectionRow(0);
    add(new JScrollPane(fileTree), BorderLayout.EAST);
}

From source file:qic.ui.ScriptsPanel.java

private void setupFileTree() {
    TreeModel model = new FileTreeModel(new File("script"));
    fileTree = new JTree(model);
    fileTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    fileTree.addTreeSelectionListener(tse -> {
        File file = (File) fileTree.getLastSelectedPathComponent();
        if (isFileEditable(file)) {
            saveCurrentScriptToFile();/* w  w w  .j  a v  a2  s . c o m*/
            currentScript = file;
            loadFileToTextArea(file);
        }
    });
    fileTree.setSelectionRow(fileTree.getRowCount() > 3 ? 3 : 1);
    add(new JScrollPane(fileTree), BorderLayout.EAST);
}

From source file:qic.ui.TermsPanel.java

private void setupFileTree() {
    TreeModel model = new FileTreeModel(new File("terms"));
    fileTree = new JTree(model);
    fileTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    fileTree.addTreeSelectionListener(tse -> {
        File file = (File) fileTree.getLastSelectedPathComponent();
        if (isFileEditable(file)) {
            saveCurrentScriptToFile();/*  w  w  w .j  a v  a  2 s  .  co m*/
            currentScript = file;
            loadFileToTextArea(file);
        }
    });
    fileTree.setSelectionRow(1);
    add(new JScrollPane(fileTree), BorderLayout.EAST);
}

From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java

/**
 * Constructor/*from  w w  w  . j a  v a 2s. c  o  m*/
 *
 * @param typeRoot            is used to create the tree starting from a specific type node
 * @param registerDoubleClick register mouse double click on tree
 */
public DBBrowserTree(byte typeRoot, boolean registerDoubleClick) {
    super();
    this.typeRoot = typeRoot;
    populateTree(typeRoot);

    setCellRenderer(new DBBrowserTreeRenderer());
    getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    setRolloverEnabled(true);
    addHighlighter(new ColorHighlighter(HighlightPredicate.ROLLOVER_ROW, null, Color.RED));

    DragGestureRecognizer dgr = DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(this,
            DnDConstants.ACTION_COPY_OR_MOVE, new DBBrowserTreeDragGestureListener());

    DBBrowserTreeDropListener dropListener = new DBBrowserTreeDropListener();
    addTreeSelectionListener(dropListener);
    setDropTarget(new DropTarget(this, dropListener));

    if (registerDoubleClick) {
        addMouseDoubleClickListener();
    }

    instance = this;

    // single data source autoconnect
    DataSourceManager manager = DefaultDataSourceManager.getInstance();
    List<DataSource> sources = manager.getDataSources();
    if (sources.size() == 1) {
        if (Globals.singleSourceAutoConnect()) {
            DataSource ds = manager.getConnectedDataSource();
            if (ds == null) {
                connectToDataSource(sources.get(0).getName());
            }
        }
    } else {
        String dataSourceName = Globals.getSystemDataSource();
        DataSource ds = manager.getDataSource(dataSourceName);
        if (ds != null) {
            connectToDataSource(dataSourceName);
        }
    }
}

From source file:ro.nextreports.designer.wizpublish.JcrBrowserTree.java

public JcrBrowserTree(final byte typeRoot, WebServiceClient client) {
    super();/*w ww.  java2  s.  c o  m*/
    this.client = client;
    populateTree(typeRoot);

    setCellRenderer(new JcrBrowserTreeRenderer());
    getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    instance = this;

    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            job(e, true);
        }

        public void mouseReleased(MouseEvent e) {
            job(e, false);
        }

        private void job(MouseEvent e, boolean pressed) {
            if (e.isPopupTrigger()) {
                final TreePath selPath = getPathForLocation(e.getX(), e.getY());
                if (selPath == null) {
                    return;
                }
                setSelectionPath(selPath);
                try {
                    final DBBrowserNode selectedNode = (DBBrowserNode) selPath.getLastPathComponent();
                    if (selectedNode != null) {

                        JPopupMenu popupMenu = new JPopupMenu();
                        boolean show = false;
                        if ((selectedNode.getDBObject().getType() == DBObject.FOLDER_REPORT)
                                || (selectedNode.getDBObject().getType() == DBObject.DATABASE)
                                || (selectedNode.getDBObject().getType() == DBObject.REPORTS_GROUP)
                                || (selectedNode.getDBObject().getType() == DBObject.CHARTS_GROUP)) {
                            JMenuItem menuItem = new JMenuItem(new PublishFolderAction(selectedNode));
                            popupMenu.add(menuItem);
                            show = true;
                        }

                        if ((typeRoot == DBObject.DATABASE)
                                && ((selectedNode.getDBObject().getType() == DBObject.FOLDER_REPORT)
                                        || (selectedNode.getDBObject().getType() == DBObject.DATABASE))) {
                            PublishDataSourceAction publishDSAction = new PublishDataSourceAction(selectedNode);

                            JMenuItem menuItem2 = new JMenuItem(publishDSAction);
                            popupMenu.add(menuItem2);
                            show = true;
                        }
                        if (show) {
                            popupMenu.show((Component) e.getSource(), e.getX(), e.getY());
                        }
                    }
                } catch (Exception ex) {
                    Show.error(ex);
                }
            }
        }
    });

}

From source file:studio.ui.Studio.java

private void createConnectionsTree() {
    if (treeConnections == null) {
        treeConnections = new KdbServicesTree(tabEditors);
        tools.setConnectionsView((KdbServicesTree) treeConnections);
        tabEditors.addFireDataListener((DataListener) treeConnections);
    }/*  ww  w  .  j  a va  2  s.  c o  m*/
    DefaultMutableTreeNode top = null;
    if (!(treeConnections.getModel() instanceof DefaultMutableTreeNode)) {
        top = new DefaultMutableTreeNode("KDB+ servers");
        treeConnections.setModel(new KdbServicesTreeModel(top));
        treeConnections.setCellRenderer(new KdbServicesTreeCellRender());

        Collection<String> hostnames = studioConfig.getHosts();
        if (hostnames != null && !hostnames.isEmpty()) {
            for (String hostname : hostnames) {
                try {
                    InetAddress.getAllByName(hostname);
                    top.add(new HostTreeNode(hostname, studioConfig.getConnections(hostname)));
                } catch (UnknownHostException ignored) {
                }
            }
        }
    }
    treeConnections.expandPath(new TreePath(top));
    treeConnections.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
}