use of javax.swing.tree.DefaultTreeCellRenderer in project vcell by virtualcell.
the class MIRIAMAnnotationEditor method getJTreeMIRIAM.
private JTree getJTreeMIRIAM() {
if (jTreeMIRIAM == null) {
try {
DefaultTreeSelectionModel ivjLocalSelectionModel;
ivjLocalSelectionModel = new DefaultTreeSelectionModel();
ivjLocalSelectionModel.setSelectionMode(1);
jTreeMIRIAM = new JTree();
jTreeMIRIAM.setName("JTree1");
jTreeMIRIAM.setToolTipText("");
jTreeMIRIAM.setBounds(0, 0, 357, 405);
jTreeMIRIAM.setMinimumSize(new java.awt.Dimension(100, 72));
jTreeMIRIAM.setSelectionModel(ivjLocalSelectionModel);
jTreeMIRIAM.setRowHeight(0);
// Add cellRenderer
DefaultTreeCellRenderer dtcr = new BioModelCellRenderer(null) {
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
// System.out.println(MIRIAMAnnotationEditor.this.getClass().getName()+".getJTreeMiriam():BioModelCellRenderer "+value.getClass()+" "+
// (value instanceof cbit.vcell.desktop.BioModelNode?
// ((cbit.vcell.desktop.BioModelNode)value).getUserObject().getClass():""));
JLabel component = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
if (value instanceof BioModelNode && ((BioModelNode) value).getUserObject() instanceof Annotation) {
component.setToolTipText("(Double-click to edit notes)");
Annotation annotation = (Annotation) ((BioModelNode) value).getUserObject();
if (annotation.toString() == null || annotation.toString().length() == 0) {
component.setText("(Double-click to edit notes)");
}
}
return component;
}
};
jTreeMIRIAM.setCellRenderer(dtcr);
MouseListener mouseListener = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
super.mouseClicked(e);
TreePath closestMousePath = jTreeMIRIAM.getClosestPathForLocation(e.getPoint().x, e.getPoint().y);
showPopup(e, closestMousePath);
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
super.mouseReleased(e);
TreePath closestMousePath = jTreeMIRIAM.getClosestPathForLocation(e.getPoint().x, e.getPoint().y);
showPopup(e, closestMousePath);
}
public void mousePressed(MouseEvent e) {
TreePath closestMousePath = jTreeMIRIAM.getClosestPathForLocation(e.getPoint().x, e.getPoint().y);
jTreeMIRIAM.setSelectionPath(closestMousePath);
showPopup(e, closestMousePath);
if (e.getClickCount() == 2) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTreeMIRIAM.getLastSelectedPathComponent();
if (node instanceof LinkNode) {
showBrowseToLink((LinkNode) node);
} else if (isNodeFreeHandTextEditable(node)) {
showEditFreehandText(node);
}
}
}
};
jTreeMIRIAM.addMouseListener(mouseListener);
} catch (java.lang.Throwable ivjExc) {
ivjExc.printStackTrace(System.out);
}
}
return jTreeMIRIAM;
}
use of javax.swing.tree.DefaultTreeCellRenderer in project vcell by virtualcell.
the class BioModelTreePanel method connEtoM2.
/**
* connEtoM2: (BioModelTreePanel.initialize() --> JTree2.cellRenderer)
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void connEtoM2() {
BioModelCellRenderer localValue = null;
try {
// Add cellRenderer
DefaultTreeCellRenderer dtcr = new BioModelCellRenderer(null) {
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
JLabel component = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
if (value instanceof BioModelNode && ((BioModelNode) value).getUserObject() instanceof Annotation) {
component.setToolTipText("(Double-click to edit notes)");
Annotation annotation = (Annotation) ((BioModelNode) value).getUserObject();
if (annotation.toString() == null || annotation.toString().length() == 0) {
component.setText("(Double-click to edit notes)");
}
}
return component;
}
};
getJTree2().setCellRenderer(dtcr);
// user code begin {2}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {3}
// user code end
handleException(ivjExc);
}
}
use of javax.swing.tree.DefaultTreeCellRenderer in project cytoscape-impl by cytoscape.
the class InstallAppsPanel method initComponents.
private void initComponents() {
searchAppsLabel = new JLabel("Search:");
installFromFileButton = new JButton("Install from File...");
filterTextField = new JTextField();
descriptionSplitPane = new JSplitPane();
tagsSplitPane = new JSplitPane();
tagsScrollPane = new JScrollPane();
tagsTree = new JTree();
resultsScrollPane = new JScrollPane();
resultsTree = new JTree();
descriptionPanel = new JPanel();
descriptionScrollPane = new JScrollPane();
descriptionTextPane = new JTextPane();
viewOnAppStoreButton = new JButton("View on App Store");
installButton = new JButton("Install");
downloadSiteLabel = new JLabel("Download Site:");
downloadSiteComboBox = new JComboBox();
manageSitesButton = new JButton("Manage Sites...");
searchAppsLabel.setVisible(!LookAndFeelUtil.isAquaLAF());
// Aqua LAF only
filterTextField.putClientProperty("JTextField.variant", "search");
filterTextField.setToolTipText("To search, start typing");
installFromFileButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
installFromFileButtonActionPerformed(evt);
}
});
descriptionSplitPane.setBorder(null);
descriptionSplitPane.setDividerLocation(390);
tagsSplitPane.setDividerLocation(175);
tagsSplitPane.setBorder(null);
DefaultMutableTreeNode treeNode1 = new DefaultMutableTreeNode("root");
DefaultMutableTreeNode treeNode2 = new DefaultMutableTreeNode("all apps (0)");
DefaultMutableTreeNode treeNode3 = new DefaultMutableTreeNode("collections (0)");
DefaultMutableTreeNode treeNode4 = new DefaultMutableTreeNode("apps by tag");
treeNode1.add(treeNode2);
treeNode1.add(treeNode3);
treeNode1.add(treeNode4);
tagsTree.setModel(new DefaultTreeModel(treeNode1));
tagsTree.setFocusable(false);
tagsTree.setRootVisible(false);
tagsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tagsScrollPane.setViewportView(tagsTree);
tagsSplitPane.setLeftComponent(tagsScrollPane);
treeNode1 = new DefaultMutableTreeNode("root");
resultsTree.setModel(new DefaultTreeModel(treeNode1));
resultsTree.setFocusable(false);
resultsTree.setRootVisible(false);
resultsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
resultsScrollPane.setViewportView(resultsTree);
tagsSplitPane.setRightComponent(resultsScrollPane);
descriptionSplitPane.setLeftComponent(tagsSplitPane);
descriptionTextPane.setContentType("text/html");
descriptionTextPane.setEditable(false);
// descriptionTextPane.setText("<html>\n <head>\n\n </head>\n <body>\n <p style=\"margin-top: 0\">\n App description is displayed here.\n </p>\n </body>\n</html>\n");
descriptionTextPane.setText("");
descriptionScrollPane.setViewportView(descriptionTextPane);
final GroupLayout descriptionPanelLayout = new GroupLayout(descriptionPanel);
descriptionPanel.setLayout(descriptionPanelLayout);
descriptionPanelLayout.setHorizontalGroup(descriptionPanelLayout.createParallelGroup(Alignment.LEADING).addComponent(descriptionScrollPane, GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE));
descriptionPanelLayout.setVerticalGroup(descriptionPanelLayout.createParallelGroup(Alignment.LEADING).addComponent(descriptionScrollPane, GroupLayout.DEFAULT_SIZE, 354, Short.MAX_VALUE));
descriptionSplitPane.setRightComponent(descriptionPanel);
viewOnAppStoreButton.setEnabled(false);
viewOnAppStoreButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
viewOnAppStoreButtonActionPerformed(evt);
}
});
installButton.setEnabled(false);
installButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
installButtonActionPerformed(evt);
}
});
downloadSiteComboBox.setModel(new DefaultComboBoxModel(new String[] { WebQuerier.DEFAULT_APP_STORE_URL }));
downloadSiteComboBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent evt) {
downloadSiteComboBoxItemStateChanged(evt);
}
});
downloadSiteComboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
downloadSiteComboBoxActionPerformed(evt);
}
});
downloadSiteComboBox.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent evt) {
downloadSiteComboBoxKeyPressed(evt);
}
});
manageSitesButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
manageSitesButtonActionPerformed(evt);
}
});
LookAndFeelUtil.equalizeSize(installFromFileButton, viewOnAppStoreButton, installButton);
final JSeparator sep = new JSeparator();
final GroupLayout layout = new GroupLayout(this);
this.setLayout(layout);
layout.setAutoCreateContainerGaps(true);
layout.setAutoCreateGaps(true);
layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(downloadSiteLabel).addComponent(downloadSiteComboBox, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addComponent(manageSitesButton)).addComponent(sep, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addGroup(layout.createSequentialGroup().addComponent(searchAppsLabel).addComponent(filterTextField, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE)).addComponent(descriptionSplitPane).addGroup(layout.createSequentialGroup().addComponent(installFromFileButton).addPreferredGap(ComponentPlacement.RELATED, 80, Short.MAX_VALUE).addComponent(viewOnAppStoreButton).addComponent(installButton)));
layout.setVerticalGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(downloadSiteLabel).addComponent(downloadSiteComboBox, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(manageSitesButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addComponent(sep, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(searchAppsLabel).addComponent(filterTextField, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addComponent(descriptionSplitPane, DEFAULT_SIZE, 360, Short.MAX_VALUE).addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(installFromFileButton).addComponent(viewOnAppStoreButton).addComponent(installButton)));
// Add a key listener to the download site combo box to listen for the enter key event
final WebQuerier webQuerier = this.appManager.getWebQuerier();
downloadSiteComboBox.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
final ComboBoxEditor editor = downloadSiteComboBox.getEditor();
final Object selectedValue = editor.getItem();
if (e.isActionKey() || e.getKeyCode() == KeyEvent.VK_ENTER) {
if (downloadSiteComboBox.getModel() instanceof DefaultComboBoxModel && selectedValue != null) {
final DefaultComboBoxModel comboBoxModel = (DefaultComboBoxModel) downloadSiteComboBox.getModel();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
boolean selectedAlreadyInList = false;
for (int i = 0; i < comboBoxModel.getSize(); i++) {
Object listElement = comboBoxModel.getElementAt(i);
if (listElement.equals(selectedValue)) {
selectedAlreadyInList = true;
break;
}
}
if (!selectedAlreadyInList) {
comboBoxModel.insertElementAt(selectedValue, 1);
editor.setItem(selectedValue);
}
}
});
}
if (webQuerier.getCurrentAppStoreUrl() != selectedValue.toString()) {
webQuerier.setCurrentAppStoreUrl(selectedValue.toString());
queryForApps();
}
}
}
});
// Make the JTextPane render HTML using the default UI font
Font font = UIManager.getFont("Label.font");
String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }";
((HTMLDocument) descriptionTextPane.getDocument()).getStyleSheet().addRule(bodyRule);
// Setup the TreeCellRenderer to make the app tags use the folder icon instead of the default leaf icon,
// and have it use the opened folder icon when selected
DefaultTreeCellRenderer tagsTreeCellRenderer = new DefaultTreeCellRenderer() {
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
// Make leaves use the open folder icon when selected
if (selected && leaf)
this.setIcon(getOpenIcon());
return this;
}
};
tagsTreeCellRenderer.setLeafIcon(tagsTreeCellRenderer.getDefaultClosedIcon());
tagsTree.setCellRenderer(tagsTreeCellRenderer);
}
use of javax.swing.tree.DefaultTreeCellRenderer in project chatty by chatty.
the class Tree method createTree.
public static JTree createTree(Map<Page, List<Page>> nodes) {
// Create nodes structure based on Map
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
for (Page parent : nodes.keySet()) {
DefaultMutableTreeNode category = new DefaultMutableTreeNode(parent);
root.add(category);
List<Page> subNodes = nodes.get(parent);
for (Page child : subNodes) {
category.add(new DefaultMutableTreeNode(child));
}
}
// Create and configure tree
JTree tree = new JTree(root);
tree.setRootVisible(false);
tree.setShowsRootHandles(false);
// Disable icons and use default renderer
DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer() {
// Border to give text some more space
private final Border BORDER = BorderFactory.createEmptyBorder(0, 3, 0, 1);
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
Component c = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
if (c instanceof JLabel) {
JLabel label = (JLabel) c;
label.setBorder(BORDER);
}
return c;
}
};
renderer.setLeafIcon(null);
renderer.setOpenIcon(null);
tree.setCellRenderer(renderer);
// Expand all branches
for (int i = 0; i < tree.getRowCount(); i++) {
tree.expandRow(i);
}
// Select closest node on click, to allow more leniency with selecting
tree.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
int row = tree.getClosestRowForLocation(e.getX(), e.getY());
if (row != -1) {
tree.setSelectionRow(row);
}
}
});
// Prevent collapsing of nodes completely
tree.addTreeWillExpandListener(new TreeWillExpandListener() {
@Override
public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
}
@Override
public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
throw new ExpandVetoException(event);
}
});
return tree;
}
use of javax.swing.tree.DefaultTreeCellRenderer in project ffx by mjschnie.
the class Hierarchy method initTree.
/**
* Initialize the Tree representation based on the Root data node
*/
public void initTree() {
addTreeSelectionListener(this);
setExpandsSelectedPaths(true);
setScrollsOnExpand(true);
// setLargeModel(true);
setEditable(false);
putClientProperty("JTree.lineStyle", "Angled");
setShowsRootHandles(true);
DefaultTreeCellRenderer tcr = new DefaultTreeCellRenderer();
tcr.setBackgroundSelectionColor(Color.yellow);
tcr.setBorderSelectionColor(Color.black);
tcr.setTextSelectionColor(Color.black);
setCellRenderer(tcr);
hierarchyModel = new DefaultTreeModel(root);
treeSelectionModel = new DefaultTreeSelectionModel();
setModel(hierarchyModel);
setSelectionModel(treeSelectionModel);
setRootVisible(false);
}
Aggregations