List of usage examples for javax.swing.tree DefaultMutableTreeNode DefaultMutableTreeNode
public DefaultMutableTreeNode(Object userObject)
From source file:org.jfree.chart.demo.SuperDemo.java
private MutableTreeNode createOverlaidChartsNode() { DefaultMutableTreeNode defaultmutabletreenode = new DefaultMutableTreeNode("Overlaid Charts"); DefaultMutableTreeNode defaultmutabletreenode1 = new DefaultMutableTreeNode( new DemoDescription("OverlaidBarChartDemo1", "OverlaidBarChartDemo1.java")); DefaultMutableTreeNode defaultmutabletreenode2 = new DefaultMutableTreeNode( new DemoDescription("OverlaidBarChartDemo2", "OverlaidBarChartDemo2.java")); DefaultMutableTreeNode defaultmutabletreenode3 = new DefaultMutableTreeNode( new DemoDescription("OverlaidXYPlotDemo1", "OverlaidXYPlotDemo1.java")); DefaultMutableTreeNode defaultmutabletreenode4 = new DefaultMutableTreeNode( new DemoDescription("OverlaidXYPlotDemo2", "OverlaidXYPlotDemo2.java")); defaultmutabletreenode.add(defaultmutabletreenode1); defaultmutabletreenode.add(defaultmutabletreenode2); defaultmutabletreenode.add(defaultmutabletreenode3); defaultmutabletreenode.add(defaultmutabletreenode4); return defaultmutabletreenode; }
From source file:com.mindcognition.mindraider.ui.swing.trash.TrashJPanel.java
/** * Add notebook node.//from www. j ava 2 s . co m * * @param parent * folder node. * @param uri * notebook URI. * @param label * notebook label. * @return the node. */ public DefaultMutableTreeNode addNotebookNode(DefaultMutableTreeNode parent, String uri, String label) { Object child = label; DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child); // store node to map to be able to get URI from node object treeNodeToResourceUriMap.put(childNode, uri); if (parent == null) { parent = rootNode; } treeModel.insertNodeInto(childNode, parent, parent.getChildCount()); return childNode; }
From source file:edu.harvard.i2b2.query.QueryConceptTreePanel.java
/** This method is called from within the constructor to * initialize the form./*from www .j a v a 2 s . co m*/ */ private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane(); jClearButton = new javax.swing.JButton(); jConstrainButton = new javax.swing.JButton(); jExcludeButton = new javax.swing.JButton(); jOccurrenceButton = new javax.swing.JButton(); jNameLabel = new javax.swing.JLabel(); setLayout(null); QueryConceptTreeNodeData tmpData = new QueryConceptTreeNodeData(); tmpData.name("working ......"); tmpData.tooltip("A root node"); tmpData.visualAttribute("FAO"); top = new DefaultMutableTreeNode(tmpData); //top = new DefaultMutableTreeNode("Root Node"); treeModel = new DefaultTreeModel(top); //treeModel.addTreeModelListener(new MyTreeModelListener()); jTree1 = new JTree(treeModel); jTree1.setEditable(true); //jTree1.getSelectionModel().setSelectionMode // (TreeSelectionModel.SINGLE_TREE_SELECTION); //jTree1.setShowsRootHandles(true); //JScrollPane treeView = new JScrollPane(jTree1); jTree1.setRootVisible(false); jTree1.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); jTree1.setCellRenderer(new MyRenderer()); ToolTipManager.sharedInstance().registerComponent(jTree1); setBorder(javax.swing.BorderFactory.createEtchedBorder()); add(jScrollPane1); //jScrollPane1.setBounds(0, 40, 180, 200); jClearButton.setFont(new java.awt.Font("Tahoma", 1, 11)); jClearButton.setText("X"); jClearButton.setToolTipText("Clear all items from panel"); jClearButton.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); jClearButton.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT); jClearButton.setMargin(new java.awt.Insets(2, 2, 2, 2)); jClearButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jClearButtonActionPerformed(evt); } }); add(jClearButton); jClearButton.setBounds(160, 0, 18, 20); jConstrainButton.setText("Dates"); jConstrainButton.setToolTipText("Constrain group by dates"); jConstrainButton.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT); jConstrainButton.setMargin(new java.awt.Insets(2, 2, 2, 2)); jConstrainButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jConstrainButtonActionPerformed(evt); } }); add(jConstrainButton); jConstrainButton.setBounds(0, 20, 40, 21); jOccurrenceButton.setText("Occurs > 0x"); jOccurrenceButton.setToolTipText("Set occurrence times"); jOccurrenceButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); jOccurrenceButton.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jOccurrenceButton.setMargin(new java.awt.Insets(6, 6, 6, 6)); jOccurrenceButton.setIconTextGap(0); jOccurrenceButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jOccurrenceButtonActionPerformed(evt); } }); add(jOccurrenceButton); jOccurrenceButton.setBounds(40, 20, 90, 21); //jExcludeButton.setMnemonic('E'); jExcludeButton.setText("Exclude"); jExcludeButton.setToolTipText("Exclude all items in group"); jExcludeButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); jExcludeButton.setMargin(new java.awt.Insets(2, 2, 2, 2)); jExcludeButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jExcludeButtonActionPerformed(evt); } }); add(jExcludeButton); jExcludeButton.setBounds(130, 20, 48, 21); jExcludeButton.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); jNameLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jNameLabel.setText("Group 1"); jNameLabel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); jNameLabel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); add(jNameLabel); jNameLabel.setBounds(0, 0, 160, 20); jTree1.addTreeExpansionListener(this); jTree1.setTransferHandler(new TextHandler()); add(jScrollPane1); jScrollPane1.setViewportView(jTree1); //jTree1.setToolTipText("Double click on a folder to view the items inside"); //jScrollPane1.getViewport().setToolTipText("Double click on a folder to view the items inside"); jScrollPane1.setBounds(0, 40, 180, 160); }
From source file:net.sf.taverna.t2.workbench.views.results.processor.RenderedProcessorResultComponent.java
/** * Update the component based on the node selected from the * ResultViewComponent tree.// w w w . j a v a 2 s . co m */ public void updateResult() { if (recognisedRenderersForMimeType == null) recognisedRenderersForMimeType = new ArrayList<>(); if (otherRenderers == null) otherRenderers = new ArrayList<>(); ProcessorResultTreeNode result = (ProcessorResultTreeNode) node; // Reference to the result data path = result.getReference(); // Enable the combo box renderersComboBox.setEnabled(true); /* * Update the 'save result' buttons appropriately as the result node had * changed */ for (int i = 0; i < saveButtonsPanel.getComponents().length; i++) { JButton saveButton = (JButton) saveButtonsPanel.getComponent(i); SaveIndividualResultSPI action = (SaveIndividualResultSPI) (saveButton.getAction()); // Update the action with the new result reference action.setResultReference(path); saveButton.setEnabled(true); } if (DataBundles.isValue(path) || DataBundles.isReference(path)) { // Enable refresh button refreshButton.setEnabled(true); List<MimeType> mimeTypes = new ArrayList<>(); try (InputStream inputstream = RendererUtils.getInputStream(path)) { mimeTypes.addAll(getMimeTypes(inputstream)); } catch (IOException e) { logger.warn("Error getting mimetype", e); } if (mimeTypes.isEmpty()) { // If MIME types is empty - add "plain/text" MIME type mimeTypes.add(new MimeType("text/plain")); } else if (mimeTypes.size() == 1 && mimeTypes.get(0).toString().equals("chemical/x-fasta")) { /* * If MIME type is recognised as "chemical/x-fasta" only then * this might be an error from MIME magic (i.e., sometimes it * recognises stuff that is not "chemical/x-fasta" as * "chemical/x-fasta" and then Seq Vista renderer is used that * causes errors) - make sure we also add the renderers for * "text/plain" and "text/xml" as it is most probably just * normal xml text and push the "chemical/x-fasta" to the bottom * of the list. */ mimeTypes.add(0, new MimeType("text/plain")); mimeTypes.add(1, new MimeType("text/xml")); } for (MimeType mimeType : mimeTypes) for (Renderer renderer : rendererRegistry.getRenderersForMimeType(mimeType.toString())) if (!recognisedRenderersForMimeType.contains(renderer)) recognisedRenderersForMimeType.add(renderer); // if there are no renderers then force text/plain if (recognisedRenderersForMimeType.isEmpty()) recognisedRenderersForMimeType = rendererRegistry.getRenderersForMimeType("text/plain"); /* * Add all other available renderers that are not recognised to be * able to handle the MIME type of the result */ otherRenderers = rendererRegistry.getRenderers(); otherRenderers.removeAll(recognisedRenderersForMimeType); mimeList = new String[recognisedRenderersForMimeType.size() + otherRenderers.size()]; rendererList = new ArrayList<>(); /* * First add the ones that can handle the MIME type of the result * item */ for (int i = 0; i < recognisedRenderersForMimeType.size(); i++) { mimeList[i] = recognisedRenderersForMimeType.get(i).getType(); rendererList.add(recognisedRenderersForMimeType.get(i)); } // Then add the other renderers just in case for (int i = 0; i < otherRenderers.size(); i++) { mimeList[recognisedRenderersForMimeType.size() + i] = otherRenderers.get(i).getType(); rendererList.add(otherRenderers.get(i)); } renderersComboBox.setModel(new DefaultComboBoxModel<>(mimeList)); if (mimeList.length > 0) { int index = 0; // Find the index of the current MIME type for this output port. for (int i = 0; i < mimeList.length; i++) if (mimeList[i].equals(lastUsedMIMEtype)) { index = i; break; } int previousindex = renderersComboBox.getSelectedIndex(); renderersComboBox.setSelectedIndex(index); /* * force rendering as setSelectedIndex will not fire an * itemstatechanged event if previousindex == index and we still * need render the result as we may have switched from a * different result item in a result list but the renderer index * stayed the same */ if (previousindex == index) renderResult(); // draw the rendered result component } } else if (DataBundles.isError(path)) { // Disable refresh button refreshButton.setEnabled(false); @SuppressWarnings("unused") ErrorDocument errorDocument; try { errorDocument = DataBundles.getError(path); } catch (IOException e) { logger.warn("Error getting the error document", e); } // Reset the renderers as we have an error item recognisedRenderersForMimeType = null; otherRenderers = null; DefaultMutableTreeNode root = new DefaultMutableTreeNode("Error Trace"); // TODO handle error documents // ResultsUtils.buildErrorDocumentTree(root, errorDocument, referenceService); JTree errorTree = new JTree(root); errorTree.setCellRenderer(new DefaultTreeCellRenderer() { @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { Component renderer = null; if (value instanceof DefaultMutableTreeNode) { Object userObject = ((DefaultMutableTreeNode) value).getUserObject(); if (userObject instanceof ErrorDocument) renderer = getErrorDocumentRenderer(tree, selected, expanded, leaf, row, hasFocus, (ErrorDocument) userObject); } if (renderer == null) renderer = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); if (renderer instanceof JLabel) { JLabel label = (JLabel) renderer; label.setIcon(null); } return renderer; } private Component getErrorDocumentRenderer(JTree tree, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus, ErrorDocument errorDocument) { return super.getTreeCellRendererComponent(tree, "<html>" + escapeHtml(errorDocument.getMessage()) + "</html>", selected, expanded, leaf, row, hasFocus); } }); renderersComboBox.setModel(new DefaultComboBoxModel<>(new String[] { ERROR_DOCUMENT })); renderedResultPanel.removeAll(); renderedResultPanel.add(errorTree, CENTER); repaint(); } }
From source file:com.mindcognition.mindraider.ui.swing.trash.TrashJPanel.java
/** * Add an child object to a parent object. * * @param parent/*from ww w . j a va 2s . c o m*/ * the parent object. * @param child * the child object. * @param shouldBeVisible * if <code>true</code> the object should be visible. * @return Returns a <code>DefaultMutableTreeNode</code> */ public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent, Object child, boolean shouldBeVisible) { DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child); if (parent == null) { parent = rootNode; } treeModel.insertNodeInto(childNode, parent, parent.getChildCount()); // Make sure the user can see the lovely new node. if (shouldBeVisible) { tree.scrollPathToVisible(new TreePath(childNode.getPath())); } return childNode; }
From source file:wsattacker.plugin.intelligentdos.ui.dialog.Result_NB.java
private TreeModel createModel() { DefaultMutableTreeNode root = new DefaultMutableTreeNode("root"); Set<String> dosAttackNameSet = new HashSet<String>(); Set<Position> elementSet = new HashSet<Position>(); for (SuccessfulAttack sa : attacks) { dosAttackNameSet.add(sa.getDoSAttack().getName()); elementSet.add(sa.getPosition()); }//from w w w . j av a2 s.c o m for (String dosAttackName : dosAttackNameSet) { DefaultMutableTreeNode dn = new DefaultMutableTreeNode(dosAttackName); root.add(dn); // for (Position position : elementSet) { DefaultMutableTreeNode el = new DefaultMutableTreeNode(position); boolean some = false; for (SuccessfulAttack sa : attacks) { if (sa.getDoSAttack().getName().equals(dosAttackName) && sa.getPosition().equals(position)) { DefaultMutableTreeNode attackNode = new DefaultMutableTreeNode(sa); el.add(attackNode); some = true; } } if (some) { dn.add(el); } } } return new DefaultTreeModel(root); }
From source file:edu.harvard.i2b2.patientSet.ui.PatientSetJPanel.java
public DefaultMutableTreeNode addNode(QueryResultData node) { DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(node); QueryResultData tmpData = new QueryResultData(); tmpData.name("working ......"); tmpData.tooltip("A tmp node"); tmpData.visualAttribute("LAO"); tmpData.type("PATIENTSET"); DefaultMutableTreeNode tmpNode = new DefaultMutableTreeNode(tmpData); treeModel.insertNodeInto(childNode, top, top.getChildCount()); if (!(node.visualAttribute().startsWith("L") || node.visualAttribute().equalsIgnoreCase("MA"))) { treeModel.insertNodeInto(tmpNode, childNode, childNode.getChildCount()); }/*from w w w . j a v a 2s.co m*/ jTree1.expandPath(new TreePath(top.getPath())); return childNode; }
From source file:org.jfree.chart.demo.SuperDemo.java
private MutableTreeNode createBarChartsNode() { DefaultMutableTreeNode defaultmutabletreenode = new DefaultMutableTreeNode("Bar Charts"); defaultmutabletreenode.add(createCategoryBarChartsNode()); defaultmutabletreenode.add(createXYBarChartsNode()); return defaultmutabletreenode; }
From source file:edu.ku.brc.specify.tasks.subpane.security.SecurityAdminPane.java
/** * Returns the root of the navigation tree model * @return the root of the navigation tree model *//*from w ww . j a va 2s . c o m*/ private DefaultTreeModel createNavigationTreeModel() { DataProviderSessionIFace session = DataProviderFactory.getInstance().createSession(); DefaultMutableTreeNode root = new DefaultMutableTreeNode(UIRegistry.getAppName()); try { // include all institutions, and inner objects recursively addInstitutionsRecursively(session, root); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SecurityAdminPane.class, ex); throw new RuntimeException(ex); } finally { if (session != null) { session.close(); } } DefaultTreeModel model = new FilteredTreeModel(root, null); return model; }
From source file:org.jfree.chart.demo.SuperDemo.java
private MutableTreeNode createCategoryBarChartsNode() { DefaultMutableTreeNode defaultmutabletreenode = new DefaultMutableTreeNode("CategoryPlot"); DefaultMutableTreeNode defaultmutabletreenode1 = new DefaultMutableTreeNode( new DemoDescription("BarChartDemo1", "BarChartDemo1.java")); DefaultMutableTreeNode defaultmutabletreenode2 = new DefaultMutableTreeNode( new DemoDescription("BarChartDemo2", "BarChartDemo2.java")); DefaultMutableTreeNode defaultmutabletreenode3 = new DefaultMutableTreeNode( new DemoDescription("BarChartDemo3", "BarChartDemo3.java")); DefaultMutableTreeNode defaultmutabletreenode4 = new DefaultMutableTreeNode( new DemoDescription("BarChartDemo4", "BarChartDemo4.java")); DefaultMutableTreeNode defaultmutabletreenode5 = new DefaultMutableTreeNode( new DemoDescription("BarChartDemo5", "BarChartDemo5.java")); DefaultMutableTreeNode defaultmutabletreenode6 = new DefaultMutableTreeNode( new DemoDescription("BarChartDemo6", "BarChartDemo6.java")); DefaultMutableTreeNode defaultmutabletreenode7 = new DefaultMutableTreeNode( new DemoDescription("BarChartDemo7", "BarChartDemo7.java")); DefaultMutableTreeNode defaultmutabletreenode8 = new DefaultMutableTreeNode( new DemoDescription("BarChartDemo8", "BarChartDemo8.java")); DefaultMutableTreeNode defaultmutabletreenode9 = new DefaultMutableTreeNode( new DemoDescription("BarChartDemo9", "BarChartDemo9.java")); DefaultMutableTreeNode defaultmutabletreenode10 = new DefaultMutableTreeNode( new DemoDescription("BarChartDemo10", "BarChartDemo10.java")); DefaultMutableTreeNode defaultmutabletreenode11 = new DefaultMutableTreeNode( new DemoDescription("BarChart3DDemo1", "BarChart3DDemo1.java")); DefaultMutableTreeNode defaultmutabletreenode12 = new DefaultMutableTreeNode( new DemoDescription("BarChart3DDemo2", "BarChart3DDemo2.java")); DefaultMutableTreeNode defaultmutabletreenode13 = new DefaultMutableTreeNode( new DemoDescription("BarChart3DDemo3", "BarChart3DDemo3.java")); DefaultMutableTreeNode defaultmutabletreenode14 = new DefaultMutableTreeNode( new DemoDescription("BarChart3DDemo4", "BarChart3DDemo4.java")); DefaultMutableTreeNode defaultmutabletreenode15 = new DefaultMutableTreeNode( new DemoDescription("CylinderChartDemo1", "CylinderChartDemo1.java")); DefaultMutableTreeNode defaultmutabletreenode16 = new DefaultMutableTreeNode( new DemoDescription("CylinderChartDemo2", "CylinderChartDemo2.java")); DefaultMutableTreeNode defaultmutabletreenode17 = new DefaultMutableTreeNode( new DemoDescription("IntervalBarChartDemo1", "IntervalBarChartDemo1.java")); DefaultMutableTreeNode defaultmutabletreenode18 = new DefaultMutableTreeNode( new DemoDescription("LayeredBarChartDemo1", "LayeredBarChartDemo1.java")); DefaultMutableTreeNode defaultmutabletreenode19 = new DefaultMutableTreeNode( new DemoDescription("LayeredBarChartDemo2", "LayeredBarChartDemo2.java")); DefaultMutableTreeNode defaultmutabletreenode20 = new DefaultMutableTreeNode( new DemoDescription("StackedBarChartDemo1", "StackedBarChartDemo1.java")); DefaultMutableTreeNode defaultmutabletreenode21 = new DefaultMutableTreeNode( new DemoDescription("StackedBarChartDemo2", "StackedBarChartDemo2.java")); DefaultMutableTreeNode defaultmutabletreenode22 = new DefaultMutableTreeNode( new DemoDescription("StackedBarChartDemo3", "StackedBarChartDemo3.java")); DefaultMutableTreeNode defaultmutabletreenode23 = new DefaultMutableTreeNode( new DemoDescription("StackedBarChartDemo4", "StackedBarChartDemo4.java")); DefaultMutableTreeNode defaultmutabletreenode24 = new DefaultMutableTreeNode( new DemoDescription("StackedBarChartDemo5", "StackedBarChartDemo5.java")); DefaultMutableTreeNode defaultmutabletreenode25 = new DefaultMutableTreeNode( new DemoDescription("StackedBarChartDemo6", "StackedBarChartDemo6.java")); DefaultMutableTreeNode defaultmutabletreenode26 = new DefaultMutableTreeNode( new DemoDescription("StackedBarChartDemo7", "StackedBarChartDemo7.java")); DefaultMutableTreeNode defaultmutabletreenode27 = new DefaultMutableTreeNode( new DemoDescription("StatisticalBarChartDemo1", "StatisticalBarChartDemo1.java")); DefaultMutableTreeNode defaultmutabletreenode28 = new DefaultMutableTreeNode( new DemoDescription("SurveyResultsDemo1", "SurveyResultsDemo1.java")); DefaultMutableTreeNode defaultmutabletreenode29 = new DefaultMutableTreeNode( new DemoDescription("SurveyResultsDemo2", "SurveyResultsDemo2.java")); DefaultMutableTreeNode defaultmutabletreenode30 = new DefaultMutableTreeNode( new DemoDescription("SurveyResultsDemo3", "SurveyResultsDemo3.java")); DefaultMutableTreeNode defaultmutabletreenode31 = new DefaultMutableTreeNode( new DemoDescription("WaterfallChartDemo1", "WaterfallChartDemo1.java")); defaultmutabletreenode.add(defaultmutabletreenode1); defaultmutabletreenode.add(defaultmutabletreenode2); defaultmutabletreenode.add(defaultmutabletreenode3); defaultmutabletreenode.add(defaultmutabletreenode4); defaultmutabletreenode.add(defaultmutabletreenode5); defaultmutabletreenode.add(defaultmutabletreenode6); defaultmutabletreenode.add(defaultmutabletreenode7); defaultmutabletreenode.add(defaultmutabletreenode8); defaultmutabletreenode.add(defaultmutabletreenode9); defaultmutabletreenode.add(defaultmutabletreenode10); defaultmutabletreenode.add(defaultmutabletreenode11); defaultmutabletreenode.add(defaultmutabletreenode12); defaultmutabletreenode.add(defaultmutabletreenode13); defaultmutabletreenode.add(defaultmutabletreenode14); defaultmutabletreenode.add(defaultmutabletreenode15); defaultmutabletreenode.add(defaultmutabletreenode16); defaultmutabletreenode.add(defaultmutabletreenode17); defaultmutabletreenode.add(defaultmutabletreenode18); defaultmutabletreenode.add(defaultmutabletreenode19); defaultmutabletreenode.add(defaultmutabletreenode20); defaultmutabletreenode.add(defaultmutabletreenode21); defaultmutabletreenode.add(defaultmutabletreenode22); defaultmutabletreenode.add(defaultmutabletreenode23); defaultmutabletreenode.add(defaultmutabletreenode24); defaultmutabletreenode.add(defaultmutabletreenode25); defaultmutabletreenode.add(defaultmutabletreenode26); defaultmutabletreenode.add(defaultmutabletreenode27); defaultmutabletreenode.add(defaultmutabletreenode28); defaultmutabletreenode.add(defaultmutabletreenode29); defaultmutabletreenode.add(defaultmutabletreenode30); defaultmutabletreenode.add(defaultmutabletreenode31); return defaultmutabletreenode; }