本文整理汇总了Java中javax.swing.tree.TreeModel类的典型用法代码示例。如果您正苦于以下问题:Java TreeModel类的具体用法?Java TreeModel怎么用?Java TreeModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TreeModel类属于javax.swing.tree包,在下文中一共展示了TreeModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scrollToNode
import javax.swing.tree.TreeModel; //导入依赖的package包/类
public void scrollToNode(final Node n) {
// has to be delayed to be sure that events for Visualizers
// were processed and TreeNodes are already in hierarchy
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
TreeNode tn = Visualizer.findVisualizer(n);
if (tn == null) {
return;
}
TreeModel model = tree.getModel();
if (!(model instanceof DefaultTreeModel)) {
return;
}
TreePath path = new TreePath(((DefaultTreeModel) model).getPathToRoot(tn));
Rectangle r = tree.getPathBounds(path);
if (r != null) {
tree.scrollRectToVisible(r);
}
}
});
}
示例2: DefaultOutlineModel
import javax.swing.tree.TreeModel; //导入依赖的package包/类
/** Creates a new instance of DefaultOutlineModel. <strong><b>Note</b>
* Do not fire table structure changes from the wrapped TableModel (value
* changes are okay). Changes that affect the number of rows must come
* from the TreeModel.
* @param treeModel The tree model
* @param tableModel The table model
* @param largeModel <code>true</code> if it's a large model tree, <code>false</code> otherwise.
* @param nodesColumnLabel Label of the node's column
*/
protected DefaultOutlineModel(TreeModel treeModel, TableModel tableModel, boolean largeModel, String nodesColumnLabel) {
this.treeModel = treeModel;
this.tableModel = tableModel;
if (nodesColumnLabel != null) {
this.nodesColumnLabel = nodesColumnLabel;
}
layout = largeModel ? (AbstractLayoutCache) new FixedHeightLayoutCache()
: (AbstractLayoutCache) new VariableHeightLayoutCache();
broadcaster = new EventBroadcaster (this);
layout.setRootVisible(true);
layout.setModel(this);
treePathSupport = new TreePathSupport(this, layout);
treePathSupport.addTreeExpansionListener(broadcaster);
treePathSupport.addTreeWillExpandListener(broadcaster);
treeModel.addTreeModelListener(broadcaster);
tableModel.addTableModelListener(broadcaster);
if (tableModel instanceof ProxyTableModel) {
((ProxyTableModel) tableModel).setOutlineModel(this);
}
}
示例3: getNextPath
import javax.swing.tree.TreeModel; //导入依赖的package包/类
TreePath getNextPath(TreePath path, boolean down) {
TreeModel _model = model.treeModel;
TreeNode node = (TreeNode)path.getLastPathComponent();
if (down && _model.getChildCount(node) > 0)
return path.pathByAddingChild(_model.getChild(node, 0));
TreePath parentPath = path.getParentPath();
if (!down && parentPath == null)
return path.pathByAddingChild(_model.getChild(node, 0));
TreeNode parent = (TreeNode)parentPath.getLastPathComponent();
int idx = _model.getIndexOfChild(parent, node) + 1;
if (_model.getChildCount(parent) > idx)
return parentPath.pathByAddingChild(_model.getChild(parent, idx));
if (!down && parentPath.getParentPath() == null) {
return parentPath.pathByAddingChild(_model.getChild(parent, 0));
} else {
return getNextPath(parentPath, false);
}
}
示例4: collapseChildren
import javax.swing.tree.TreeModel; //导入依赖的package包/类
public void collapseChildren(int row) {
if (tree != null) try {
markExpansionTransaction();
TreePath tpath = tree.getPathForRow(row);
if (tpath == null || tree.isCollapsed(tpath)) return;
TreeModel tmodel = tree.getModel();
Object selected = tpath.getLastPathComponent();
int nchildren = tmodel.getChildCount(selected);
for (int i = 0; i < nchildren; i++)
tree.collapsePath(tpath.pathByAddingChild(tmodel.getChild(selected, i)));
} finally {
clearExpansionTransaction();
}
}
示例5: expandPlainPath
import javax.swing.tree.TreeModel; //导入依赖的package包/类
public void expandPlainPath(int row, int maxChildren) {
if (tree != null) try {
markExpansionTransaction();
TreePath tpath = tree.getPathForRow(row);
if (tpath == null) return;
TreeModel tmodel = tree.getModel();
int childCount = tmodel.getChildCount(tpath.getLastPathComponent());
while (childCount > 0 && childCount <= maxChildren) {
tpath = tpath.pathByAddingChild(tmodel.getChild(tpath.getLastPathComponent(), 0));
childCount = tmodel.getChildCount(tpath.getLastPathComponent());
}
tree.putClientProperty(UIUtils.PROP_AUTO_EXPANDING, Boolean.TRUE);
try { tree.expandPath(tpath); selectPath(tpath, true); }
finally { tree.putClientProperty(UIUtils.PROP_AUTO_EXPANDING, null); }
} finally {
clearExpansionTransaction();
}
}
示例6: expandFirstPath
import javax.swing.tree.TreeModel; //导入依赖的package包/类
public void expandFirstPath(int row) {
if (tree != null) try {
markExpansionTransaction();
TreePath tpath = tree.getPathForRow(row);
if (tpath == null) return;
TreeModel tmodel = tree.getModel();
while (tmodel.getChildCount(tpath.getLastPathComponent()) > 0)
tpath = tpath.pathByAddingChild(tmodel.getChild(tpath.getLastPathComponent(), 0));
tree.putClientProperty(UIUtils.PROP_AUTO_EXPANDING, Boolean.TRUE);
try { selectPath(tpath, true); }
finally { tree.putClientProperty(UIUtils.PROP_AUTO_EXPANDING, null); }
} finally {
clearExpansionTransaction();
}
}
示例7: createTreeView
import javax.swing.tree.TreeModel; //导入依赖的package包/类
private void createTreeView() {
synchronized (lock) {
releaseTreeView();
treeView = new DebugTreeView();
treeView.setRootVisible(false);
treeView.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
treeView.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
treeView.getAccessibleContext().setAccessibleName(NbBundle.getMessage(DebuggingViewComponent.class, "DebuggingViewComponent.treeView.AccessibleContext.accessibleName")); // NOI18N
treeView.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(DebuggingViewComponent.class, "DebuggingViewComponent.treeView.AccessibleContext.accessibleDescription")); // NOI18N
treeView.getTree().addMouseWheelListener(this);
treeView.addTreeExpansionListener(this);
TreeModel model = treeView.getTree().getModel();
model.addTreeModelListener(this);
treeView.getViewport().addChangeListener(this);
treeView.getTree().setScrollsOnExpand(false);
mainPanel.add(treeView, BorderLayout.CENTER);
}
}
示例8: scrollNodeToVisible
import javax.swing.tree.TreeModel; //导入依赖的package包/类
private void scrollNodeToVisible( final Node n ) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
TreeNode tn = Visualizer.findVisualizer(n);
if (tn == null) {
return;
}
TreeModel model = tree.getModel();
if (!(model instanceof DefaultTreeModel)) {
return;
}
TreePath path = new TreePath(((DefaultTreeModel) model).getPathToRoot(tn));
if( null == path )
return;
Rectangle r = tree.getPathBounds(path);
if (r != null) {
tree.scrollRectToVisible(r);
}
}
});
}
示例9: expandAllPaths
import javax.swing.tree.TreeModel; //导入依赖的package包/类
/**
* Opens all paths in the given node and all nodes below that.
*
* @param path
* the tree path to the node to expand
* @param treeModel
* the tree model
* @see JTree#expandPath(TreePath)
*/
protected void expandAllPaths(TreePath path, TreeModel treeModel) {
expandPath(path);
final Object node = path.getLastPathComponent();
final int n = treeModel.getChildCount(node);
for (int index = 0; index < n; index++) {
final Object child = treeModel.getChild(node, index);
expandAllPaths(path.pathByAddingChild(child));
}
}
示例10: run
import javax.swing.tree.TreeModel; //导入依赖的package包/类
@Override
public void run() {
try {
Database database = JDBCMetaDataUtil.getMetaData(environment, true, true, true, true,
".*", exclusionPatternProvider.getValue(), true, true);
DatabasePane.this.importer = importer;
final TreeModel model = new SwingTreeModelAdapter<DBObject>(new DatabaseTreeModel(database));
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
tree = new DatabaseTree(model);
scrollPane.setViewportView(tree);
}
});
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例11: populateTrees
import javax.swing.tree.TreeModel; //导入依赖的package包/类
private void populateTrees() {
licenseFilterMenu.setLicenses();
TreeModel issuesTreeModel = new DefaultTreeModel(new ScanTreeNode("SeveritiesTree"));
TreeModel licensesTreeModel = new DefaultTreeModel(new ScanTreeNode("LicensesTree"));
ScanManager scanManager = ScanManagerFactory.getScanManager(project);
if (scanManager != null) {
scanManager.filterAndSort(issuesTreeModel, licensesTreeModel);
}
ScanTreeNode root = (ScanTreeNode) issuesTreeModel.getRoot();
issuesCount.setText("Issues (" + root.getIssueCount() + ") ");
issuesComponentsTree.setModel(issuesTreeModel);
issuesComponentsTree.validate();
issuesComponentsTree.repaint();
licensesComponentsTree.setModel(licensesTreeModel);
licensesComponentsTree.validate();
licensesComponentsTree.repaint();
issuesTreeExpansionListener.setIssuesCountPanel();
}
示例12: getTreeModel
import javax.swing.tree.TreeModel; //导入依赖的package包/类
protected static TreeModel getTreeModel() {
root = new DefaultMutableTreeNode("Root");
a = new DefaultMutableTreeNode("A");
root.add(a);
a1 = new DefaultMutableTreeNode("a1");
a.add(a1);
b = new DefaultMutableTreeNode("B");
root.add(b);
b1 = new DefaultMutableTreeNode("b1");
b.add(b1);
b2 = new DefaultMutableTreeNode("b2");
b.add(b2);
c = new DefaultMutableTreeNode("C");
root.add(c);
c1 = new DefaultMutableTreeNode("c1");
c.add(c1);
return new DefaultTreeModel(root);
}
示例13: SelectionTreeItemListener
import javax.swing.tree.TreeModel; //导入依赖的package包/类
public SelectionTreeItemListener(SelectionPanel owner) {
if (owner == null)
throw new IllegalArgumentException();
this.owner = owner;
TreeModel model = owner.getTree().getModel();
Object root = owner.getTree().getModel().getRoot();
ePath = new TreePath(new Object[] { root, model.getChild(root, 0) });
vPath = new TreePath(new Object[] { root, model.getChild(root, 1) });
}
示例14: updateTree
import javax.swing.tree.TreeModel; //导入依赖的package包/类
/**
* Updates the tree according to the textual representation of the tree
* model in the text area.
*/
private void updateTree() {
String txt = textArea.getText();
int tabSize = textArea.getTabSize();
StringBuilder sb = new StringBuilder(tabSize);
for (int i=0; i<tabSize; i++) {
sb.append(" "); // NOI18N
}
txt = txt.replace("\t", sb.toString()); // NOI18N
TreeModel model = propEditor.createTreeModel(txt);
tree.setModel(model);
expandTree();
propEditor.setValue(model);
}
示例15: ExplorerTree
import javax.swing.tree.TreeModel; //导入依赖的package包/类
ExplorerTree(TreeModel model) {
super(model);
toggleClickCount = 0;
// fix for #18292
// default action map for JTree defines these shortcuts
// but we use our own mechanism for handling them
// following lines disable default L&F handling (if it is
// defined on Ctrl-c, Ctrl-v and Ctrl-x)
getInputMap().put(KeyStroke.getKeyStroke("control C"), "none"); // NOI18N
getInputMap().put(KeyStroke.getKeyStroke("control V"), "none"); // NOI18N
getInputMap().put(KeyStroke.getKeyStroke("control X"), "none"); // NOI18N
getInputMap().put(KeyStroke.getKeyStroke("COPY"), "none"); // NOI18N
getInputMap().put(KeyStroke.getKeyStroke("PASTE"), "none"); // NOI18N
getInputMap().put(KeyStroke.getKeyStroke("CUT"), "none"); // NOI18N
if (Utilities.isMac()) {
getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.META_MASK), "none"); // NOI18N
getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.META_MASK), "none"); // NOI18N
getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.META_MASK), "none"); // NOI18N
}
setupSearch();
if (!GraphicsEnvironment.isHeadless()) {
setDragEnabled(true);
}
}