下面列出了怎么用javax.swing.tree.DefaultTreeSelectionModel的API类实例代码及写法,或者点击链接到github查看源代码。
public PullRequestsTreeModel() {
super(null);
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);
}
private void setup() {
root = new JPanel(new BorderLayout());
JScrollPane scroll = new JBScrollPane();
root.add(scroll, BorderLayout.CENTER);
connectionTree = new Tree();
scroll.setViewportView(connectionTree);
connectionTree.getEmptyText().setText(P4Bundle.getString("connection.tree.initial"));
connectionTree.setEditable(false);
connectionTreeModel = new DefaultTreeModel(treeNode);
connectionTree.setModel(connectionTreeModel);
connectionTree.setCellRenderer(new ConnectionTreeCellRenderer());
connectionTree.setRootVisible(false);
DefaultTreeSelectionModel selectionModel = new DefaultTreeSelectionModel();
selectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
connectionTree.setSelectionModel(selectionModel);
ActionGroup actionButtons = createActionGroup();
ActionToolbar toolbar =
ActionManager.getInstance().createActionToolbar("p4.active-connection",
actionButtons, false);
root.add(toolbar.getComponent(), BorderLayout.WEST);
// TODO add context menu support for each selected node type.
// TODO add support for navigating to a file if a FilePath is selected.
}
/**
* Creates the JTree for the report configuration.
*
* @return the tree component.
* @throws ConfigTreeModelException if the model could not be built.
*/
private JComponent createEntryTree( final boolean includeGlobals ) {
treeModel = new ConfigTreeModel( packageManager, includeGlobals );
final TreeSelectionModel selectionModel = new DefaultTreeSelectionModel();
selectionModel.setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION );
tree = new JTree( treeModel );
tree.setSelectionModel( selectionModel );
tree.setCellRenderer( new ConfigTreeRenderer() );
tree.setRootVisible( false );
tree.setShowsRootHandles( true );
tree.addTreeSelectionListener( new ModuleTreeSelectionHandler() );
return new JScrollPane
( tree, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER );
}
protected void init() {
setTitle( EditorExpressionsMessages.getString( "ExpressionChooserDialog.Title" ) );
setModal( true );
final DefaultTreeSelectionModel selectionModel = new DefaultTreeSelectionModel();
selectionModel.setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION );
selectionModel.addTreeSelectionListener( new ExpressionSelectionHandler() );
expressionsTree = new JTree( ExpressionsTreeModel.getTreeModel() );
expressionsTree.setRootVisible( false );
expressionsTree.setSelectionModel( selectionModel );
expressionsTree.addMouseListener( new DblClickHandler() );
expressionsTree.setCellRenderer( new ExpressionTreeCellRenderer() );
addAction = new AddAction();
super.init();
}
/**
* Creates a new tree object.
*
* @param parent Parent window used for dialogs.
* @param graph Graph shown in the window.
* @param manager Provides tag information.
*/
public CTagsTree(final JFrame parent, final ZyGraph graph, final ITagManager manager) {
m_parent = Preconditions.checkNotNull(parent, "IE02308: Perent argument can not be null");
m_graph = Preconditions.checkNotNull(graph, "IE01776: Graph can not be null");
m_tagManager = Preconditions.checkNotNull(manager, "IE01777: Manager argument can not be null");
m_model = new CTagsTreeModel(this);
setModel(m_model);
getModel().addTreeModelListener(new InternalModelListener());
addMouseListener(m_mouseListener);
m_graph.addListener(m_graphSelectionListener);
m_graph.addListener(m_graphVisibilityListener);
setRootVisible(false);
m_rootNode = new CRootTagTreeNode(parent, this, graph, m_tagManager);
m_model.setRoot(m_rootNode);
setCellRenderer(new CTagTreeCellRenderer()); // ATTENTION: UNDER NO CIRCUMSTANCES MOVE THIS LINE
// ABOVE THE SETROOT LINE
m_model.nodeStructureChanged(m_rootNode);
final List<IDropHandler> handlers = new ArrayList<IDropHandler>();
handlers.add(new CTagSortingHandler());
new CDefaultTransferHandler(this, DnDConstants.ACTION_COPY_OR_MOVE, handlers);
final DefaultTreeSelectionModel selectionModel = new DefaultTreeSelectionModel();
selectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
setSelectionModel(selectionModel);
final InputMap windowImap = getInputMap(JComponent.WHEN_FOCUSED);
windowImap.put(HotKeys.DELETE_HK.getKeyStroke(), "DELETE");
getActionMap().put("DELETE", CActionProxy.proxy(new DeleteAction()));
}
public TypesTree() {
setRootVisible(false);
setDragEnabled(true);
setDropMode(DropMode.INSERT); // Dropped objects are inserted behind the drop location.
setToggleClickCount(1); // Child nodes expand with a single click.
final DefaultTreeSelectionModel selectionModel = new DefaultTreeSelectionModel();
selectionModel.setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
setSelectionModel(selectionModel);
final IconNodeRenderer renderer = new IconNodeRenderer();
renderer.setFont(GuiHelper.MONOSPACED_FONT);
setCellRenderer(renderer);
}
/**
* Frees allocated resources.
*/
public void dispose() {
m_selectionHistory.removeHistoryListener(m_selectionHistoryListener);
m_graph.removeListener(m_graphSelectionListener);
m_tree.removeMouseListener(m_treeMouseListener);
m_tree.removeTreeSelectionListener(m_treeSelectionListener);
m_tree.setSelectionModel(new DefaultTreeSelectionModel());
}
/**
* Inits the.
*/
private void init() {
// Set the title.
this.setTitle("Type System Editor");
JSplitPane contentPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
this.setContentPane(contentPane);
// Set up the type tree. Use simple DefaultTreeModel.
DefaultMutableTreeNode root = new DefaultMutableTreeNode("<html><b>No CAS!</b></html>");
DefaultTreeModel treeModel = new DefaultTreeModel(root);
this.typeTree = new JTree(treeModel);
this.typeTree.addTreeSelectionListener(new TypeTreeSelectionListener());
TreeSelectionModel treeSelectionModel = new DefaultTreeSelectionModel();
treeSelectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
this.typeTree.setSelectionModel(treeSelectionModel);
JScrollPane treePane = new JScrollPane(this.typeTree);
contentPane.setLeftComponent(treePane);
DefaultTreeCellRenderer cellRenderer = new DefaultTreeCellRenderer();
cellRenderer.setLeafIcon(null);
// cellRenderer.setIcon(null);
cellRenderer.setClosedIcon(null);
cellRenderer.setOpenIcon(null);
this.typeTree.setCellRenderer(cellRenderer);
// Set up the feature table.
this.featureTable = new JTable(new FeatureTableModel());
JScrollPane featurePane = new JScrollPane(this.featureTable);
featurePane.getViewport().setBackground(Color.WHITE);
contentPane.setRightComponent(featurePane);
this.setJMenuBar(createMenuBar());
}
public SelectionListener(DefaultTreeModel treeModel, JList list, DefaultListModel otherListModel, DefaultTreeSelectionModel otherTreeModel) {
this.treeModel = treeModel;
this.list = list;
this.otherListModel = otherListModel;
this.otherTreeSelectionModel = otherTreeModel;
}
public SelectionListener(DefaultTreeModel treeModel, JList list, DefaultListModel otherListModel, DefaultTreeSelectionModel otherTreeModel) {
this.treeModel = treeModel;
this.list = list;
this.otherListModel = otherListModel;
this.otherTreeSelectionModel = otherTreeModel;
}
/**
* Frees allocated resources.
*/
public void dispose() {
taggingPanel.getTree().dispose();
taggingPanel.getTree().setSelectionModel(new DefaultTreeSelectionModel());
}