List of usage examples for javax.swing JTree JTree
public JTree()
JTree
with a sample model. From source file:org.openmicroscopy.shoola.agents.treeviewer.util.MoveGroupSelectionDialog.java
/** * Sets the values where to import the data. * /*from w w w .j a va2 s .co m*/ * @param targets The values to display. */ public void setTargets(Collection<DataObject> targets) { Container c = getContentPane(); c.remove(body); c.remove(1); treeDisplay = new JTree(); treeDisplay.setVisible(true); treeDisplay.setRootVisible(false); ToolTipManager.sharedInstance().registerComponent(treeDisplay); treeDisplay.setCellRenderer(new TreeCellRenderer(userID)); treeDisplay.setShowsRootHandles(true); TreeImageSet root = new TreeImageSet(""); treeDisplay.setModel(new DefaultTreeModel(root)); treeDisplay.addTreeSelectionListener(this); if (CollectionUtils.isEmpty(targets)) { buildNoContentPane(); return; } Set<TreeImageDisplay> nodes = TreeViewerTranslator.transformHierarchy(new ArrayList<Object>(targets)); List<TreeImageDisplay> transformedNodes = prepareSortedList(sorter.sort(nodes)); if (transformedNodes.size() == 0) { buildNoContentPane(); return; } DefaultTreeModel dtm = (DefaultTreeModel) treeDisplay.getModel(); buildTreeNode(root, transformedNodes, dtm); dtm.reload(); c.add(new JScrollPane(treeDisplay), BorderLayout.CENTER); c.add(buildToolBar(), BorderLayout.SOUTH); validate(); repaint(); }
From source file:org.openmicroscopy.shoola.agents.util.SelectionWizardUI.java
/** Initializes the components composing the display.*/ private void initComponents() { filterAnywhere = true;//from ww w .j a va 2s . c o m filterArea = new JTextField(); originalColor = filterArea.getForeground(); setTextFieldDefault(DEFAULT_FILTER_TEXT); StringBuilder builder = new StringBuilder(); builder.append("Filter"); if (TagAnnotationData.class.equals(type)) { builder.append(" Tags."); } else if (FileAnnotationData.class.equals(type)) { builder.append(" Attachments."); } else if (DatasetData.class.equals(type)) { builder.append(" Datasets."); } else builder.append("."); filterArea.setToolTipText(builder.toString()); filterArea.getDocument().addDocumentListener(this); filterArea.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent evt) { String value = filterArea.getText(); if (StringUtils.isBlank(value)) { setTextFieldDefault(DEFAULT_FILTER_TEXT); } } @Override public void focusGained(FocusEvent evt) { } }); filterArea.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent evt) { String value = filterArea.getText(); if (DEFAULT_FILTER_TEXT.equals(value)) { setTextFieldDefault(null); } } }); filterArea.addKeyListener(new KeyAdapter() { /** * Adds the items to the selected list. * @see KeyListener#keyPressed(KeyEvent) */ public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER && filterArea.isFocusOwner()) { addItem(); //reset filter setTextFieldDefault(DEFAULT_FILTER_TEXT); availableItemsListbox.requestFocus(); } } }); sorter = new ViewerSorter(); availableItemsListbox = new JTree(); initializeTree(availableItemsListbox, user); availableItemsListbox.addKeyListener(new KeyAdapter() { /** * Adds the items to the selected list. * @see KeyListener#keyPressed(KeyEvent) */ public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER && availableItemsListbox.isFocusOwner()) { addItem(); } } }); availableItemsListbox.addMouseListener(new MouseAdapter() { /** * Adds the items to the selected list. * @see MouseListener#mouseReleased(MouseEvent) */ public void mouseReleased(MouseEvent e) { if (e.getClickCount() == 2) { if (availableItemsListbox.isFocusOwner()) addItem(); } } }); availableItemsListbox.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent evt) { firePropertyChange(AVAILABLE_SELECTION_CHANGE, Boolean.TRUE, Boolean.FALSE); } }); selectedItemsListbox = new JTree(); initializeTree(selectedItemsListbox, user); selectedItemsListbox.addKeyListener(new KeyAdapter() { /** * Removes the selected elements from the selected list. * @see KeyListener#keyPressed(KeyEvent) */ public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER && selectedItemsListbox.isFocusOwner()) { removeItem(); } } }); selectedItemsListbox.addMouseListener(new MouseAdapter() { /** * Removes the selected elements from the selected list. * @see MouseListener#mouseReleased(MouseEvent) */ public void mouseReleased(MouseEvent e) { if (e.getClickCount() == 2) { if (selectedItemsListbox.isFocusOwner()) removeItem(); } } }); IconManager icons = IconManager.getInstance(); addButton = new JButton(icons.getIcon(IconManager.RIGHT_ARROW)); removeButton = new JButton(icons.getIcon(IconManager.LEFT_ARROW)); addAllButton = new JButton(icons.getIcon(IconManager.DOUBLE_RIGHT_ARROW)); removeAllButton = new JButton(icons.getIcon(IconManager.DOUBLE_LEFT_ARROW)); addButton.setActionCommand("" + ADD); addButton.addActionListener(this); addAllButton.setActionCommand("" + ADD_ALL); addAllButton.addActionListener(this); removeButton.setActionCommand("" + REMOVE); removeButton.addActionListener(this); removeAllButton.setActionCommand("" + REMOVE_ALL); removeAllButton.addActionListener(this); setImmutableElements(null); }
From source file:org.parosproxy.paros.view.SiteMapPanel.java
/** * This method initializes treeSite/*from ww w . ja v a 2 s . com*/ * * @return JTree */ public JTree getTreeSite() { if (treeSite == null) { treeSite = new JTree(); treeSite.setShowsRootHandles(true); treeSite.setName("treeSite"); treeSite.setToggleClickCount(1); treeSite.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0) { // ZAP: Select site list item on right click TreePath tp = treeSite.getPathForLocation(e.getPoint().x, e.getPoint().y); if (tp != null) { boolean select = true; // Only select a new item if the current item is not // already selected - this is to allow multiple items // to be selected if (treeSite.getSelectionPaths() != null) { for (TreePath t : treeSite.getSelectionPaths()) { if (t.equals(tp)) { select = false; break; } } } if (select) { treeSite.getSelectionModel().setSelectionPath(tp); } } View.getSingleton().getPopupMenu().show(e.getComponent(), e.getX(), e.getY()); } } }); treeSite.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { HttpMessage msg = null; SiteNode node = (SiteNode) treeSite.getLastSelectedPathComponent(); if (node == null) { return; } if (!node.isRoot()) { try { msg = node.getHistoryReference().getHttpMessage(); } catch (Exception e1) { // ZAP: Log exceptions log.warn(e1.getMessage(), e1); return; } HttpPanel reqPanel = getView().getRequestPanel(); HttpPanel resPanel = getView().getResponsePanel(); reqPanel.setMessage(msg, true); resPanel.setMessage(msg, false); // ZAP: Call SiteMapListenners for (SiteMapListener listener : listenners) { listener.nodeSelected(node); } } } }); } return treeSite; }
From source file:org.pentaho.ui.xul.swing.tags.SwingTree.java
@Override public void layout() { XulComponent primaryColumn = this.getElementByXPath("//treecol[@primary='true']"); //$NON-NLS-1$ XulComponent isaContainer = this.getElementByXPath("treechildren/treeitem[@container='true']"); //$NON-NLS-1$ isHierarchical = (primaryColumn != null) || (isaContainer != null); if (isHierarchical) { tree = new JTree(); if (treeSelectionListener != null) { tree.getSelectionModel().addTreeSelectionListener(treeSelectionListener); }/* w w w. j a v a 2 s . c o m*/ tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { SwingTree.this.changeSupport.firePropertyChange("selectedRows", null, //$NON-NLS-1$ SwingTree.this.getSelectedRows()); SwingTree.this.changeSupport.firePropertyChange("absoluteSelectedRows", null, //$NON-NLS-1$ SwingTree.this.getAbsoluteSelectedRows()); SwingTree.this.fireSelectedItem(); } }); } else { table = new ScrollableJTable(); if (selectionListener != null) { table.getSelectionModel().addListSelectionListener(selectionListener); } table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent event) { if (event.getValueIsAdjusting() == true) { return; } SwingTree.this.changeSupport.firePropertyChange("selectedRows", null, //$NON-NLS-1$ SwingTree.this.getSelectedRows()); SwingTree.this.fireSelectedItem(); } }); } JComponent comp = (table != null ? table : tree); ToolTipManager.sharedInstance().unregisterComponent(comp); if (table != null) { ToolTipManager.sharedInstance().unregisterComponent(table.getTableHeader()); table.setRowHeight(18); scrollpane = new JScrollPane(table); setupTable(); } else { setupTree(); scrollpane = new JScrollPane(tree); } setManagedObject(scrollpane.getViewport()); }
From source file:org.sonar.scanner.protocol.viewer.ScannerReportViewerApp.java
/** * Initialize the contents of the frame. *//* w w w. j a v a 2 s . c om*/ 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:plugin.notes.gui.NotesView.java
/** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor./*w w w . ja v a2 s . c o m*/ */ private void initComponents() { //GEN-BEGIN:initComponents jSplitPane1 = new FlippingSplitPane(); jScrollPane1 = new JScrollPane(); notesTree = new JTree(); jPanel1 = new JPanel(); jScrollPane2 = new JScrollPane(); editor = new JTextPane(); jPanel2 = new JPanel(); fileBar = new JToolBar(); newButton = new JButton(); saveButton = new JButton(); exportButton = new JButton(); revertButton = new JButton(); deleteButton = new JButton(); clipboardBar = new JToolBar(); cutButton = new JButton(); copyButton = new JButton(); pasteButton = new JButton(); formatBar = new JToolBar(); sizeCB = new JComboBox(); boldButton = new JButton(); italicButton = new JButton(); underlineButton = new JButton(); colorButton = new JButton(); bulletButton = new JButton(); enumButton = new JButton(); imageButton = new JButton(); alignmentBar = new JToolBar(); leftJustifyButton = new JButton(); centerJustifyButton = new JButton(); rightJustifyButton = new JButton(); filePane = new JPanel(); fileLeft = new JButton(); fileRight = new JButton(); filesBar = new JToolBar(); setLayout(new java.awt.BorderLayout()); jSplitPane1.setDividerLocation(175); jSplitPane1.setDividerSize(5); jScrollPane1.setViewportView(notesTree); jSplitPane1.setLeftComponent(jScrollPane1); jPanel1.setLayout(new java.awt.BorderLayout()); editor.addCaretListener(this::editorCaretUpdate); jScrollPane2.setViewportView(editor); jPanel1.add(jScrollPane2, java.awt.BorderLayout.CENTER); jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0)); newButton.setIcon(Icons.stock_new.getImageIcon()); newButton.setToolTipText("New Node"); newButton.setBorder(new EtchedBorder()); newButton.setEnabled(false); newButton.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { newButtonActionPerformed(); } }); fileBar.add(newButton); saveButton.setIcon(Icons.stock_save.getImageIcon()); saveButton.setToolTipText("Save Node"); saveButton.setBorder(new EtchedBorder()); saveButton.setEnabled(false); saveButton.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { saveButtonActionPerformed(); } }); fileBar.add(saveButton); exportButton.setIcon(Icons.stock_export.getImageIcon()); exportButton.setToolTipText("Export"); exportButton.setBorder(new EtchedBorder()); exportButton.setEnabled(false); exportButton.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { exportButtonActionPerformed(); } }); fileBar.add(exportButton); revertButton.setIcon(Icons.stock_revert.getImageIcon()); revertButton.setToolTipText("Revert to Saved"); revertButton.setBorder(new EtchedBorder()); revertButton.setEnabled(false); revertButton.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { revertButtonActionPerformed(); } }); fileBar.add(revertButton); deleteButton.setIcon(Icons.stock_broken_image.getImageIcon()); deleteButton.setToolTipText("Delete Node"); deleteButton.setBorder(new EtchedBorder()); deleteButton.setEnabled(false); deleteButton.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { deleteButtonActionPerformed(); } }); fileBar.add(deleteButton); jPanel2.add(fileBar); cutButton.setIcon(Icons.stock_cut.getImageIcon()); cutButton.setToolTipText("Cut"); cutButton.setBorder(new EtchedBorder()); cutButton.addActionListener(this::cutButtonActionPerformed); clipboardBar.add(cutButton); copyButton.setIcon(Icons.stock_copy.getImageIcon()); copyButton.setToolTipText("Copy"); copyButton.setBorder(new EtchedBorder()); copyButton.addActionListener(this::copyButtonActionPerformed); clipboardBar.add(copyButton); pasteButton.setIcon(Icons.stock_paste.getImageIcon()); pasteButton.setToolTipText("Paste"); pasteButton.setBorder(new EtchedBorder()); pasteButton.addActionListener(this::pasteButtonActionPerformed); clipboardBar.add(pasteButton); jPanel2.add(clipboardBar); sizeCB.setToolTipText("Size"); sizeCB.setBorder(new EtchedBorder()); sizeCB.addActionListener(this::sizeCBActionPerformed); formatBar.add(sizeCB); boldButton.setIcon(Icons.stock_text_bold.getImageIcon()); boldButton.setToolTipText("Bold"); boldButton.setBorder(new EtchedBorder()); boldButton.addActionListener(this::boldButtonActionPerformed); formatBar.add(boldButton); italicButton.setIcon(Icons.stock_text_italic.getImageIcon()); italicButton.setToolTipText("Italic"); italicButton.setBorder(new EtchedBorder()); italicButton.addActionListener(this::italicButtonActionPerformed); formatBar.add(italicButton); underlineButton.setIcon(Icons.stock_text_underline.getImageIcon()); underlineButton.setToolTipText("Underline"); underlineButton.setBorder(new EtchedBorder()); underlineButton.addActionListener(this::underlineButtonActionPerformed); formatBar.add(underlineButton); colorButton.setForeground(java.awt.SystemColor.text); colorButton.setIcon(Icons.createImageIcon("menu-mode-RGB-alt.png")); colorButton.setToolTipText("Color"); colorButton.setBorder(new EtchedBorder()); colorButton.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { colorButtonActionPerformed(); } }); formatBar.add(colorButton); bulletButton.setIcon(Icons.stock_list_bulet.getImageIcon()); bulletButton.setToolTipText("Bulleted List"); bulletButton.setAction(actionListUnordered); bulletButton.setBorder(new EtchedBorder()); formatBar.add(bulletButton); enumButton.setIcon(Icons.stock_list_enum.getImageIcon()); enumButton.setToolTipText("Numbered List"); enumButton.setAction(actionListOrdered); enumButton.setBorder(new EtchedBorder()); formatBar.add(enumButton); imageButton.setIcon(Icons.stock_insert_graphic.getImageIcon()); imageButton.setBorder(new EtchedBorder()); imageButton.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { imageButtonActionPerformed(); } }); formatBar.add(imageButton); jPanel2.add(formatBar); leftJustifyButton.setIcon(Icons.stock_text_align_left.getImageIcon()); leftJustifyButton.setToolTipText("Left Justify"); leftJustifyButton.setBorder(new EtchedBorder()); leftJustifyButton.addActionListener(this::leftJustifyButtonActionPerformed); alignmentBar.add(leftJustifyButton); centerJustifyButton.setIcon(Icons.stock_text_align_center.getImageIcon()); centerJustifyButton.setToolTipText("Center"); centerJustifyButton.setBorder(new EtchedBorder()); centerJustifyButton.addActionListener(this::centerJustifyButtonActionPerformed); alignmentBar.add(centerJustifyButton); rightJustifyButton.setIcon(Icons.stock_text_align_right.getImageIcon()); rightJustifyButton.setToolTipText("Right Justify"); rightJustifyButton.setBorder(new EtchedBorder()); rightJustifyButton.addActionListener(this::rightJustifyButtonActionPerformed); alignmentBar.add(rightJustifyButton); jPanel2.add(alignmentBar); jPanel1.add(jPanel2, java.awt.BorderLayout.NORTH); filePane.setLayout(new BoxLayout(filePane, BoxLayout.X_AXIS)); fileLeft.setText("<"); fileLeft.setBorder(new EtchedBorder()); fileLeft.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { fileLeftActionPerformed(); } }); filePane.add(fileLeft); fileRight.setText(">"); fileRight.setBorder(new EtchedBorder()); fileRight.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { fileRightActionPerformed(); } }); filePane.add(fileRight); filePane.add(filesBar); jPanel1.add(filePane, java.awt.BorderLayout.SOUTH); jSplitPane1.setRightComponent(jPanel1); add(jSplitPane1, java.awt.BorderLayout.CENTER); }