use of javax.swing.tree.DefaultTreeCellRenderer in project jdk8u_jdk by JetBrains.
the class bug7142955 method main.
public static void main(String[] args) throws Exception {
UIManager.put("Tree.rendererFillBackground", Boolean.FALSE);
UIManager.put("Tree.textBackground", TEST_COLOR);
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
int w = 200;
int h = 100;
BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics g = image.getGraphics();
g.setColor(Color.WHITE);
g.fillRect(0, 0, image.getWidth(), image.getHeight());
DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
renderer.setSize(w, h);
renderer.paint(g);
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
if (image.getRGB(x, y) == TEST_COLOR.getRGB()) {
throw new RuntimeException("Test bug7142955 failed");
}
}
}
System.out.println("Test bug7142955 passed.");
}
});
}
use of javax.swing.tree.DefaultTreeCellRenderer in project jabref by JabRef.
the class FindUnlinkedFilesDialog method createTree.
/**
* Creates the tree view, that holds the data structure. <br>
* <br>
* Initially, the root node is <b>not</b> visible, so that the tree appears empty at the beginning.
*/
private void createTree() {
/**
* Mouse listener to listen for mouse events on the tree. <br>
* This will mark the selected tree entry as "selected" or "unselected",
* which will cause this nodes checkbox to appear as either "checked" or
* "unchecked".
*/
treeMouseListener = new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
int x = e.getX();
int y = e.getY();
int row = tree.getRowForLocation(x, y);
TreePath path = tree.getPathForRow(row);
if (path != null) {
CheckableTreeNode node = (CheckableTreeNode) path.getLastPathComponent();
if (e.getClickCount() == 2) {
Object userObject = node.getUserObject();
if ((userObject instanceof FileNodeWrapper) && node.isLeaf()) {
FileNodeWrapper fnw = (FileNodeWrapper) userObject;
try {
JabRefDesktop.openExternalViewer(JabRefGUI.getMainFrame().getCurrentBasePanel().getBibDatabaseContext(), fnw.file.getAbsolutePath(), FieldName.PDF);
} catch (IOException e1) {
LOGGER.info("Error opening file", e1);
}
}
} else {
node.check();
tree.invalidate();
tree.repaint();
}
}
}
};
CheckableTreeNode startNode = new CheckableTreeNode("ROOT");
DefaultTreeModel model = new DefaultTreeModel(startNode);
tree.setModel(model);
tree.setRootVisible(false);
DefaultTreeCellRenderer renderer = new CheckboxTreeCellRenderer();
tree.setCellRenderer(renderer);
tree.addMouseListener(treeMouseListener);
}
use of javax.swing.tree.DefaultTreeCellRenderer in project Gargoyle by callakrsos.
the class DesignerFx method createNoImageTreeCellRenderer.
private TreeCellRenderer createNoImageTreeCellRenderer() {
DefaultTreeCellRenderer treeCellRenderer = new DefaultTreeCellRenderer();
treeCellRenderer.setLeafIcon(null);
treeCellRenderer.setOpenIcon(null);
treeCellRenderer.setClosedIcon(null);
return treeCellRenderer;
}
use of javax.swing.tree.DefaultTreeCellRenderer in project jdk8u_jdk by JetBrains.
the class SynthTreeUI method paint.
/**
* Paints the specified component.
*
* @param context context for the component being painted
* @param g the {@code Graphics} object used for painting
* @see #update(Graphics,JComponent)
*/
protected void paint(SynthContext context, Graphics g) {
paintContext = context;
updateLeadSelectionRow();
Rectangle paintBounds = g.getClipBounds();
Insets insets = tree.getInsets();
TreePath initialPath = getClosestPathForLocation(tree, 0, paintBounds.y);
Enumeration paintingEnumerator = treeState.getVisiblePathsFrom(initialPath);
int row = treeState.getRowForPath(initialPath);
int endY = paintBounds.y + paintBounds.height;
TreeModel treeModel = tree.getModel();
SynthContext cellContext = getContext(tree, Region.TREE_CELL);
drawingCache.clear();
setHashColor(context.getStyle().getColor(context, ColorType.FOREGROUND));
if (paintingEnumerator != null) {
// First pass, draw the rows
boolean done = false;
boolean isExpanded;
boolean hasBeenExpanded;
boolean isLeaf;
Rectangle rowBounds = new Rectangle(0, 0, tree.getWidth(), 0);
Rectangle bounds;
TreePath path;
TreeCellRenderer renderer = tree.getCellRenderer();
DefaultTreeCellRenderer dtcr = (renderer instanceof DefaultTreeCellRenderer) ? (DefaultTreeCellRenderer) renderer : null;
configureRenderer(cellContext);
while (!done && paintingEnumerator.hasMoreElements()) {
path = (TreePath) paintingEnumerator.nextElement();
bounds = getPathBounds(tree, path);
if ((path != null) && (bounds != null)) {
isLeaf = treeModel.isLeaf(path.getLastPathComponent());
if (isLeaf) {
isExpanded = hasBeenExpanded = false;
} else {
isExpanded = treeState.getExpandedState(path);
hasBeenExpanded = tree.hasBeenExpanded(path);
}
rowBounds.y = bounds.y;
rowBounds.height = bounds.height;
paintRow(renderer, dtcr, context, cellContext, g, paintBounds, insets, bounds, rowBounds, path, row, isExpanded, hasBeenExpanded, isLeaf);
if ((bounds.y + bounds.height) >= endY) {
done = true;
}
} else {
done = true;
}
row++;
}
// Draw the connecting lines and controls.
// Find each parent and have them draw a line to their last child
boolean rootVisible = tree.isRootVisible();
TreePath parentPath = initialPath;
parentPath = parentPath.getParentPath();
while (parentPath != null) {
paintVerticalPartOfLeg(g, paintBounds, insets, parentPath);
drawingCache.put(parentPath, Boolean.TRUE);
parentPath = parentPath.getParentPath();
}
done = false;
paintingEnumerator = treeState.getVisiblePathsFrom(initialPath);
while (!done && paintingEnumerator.hasMoreElements()) {
path = (TreePath) paintingEnumerator.nextElement();
bounds = getPathBounds(tree, path);
if ((path != null) && (bounds != null)) {
isLeaf = treeModel.isLeaf(path.getLastPathComponent());
if (isLeaf) {
isExpanded = hasBeenExpanded = false;
} else {
isExpanded = treeState.getExpandedState(path);
hasBeenExpanded = tree.hasBeenExpanded(path);
}
// See if the vertical line to the parent has been drawn.
parentPath = path.getParentPath();
if (parentPath != null) {
if (drawingCache.get(parentPath) == null) {
paintVerticalPartOfLeg(g, paintBounds, insets, parentPath);
drawingCache.put(parentPath, Boolean.TRUE);
}
paintHorizontalPartOfLeg(g, paintBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf);
} else if (rootVisible && row == 0) {
paintHorizontalPartOfLeg(g, paintBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf);
}
if (shouldPaintExpandControl(path, row, isExpanded, hasBeenExpanded, isLeaf)) {
paintExpandControl(g, paintBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf);
}
if ((bounds.y + bounds.height) >= endY) {
done = true;
}
} else {
done = true;
}
row++;
}
}
cellContext.dispose();
paintDropLine(g);
// Empty out the renderer pane, allowing renderers to be gc'ed.
rendererPane.removeAll();
paintContext = null;
}
use of javax.swing.tree.DefaultTreeCellRenderer in project jdk8u_jdk by JetBrains.
the class SynthTreeUI method createDefaultCellEditor.
/**
* {@inheritDoc}
*/
@Override
protected TreeCellEditor createDefaultCellEditor() {
TreeCellRenderer renderer = tree.getCellRenderer();
DefaultTreeCellEditor editor;
if (renderer != null && (renderer instanceof DefaultTreeCellRenderer)) {
editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer) renderer);
} else {
editor = new SynthTreeCellEditor(tree, null);
}
return editor;
}
Aggregations