Search in sources :

Example 26 with DefaultTreeCellRenderer

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.");
        }
    });
}
Also used : DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) BufferedImage(java.awt.image.BufferedImage)

Example 27 with DefaultTreeCellRenderer

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);
}
Also used : MouseEvent(java.awt.event.MouseEvent) TreePath(javax.swing.tree.TreePath) MouseAdapter(java.awt.event.MouseAdapter) IOException(java.io.IOException) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer)

Example 28 with DefaultTreeCellRenderer

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;
}
Also used : DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer)

Example 29 with DefaultTreeCellRenderer

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;
}
Also used : TreeCellRenderer(javax.swing.tree.TreeCellRenderer) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) TreeModel(javax.swing.tree.TreeModel) Insets(java.awt.Insets) Enumeration(java.util.Enumeration) TreePath(javax.swing.tree.TreePath) Rectangle(java.awt.Rectangle) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer)

Example 30 with DefaultTreeCellRenderer

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;
}
Also used : TreeCellRenderer(javax.swing.tree.TreeCellRenderer) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) DefaultTreeCellEditor(javax.swing.tree.DefaultTreeCellEditor) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer)

Aggregations

DefaultTreeCellRenderer (javax.swing.tree.DefaultTreeCellRenderer)36 JTree (javax.swing.JTree)13 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)13 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)12 TreePath (javax.swing.tree.TreePath)10 MouseAdapter (java.awt.event.MouseAdapter)7 MouseEvent (java.awt.event.MouseEvent)7 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)7 TreeCellRenderer (javax.swing.tree.TreeCellRenderer)7 Dimension (java.awt.Dimension)4 JLabel (javax.swing.JLabel)4 JPanel (javax.swing.JPanel)4 JScrollPane (javax.swing.JScrollPane)4 TreeSelectionListener (javax.swing.event.TreeSelectionListener)4 Topic (com.igormaznitsa.mindmap.model.Topic)3 BorderLayout (java.awt.BorderLayout)3 Component (java.awt.Component)3 ActionEvent (java.awt.event.ActionEvent)3 KeyAdapter (java.awt.event.KeyAdapter)3 KeyEvent (java.awt.event.KeyEvent)3