List of usage examples for javax.swing.tree DefaultTreeModel DefaultTreeModel
@ConstructorProperties({ "root" }) public DefaultTreeModel(TreeNode root)
From source file:org.syncope.console.commons.RoleTreeBuilder.java
public TreeModel build(final List<RoleTO> roles) { DefaultMutableTreeNode fakeroot = new DefaultMutableTreeNode(new FakeRootRoleTO()); populateSubtree(fakeroot, roles);//from ww w . ja v a 2 s. c o m return new DefaultTreeModel(fakeroot); }
From source file:components.DynamicTree.java
public DynamicTree() { super(new GridLayout(1, 0)); rootNode = new DefaultMutableTreeNode("Root Node"); treeModel = new DefaultTreeModel(rootNode); treeModel.addTreeModelListener(new MyTreeModelListener()); tree = new JTree(treeModel); tree.setEditable(true);/* w ww .j a va2s . co m*/ tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.setShowsRootHandles(true); JScrollPane scrollPane = new JScrollPane(tree); add(scrollPane); }
From source file:com.mindcognition.mindraider.ui.swing.explorer.LabelsTree.java
public LabelsTree(NotebooksTree notebooksTree) { labelsRootNode = new DefaultMutableTreeNode( new LabelNodeUserObject(Messages.getString("ExplorerJPanel.rootNode"), 333, null)); labelsTreeModel = new DefaultTreeModel(labelsRootNode); labelsTreeModel.addTreeModelListener(new LabelsTreeModelListener()); setModel(labelsTreeModel);//from w w w.j ava 2s . com setEditable(false); getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); addTreeExpansionListener(new TreeExpansionListenerImplementation()); addTreeWillExpandListener(new TreeWillExpandListenerImplementation()); setShowsRootHandles(true); // tree rendered setCellRenderer(new LabelsTreeCellRenderer()); // subscribe for folder custodian events e.g. folder creation MindRaider.labelCustodian.subscribe(this); // tree node selection listener addTreeSelectionListener(new LabelsTreeSelectionListener(this, notebooksTree)); reloadModel(); }
From source file:ClassTree.java
public ClassTreeFrame() { setTitle("ClassTree"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // the root of the class tree is Object root = new DefaultMutableTreeNode(java.lang.Object.class); model = new DefaultTreeModel(root); tree = new JTree(model); // add this class to populate the tree with some data addClass(getClass());//ww w. j av a 2s .co m // set up node icons ClassNameTreeCellRenderer renderer = new ClassNameTreeCellRenderer(); renderer.setClosedIcon(new ImageIcon("red-ball.gif")); renderer.setOpenIcon(new ImageIcon("yellow-ball.gif")); renderer.setLeafIcon(new ImageIcon("blue-ball.gif")); tree.setCellRenderer(renderer); // set up selection mode tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent event) { // the user selected a different node--update description TreePath path = tree.getSelectionPath(); if (path == null) return; DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) path.getLastPathComponent(); Class<?> c = (Class<?>) selectedNode.getUserObject(); String description = getFieldDescription(c); textArea.setText(description); } }); int mode = TreeSelectionModel.SINGLE_TREE_SELECTION; tree.getSelectionModel().setSelectionMode(mode); // this text area holds the class description textArea = new JTextArea(); // add tree and text area JPanel panel = new JPanel(); panel.setLayout(new GridLayout(1, 2)); panel.add(new JScrollPane(tree)); panel.add(new JScrollPane(textArea)); add(panel, BorderLayout.CENTER); addTextField(); }
From source file:gov.sandia.umf.platform.ui.jobs.RunPanel.java
public RunPanel() { root = new NodeBase(); model = new DefaultTreeModel(root); tree = new JTree(model); tree.setRootVisible(false);/*www .j a v a2 s. c om*/ tree.setShowsRootHandles(true); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); tree.setCellRenderer(new DefaultTreeCellRenderer() { @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); NodeBase node = (NodeBase) value; Icon icon = node.getIcon(expanded); // A node knows whether it should hold other nodes or not, so don't pass leaf to it. if (icon == null) { if (leaf) icon = getDefaultLeafIcon(); else if (expanded) icon = getDefaultOpenIcon(); else icon = getDefaultClosedIcon(); } setIcon(icon); return this; } }); tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { NodeBase newNode = (NodeBase) tree.getLastSelectedPathComponent(); if (newNode == null) return; if (newNode == displayNode) return; if (displayThread != null) synchronized (displayText) { displayThread.stop = true; } displayNode = newNode; if (displayNode instanceof NodeFile) viewFile(); else if (displayNode instanceof NodeJob) viewJob(); } }); tree.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { int keycode = e.getKeyCode(); if (keycode == KeyEvent.VK_DELETE || keycode == KeyEvent.VK_BACK_SPACE) { delete(); } } }); tree.addTreeWillExpandListener(new TreeWillExpandListener() { public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException { TreePath path = event.getPath(); // TODO: can this ever be null? Object o = path.getLastPathComponent(); if (o instanceof NodeJob) ((NodeJob) o).build(tree); } public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException { } }); tree.addTreeExpansionListener(new TreeExpansionListener() { public void treeExpanded(TreeExpansionEvent event) { Rectangle node = tree.getPathBounds(event.getPath()); Rectangle visible = treePane.getViewport().getViewRect(); visible.height -= node.y - visible.y; visible.y = node.y; tree.repaint(visible); } public void treeCollapsed(TreeExpansionEvent event) { Rectangle node = tree.getPathBounds(event.getPath()); Rectangle visible = treePane.getViewport().getViewRect(); visible.height -= node.y - visible.y; visible.y = node.y; tree.repaint(visible); } }); Thread refreshThread = new Thread() { public void run() { try { // Initial load synchronized (running) { for (MNode n : AppData.runs) running.add(0, new NodeJob(n)); // This should be efficient on a doubly-linked list. for (NodeJob job : running) root.add(job); } EventQueue.invokeLater(new Runnable() { public void run() { model.nodeStructureChanged(root); if (model.getChildCount(root) > 0) tree.setSelectionRow(0); } }); // Periodic refresh to show status of running jobs int shortCycles = 100; // Force full scan on first cycle. while (true) { NodeBase d = displayNode; // Make local copy (atomic action) to prevent it changing from under us if (d instanceof NodeJob) ((NodeJob) d).monitorProgress(RunPanel.this); if (shortCycles++ < 20) { Thread.sleep(1000); continue; } shortCycles = 0; synchronized (running) { Iterator<NodeJob> i = running.iterator(); while (i.hasNext()) { NodeJob job = i.next(); if (job != d) job.monitorProgress(RunPanel.this); if (job.complete >= 1) i.remove(); } } } } catch (InterruptedException e) { } } }; refreshThread.setDaemon(true); refreshThread.start(); displayText = new JTextArea(); displayText.setEditable(false); final JCheckBox chkFixedWidth = new JCheckBox("Fixed-Width Font"); chkFixedWidth.setFocusable(false); chkFixedWidth.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int size = displayText.getFont().getSize(); if (chkFixedWidth.isSelected()) { displayText.setFont(new Font(Font.MONOSPACED, Font.PLAIN, size)); } else { displayText.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, size)); } } }); displayPane.setViewportView(displayText); ActionListener graphListener = new ActionListener() { public void actionPerformed(ActionEvent e) { if (displayNode instanceof NodeFile) { NodeFile nf = (NodeFile) displayNode; if (nf.type == NodeFile.Type.Output || nf.type == NodeFile.Type.Result) { String graphType = e.getActionCommand(); if (displayPane.getViewport().getView() instanceof ChartPanel && displayGraph.equals(graphType)) { viewFile(); displayGraph = ""; } else { if (graphType.equals("Graph")) { Plot plot = new Plot(nf.path.getAbsolutePath()); if (!plot.columns.isEmpty()) displayPane.setViewportView(plot.createGraphPanel()); } else // Raster { Raster raster = new Raster(nf.path.getAbsolutePath(), displayPane.getHeight()); displayPane.setViewportView(raster.createGraphPanel()); } displayGraph = graphType; } } } } }; buttonGraph = new JButton("Graph", ImageUtil.getImage("analysis.gif")); buttonGraph.setFocusable(false); buttonGraph.addActionListener(graphListener); buttonGraph.setActionCommand("Graph"); buttonRaster = new JButton("Raster", ImageUtil.getImage("prnplot.gif")); buttonRaster.setFocusable(false); buttonRaster.addActionListener(graphListener); buttonRaster.setActionCommand("Raster"); Lay.BLtg(this, "C", Lay.SPL(Lay.BL("C", treePane = Lay.sp(tree)), Lay.BL("N", Lay.FL(chkFixedWidth, Lay.FL(buttonGraph, buttonRaster), "hgap=50"), "C", displayPane), "divpixel=250")); setFocusCycleRoot(true); }
From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.BeanInspectorPanel.java
/** Creates new form BeanInspectorPanel */ public BeanInspectorPanel() { initComponents();/*from ww w . java 2 s.com*/ DefaultTreeModel dttm = (DefaultTreeModel) jTree1.getModel(); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); jTree1.setModel(new DefaultTreeModel(root)); jTree1.setCellRenderer(new JBTreeCellRenderer()); //applyI18n(); }
From source file:com.sec.ose.osi.ui.frm.main.identification.JTreeAllFiles.java
public JTreeAllFiles() { codeTreeModel = new CodeTreeModel(CodeTreeAPIWrapper.getCodeTree("")); defaultMutableTreeNode = codeTreeModel.makeTree(); defaultTreeModel = new DefaultTreeModel(defaultMutableTreeNode); this.setModel(defaultTreeModel); this.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); this.setCellRenderer(new MyTreeRenderer()); this.addTreeSelectionListener(new FileSelectionListener()); }
From source file:org.bigtester.ate.model.casestep.RepeatStepExecutionLogger.java
/** * Step in processing./*from ww w . jav a 2 s. co m*/ * * @param event the event */ public void stepInProcessing(RepeatStepInOutEvent event) { //preserve this step initial value for future nested repeatStep case RepeatStep rStep2 = (RepeatStep) event.getSource(); if (null == rStep2) throw GlobalUtils.createInternalError("event of spring for repeatstep"); RepeatStep rStep; try { rStep = (RepeatStep) rStep2.clone(); RepeatStepExecutionLoggerNode newNode = new RepeatStepExecutionLoggerNode(event.getRepeatStepName(), rStep, rStep2); final RepeatStepExecutionLoggerNode currentRepeatStepNode2 = currentRepeatStepNode; if (currentRepeatStepNode2 == null) { DefaultTreeModel repeatStepTree = new DefaultTreeModel(newNode); repeatStepTrees.put(event.getRepeatStepName(), repeatStepTree); currentExecutionTree = repeatStepTrees.get(event.getRepeatStepName()); } else { repeatStepExternalNode = currentRepeatStepNode2; currentRepeatStepNode2.add(newNode); } currentRepeatStepNode = newNode; } catch (CloneNotSupportedException cne) { throw GlobalUtils.createInternalError("preserve repeatstep", cne); } }
From source file:Main.java
private static DefaultTreeModel getTreeModel() { MutableTreeNode root = new DefaultMutableTreeNode("1"); DefaultMutableTreeNode cover = new DefaultMutableTreeNode("A"); cover.insert(new DefaultMutableTreeNode("P"), 0); cover.insert(new DefaultMutableTreeNode("S"), 0); root.insert(cover, 0);/* www . j av a 2 s .com*/ DefaultMutableTreeNode base = new DefaultMutableTreeNode("B"); base.insert(new DefaultMutableTreeNode("S"), 0); base.insert(new DefaultMutableTreeNode("H"), 0); root.insert(base, 0); DefaultTreeModel model = new DefaultTreeModel(root); return model; }
From source file:edu.ucla.stat.SOCR.chart.ChartTree.java
private TreeModel createTreeModel() { DefaultMutableTreeNode root = new DefaultMutableTreeNode("SOCRCharts"); root.add(createPieChartsNode());// ww w. j a v a 2 s .c o m root.add(createBarChartsNode()); root.add(createLineChartsNode()); root.add(createAreaChartsNode()); // root.add(createTimeSeriesChartsNode()); // root.add(createFinancialChartsNode()); // root.add(createXYChartsNode()); // root.add(createMeterChartsNode()); // root.add(createMultipleAxisChartsNode()); // root.add(createCombinedAxisChartsNode()); // root.add(createGanttChartsNode()); root.add(createMiscellaneousChartsNode()); return new DefaultTreeModel(root); }