use of javax.swing.tree.DefaultTreeCellRenderer in project groovy-core by groovy.
the class ClosureRenderer method render.
private Component render() {
if (children.isEmpty() || defaultRenderer) {
defaultRenderer = true;
children.clear();
if (table != null) {
TableCellRenderer tcr;
if (tableHeader) {
tcr = table.getTableHeader().getDefaultRenderer();
} else {
tcr = table.getDefaultRenderer(table.getColumnClass(column));
}
children.add(tcr.getTableCellRendererComponent(table, value, selected, focused, row, column));
} else if (tree != null) {
TreeCellRenderer tcr;
tcr = new DefaultTreeCellRenderer();
children.add(tcr.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, focused));
} else if (list != null) {
ListCellRenderer lcr = (ListCellRenderer) UIManager.get("List.cellRenderer");
if (lcr == null) {
lcr = new DefaultListCellRenderer();
}
children.add(lcr.getListCellRendererComponent(list, value, row, selected, focused));
}
}
Object o = update.call();
if (o instanceof Component) {
return (Component) o;
} else {
return (Component) children.get(0);
}
}
use of javax.swing.tree.DefaultTreeCellRenderer in project zaproxy by zaproxy.
the class SiteMapPanel method getTreeSite.
/**
* This method initializes treeSite
*
* @return javax.swing.JTree
*/
public JTree getTreeSite() {
if (treeSite == null) {
treeSite = new JTree(new DefaultTreeModel(new DefaultMutableTreeNode()));
treeSite.setShowsRootHandles(true);
treeSite.setName("treeSite");
treeSite.setToggleClickCount(1);
// Force macOS L&F to query the row height from SiteMapTreeCellRenderer to hide the
// filtered nodes.
// Other L&Fs hide the filtered nodes by default.
LookAndFeel laf = UIManager.getLookAndFeel();
if (laf != null && Constant.isMacOsX() && UIManager.getSystemLookAndFeelClassName().equals(laf.getClass().getName())) {
treeSite.setRowHeight(0);
}
treeSite.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
@Override
public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
SiteNode node = (SiteNode) treeSite.getLastSelectedPathComponent();
if (node == null) {
return;
}
if (!node.isRoot()) {
HttpMessage msg = null;
try {
msg = node.getHistoryReference().getHttpMessage();
} catch (Exception e1) {
// ZAP: Log exceptions
log.warn(e1.getMessage(), e1);
return;
}
getView().displayMessage(msg);
// ZAP: Call SiteMapListenners
for (SiteMapListener listener : listeners) {
listener.nodeSelected(node);
}
} else {
// ZAP: clear the views when the root is selected
getView().displayMessage(null);
}
}
});
treeSite.setComponentPopupMenu(new SitesCustomPopupMenu());
// ZAP: Add custom tree cell renderer.
DefaultTreeCellRenderer renderer = new SiteMapTreeCellRenderer(listeners);
treeSite.setCellRenderer(renderer);
String deleteSiteNode = "zap.delete.sitenode";
treeSite.getInputMap().put(getView().getDefaultDeleteKeyStroke(), deleteSiteNode);
treeSite.getActionMap().put(deleteSiteNode, new AbstractAction() {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent e) {
ExtensionHistory extHistory = Control.getSingleton().getExtensionLoader().getExtension(ExtensionHistory.class);
if (extHistory == null || treeSite.getSelectionCount() == 0) {
return;
}
int result = View.getSingleton().showConfirmDialog(Constant.messages.getString("sites.purge.warning"));
if (result != JOptionPane.YES_OPTION) {
return;
}
SiteMap siteMap = Model.getSingleton().getSession().getSiteTree();
for (TreePath path : treeSite.getSelectionPaths()) {
extHistory.purge(siteMap, (SiteNode) path.getLastPathComponent());
}
}
});
}
return treeSite;
}
use of javax.swing.tree.DefaultTreeCellRenderer in project zaproxy by zaproxy.
the class AbstractParamContainerPanel method getTreeParam.
/**
* This method initializes treeParam
*
* @return javax.swing.JTree
*/
private JTree getTreeParam() {
if (treeParam == null) {
treeParam = new JTree();
treeParam.setModel(getTreeModel());
treeParam.setShowsRootHandles(true);
treeParam.setRootVisible(true);
treeParam.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
@Override
public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) getTreeParam().getLastSelectedPathComponent();
if (node == null) {
return;
}
String name = (String) node.getUserObject();
if (getParamPanel(name) == null) {
if (node.getChildCount() == 0) {
return;
}
name = (String) ((DefaultMutableTreeNode) node.getFirstChild()).getUserObject();
}
showParamPanel(name);
}
});
DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
renderer.setLeafIcon(null);
renderer.setOpenIcon(null);
renderer.setClosedIcon(null);
treeParam.setCellRenderer(renderer);
treeParam.setRowHeight(DisplayUtils.getScaledSize(18));
treeParam.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
TreePath path = treeParam.getClosestPathForLocation(e.getX(), e.getY());
if (path != null && !treeParam.isPathSelected(path)) {
treeParam.setSelectionPath(path);
}
}
});
}
return treeParam;
}
use of javax.swing.tree.DefaultTreeCellRenderer in project groovy by apache.
the class ClosureRenderer method render.
private Component render() {
if (children.isEmpty() || defaultRenderer) {
defaultRenderer = true;
children.clear();
if (table != null) {
TableCellRenderer tcr;
if (tableHeader) {
tcr = table.getTableHeader().getDefaultRenderer();
} else {
tcr = table.getDefaultRenderer(table.getColumnClass(column));
}
children.add(tcr.getTableCellRendererComponent(table, value, selected, focused, row, column));
} else if (tree != null) {
TreeCellRenderer tcr;
tcr = new DefaultTreeCellRenderer();
children.add(tcr.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, focused));
} else if (list != null) {
ListCellRenderer lcr = (ListCellRenderer) UIManager.get("List.cellRenderer");
if (lcr == null) {
lcr = new DefaultListCellRenderer();
}
children.add(lcr.getListCellRendererComponent(list, value, row, selected, focused));
}
}
Object o = update.call();
if (o instanceof Component) {
return (Component) o;
} else {
return (Component) children.get(0);
}
}
use of javax.swing.tree.DefaultTreeCellRenderer in project intellij-community by JetBrains.
the class PackageChooserDialog method createCenterPanel.
protected JComponent createCenterPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
myModel = new DefaultTreeModel(new DefaultMutableTreeNode());
createTreeModel();
myTree = new Tree(myModel);
UIUtil.setLineStyleAngled(myTree);
myTree.setCellRenderer(new DefaultTreeCellRenderer() {
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
setIcon(PlatformIcons.PACKAGE_ICON);
if (value instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
Object object = node.getUserObject();
if (object instanceof PsiPackage) {
String name = ((PsiPackage) object).getName();
if (name != null && name.length() > 0) {
setText(name);
} else {
setText(IdeBundle.message("node.default"));
}
}
}
return this;
}
});
JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree);
scrollPane.setPreferredSize(JBUI.size(500, 300));
new TreeSpeedSearch(myTree, new Convertor<TreePath, String>() {
public String convert(TreePath path) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
Object object = node.getUserObject();
if (object instanceof PsiPackage)
return ((PsiPackage) object).getName();
else
return "";
}
});
myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
PsiPackage selection = getTreeSelection();
if (selection != null) {
String name = selection.getQualifiedName();
setTitle(myTitle + " - " + ("".equals(name) ? IdeBundle.message("node.default.package") : name));
} else {
setTitle(myTitle);
}
updatePathFromTree();
}
});
panel.add(scrollPane, BorderLayout.CENTER);
DefaultActionGroup group = createActionGroup(myTree);
final JPanel northPanel = new JPanel(new BorderLayout());
panel.add(northPanel, BorderLayout.NORTH);
ActionToolbar toolBar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true);
northPanel.add(toolBar.getComponent(), BorderLayout.WEST);
setupPathComponent(northPanel);
return panel;
}
Aggregations