List of usage examples for javax.swing.tree DefaultMutableTreeNode depthFirstEnumeration
public Enumeration<TreeNode> depthFirstEnumeration()
From source file:MainClass.java
public static void main(String args[]) { JFrame frame = new JFrame("Traverse Tree"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTree tree = new JTree(); tree.setRootVisible(true);/*from w w w . j a v a 2 s . c o m*/ TreeModel model = tree.getModel(); Object rootObject = model.getRoot(); if ((rootObject != null) && (rootObject instanceof DefaultMutableTreeNode)) { DefaultMutableTreeNode r = (DefaultMutableTreeNode) rootObject; printDescendents(r); Enumeration breadth = r.breadthFirstEnumeration(); Enumeration depth = r.depthFirstEnumeration(); Enumeration preOrder = r.preorderEnumeration(); printEnumeration(breadth, "Breadth"); printEnumeration(depth, "Depth"); printEnumeration(preOrder, "Pre"); } TreeSelectionListener treeSelectionListener = new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent treeSelectionEvent) { JTree treeSource = (JTree) treeSelectionEvent.getSource(); TreePath path = treeSource.getSelectionPath(); System.out.println(path); System.out.println(path.getPath()); System.out.println(path.getParentPath()); System.out.println(((DefaultMutableTreeNode) path.getLastPathComponent()).getUserObject()); System.out.println(path.getPathCount()); } }; tree.addTreeSelectionListener(treeSelectionListener); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 400); frame.setVisible(true); }
From source file:com.pironet.tda.SunJDKParser.java
private void updateChildCount(DefaultMutableTreeNode threadOrMonitorNode, boolean isThreadNode) { int count = 0; for (Enumeration e = threadOrMonitorNode.depthFirstEnumeration(); e.hasMoreElements();) { Object element = e.nextElement(); ThreadInfo mi = (ThreadInfo) (((DefaultMutableTreeNode) element).getUserObject()); if (mi.getName().startsWith("Thread")) { count++;// w ww .j a va 2s .c om } } ThreadInfo mi = (ThreadInfo) threadOrMonitorNode.getUserObject(); if (ThreadDumpInfo.areALotOfWaiting(count)) { mi.setALotOfWaiting(true); } if (isThreadNode) { count--; } mi.setChildCount(count); if (count > 1) { mi.setName(mi.getName() + ": " + count + " Blocked threads"); } else if (count == 1) { mi.setName(mi.getName() + ": " + count + " Blocked thread"); } // Recurse for (Enumeration e = threadOrMonitorNode.children(); e.hasMoreElements();) { updateChildCount((DefaultMutableTreeNode) e.nextElement(), !isThreadNode); } }
From source file:org.kuali.maven.plugins.externals.MojoHelper.java
public void writePoms(DefaultMutableTreeNode node, File baseDir) { int count = 0; Enumeration<?> e = node.depthFirstEnumeration(); while (e.hasMoreElements()) { DefaultMutableTreeNode element = (DefaultMutableTreeNode) e.nextElement(); Project project = (Project) element.getUserObject(); File pom = project.getPom(); String oldContents = read(pom); String newContents = project.getPomContents(); if (!oldContents.equals(newContents)) { logger.debug("Updating " + pom.getAbsolutePath()); write(pom, newContents);// ww w . ja v a2 s . c o m count++; } } logger.info("Updated " + count + " Maven pom's"); }
From source file:org.kuali.maven.plugins.externals.MojoHelper.java
public void writePoms(DefaultMutableTreeNode node, File baseDir, File checkoutDir) { int count = 0; Enumeration<?> e = node.depthFirstEnumeration(); while (e.hasMoreElements()) { DefaultMutableTreeNode element = (DefaultMutableTreeNode) e.nextElement(); Project project = (Project) element.getUserObject(); File pom = project.getPom(); String relativePath = getRelativePath(baseDir, pom); File newPom = new File(checkoutDir.getAbsolutePath() + File.separator + relativePath); String oldContents = read(pom); String newContents = project.getPomContents(); if (!oldContents.equals(newContents)) { logger.debug("Updating " + newPom.getAbsolutePath()); write(newPom, newContents);// w ww . j av a 2 s .c o m count++; } } logger.info("Updated " + count + " Maven pom's"); }
From source file:op.controlling.PnlQMSSchedule.java
private void initPanel() { i18n();/* ww w . j a v a 2 s .com*/ txtDueDays.setText(Integer.toString(qmssched.getDuedays())); spinTaeglich.setModel(new SpinnerNumberModel(1, 1, 365, 1)); spinWoche.setModel(new SpinnerNumberModel(1, 1, 52, 1)); spinMonat.setModel(new SpinnerNumberModel(1, 1, 12, 1)); spinYearly.setModel(new SpinnerNumberModel(1, 1, 10, 1)); spinDayInMonth.setModel(new SpinnerNumberModel(1, 1, 31, 1)); spinTaeglich.setValue(Math.max(qmssched.getDaily(), 1)); spinWoche.setValue(Math.max(qmssched.getWeekly(), 1)); spinMonat.setValue(Math.max(qmssched.getMonthly(), 1)); spinDayInMonth.setValue(Math.max(qmssched.getDayinmonth(), 1)); spinYearly.setValue(Math.max(qmssched.getYearly(), 1)); cbMon.setSelected(true); cmbMonth.setSelectedIndex(qmssched.isYearly() ? qmssched.getMonthinyear() - 1 : 0); spinDayInMonthInYear.setModel(new SpinnerNumberModel(qmssched.isYearly() ? qmssched.getDayinmonth() : 1, 1, maxdays[cmbMonth.getSelectedIndex()], 1)); cmbMonth.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { spinDayInMonthInYear .setModel(new SpinnerNumberModel(1, 1, maxdays[cmbMonth.getSelectedIndex()], 1)); } } }); if (qmssched.isDaily()) { tabWdh.setSelectedIndex(TAB_DAILY); } else if (qmssched.isWeekly()) { cbMon.setSelected(qmssched.getWeekday() == DateTimeConstants.MONDAY); cbDie.setSelected(qmssched.getWeekday() == DateTimeConstants.TUESDAY); cbMit.setSelected(qmssched.getWeekday() == DateTimeConstants.WEDNESDAY); cbDon.setSelected(qmssched.getWeekday() == DateTimeConstants.THURSDAY); cbFre.setSelected(qmssched.getWeekday() == DateTimeConstants.FRIDAY); cbSam.setSelected(qmssched.getWeekday() == DateTimeConstants.SATURDAY); cbSon.setSelected(qmssched.getWeekday() == DateTimeConstants.SUNDAY); tabWdh.setSelectedIndex(TAB_WEEKLY); } else if (qmssched.isMonthly()) { spinDayInMonth.setValue(qmssched.getDayinmonth()); cmbTag.setSelectedIndex(qmssched.getWeekday()); tabWdh.setSelectedIndex(TAB_MONTHLY); } else if (qmssched.isYearly()) { spinYearly.setValue(qmssched.getYearly()); spinDayInMonthInYear.setValue(qmssched.getDayinmonth()); cmbMonth.setSelectedIndex(qmssched.getMonthinyear() - 1); tabWdh.setSelectedIndex(TAB_YEARLY); } jdcStartingOn.setMinSelectableDate(new Date()); jdcStartingOn.setDate(qmssched.getStartingOn()); ArrayList<Date> timelist = SYSCalendar.getTimeList(); DefaultComboBoxModel dcbm = new DefaultComboBoxModel(timelist.toArray()); dcbm.insertElementAt(null, 0); txtBemerkung.setText(qmssched.getText()); txtQMS.setText(qmssched.getMeasure()); cmbLocation.setTreeModel(new DefaultTreeModel(StationTools.getCompleteStructure())); Object userObject = null; if (qmssched.getHome() != null) { userObject = qmssched.getHome(); } else if (qmssched.getStation() != null) { userObject = qmssched.getStation(); } int row = 0; if (userObject == null) { cmbLocation.setSelectedItem(null); } else { DefaultMutableTreeNode root = (DefaultMutableTreeNode) cmbLocation.getTreeModel().getRoot(); DefaultMutableTreeNode theNode = null; for (Enumeration e = root.depthFirstEnumeration(); e.hasMoreElements() && theNode == null;) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement(); if (userObject.equals(node.getUserObject())) { cmbLocation.setSelectedItem(node); break; } row++; } } }
From source file:org.icefaces.application.showcase.view.bean.ApplicationController.java
/** * Utility method to find a tree node by its ID. * * @param nodeId node Id of node to to find in tree. * @return node specified by ID or null of no node of that ID is found. *///from w w w. j av a 2 s . c o m private DefaultMutableTreeNode findTreeNode(String nodeId) { ApplicationSessionModel applicationModel = (ApplicationSessionModel) FacesUtils .getManagedBean(BeanNames.APPLICATION_MODEL); Collection<DefaultTreeModel> trees = applicationModel.getNavigationTrees().values(); DefaultMutableTreeNode node; DefaultMutableTreeNode rootNode; // search all trees defined by meta data using a depthFirst search. for (DefaultTreeModel treeModel : trees) { rootNode = (DefaultMutableTreeNode) treeModel.getRoot(); Enumeration nodes = rootNode.depthFirstEnumeration(); while (nodes.hasMoreElements()) { node = (DefaultMutableTreeNode) nodes.nextElement(); NavigationTreeNode tmp = (NavigationTreeNode) node.getUserObject(); if (tmp.getNodeId() != null && tmp.getNodeId().equals(nodeId)) { return node; } } } return null; }
From source file:ropes.MainWindow.java
private DefaultMutableTreeNode findNode(DefaultMutableTreeNode root, String s) { //reutrn node if exist in jtree @SuppressWarnings("unchecked") Enumeration<DefaultMutableTreeNode> e = root.depthFirstEnumeration(); while (e.hasMoreElements()) { DefaultMutableTreeNode node = e.nextElement(); if (node.toString().equalsIgnoreCase(s)) { return node; }//from ww w. j ava 2s.c om } return null; }