use of javax.swing.tree.TreeCellRenderer in project checkstyle by checkstyle.
the class TreeTableCellRenderer method updateUI.
/**
* UpdateUI is overridden to set the colors of the Tree's renderer
* to match that of the table.
*/
@Override
public void updateUI() {
super.updateUI();
// Make the tree's cell renderer use the table's cell selection
// colors.
final TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
final DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tcr;
// For 1.1 uncomment this, 1.2 has a bug that will cause an
// exception to be thrown if the border selection color is
// null.
// renderer.setBorderSelectionColor(null);
renderer.setTextSelectionColor(UIManager.getColor("Table.selectionForeground"));
renderer.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground"));
}
}
use of javax.swing.tree.TreeCellRenderer 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.TreeCellRenderer in project intellij-community by JetBrains.
the class MavenUIUtil method installCheckboxRenderer.
public static void installCheckboxRenderer(final SimpleTree tree, final CheckboxHandler handler) {
final JCheckBox checkbox = new JCheckBox();
final JPanel panel = new JPanel(new BorderLayout());
panel.add(checkbox, BorderLayout.WEST);
final TreeCellRenderer baseRenderer = tree.getCellRenderer();
tree.setCellRenderer(new TreeCellRenderer() {
public Component getTreeCellRendererComponent(final JTree tree, final Object value, final boolean selected, final boolean expanded, final boolean leaf, final int row, final boolean hasFocus) {
final Component baseComponent = baseRenderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
final Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
if (!handler.isVisible(userObject)) {
return baseComponent;
}
final Color foreground = selected ? UIUtil.getTreeSelectionForeground() : UIUtil.getTreeTextForeground();
Color background = selected ? UIUtil.getTreeSelectionBackground(hasFocus) : UIUtil.getTreeTextBackground();
panel.add(baseComponent, BorderLayout.CENTER);
panel.setBackground(background);
panel.setForeground(foreground);
CheckBoxState state = handler.getState(userObject);
checkbox.setSelected(state != CheckBoxState.UNCHECKED);
checkbox.setEnabled(state != CheckBoxState.PARTIAL);
checkbox.setBackground(background);
checkbox.setForeground(foreground);
return panel;
}
});
tree.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
int row = tree.getRowForLocation(e.getX(), e.getY());
if (row >= 0) {
TreePath path = tree.getPathForRow(row);
if (!isCheckboxEnabledFor(path, handler))
return;
Rectangle checkBounds = checkbox.getBounds();
checkBounds.setLocation(tree.getRowBounds(row).getLocation());
if (checkBounds.contains(e.getPoint())) {
handler.toggle(path, e);
e.consume();
tree.setSelectionRow(row);
}
}
}
});
tree.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
TreePath[] treePaths = tree.getSelectionPaths();
if (treePaths != null) {
for (TreePath treePath : treePaths) {
if (!isCheckboxEnabledFor(treePath, handler))
continue;
handler.toggle(treePath, e);
}
e.consume();
}
}
}
});
}
use of javax.swing.tree.TreeCellRenderer in project intellij-community by JetBrains.
the class TreeTableTree method updateUI.
public void updateUI() {
super.updateUI();
TreeCellRenderer tcr = super.getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = (DefaultTreeCellRenderer) tcr;
dtcr.setTextSelectionColor(UIUtil.getTableSelectionForeground());
dtcr.setBackgroundSelectionColor(UIUtil.getTableSelectionBackground());
}
}
use of javax.swing.tree.TreeCellRenderer in project intellij-community by JetBrains.
the class MultilineTreeCellRenderer method installRenderer.
public static JScrollPane installRenderer(final JTree tree, final MultilineTreeCellRenderer renderer) {
final TreeCellRenderer defaultRenderer = tree.getCellRenderer();
JScrollPane scrollpane = new JBScrollPane(tree) {
private int myAddRemoveCounter = 0;
private boolean myShouldResetCaches = false;
public void setSize(Dimension d) {
boolean isChanged = getWidth() != d.width || myShouldResetCaches;
super.setSize(d);
if (isChanged)
resetCaches();
}
public void reshape(int x, int y, int w, int h) {
boolean isChanged = w != getWidth() || myShouldResetCaches;
super.reshape(x, y, w, h);
if (isChanged)
resetCaches();
}
private void resetCaches() {
resetHeightCache(tree, defaultRenderer, renderer);
myShouldResetCaches = false;
}
public void addNotify() {
//To change body of overriden methods use Options | File Templates.
super.addNotify();
if (myAddRemoveCounter == 0)
myShouldResetCaches = true;
myAddRemoveCounter++;
}
public void removeNotify() {
//To change body of overriden methods use Options | File Templates.
super.removeNotify();
myAddRemoveCounter--;
}
};
scrollpane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
tree.setCellRenderer(renderer);
scrollpane.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
resetHeightCache(tree, defaultRenderer, renderer);
}
public void componentShown(ComponentEvent e) {
// componentResized not called when adding to opened tool window.
// Seems to be BUG#4765299, however I failed to create same code to reproduce it.
// To reproduce it with IDEA: 1. remove this method, 2. Start any Ant task, 3. Keep message window open 4. start Ant task again.
resetHeightCache(tree, defaultRenderer, renderer);
}
});
return scrollpane;
}
Aggregations