本文整理汇总了Java中javax.swing.tree.DefaultTreeModel类的典型用法代码示例。如果您正苦于以下问题:Java DefaultTreeModel类的具体用法?Java DefaultTreeModel怎么用?Java DefaultTreeModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultTreeModel类属于javax.swing.tree包,在下文中一共展示了DefaultTreeModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SelecioneByDiagramaSelecionado
import javax.swing.tree.DefaultTreeModel; //导入依赖的package包/类
public void SelecioneByDiagramaSelecionado() {
DefaultTreeModel df = (DefaultTreeModel) tree.getModel();
if (df.getRoot() instanceof TreeItem) {
TreeItem root = (TreeItem) df.getRoot();
TreePath pt = new TreePath(root);
if (diagrama.getSelecionado() == null || !(diagrama.getSelecionado() instanceof Forma)) {
return;
}
for (int i = 0; i < root.getChildCount(); i++) {
TreeItem item = (TreeItem) root.getChildAt(i);
if (item.getId() == diagrama.getSelecionado().getID()) {
tree.setSelectionPath(pt.pathByAddingChild(item));
break;
}
}
}
btnOK.setText("OK");
btnFechar.setVisible(false);
}
示例2: AssetTree
import javax.swing.tree.DefaultTreeModel; //导入依赖的package包/类
public AssetTree() {
this.nodeRoot = new DefaultMutableTreeNode(new IconTreeListItem(Resources.get("assettree_assets"), ASSET_ICON));
this.nodeSpritesheets = new DefaultMutableTreeNode(new IconTreeListItem(Resources.get("assettree_spritesheets"), SPRITESHEET_ICON));
this.nodeSpriteProps = new DefaultMutableTreeNode(new IconTreeListItem(Resources.get("assettree_spritesheets_props"), PROP_ICON));
this.nodeSpriteMisc = new DefaultMutableTreeNode(new IconTreeListItem(Resources.get("assettree_spritesheets_misc"), MISC_ICON));
this.nodeSpritesheets.add(this.nodeSpriteProps);
this.nodeSpritesheets.add(this.nodeSpriteMisc);
this.nodeRoot.add(nodeSpritesheets);
this.entitiesTreeModel = new DefaultTreeModel(this.nodeRoot);
this.setModel(this.entitiesTreeModel);
this.setCellRenderer(new IconTreeListRenderer());
this.setMaximumSize(new Dimension(0, 250));
for (int i = 0; i < this.getRowCount(); i++) {
this.expandRow(i);
}
this.addTreeSelectionListener(e -> {
loadAssetsOfCurrentSelection(e.getPath());
});
}
示例3: getCodeValue
import javax.swing.tree.DefaultTreeModel; //导入依赖的package包/类
/**
* Returns textual representation of the tree model.
*
* @return textual representation of the tree model.
*/
String getCodeValue() {
Object value = getValue();
if (value instanceof DefaultTreeModel) {
DefaultTreeModel model = (DefaultTreeModel)value;
Object root = model.getRoot();
if (root instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode)root;
Object userObject = rootNode.getUserObject();
if (userObject instanceof CodeUserObject) {
CodeUserObject code = (CodeUserObject)userObject;
return code.code;
}
}
}
return null;
}
示例4: setRefactoringEnabled
import javax.swing.tree.DefaultTreeModel; //导入依赖的package包/类
void setRefactoringEnabled(boolean enabled, boolean isRefreshing) {
checkEventThread();
if (tree != null) {
if (!enabled) {
CheckNode c = (CheckNode) tree.getModel().getRoot();
if (!isRefreshing) {
c.setNeedsRefresh();
} else {
c.setDisabled();
}
tree.setModel(new DefaultTreeModel(c, false));
}
// tree.validate();
tree.setEnabled(enabled);
if (refactorButton != null) {
refactorButton.setEnabled(enabled);
}
}
if (refactorButton != null) {
refactorButton.requestFocusInWindow();
} else if (tree != null) {
tree.requestFocusInWindow();
}
}
示例5: caretUpdate
import javax.swing.tree.DefaultTreeModel; //导入依赖的package包/类
public void caretUpdate (CaretEvent e) {
if (rootNode == null) return;
ASTPath path = rootNode.findPath (e.getDot ());
if (path == null) return;
TreeNode tNode = (TreeNode) tree.getModel ().getRoot ();
List<TreeNode> treePath = new ArrayList<TreeNode> ();
Iterator it = path.listIterator ();
if (!it.hasNext ()) return;
it.next ();
treePath.add (tNode);
while (tNode instanceof TNode && it.hasNext ()) {
tNode = ((TNode) tNode).getTreeNode (it.next ());
if (tNode == null) throw new NullPointerException ();
treePath.add (tNode);
}
TreePath treePath2 = new TreePath (treePath.toArray ());
DefaultTreeModel model = new DefaultTreeModel ((TreeNode) tree.getModel ().getRoot ());
tree.setModel (model);
tree.setSelectionPath (treePath2);
tree.scrollPathToVisible (treePath2);
}
示例6: refresh
import javax.swing.tree.DefaultTreeModel; //导入依赖的package包/类
private void refresh () {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
AbstractDocument doc = getCurrentDocument ();
TokenSequence ts = null;
if (doc != null)
try {
doc.readLock ();
TokenHierarchy tokenHierarchy = TokenHierarchy.get (doc);
if (tokenHierarchy == null) return;
ts = tokenHierarchy.tokenSequence ();
} finally {
doc.readUnlock ();
}
if (ts == null)
tree.setModel (new DefaultTreeModel (new DefaultMutableTreeNode ()));
else
tree.setModel (new DefaultTreeModel (new TSNode (null, ts, null, 0, 0)));
JEditorPane editor = getCurrentEditor ();
if (editor != null) {
int position = getCurrentEditor ().getCaret ().getDot ();
selectPath (position);
}
}
});
}
示例7: refresh
import javax.swing.tree.DefaultTreeModel; //导入依赖的package包/类
/**
* Updates the JTree with class files loaded from the current jar.
*/
public void refresh() {
JarData jar = Recaf.INSTANCE.jarData;
if (jar == null) {
return;
}
// TODO: Expand new tree model to match the original
// Root node
String jarName = (jar.jar != null) ? jar.jar.getName() : "?";
ASMTreeNode root = new ASMTreeNode(jarName, null);
DefaultTreeModel model = new DefaultTreeModel(root);
tree.setModel(model);
// Iterate classes
List<String> names = Streams.sortedNameList(jar.classes.keySet());
for (String className : names) {
if (!jar.classes.containsKey(className)) {
continue;
}
ClassNode node = jar.classes.get(className);
// Create directory path based on current node name.
ArrayList<String> dirPath = new ArrayList<String>(Arrays.asList(node.name.split("/")));
// Create directory of nodes
Swing.generateTreePath(root, dirPath, node, model);
}
model.setRoot(root);
}
示例8: clear
import javax.swing.tree.DefaultTreeModel; //导入依赖的package包/类
void clear() {
this.txtClassName.setText("");
this.txtSuperClassName.setText("");
this.txtMagicNumber.setText("");
this.txtMajorVersion.setText("");
this.txtMinorVersion.setText("");
this.chkFinal.setSelected(false);
this.chkPublic.setSelected(false);
this.chkSuper.setSelected(false);
this.chkInterface.setSelected(false);
this.chkAbstract.setSelected(false);
this.interfacesRootNode.removeAllChildren();
this.treeInterfaces.setModel(new DefaultTreeModel(this.interfacesRootNode));
this.txtNewInterfaceName.setText("");
this.txtConstPoolIndex.setText("");
}
示例9: connect
import javax.swing.tree.DefaultTreeModel; //导入依赖的package包/类
void connect( JTree errorTree, DefaultTreeModel errModel, JComboBox severityComboBox,
JCheckBox tasklistCheckBox, JPanel customizerPanel,
JEditorPane descriptionTextArea) {
this.errorTree = errorTree;
this.errModel = errModel;
this.severityComboBox = severityComboBox;
this.tasklistCheckBox = tasklistCheckBox;
this.customizerPanel = customizerPanel;
this.descriptionTextArea = descriptionTextArea;
valueChanged( null );
errorTree.addKeyListener(this);
errorTree.addMouseListener(this);
errorTree.getSelectionModel().addTreeSelectionListener(this);
severityComboBox.addActionListener(this);
tasklistCheckBox.addChangeListener(this);
}
示例10: saveObjectToGroup
import javax.swing.tree.DefaultTreeModel; //导入依赖的package包/类
private void saveObjectToGroup(ObjectGroup<MobileORObject> group, MobileTreeNode mobileNode) {
MobileORObject dupObj = null;
MobileORObject dummyObject = getDummyObject(mobileNode);
for (MobileORObject object : group.getObjects()) {
if (object.isEqualOf(dummyObject)) {
dupObj = object;
}
}
if (dupObj == null) {
String objName = dummyObject.getName();
int i = 1;
while (group.getObjectByName(objName) != null) {
objName = dummyObject.getName() + i++;
}
MobileORObject newObj = group.addObject(objName);
dummyObject.clone(newObj);
LOG.log(Level.INFO, "Object Added : {0}", objName);
((DefaultTreeModel) objectTree.getTree().getModel()).nodesWereInserted(group, new int[]{group.getChildCount() - 1});
if (group.getChildCount() == 2) {
((DefaultTreeModel) objectTree.getTree().getModel()).reload(group.getParent());
}
} else {
LOG.log(Level.WARNING, "Object Similar To\nObject : {0}", dupObj.getName());
}
}
示例11: setModels
import javax.swing.tree.DefaultTreeModel; //导入依赖的package包/类
public void setModels(final DefaultListModel mpModel, final DefaultListModel cpModel) {
this.model = new JoinModel(mpModel, cpModel);
this.list.setModel(this.model);
DefaultTreeModel mpTreeModel = toTreeModel(mpModel, MODULEPATH);
DefaultTreeModel cpTreeModel = toTreeModel(cpModel, CLASSPATH);
mpModel.addListDataListener(new ListModelListener(mpModel, mpTreeModel, mpTree));
cpModel.addListDataListener(new ListModelListener(cpModel, cpTreeModel, cpTree));
mpTree.setModel(mpTreeModel);
cpTree.setModel(cpTreeModel);
SelectionModel mpTreeSelectionModel = new SelectionModel();
SelectionModel cpTreeSelectionModel = new SelectionModel();
mpTreeSelectionModel.addTreeSelectionListener(new SelectionListener(mpTreeModel, this.list, null, cpTreeSelectionModel));
cpTreeSelectionModel.addTreeSelectionListener(new SelectionListener(cpTreeModel, this.list, mpModel, mpTreeSelectionModel));
mpTree.setSelectionModel(mpTreeSelectionModel);
cpTree.setSelectionModel(cpTreeSelectionModel);
}
示例12: setRootNode
import javax.swing.tree.DefaultTreeModel; //导入依赖的package包/类
void setRootNode(final TreeNode root) {
if(root != null) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
tree.setModel(new DefaultTreeModel(root));
for (int i = 0; i < tree.getRowCount(); i++) {
tree.expandRow(i);
}
listScrollPane.setVisible(true);
titleLabel.setVisible(true);
initPanel.setVisible(false);
}
});
} else {
messageLabel.setText(NbBundle.getMessage(RevertDeletedAction.class, "MSG_NO_FILES")); // NOI18N
}
}
示例13: setSelected
import javax.swing.tree.DefaultTreeModel; //导入依赖的package包/类
public void setSelected(Object node, Boolean selected) {
Object userObject = ((DefaultMutableTreeNode) node).getUserObject();
if (((DefaultMutableTreeNode) node).isRoot()) {
getOptionsExportModel().setState(OptionsExportModel.State.valueOf(selected));
} else if (userObject instanceof OptionsExportModel.Category) {
((OptionsExportModel.Category) userObject).setState(OptionsExportModel.State.valueOf(selected));
} else if (userObject instanceof OptionsExportModel.Item) {
((OptionsExportModel.Item) userObject).setEnabled(selected);
// update parent category
Object parent = ((TreeNode) node).getParent();
updateCategoryNode((DefaultMutableTreeNode) parent);
}
// fire an event to refresh parent or child nodes
((DefaultTreeModel) treeModel).nodeChanged((TreeNode) node);
dialogDescriptor.setValid(isPanelValid());
scrollPaneOptions.repaint();
}
示例14: scrollNodeToVisible
import javax.swing.tree.DefaultTreeModel; //导入依赖的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);
}
}
});
}
示例15: MapPlacesViewer
import javax.swing.tree.DefaultTreeModel; //导入依赖的package包/类
public MapPlacesViewer(MapPlaces places,
MapPlace root,
boolean topFrame,
int xPos, int yPos) {
this.places = places;
this.topFrame = topFrame;
this.rootPlace = root;
this.rootNode = createTreeNodes(root);
treeModel= new DefaultTreeModel(rootNode);
bookmarkTree = new JTree(treeModel);
this.initialXPos = xPos;
this.initialYPos = yPos;
initBookmarkFrame();
MapPlacesViewer.mapViewers.add(this);
}