List of usage examples for javax.swing.tree DefaultTreeModel DefaultTreeModel
@ConstructorProperties({ "root" }) public DefaultTreeModel(TreeNode root)
From source file:org.photovault.swingui.volumetree.VolumeTreeController.java
public VolumeTreeController(AbstractController parent) { super(parent); rootNode = new DefaultMutableTreeNode(); model = new DefaultTreeModel(rootNode); view = new JTree(model); view.setShowsRootHandles(true);//from w w w .j a v a 2 s . com view.setRootVisible(true); view.addTreeWillExpandListener(this); view.addTreeSelectionListener(this); SwingUtilities.invokeLater(new Runnable() { public void run() { initVolumes(); } }); }
From source file:org.sakaiproject.scorm.ui.player.components.ActivityTree.java
protected void bindModel(SessionBean sessionBean) { TreeModel treeModel = sequencingService.getTreeModel(sessionBean); if (null != treeModel) { setModel(new Model((Serializable) treeModel)); isEmpty = false;/*from w w w .j a va 2 s. c om*/ } else { setModel(new Model(new DefaultTreeModel(new DefaultMutableTreeNode()))); } if (!isEmpty && sessionBean != null) { selectNode(sessionBean.getActivityId()); } }
From source file:org.sintef.thingml.FilePanel.java
public FilePanel(final ThingMLPanel editor, final ThingMLFrame frame, File rootF) { this.setLayout(new BorderLayout()); add(new JScrollPane(tree), BorderLayout.CENTER); File root = rootF;//w w w . j av a2s . c o m if (root == null) { JFileChooser filechooser = new JFileChooser(); filechooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); filechooser.setDialogTitle("Select base directory for ThingML files"); File dir = ThingMLSettings.getInstance().get_default_work_dir(); if (dir != null) { filechooser.setSelectedFile(dir); } int returnVal = filechooser.showOpenDialog(null); if (filechooser.getSelectedFile() != null && returnVal == JFileChooser.APPROVE_OPTION) { ThingMLSettings.getInstance().store_default_work_dir(filechooser.getSelectedFile()); root = filechooser.getSelectedFile(); } else { System.exit(0); } } FileFilter fileFilter = new FileFilter() { @Override public boolean accept(File f) { return f.getName().endsWith(".thingml"); } }; final File root2 = root; try { simpleFileManager = new SimpleFileManager(root, fileFilter); } catch (IOException e) { e.printStackTrace(); } tree.setModel(new DefaultTreeModel(simpleFileManager.getDirectoryTree())); simpleFileManager.startMonitoring(); FileMonitor fileMonitor = simpleFileManager.getFileMonitor(); fileMonitor.addClient(this); tree.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { TreePath path = e.getNewLeadSelectionPath(); String file = path.getLastPathComponent().toString(); while (path.getParentPath() != null) { path = path.getParentPath(); file = path.getLastPathComponent() + "/" + file; } if (file.indexOf("/") > -1) { File fileF = new File(root2 + "/" + file.substring(file.indexOf("/"))); if (fileF.isFile()) { try { final InputStream input = new FileInputStream(fileF.getAbsolutePath()); final java.util.List<String> packLines = IOUtils.readLines(input); String content = ""; for (String line : packLines) { content += line + "\n"; } input.close(); editor.loadText(content, fileF); frame.setTitle("ThingML Editor : " + e.getNewLeadSelectionPath().getLastPathComponent().toString()); } catch (Exception ex) { ex.printStackTrace(); } } } } }); }
From source file:org.sintef.thingml.FilePanel.java
@Override public void run() { simpleFileManager.refresh(); tree.setModel(new DefaultTreeModel(simpleFileManager.getDirectoryTree())); }
From source file:org.sleuthkit.autopsy.experimental.autoingest.FileExporterSettingsPanel.java
public FileExporterSettingsPanel(JDialog jDialog) { timeSettings.setFormatForDisplayTime( PickerUtilities.createFormatterFromPatternString("HH:mm:ss", timeSettings.getLocale())); timeSettings.setFormatForMenuTimes(/*ww w . j a va 2 s .c om*/ PickerUtilities.createFormatterFromPatternString("HH:mm", timeSettings.getLocale())); initComponents(); rootNode = new DefaultMutableTreeNode(new Item(ROOTNODE, ROOTNODE, ItemType.RULE_SET)); trRuleList.setModel(new DefaultTreeModel(rootNode)); this.jDialog = jDialog; attributeListModel = (DefaultListModel<String>) lsAttributeList.getModel(); rootDirectoryChooser .setCurrentDirectory(rootDirectoryChooser.getFileSystemView().getParentDirectory(new File("C:\\"))); //NON-NLS rootDirectoryChooser.setAcceptAllFileFilterUsed(false); rootDirectoryChooser.setDialogTitle(NbBundle.getMessage(FileExporterSettingsPanel.class, "FileExporterSettingsPanel.ChooseRootDirectory")); rootDirectoryChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); reportDirectoryChooser.setCurrentDirectory( reportDirectoryChooser.getFileSystemView().getParentDirectory(new File("C:\\"))); //NON-NLS reportDirectoryChooser.setAcceptAllFileFilterUsed(false); reportDirectoryChooser.setDialogTitle(NbBundle.getMessage(FileExporterSettingsPanel.class, "FileExporterSettingsPanel.ChooseReportDirectory")); reportDirectoryChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // Add text prompt to the text box fields TextPrompt textPromptRuleName = new TextPrompt( NbBundle.getMessage(FileExporterSettingsPanel.class, "FileExporterSettingsPanel.RuleName"), tbRuleName); textPromptRuleName.setForeground(Color.LIGHT_GRAY); textPromptRuleName.changeAlpha(0.9f); TextPrompt textPromptRootDirectory = new TextPrompt( NbBundle.getMessage(FileExporterSettingsPanel.class, "FileExporterSettingsPanel.RootDirectory"), tbRootDirectory); textPromptRootDirectory.setForeground(Color.LIGHT_GRAY); textPromptRootDirectory.changeAlpha(0.9f); TextPrompt textPromptReportDirectory = new TextPrompt( NbBundle.getMessage(FileExporterSettingsPanel.class, "FileExporterSettingsPanel.ReportDirectory"), tbReportDirectory); textPromptReportDirectory.setForeground(Color.LIGHT_GRAY); textPromptReportDirectory.changeAlpha(0.9f); TextPrompt textPromptReportAttributeValue = new TextPrompt( NbBundle.getMessage(FileExporterSettingsPanel.class, "FileExporterSettingsPanel.AttributeValue"), tbAttributeValue); textPromptReportAttributeValue.setForeground(Color.LIGHT_GRAY); textPromptReportAttributeValue.changeAlpha(0.9f); for (SizeUnit item : SizeUnit.values()) { comboBoxFileSizeUnits.addItem(item.toString()); } for (RelationalOp item : RelationalOp.values()) { comboBoxFileSizeComparison.addItem(item.getSymbol()); comboBoxAttributeComparison.addItem(item.getSymbol()); } comboBoxValueType.addItem(BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.INTEGER.getLabel()); comboBoxValueType.addItem(BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.LONG.getLabel()); comboBoxValueType.addItem(BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.DOUBLE.getLabel()); comboBoxValueType.addItem(BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.STRING.getLabel()); comboBoxValueType.addItem(BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.DATETIME.getLabel()); comboBoxValueType.addItem(BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.BYTE.getLabel()); comboBoxValueType.addItem(UNSET); load(); trRuleList.setCellRenderer(new DefaultTreeCellRenderer() { private static final long serialVersionUID = 1L; private final ImageIcon ruleSetIcon = new ImageIcon( ImageUtilities.loadImage("org/sleuthkit/autopsy/experimental/images/ruleset-icon.png", false)); private final ImageIcon ruleIcon = new ImageIcon(ImageUtilities .loadImage("org/sleuthkit/autopsy/experimental/images/extracted_content.png", false)); private final ImageIcon sizeIcon = new ImageIcon( ImageUtilities.loadImage("org/sleuthkit/autopsy/experimental/images/file-size-16.png", false)); private final ImageIcon artifactIcon = new ImageIcon( ImageUtilities.loadImage("org/sleuthkit/autopsy/experimental/images/artifact-icon.png", false)); private final ImageIcon mimetypeIcon = new ImageIcon( ImageUtilities.loadImage("org/sleuthkit/autopsy/experimental/images/mime-icon.png", false)); private final ImageIcon otherIcon = new ImageIcon( ImageUtilities.loadImage("org/sleuthkit/autopsy/experimental/images/knownbad-icon.png", false)); @Override public Component getTreeCellRendererComponent(javax.swing.JTree tree, Object value, boolean selected, boolean expanded, boolean isLeaf, int row, boolean focused) { Component component = super.getTreeCellRendererComponent(tree, value, selected, expanded, isLeaf, row, focused); Icon icon; switch (((Item) ((DefaultMutableTreeNode) value).getUserObject()).getItemType()) { case ARTIFACT_CLAUSE: icon = artifactIcon; break; case MIME_TYPE_CLAUSE: icon = mimetypeIcon; break; case RULE: icon = ruleIcon; break; case SIZE_CLAUSE: icon = sizeIcon; break; case RULE_SET: icon = ruleSetIcon; break; default: icon = otherIcon; break; } setIcon(icon); return component; } }); populateMimeTypes(); populateArtifacts(); populateAttributes(); populateRuleTree(); tbRuleName.getDocument().addDocumentListener(new DocumentListener() { @Override public void changedUpdate(DocumentEvent e) { setSaveButton(); } @Override public void removeUpdate(DocumentEvent e) { setSaveButton(); } @Override public void insertUpdate(DocumentEvent e) { setSaveButton(); } }); comboBoxMimeValue.getEditor().getEditorComponent().addFocusListener(new java.awt.event.FocusListener() { @Override public void focusGained(FocusEvent e) { comboBoxMimeValue.showPopup(); comboBoxMimeValue.getEditor().selectAll(); } @Override public void focusLost(FocusEvent e) { // do nothing } }); comboBoxArtifactName.getEditor().getEditorComponent().addFocusListener(new java.awt.event.FocusListener() { @Override public void focusGained(FocusEvent e) { comboBoxArtifactName.showPopup(); comboBoxArtifactName.getEditor().selectAll(); } @Override public void focusLost(FocusEvent e) { // do nothing } }); comboBoxAttributeName.getEditor().getEditorComponent().addFocusListener(new java.awt.event.FocusListener() { @Override public void focusGained(FocusEvent e) { comboBoxAttributeName.showPopup(); comboBoxAttributeName.getEditor().selectAll(); } @Override public void focusLost(FocusEvent e) { // do nothing } }); comboBoxMimeTypeComparison.addItem(RelationalOp.Equals.getSymbol()); comboBoxMimeTypeComparison.addItem(RelationalOp.NotEquals.getSymbol()); treeSelectionModel = trRuleList.getSelectionModel(); defaultTreeModel = (DefaultTreeModel) trRuleList.getModel(); bnDeleteRule.setEnabled(false); String selectedAttribute = comboBoxAttributeName.getSelectedItem().toString(); comboBoxValueType.setSelectedItem(selectedAttribute); localRule = makeRuleFromUserInput(); listSelectionListener = this::lsAttributeListValueChanged; lsAttributeList.addListSelectionListener(listSelectionListener); treeSelectionListener = this::trRuleListValueChanged; trRuleList.addTreeSelectionListener(treeSelectionListener); setDeleteAttributeButton(); setSaveButton(); }
From source file:org.sonar.scanner.protocol.viewer.ScannerReportViewerApp.java
private void loadComponents() { int rootComponentRef = metadata.getRootComponentRef(); Component component = reader.readComponent(rootComponentRef); DefaultMutableTreeNode project = createNode(component); loadChildren(component, project);//from w w w .j av a 2 s . com getComponentTree().setModel(new DefaultTreeModel(project)); }
From source file:org.sonar.scanner.protocol.viewer.ScannerReportViewerApp.java
/** * Initialize the contents of the frame. */// ww w . j a va 2 s. co m private void initialize() { try { for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (Exception e) { // If Nimbus is not available, you can set the GUI to another look and feel. } frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); splitPane = new JSplitPane(); frame.getContentPane().add(splitPane, BorderLayout.CENTER); tabbedPane = new JTabbedPane(JTabbedPane.TOP); tabbedPane.setPreferredSize(new Dimension(500, 7)); splitPane.setRightComponent(tabbedPane); componentDetailsTab = new JScrollPane(); tabbedPane.addTab("Component details", null, componentDetailsTab, null); componentEditor = new JEditorPane(); componentDetailsTab.setViewportView(componentEditor); sourceTab = new JScrollPane(); tabbedPane.addTab("Source", null, sourceTab, null); sourceEditor = createSourceEditor(); sourceEditor.setEditable(false); sourceTab.setViewportView(sourceEditor); textLineNumber = createTextLineNumber(); sourceTab.setRowHeaderView(textLineNumber); highlightingTab = new JScrollPane(); tabbedPane.addTab("Highlighting", null, highlightingTab, null); highlightingEditor = new JEditorPane(); highlightingTab.setViewportView(highlightingEditor); symbolTab = new JScrollPane(); tabbedPane.addTab("Symbol references", null, symbolTab, null); symbolEditor = new JEditorPane(); symbolTab.setViewportView(symbolEditor); coverageTab = new JScrollPane(); tabbedPane.addTab("Coverage", null, coverageTab, null); coverageEditor = new JEditorPane(); coverageTab.setViewportView(coverageEditor); duplicationTab = new JScrollPane(); tabbedPane.addTab("Duplications", null, duplicationTab, null); duplicationEditor = new JEditorPane(); duplicationTab.setViewportView(duplicationEditor); testsTab = new JScrollPane(); tabbedPane.addTab("Tests", null, testsTab, null); testsEditor = new JEditorPane(); testsTab.setViewportView(testsEditor); issuesTab = new JScrollPane(); tabbedPane.addTab("Issues", null, issuesTab, null); issuesEditor = new JEditorPane(); issuesTab.setViewportView(issuesEditor); measuresTab = new JScrollPane(); tabbedPane.addTab("Measures", null, measuresTab, null); measuresEditor = new JEditorPane(); measuresTab.setViewportView(measuresEditor); scmTab = new JScrollPane(); tabbedPane.addTab("SCM", null, scmTab, null); scmEditor = new JEditorPane(); scmTab.setViewportView(scmEditor); activeRuleTab = new JScrollPane(); tabbedPane.addTab("ActiveRules", null, activeRuleTab, null); activeRuleEditor = new JEditorPane(); activeRuleTab.setViewportView(activeRuleEditor); treeScrollPane = new JScrollPane(); treeScrollPane.setPreferredSize(new Dimension(200, 400)); splitPane.setLeftComponent(treeScrollPane); componentTree = new JTree(); componentTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("empty") { { } })); treeScrollPane.setViewportView(componentTree); componentTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); componentTree.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) componentTree.getLastSelectedPathComponent(); if (node == null) { // Nothing is selected. return; } frame.setCursor(new Cursor(Cursor.WAIT_CURSOR)); updateDetails((Component) node.getUserObject()); frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } }); frame.pack(); }
From source file:org.tellervo.desktop.tridasv2.ui.ComponentViewer.java
private void setupTree() { treeModel = new DefaultTreeModel(null); tree = new JTree(treeModel); tree.setCellRenderer(new ComponentTreeCellRenderer()); // popup menu tree.addMouseListener(new PopupListener() { @Override/* w w w. j av a 2 s. co m*/ public void showPopup(MouseEvent e) { TreePath path = tree.getPathForLocation(e.getX(), e.getY()); DefaultMutableTreeNode node = (path == null) ? null : (DefaultMutableTreeNode) path.getLastPathComponent(); if (node == null) return; // ensure we select the node... tree.setSelectionPath(path); // get the element Element element = (Element) node.getUserObject(); // create and show the menu JPopupMenu popup = new ElementListPopupMenu(element, ComponentViewer.this); popup.show(tree, e.getX(), e.getY()); } }); ToolTipManager.sharedInstance().setInitialDelay(0); tree.setToolTipText(""); }
From source file:org.tellervo.desktop.tridasv2.ui.ComponentViewerOld.java
private void setupTree() { treeModel = new DefaultTreeModel(null); tree = new JTree(treeModel); tree.setCellRenderer(new ComponentTreeCellRenderer()); // popup menu tree.addMouseListener(new PopupListener() { @Override/*w ww . ja v a2 s . co m*/ public void showPopup(MouseEvent e) { TreePath path = tree.getPathForLocation(e.getX(), e.getY()); DefaultMutableTreeNode node = (path == null) ? null : (DefaultMutableTreeNode) path.getLastPathComponent(); if (node == null) return; // ensure we select the node... tree.setSelectionPath(path); // get the element Element element = (Element) node.getUserObject(); // create and show the menu JPopupMenu popup = new ElementListPopupMenu(element, ComponentViewerOld.this); popup.show(tree, e.getX(), e.getY()); } }); ToolTipManager.sharedInstance().setInitialDelay(0); tree.setToolTipText(""); }
From source file:org.wings.STree.java
/** * Creates and returns a sample TreeModel. Used primarily for beanbuilders. * to show something interesting.// w w w . jav a 2 s .co m * * @return the default TreeModel */ protected static TreeModel getDefaultTreeModel() { DefaultMutableTreeNode root = new DefaultMutableTreeNode("STree"); DefaultMutableTreeNode parent; parent = new DefaultMutableTreeNode("colors"); root.add(parent); parent.add(new DefaultMutableTreeNode("blue")); parent.add(new DefaultMutableTreeNode("violet")); parent.add(new DefaultMutableTreeNode("red")); parent.add(new DefaultMutableTreeNode("yellow")); parent = new DefaultMutableTreeNode("sports"); root.add(parent); parent.add(new DefaultMutableTreeNode("basketball")); parent.add(new DefaultMutableTreeNode("soccer")); parent.add(new DefaultMutableTreeNode("football")); parent.add(new DefaultMutableTreeNode("hockey")); parent = new DefaultMutableTreeNode("food"); root.add(parent); parent.add(new DefaultMutableTreeNode("hot dogs")); parent.add(new DefaultMutableTreeNode("pizza")); parent.add(new DefaultMutableTreeNode("ravioli")); parent.add(new DefaultMutableTreeNode("bananas")); return new DefaultTreeModel(root); }