Example usage for javax.swing.tree DefaultTreeSelectionModel DefaultTreeSelectionModel

List of usage examples for javax.swing.tree DefaultTreeSelectionModel DefaultTreeSelectionModel

Introduction

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

Prototype

public DefaultTreeSelectionModel() 

Source Link

Document

Creates a new instance of DefaultTreeSelectionModel that is empty, with a selection mode of DISCONTIGUOUS_TREE_SELECTION.

Usage

From source file:com.microsoft.alm.plugin.idea.git.ui.pullrequest.PullRequestsTreeModel.java

public PullRequestsTreeModel() {
    super(null);//  w  w  w  .j av a 2  s. co m

    this.root = new PRTreeNode(TfPluginBundle.message(TfPluginBundle.KEY_VCS_PR_TITLE));
    setRoot(root);
    this.requestedByMeRoot = new PRTreeNode(TfPluginBundle.message(TfPluginBundle.KEY_VCS_PR_REQUESTED_BY_ME));
    root.insert(requestedByMeRoot, 0);
    this.assignedToMeRoot = new PRTreeNode(TfPluginBundle.message(TfPluginBundle.KEY_VCS_PR_ASSIGNED_TO_ME));
    root.insert(assignedToMeRoot, 1);

    allRequestedByMePullRequests = new ArrayList<GitPullRequest>();
    allAssignedToMePullRequests = new ArrayList<GitPullRequest>();

    selectionModel = new DefaultTreeSelectionModel();
    selectionModel.setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
}

From source file:org.feistymeow.dragdrop.dragdrop_tree_test.java

public dragdrop_tree_test(String startPath) {
    super("dragdrop_test");

    // create the tree, configure it to show our hashtable nodes, and put it in
    // a scroll pane.
    larch = new DraggableDroppableTree(startPath);
    DefaultTreeModel treeModel = (DefaultTreeModel) larch.getModel();
    larch.setCellRenderer(new CustomCellRenderer());
    TreeSelectionModel selmod = new DefaultTreeSelectionModel();
    selmod.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    larch.setSelectionModel(selmod);//from   w  w  w.j  a va2 s  .  c om
    larch.addTreeSelectionListener(this);
    JScrollPane listScrollPane = new JScrollPane(larch);
    // get the files that live in the specified directory.
    String dirName = startPath + "/"; // make sure we think of it as a
                                      // directory.
    String filelist[] = new File(dirName).list();
    MutableTreeNode root_node = (MutableTreeNode) treeModel.getRoot();
    if (root_node == null) {
        logger.error("something is not right about tree.  has null root.");
        System.exit(1);
    }
    // load up the tree with the files in the directory they passed.
    for (int i = 0; i < filelist.length; i++) {
        String thisFileSt = dirName + filelist[i];
        File thisFile = new File(thisFileSt);
        // skip directories for now.
        if (thisFile.isDirectory())
            continue;
        // skip dot files.
        if (filelist[i].startsWith("."))
            continue;
        try {
            // need to trap exceptions from the URI/URL functions.
            DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(makeNode(thisFile.getName(),
                    thisFile.toURI().toURL().toString(), thisFile.getAbsolutePath()));
            treeModel.insertNodeInto(newNode, root_node, root_node.getChildCount());
        } catch (java.net.MalformedURLException e) {
            logger.warn("caught an exception while trying to process path: " + thisFile.getAbsolutePath());
        }
    }

    // set our status bar to have the current path info.
    fileName = new JTextField(50);
    // select the root.
    larch.setSelectionPath(larch.getPathForRow(0));

    // pop out all the nodes.
    larch.expandAll();

    // Create a panel that uses FlowLayout (the default).
    JPanel buttonPane = new JPanel();
    buttonPane.add(fileName);

    Container contentPane = getContentPane();
    contentPane.add(listScrollPane, BorderLayout.CENTER);
    contentPane.add(buttonPane, BorderLayout.NORTH);
}

From source file:org.intermine.modelviewer.swing.ModelViewer.java

/**
 * Lays out the components within this panel and wires up the relevant
 * event listeners.//  w  ww.  j av a2  s .  c  o m
 */
private void init() {

    FileFilter xmlFilter = new XmlFileFilter();
    projectFileChooser = new JFileChooser();
    projectFileChooser.addChoosableFileFilter(xmlFilter);
    projectFileChooser.setAcceptAllFileFilterUsed(false);
    projectFileChooser.setFileFilter(xmlFilter);

    File lastProjectFile = MineManagerBackingStore.getInstance().getLastProjectFile();
    if (lastProjectFile != null) {
        projectFileChooser.setSelectedFile(lastProjectFile);
    }

    initButtonPanel();

    classTreeModel = new ClassTreeModel();
    classTree = new JTree(classTreeModel);
    classTree.setCellRenderer(new ClassTreeCellRenderer());
    classTree.setRootVisible(false);
    classTree.setShowsRootHandles(true);

    Box vbox = Box.createVerticalBox();
    vbox.add(new JScrollPane(classTree));
    vbox.add(buttonPanel);

    DefaultTreeSelectionModel selectionModel = new DefaultTreeSelectionModel();
    selectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    classTree.setSelectionModel(selectionModel);

    classTree.addTreeSelectionListener(new ClassTreeSelectionListener());

    attributeTableModel = new AttributeTableModel();
    attributeTable = new AttributeTable(attributeTableModel);

    referenceTableModel = new ReferenceTableModel();
    referenceTable = new ReferenceTable(referenceTableModel);

    graphModel = new mxGraphModel();
    graph = new CustomisedMxGraph(graphModel);

    graphComponent = new mxGraphComponent(graph);
    graphComponent.setEscapeEnabled(true);

    JTabbedPane tableTab = new JTabbedPane(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
    tableTab.add(Messages.getMessage("tab.attributes"), new JScrollPane(attributeTable));
    tableTab.add(Messages.getMessage("tab.references"), new JScrollPane(referenceTable));

    JSplitPane rightSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, tableTab, graphComponent);

    JSplitPane mainSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, vbox, rightSplit);

    setOpaque(true);
    setLayout(new BorderLayout());
    add(mainSplit, BorderLayout.CENTER);

    rightSplit.setDividerLocation(150);
    mainSplit.setDividerLocation(200);

}