List of usage examples for javax.swing JTree setCellRenderer
@BeanProperty(description = "The TreeCellRenderer that will be used to draw each cell.") public void setCellRenderer(TreeCellRenderer x)
TreeCellRenderer
that will be used to draw each cell. From source file:de.codesourcery.jasm16.ide.ui.views.WorkspaceExplorer.java
private JPanel createPanel() { treeModel = createTreeModel();/*from ww w . ja va 2 s.c om*/ tree.setModel(treeModel); setColors(tree); tree.setRootVisible(false); // for (int i = 0; i < tree.getRowCount(); i++) { // tree.expandRow(i); // } tree.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_DELETE) { final WorkspaceTreeNode selection = getSelectedNode(); if (selection != null) { deleteResource(selection); } } else if (e.getKeyCode() == KeyEvent.VK_F5) { refreshWorkspace(null); } } }); tree.addMouseListener(new MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { final TreePath path = tree.getPathForLocation(e.getX(), e.getY()); if (path != null) { final WorkspaceTreeNode selected = (WorkspaceTreeNode) path.getLastPathComponent(); final IAssemblyProject project = getProject(selected); try { if (project != null) { onTreeNodeLeftClick(project, selected); } else { System.err.println("Unable to locate project for " + selected); } } catch (IOException e1) { LOG.error("mouseClicked(): Internal error", e1); } } } } }); final TreeSelectionListener selectionListener = new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { } }; tree.getSelectionModel().addTreeSelectionListener(selectionListener); tree.setCellRenderer(new DefaultTreeCellRenderer() { public Color getTextSelectionColor() { return Color.GREEN; }; public java.awt.Color getTextNonSelectionColor() { return Color.GREEN; }; public Color getBackgroundSelectionColor() { return Color.BLACK; }; public Color getBackgroundNonSelectionColor() { return Color.BLACK; }; public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { java.awt.Component result = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); String label = value.toString(); Color color = getTextColor(); if (value instanceof WorkspaceTreeNode) { if (value instanceof ProjectNode) { final ProjectNode projectNode = (ProjectNode) value; final IAssemblyProject project = projectNode.getValue(); label = project.getName(); if (project.isClosed()) { color = Color.LIGHT_GRAY; } else { if (projectNode.hasCompilationErrors()) { color = Color.RED; } } } else if (value instanceof FileNode) { FileNode fn = (FileNode) value; label = fn.getValue().getName(); switch (fn.type) { case DIRECTORY: if (fn.hasCompilationErrors()) { color = Color.RED; } break; case OBJECT_FILE: label = "[O] " + label; break; case EXECUTABLE: label = "[E] " + label; break; case SOURCE_CODE: label = "[S] " + label; if (fn.hasCompilationErrors()) { color = Color.RED; } break; default: // ok } } } setForeground(color); setText(label); return result; }; }); setupPopupMenu(); final JScrollPane pane = new JScrollPane(tree); setColors(pane); final JPanel result = new JPanel(); result.setLayout(new GridBagLayout()); GridBagConstraints cnstrs = constraints(0, 0, true, true, GridBagConstraints.BOTH); setColors(result); result.add(pane, cnstrs); return result; }
From source file:base.BasePlayer.AddGenome.java
public AddGenome() { super(new BorderLayout()); makeGenomes();/*from w w w . j a v a 2 s .c o m*/ tree = new JTree(root); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); sizeError.setForeground(Draw.redColor); sizeError.setVisible(true); treemodel = (DefaultTreeModel) tree.getModel(); remscroll = new JScrollPane(remtable); tree.setCellRenderer(new DefaultTreeCellRenderer() { private static final long serialVersionUID = 1L; private Icon collapsedIcon = UIManager.getIcon("Tree.collapsedIcon"); private Icon expandedIcon = UIManager.getIcon("Tree.expandedIcon"); // private Icon leafIcon = UIManager.getIcon("Tree.leafIcon"); private Icon addIcon = UIManager.getIcon("Tree.closedIcon"); // private Icon saveIcon = UIManager.getIcon("OptionPane.informationIcon"); @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean isLeaf, int row, boolean focused) { Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, isLeaf, row, focused); if (!isLeaf) { //setFont(getFont().deriveFont(Font.PLAIN)); if (expanded) { setIcon(expandedIcon); } else { setIcon(collapsedIcon); } /* if(((DefaultMutableTreeNode) value).getUserObject().toString().equals("Annotations")) { this.setFocusable(false); setFont(getFont().deriveFont(Font.BOLD)); setIcon(null); } */ } else { if (((DefaultMutableTreeNode) value).getUserObject().toString().equals("Annotations")) { // setFont(getFont().deriveFont(Font.PLAIN)); setIcon(null); } else if (((DefaultMutableTreeNode) value).getUserObject().toString().startsWith("Add new")) { // setFont(getFont().deriveFont(Font.PLAIN)); setIcon(addIcon); } else { // setFont(getFont().deriveFont(Font.ITALIC)); setIcon(null); // setIcon(leafIcon); } } return c; } }); tree.addMouseListener(this); tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { try { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node == null) return; selectedNode = node; if (node.isLeaf()) { checkUpdates.setEnabled(false); } else { checkUpdates.setEnabled(true); } if (node.toString().startsWith("Add new") || node.toString().equals("Annotations")) { remove.setEnabled(false); } else { remove.setEnabled(true); } genometable.clearSelection(); download.setEnabled(false); } catch (Exception ex) { ex.printStackTrace(); } } }); tree.setToggleClickCount(1); tree.setRootVisible(false); treescroll = new JScrollPane(tree); checkGenomes(); genomeFileText = new JLabel("Select reference fasta-file"); annotationFileText = new JLabel("Select annotation gff3-file"); genomeName = new JTextField("Give name of the genome"); openRef = new JButton("Browse"); openAnno = new JButton("Browse"); add = new JButton("Add"); download = new JButton("Download"); checkEnsembl = new JButton("Ensembl fetch"); checkEnsembl.setMinimumSize(Main.buttonDimension); checkEnsembl.addActionListener(this); getLinks = new JButton("Get file links."); remove = new JButton("Remove"); checkUpdates = new JButton("Check updates"); download.setEnabled(false); getLinks.setEnabled(false); getLinks.addActionListener(this); remove.setEnabled(false); download.addActionListener(this); remove.addActionListener(this); panel.setBackground(Draw.sidecolor); checkUpdates.addActionListener(this); this.setBackground(Draw.sidecolor); frame.getContentPane().setBackground(Draw.sidecolor); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.insets = new Insets(2, 4, 2, 4); c.gridwidth = 2; genometable.setSelectionMode(0); genometable.setShowGrid(false); remtable.setSelectionMode(0); remtable.setShowGrid(false); JScrollPane scroll = new JScrollPane(); scroll.getViewport().setBackground(Color.white); scroll.getViewport().add(genometable); remscroll.getViewport().setBackground(Color.white); genometable.addMouseListener(this); remtable.addMouseListener(this); // panel.add(welcomeLabel,c); // c.gridy++; c.anchor = GridBagConstraints.NORTHWEST; panel.add(new JLabel("Download genome reference and annotation"), c); c.gridx++; c.anchor = GridBagConstraints.NORTHEAST; panel.add(checkEnsembl, c); c.anchor = GridBagConstraints.NORTHWEST; c.weightx = 1; c.weighty = 1; c.fill = GridBagConstraints.BOTH; c.gridx = 0; c.gridy++; //c.fill = GridBagConstraints.NONE; panel.add(scroll, c); c.gridy++; c.fill = GridBagConstraints.NONE; panel.add(download, c); c.gridx = 1; panel.add(sizeError, c); c.gridx = 1; panel.add(getLinks, c); c.gridy++; c.gridx = 0; c.fill = GridBagConstraints.BOTH; panel.add(new JLabel("Add/Remove installed genomes manually"), c); c.gridy++; panel.add(treescroll, c); c.gridy++; c.fill = GridBagConstraints.NONE; c.gridwidth = 1; remove.setMinimumSize(Main.buttonDimension); panel.add(remove, c); c.gridx = 1; panel.add(checkUpdates, c); checkUpdates.setMinimumSize(Main.buttonDimension); checkUpdates.setEnabled(false); c.gridwidth = 2; c.gridx = 0; c.gridy++; try { if (Main.genomeDir != null) { genomedirectory.setText(Main.genomeDir.getCanonicalPath()); } genomedirectory.setEditable(false); genomedirectory.setBackground(Color.white); genomedirectory.setForeground(Color.black); } catch (IOException e1) { e1.printStackTrace(); } panel.add(new JLabel("Genome directory:"), c); c.gridy++; panel.add(genomedirectory, c); /* c.fill = GridBagConstraints.BOTH; c.gridy++; panel.add(new JLabel("Add genome manually"),c); c.gridy++; c.gridwidth = 2; panel.add(new JSeparator(),c); c.gridwidth = 1; c.gridy++; panel.add(genomeFileText, c); c.fill = GridBagConstraints.NONE; c.gridx = 1; panel.add(openRef, c); c.gridx = 0; openRef.addActionListener(this); c.gridy++; panel.add(annotationFileText,c); c.gridx=1; panel.add(openAnno, c); c.gridy++; panel.add(add,c); openAnno.addActionListener(this); add.addActionListener(this); add.setEnabled(false); */ add(panel, BorderLayout.NORTH); if (Main.drawCanvas != null) { setFonts(Main.menuFont); } /* html.append("<a href=http:Homo_sapiens_GRCh37:Ensembl_genes> Homo sapiens GRCh37 with Ensembl</a> or <a href=http:Homo_sapiens_GRCh37:RefSeq_genes>RefSeq</a> gene annotations<br>"); html.append("<a href=http:Homo_sapiens_GRCh38:Ensembl_genes> Homo sapiens GRCh38 with Ensembl</a> or <a href=http:Homo_sapiens_GRCh38:RefSeq_genes>RefSeq</a> gene annotations<br><br>"); html.append("<a href=http:Mus_musculus_GRCm38:Ensembl_genes> Mus musculus GRCm38 with Ensembl</a> or <a href=http:Mus_musculus_GRCm38:RefSeq_genes>RefSeq</a> gene annotations<br>"); html.append("<a href=http:Rattus_norvegicus:Ensembl_genes> Rattus norvegicus with Ensembl gene annotations</a><br>"); html.append("<a href=http:Saccharomyces_cerevisiae:Ensembl_genes> Saccharomyces cerevisiae with Ensembl gene annotation</a><br>"); html.append("<a href=http:Ciona_intestinalis:Ensembl_genes> Ciona intestinalis with Ensembl gene annotation</a><br>"); Object[] row = {"Homo_sapiens_GRCh37"}; Object[] row = {"Homo_sapiens_GRCh38"}; model.addRow(row); /* genomeName.setPreferredSize(new Dimension(300,20)); this.add(genomeName); this.add(new JSeparator()); this.add(openRef); openRef.addActionListener(this); this.add(genomeFileText); this.add(openAnno); openAnno.addActionListener(this); this.add(annotationFileText); this.add(add); add.addActionListener(this); if(annotation) { openRef.setVisible(false); genomeFileText.setVisible(false); genomeName.setEditable(false); } genomeFileText.setEditable(false); annotationFileText.setEditable(false);*/ }
From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java
private JPanel createAParameterBox(final boolean first) { final JLabel runLabel = new JLabel("<html><b>Number of runs:</b> 0</html>"); final JLabel warningLabel = new JLabel(); final JButton closeButton = new JButton(); closeButton.setOpaque(false);/*from w ww .j a v a 2 s.c o m*/ closeButton.setBorder(null); closeButton.setFocusable(false); if (!first) { closeButton.setRolloverIcon(PARAMETER_BOX_REMOVE); closeButton.setRolloverEnabled(true); closeButton.setIcon(RGBGrayFilter.getDisabledIcon(closeButton, PARAMETER_BOX_REMOVE)); closeButton.setActionCommand(ACTIONCOMMAND_REMOVE_BOX); } final JScrollPane treeScrPane = new JScrollPane(); final DefaultMutableTreeNode treeRoot = new DefaultMutableTreeNode(); final JTree tree = new JTree(treeRoot); ToolTipManager.sharedInstance().registerComponent(tree); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.setCellRenderer(new ParameterBoxTreeRenderer()); tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(final TreeSelectionEvent e) { final TreePath selectionPath = tree.getSelectionPath(); boolean success = true; if (editedNode != null && (selectionPath == null || !editedNode.equals(selectionPath.getLastPathComponent()))) success = modify(); if (success) { if (selectionPath != null) { cancelAllSelectionBut(tree); final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath .getLastPathComponent(); if (!node.equals(editedNode)) { ParameterInATree userObj = null; final DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); if (!node.isRoot() && selectionPath.getPathCount() == model.getPathToRoot(node).length) { userObj = (ParameterInATree) node.getUserObject(); final ParameterInfo info = userObj.info; editedNode = node; editedTree = tree; edit(info); } else { tree.setSelectionPath(null); if (cancelButton.isEnabled()) cancelButton.doClick(); resetSettings(); enableDisableSettings(false); editedNode = null; editedTree = null; } updateDescriptionField(userObj); } else updateDescriptionField(); } else updateDescriptionField(); enableDisableParameterCombinationButtons(); } else { final DefaultTreeModel model = (DefaultTreeModel) editedTree.getModel(); final DefaultMutableTreeNode storedEditedNode = editedNode; editedNode = null; tree.setSelectionPath(null); editedNode = storedEditedNode; editedTree.setSelectionPath(new TreePath(model.getPathToRoot(editedNode))); } } }); treeScrPane.setViewportView(tree); treeScrPane.setBorder(null); treeScrPane.setViewportBorder(null); treeScrPane.setPreferredSize(new Dimension(450, 250)); final JButton upButton = new JButton(); upButton.setOpaque(false); upButton.setRolloverEnabled(true); upButton.setIcon(PARAMETER_UP_ICON); upButton.setRolloverIcon(PARAMETER_UP_ICON_RO); upButton.setDisabledIcon(PARAMETER_UP_ICON_DIS); upButton.setBorder(null); upButton.setToolTipText("Move up the selected parameter"); upButton.setActionCommand(ACTIONCOMMAND_MOVE_UP); final JButton downButton = new JButton(); downButton.setOpaque(false); downButton.setRolloverEnabled(true); downButton.setIcon(PARAMETER_DOWN_ICON); downButton.setRolloverIcon(PARAMETER_DOWN_ICON_RO); downButton.setDisabledIcon(PARAMETER_DOWN_ICON_DIS); downButton.setBorder(null); downButton.setToolTipText("Move down the selected parameter"); downButton.setActionCommand(ACTIONCOMMAND_MOVE_DOWN); final JPanel mainPanel = FormsUtils.build("~ f:p:g ~ p ~ r:p", "012||" + "333||" + "44_||" + "445||" + "446||" + "44_ f:p:g", runLabel, first ? "" : warningLabel, first ? warningLabel : closeButton, new FormsUtils.Separator(""), treeScrPane, upButton, downButton) .getPanel(); mainPanel.setBorder(BorderFactory.createTitledBorder("")); final JButton addButton = new JButton(); addButton.setOpaque(false); addButton.setRolloverEnabled(true); addButton.setIcon(PARAMETER_ADD_ICON); addButton.setRolloverIcon(PARAMETER_ADD_ICON_RO); addButton.setDisabledIcon(PARAMETER_ADD_ICON_DIS); addButton.setBorder(null); addButton.setToolTipText("Add selected parameter"); addButton.setActionCommand(ACTIONCOMMAND_ADD_PARAM); final JButton removeButton = new JButton(); removeButton.setOpaque(false); removeButton.setRolloverEnabled(true); removeButton.setIcon(PARAMETER_REMOVE_ICON); removeButton.setRolloverIcon(PARAMETER_REMOVE_ICON_RO); removeButton.setDisabledIcon(PARAMETER_REMOVE_ICON_DIS); removeButton.setBorder(null); removeButton.setToolTipText("Remove selected parameter"); removeButton.setActionCommand(ACTIONCOMMAND_REMOVE_PARAM); final JPanel result = FormsUtils.build("p ~ f:p:g", "_0 f:p:g||" + "10 p ||" + "20 p||" + "_0 f:p:g", mainPanel, addButton, removeButton).getPanel(); Style.registerCssClasses(result, Dashboard.CSS_CLASS_COMMON_PANEL); final ParameterCombinationGUI pcGUI = new ParameterCombinationGUI(tree, treeRoot, runLabel, warningLabel, addButton, removeButton, upButton, downButton); parameterTreeBranches.add(pcGUI); final ActionListener boxActionListener = new ActionListener() { //==================================================================================================== // methods //---------------------------------------------------------------------------------------------------- public void actionPerformed(final ActionEvent e) { final String cmd = e.getActionCommand(); if (ACTIONCOMMAND_ADD_PARAM.equals(cmd)) handleAddParameter(pcGUI); else if (ACTIONCOMMAND_REMOVE_PARAM.equals(cmd)) handleRemoveParameter(tree); else if (ACTIONCOMMAND_REMOVE_BOX.equals(cmd)) handleRemoveBox(tree); else if (ACTIONCOMMAND_MOVE_UP.equals(cmd)) handleMoveUp(); else if (ACTIONCOMMAND_MOVE_DOWN.equals(cmd)) handleMoveDown(); } //---------------------------------------------------------------------------------------------------- private void handleAddParameter(final ParameterCombinationGUI pcGUI) { final Object[] selectedValues = parameterList.getSelectedValues(); if (selectedValues != null && selectedValues.length > 0) { final AvailableParameter[] params = new AvailableParameter[selectedValues.length]; System.arraycopy(selectedValues, 0, params, 0, selectedValues.length); addParameterToTree(params, pcGUI); enableDisableParameterCombinationButtons(); } } //---------------------------------------------------------------------------------------------------- private void handleRemoveParameter(final JTree tree) { final TreePath selectionPath = tree.getSelectionPath(); if (selectionPath != null) { cancelButton.doClick(); final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath .getLastPathComponent(); if (!node.isRoot()) { final DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent(); if (parentNode.isRoot()) { removeParameter(tree, node, parentNode); enableDisableParameterCombinationButtons(); } } } } //---------------------------------------------------------------------------------------------------- private void handleRemoveBox(final JTree tree) { final int answer = Utilities.askUser(dashboard, false, "Comfirmation", "This operation deletes the combination.", "All related parameter returns back to the list on the left side.", "Are you sure?"); if (answer == 1) { final DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel(); if (tree.getSelectionCount() > 0) { editedNode = null; tree.setSelectionPath(null); if (cancelButton.isEnabled()) cancelButton.doClick(); } final DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel.getRoot(); for (int i = 0; i < root.getChildCount(); ++i) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) root.getChildAt(i); removeParameter(tree, node, root); } enableDisableParameterCombinationButtons(); parameterTreeBranches.remove(pcGUI); combinationsPanel.remove(result); combinationsPanel.revalidate(); updateNumberOfRuns(); } } //---------------------------------------------------------------------------------------------------- private void removeParameter(final JTree tree, final DefaultMutableTreeNode node, final DefaultMutableTreeNode parentNode) { final ParameterInATree userObj = (ParameterInATree) node.getUserObject(); final ParameterInfo originalInfo = findOriginalInfo(userObj.info); if (originalInfo != null) { final DefaultListModel model = (DefaultListModel) parameterList.getModel(); model.addElement(new AvailableParameter(originalInfo, currentModelHandler.getModelClass())); final DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel(); treeModel.removeNodeFromParent(node); updateNumberOfRuns(); tree.expandPath(new TreePath(treeModel.getPathToRoot(parentNode))); } else throw new IllegalStateException( "Parameter " + userObj.info.getName() + " is not found in the model."); } //---------------------------------------------------------------------------------------------------- private void handleMoveUp() { final TreePath selectionPath = tree.getSelectionPath(); if (selectionPath != null) { boolean success = true; if (editedNode != null) success = modify(); if (success) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath .getLastPathComponent(); final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); if (parent == null || parent.getFirstChild().equals(node)) { tree.setSelectionPath(null); // we need this to preserve the state of the parameter settings panel tree.setSelectionPath(new TreePath(node.getPath())); return; } final int index = parent.getIndex(node); final DefaultTreeModel treemodel = (DefaultTreeModel) tree.getModel(); treemodel.removeNodeFromParent(node); treemodel.insertNodeInto(node, parent, index - 1); tree.setSelectionPath(new TreePath(node.getPath())); } } } //---------------------------------------------------------------------------------------------------- private void handleMoveDown() { final TreePath selectionPath = tree.getSelectionPath(); if (selectionPath != null) { boolean success = true; if (editedNode != null) success = modify(); if (success) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath .getLastPathComponent(); final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); if (parent == null || parent.getLastChild().equals(node)) { tree.setSelectionPath(null); // we need this to preserve the state of the parameter settings panel tree.setSelectionPath(new TreePath(node.getPath())); return; } final int index = parent.getIndex(node); final DefaultTreeModel treemodel = (DefaultTreeModel) tree.getModel(); treemodel.removeNodeFromParent(node); treemodel.insertNodeInto(node, parent, index + 1); tree.setSelectionPath(new TreePath(node.getPath())); } } } }; GUIUtils.addActionListener(boxActionListener, closeButton, upButton, downButton, addButton, removeButton); result.setPreferredSize(new Dimension(500, 250)); enableDisableParameterCombinationButtons(); Style.apply(result, dashboard.getCssStyle()); return result; }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
private void resetTrees(int fontSize) { int rowHeight = 0; if (fontSize < 14) { currentIconDirectory = "icons/16/"; rowHeight = 16;/* w w w . j a va 2 s . com*/ } else if (fontSize < 18) { currentIconDirectory = "icons/24/"; rowHeight = 24; } else if (fontSize < 22) { currentIconDirectory = "icons/32/"; rowHeight = 32; } else if (fontSize < 26) { currentIconDirectory = "icons/48/"; rowHeight = 48; } else if (fontSize < 30) { currentIconDirectory = "icons/64/"; rowHeight = 64; } else { currentIconDirectory = "icons/128/"; rowHeight = 128; } for (JTree tree : trees) { tree.setRowHeight(rowHeight); tree.setCellRenderer(new IconRenderer(currentIconDirectory)); DepositTreeEditor editor = (DepositTreeEditor) tree.getCellEditor(); editor.setStandardFont(standardFont); } }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
private void addTreeSelectionListener(JTree theTree) { if (theTree == null) { return;/*from w w w .j ava 2 s .c o m*/ } trees.add(theTree); theTree.setCellEditor(new DepositTreeEditor(theTree, new DefaultTreeCellRenderer(), new DefaultCellEditor( new TreeEditorField(applicationProperties.getApplicationData().getMaximumStructureLength())))); theTree.setUI(new CustomTreeUI()); theTree.setCellRenderer(new IconRenderer(currentIconDirectory)); theTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() { public void valueChanged(javax.swing.event.TreeSelectionEvent evt) { treeValueChanged(evt); } }); }
From source file:org.apache.jmeter.gui.MainFrame.java
/** * Create and initialize the GUI representation of the test tree. * * @param treeModel/* w w w .j a v a2 s.c om*/ * the test tree model * @param treeListener * the test tree listener * * @return the initialized test tree GUI */ private JTree makeTree(TreeModel treeModel, JMeterTreeListener treeListener) { JTree treevar = new JTree(treeModel) { private static final long serialVersionUID = 240L; @Override public String getToolTipText(MouseEvent event) { TreePath path = this.getPathForLocation(event.getX(), event.getY()); if (path != null) { Object treeNode = path.getLastPathComponent(); if (treeNode instanceof DefaultMutableTreeNode) { Object testElement = ((DefaultMutableTreeNode) treeNode).getUserObject(); if (testElement instanceof TestElement) { String comment = ((TestElement) testElement).getComment(); if (comment != null && comment.length() > 0) { return comment; } } } } return null; } }; treevar.setToolTipText(""); treevar.setCellRenderer(getCellRenderer()); treevar.setRootVisible(false); treevar.setShowsRootHandles(true); treeListener.setJTree(treevar); treevar.addTreeSelectionListener(treeListener); treevar.addMouseListener(treeListener); treevar.addKeyListener(treeListener); // enable drag&drop, install a custom transfer handler treevar.setDragEnabled(true); treevar.setDropMode(DropMode.ON_OR_INSERT); treevar.setTransferHandler(new JMeterTreeTransferHandler()); addQuickComponentHotkeys(treevar); return treevar; }
From source file:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultTreeView.java
@Override public void refreshView(final ViewState state) { Rectangle visibleRect = null; if (this.tree != null) { visibleRect = this.tree.getVisibleRect(); }/*from ww w.j a v a2s . c o m*/ this.removeAll(); this.actionsMenu = this.createPopupMenu(state); DefaultMutableTreeNode root = new DefaultMutableTreeNode("WORKFLOWS"); for (ModelGraph graph : state.getGraphs()) { root.add(this.buildTree(graph, state)); } tree = new JTree(root); tree.setShowsRootHandles(true); tree.setRootVisible(false); tree.add(this.actionsMenu); if (state.getSelected() != null) { // System.out.println("SELECTED: " + state.getSelected()); TreePath treePath = this.getTreePath(root, state.getSelected()); if (state.getCurrentMetGroup() != null) { treePath = this.getTreePath(treePath, state); } else if (Boolean.parseBoolean(state.getFirstPropertyValue(EXPAND_STATIC_METADATA))) { DefaultMutableTreeNode baseNode = (DefaultMutableTreeNode) treePath.getLastPathComponent(); for (int i = 0; i < baseNode.getChildCount(); i++) { if (((DefaultMutableTreeNode) baseNode.getChildAt(i)).getUserObject() .equals("static-metadata")) { treePath = new TreePath(((DefaultMutableTreeNode) baseNode.getChildAt(i)).getPath()); break; } } } else if (Boolean.parseBoolean(state.getFirstPropertyValue(EXPAND_PRECONDITIONS))) { if (treePath == null) { treePath = this.getTreePath(root, state.getSelected().getPreConditions()); } DefaultMutableTreeNode baseNode = (DefaultMutableTreeNode) treePath.getLastPathComponent(); for (int i = 0; i < baseNode.getChildCount(); i++) { if (((DefaultMutableTreeNode) baseNode.getChildAt(i)).getUserObject() .equals("pre-conditions")) { treePath = new TreePath(((DefaultMutableTreeNode) baseNode.getChildAt(i)).getPath()); break; } } } else if (Boolean.parseBoolean(state.getFirstPropertyValue(EXPAND_POSTCONDITIONS))) { if (treePath == null) { treePath = this.getTreePath(root, state.getSelected().getPostConditions()); } DefaultMutableTreeNode baseNode = (DefaultMutableTreeNode) treePath.getLastPathComponent(); for (int i = 0; i < baseNode.getChildCount(); i++) { if (((DefaultMutableTreeNode) baseNode.getChildAt(i)).getUserObject() .equals("post-conditions")) { treePath = new TreePath(((DefaultMutableTreeNode) baseNode.getChildAt(i)).getPath()); break; } } } this.tree.expandPath(treePath); this.tree.setSelectionPath(treePath); } tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { if (e.getPath().getLastPathComponent() instanceof DefaultMutableTreeNode) { DefaultTreeView.this.resetProperties(state); DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent(); if (node.getUserObject() instanceof ModelGraph) { state.setSelected((ModelGraph) node.getUserObject()); state.setCurrentMetGroup(null); DefaultTreeView.this.notifyListeners(); } else if (node.getUserObject().equals("static-metadata") || node.getUserObject().equals("pre-conditions") || node.getUserObject().equals("post-conditions")) { state.setSelected((ModelGraph) ((DefaultMutableTreeNode) node.getParent()).getUserObject()); state.setCurrentMetGroup(null); state.setProperty(EXPAND_STATIC_METADATA, Boolean.toString(node.getUserObject().equals("static-metadata"))); state.setProperty(EXPAND_PRECONDITIONS, Boolean.toString(node.getUserObject().equals("pre-conditions"))); state.setProperty(EXPAND_POSTCONDITIONS, Boolean.toString(node.getUserObject().equals("post-conditions"))); DefaultTreeView.this.notifyListeners(); } else if (node.getUserObject() instanceof ConcurrentHashMap) { DefaultMutableTreeNode metNode = null; String group = null; Object[] path = e.getPath().getPath(); for (int i = path.length - 1; i >= 0; i--) { if (((DefaultMutableTreeNode) path[i]).getUserObject() instanceof ModelGraph) { metNode = (DefaultMutableTreeNode) path[i]; break; } else if (((DefaultMutableTreeNode) path[i]) .getUserObject() instanceof ConcurrentHashMap) { if (group == null) { group = (String) ((ConcurrentHashMap<String, String>) ((DefaultMutableTreeNode) path[i]) .getUserObject()).keySet().iterator().next(); } else { group = (String) ((ConcurrentHashMap<String, String>) ((DefaultMutableTreeNode) path[i]) .getUserObject()).keySet().iterator().next() + "/" + group; } } } ModelGraph graph = (ModelGraph) metNode.getUserObject(); state.setSelected(graph); state.setCurrentMetGroup(group); DefaultTreeView.this.notifyListeners(); } else { state.setSelected(null); DefaultTreeView.this.notifyListeners(); } } } }); tree.setCellRenderer(new TreeCellRenderer() { public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; if (node.getUserObject() instanceof String) { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); JLabel label = new JLabel((String) node.getUserObject()); label.setForeground(Color.blue); panel.add(label, BorderLayout.CENTER); panel.setBackground(selected ? Color.lightGray : Color.white); return panel; } else if (node.getUserObject() instanceof ModelGraph) { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); JLabel iconLabel = new JLabel( ((ModelGraph) node.getUserObject()).getModel().getExecutionType() + ": "); iconLabel.setForeground(((ModelGraph) node.getUserObject()).getModel().getColor()); iconLabel.setBackground(Color.white); JLabel idLabel = new JLabel(((ModelGraph) node.getUserObject()).getModel().getModelName()); idLabel.setBackground(Color.white); panel.add(iconLabel, BorderLayout.WEST); panel.add(idLabel, BorderLayout.CENTER); panel.setBackground(selected ? Color.lightGray : Color.white); return panel; } else if (node.getUserObject() instanceof ConcurrentHashMap) { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); String group = (String) ((ConcurrentHashMap<String, String>) node.getUserObject()).keySet() .iterator().next(); JLabel nameLabel = new JLabel(group + " : "); nameLabel.setForeground(Color.blue); nameLabel.setBackground(Color.white); JLabel valueLabel = new JLabel( ((ConcurrentHashMap<String, String>) node.getUserObject()).get(group)); valueLabel.setForeground(Color.darkGray); valueLabel.setBackground(Color.white); panel.add(nameLabel, BorderLayout.WEST); panel.add(valueLabel, BorderLayout.EAST); panel.setBackground(selected ? Color.lightGray : Color.white); return panel; } else { return new JLabel(); } } }); tree.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3 && DefaultTreeView.this.tree.getSelectionPath() != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) DefaultTreeView.this.tree .getSelectionPath().getLastPathComponent(); if (node.getUserObject() instanceof String && !(node.getUserObject().equals("pre-conditions") || node.getUserObject().equals("post-conditions"))) { return; } orderSubMenu.setEnabled(node.getUserObject() instanceof ModelGraph && !((ModelGraph) node.getUserObject()).isCondition() && ((ModelGraph) node.getUserObject()).getParent() != null); DefaultTreeView.this.actionsMenu.show(DefaultTreeView.this.tree, e.getX(), e.getY()); } } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } }); this.scrollPane = new JScrollPane(tree, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); this.add(this.scrollPane, BorderLayout.CENTER); if (visibleRect != null) { this.tree.scrollRectToVisible(visibleRect); } this.revalidate(); }
From source file:org.apache.oodt.cas.workflow.gui.perspective.view.impl.GlobalConfigView.java
@Override public void refreshView(ViewState state) { Rectangle visibleRect = null; if (this.tree != null) { visibleRect = this.tree.getVisibleRect(); }//from w w w .j a va 2 s. c o m DefaultMutableTreeNode root = new DefaultMutableTreeNode("GlobalConfig"); if (state != null && state.getGlobalConfigGroups() != null) { if (globalConfig != null && globalConfig.keySet().equals(state.getGlobalConfigGroups().keySet()) && globalConfig.values().equals(state.getGlobalConfigGroups().values())) { return; } this.removeAll(); for (ConfigGroup group : (globalConfig = state.getGlobalConfigGroups()).values()) { HashSet<String> keys = new HashSet<String>(); DefaultMutableTreeNode groupNode = new DefaultMutableTreeNode(new Group(group.getName())); root.add(groupNode); for (String key : group.getMetadata().getAllKeys()) { keys.add(key); DefaultMutableTreeNode keyNode = new DefaultMutableTreeNode(new Key(key)); groupNode.add(keyNode); DefaultMutableTreeNode valueNode = new DefaultMutableTreeNode( new Value(StringUtils.join(group.getMetadata().getAllMetadata(key), ","))); keyNode.add(valueNode); } if (group.getExtends() != null) { List<String> extendsGroups = new Vector<String>(group.getExtends()); Collections.reverse(extendsGroups); for (String extendsGroup : extendsGroups) { List<String> groupKeys = state.getGlobalConfigGroups().get(extendsGroup).getMetadata() .getAllKeys(); groupKeys.removeAll(keys); if (groupKeys.size() > 0) { for (String key : groupKeys) { if (!keys.contains(key)) { keys.add(key); DefaultMutableTreeNode keyNode = new DefaultMutableTreeNode( new ExtendsKey(extendsGroup, key)); groupNode.add(keyNode); DefaultMutableTreeNode valueNode = new DefaultMutableTreeNode( new ExtendsValue(StringUtils.join(state.getGlobalConfigGroups() .get(extendsGroup).getMetadata().getAllMetadata(key), ","))); keyNode.add(valueNode); } } } } } } tree = new JTree(root); tree.setShowsRootHandles(true); tree.setRootVisible(false); tree.setCellRenderer(new TreeCellRenderer() { public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; if (node.getUserObject() instanceof Key) { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); JLabel label = new JLabel(node.getUserObject().toString()); label.setForeground(Color.darkGray); panel.add(label, BorderLayout.CENTER); panel.setBackground(selected ? Color.lightGray : Color.white); return panel; } else if (node.getUserObject() instanceof ExtendsKey) { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); ExtendsKey key = (ExtendsKey) node.getUserObject(); JLabel groupLabel = new JLabel("(" + key.getGroup() + ") "); groupLabel.setForeground(Color.black); JLabel keyLabel = new JLabel(key.getValue()); keyLabel.setForeground(Color.gray); panel.add(groupLabel, BorderLayout.WEST); panel.add(keyLabel, BorderLayout.CENTER); panel.setBackground(selected ? Color.lightGray : Color.white); return panel; } else if (node.getUserObject() instanceof Group) { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); JLabel label = new JLabel(node.getUserObject().toString()); label.setForeground(Color.black); label.setBackground(Color.white); panel.add(label, BorderLayout.CENTER); panel.setBackground(selected ? Color.lightGray : Color.white); return panel; } else if (node.getUserObject() instanceof Value) { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.setBorder(new EtchedBorder(1)); JLabel label = new JLabel(node.getUserObject().toString()); label.setForeground(Color.black); panel.add(label, BorderLayout.CENTER); panel.setBackground(selected ? Color.lightGray : Color.white); return panel; } else if (node.getUserObject() instanceof ExtendsValue) { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.setBorder(new EtchedBorder(1)); JLabel label = new JLabel(node.getUserObject().toString()); label.setForeground(Color.gray); panel.add(label, BorderLayout.CENTER); panel.setBackground(selected ? Color.lightGray : Color.white); return panel; } else { return new JLabel(); } } }); } this.setBorder(new EtchedBorder()); JLabel panelName = new JLabel("Global-Config Groups"); panelName.setBorder(new EtchedBorder()); this.add(panelName, BorderLayout.NORTH); JScrollPane scrollPane = new JScrollPane(tree, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); tabbedPane = new JTabbedPane(); tabbedPane.addTab("Tree", scrollPane); tabbedPane.addTab("Table", new JPanel()); this.add(tabbedPane, BorderLayout.CENTER); if (visibleRect != null) { this.tree.scrollRectToVisible(visibleRect); } this.revalidate(); }
From source file:org.openmicroscopy.shoola.agents.util.SelectionWizardUI.java
/** * Initializes the specified tree/* w w w .j ava 2 s .co m*/ * * @param tree The tree to handle. * @param user The user currently logged in. */ private void initializeTree(JTree tree, ExperimenterData user) { tree.setVisible(true); tree.setRootVisible(false); ToolTipManager.sharedInstance().registerComponent(tree); tree.setCellRenderer(new TreeCellRenderer(user.getId())); tree.setShowsRootHandles(true); TreeImageSet root = new TreeImageSet(""); tree.setModel(new DefaultTreeModel(root)); }
From source file:org.richie.codeGen.ui.CodeGenMainUI.java
/** * @param list//from ww w . j a v a 2s . c o m * @return */ private JTree initTreeData(List<Table> list) { TableTreeNode root = null; if (list == null || list.size() == 0) { root = new TableTreeNode(""); } else { root = new TableTreeNode(list.get(0).getDataBaseCode() + ":" + list.get(0).getDataBaseName()); for (Table table : list) { list.get(0).getDataBaseName(); TableTreeNode node = new TableTreeNode(table); root.add(node); List<Column> columnList = table.getFields(); for (Column column : columnList) { TableTreeNode columnNode = new TableTreeNode(column); node.add(columnNode); } } } JTree newTree = new JTree(root); newTree.setCellRenderer(new TableTreeRender()); newTree.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent me) { doMouseClicked(me); } }); return newTree; }