Java Code Examples for javax.swing.tree.TreeCellRenderer

The following examples show how to use javax.swing.tree.TreeCellRenderer. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: size-analyzer   Source File: AnalyzeSizeToolWindowTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void categoryNodesHaveCorrectExtraInformation() {
  JPanel toolPanel = toolWindow.getContent();
  Component[] components = toolPanel.getComponents();
  OnePixelSplitter splitter = (OnePixelSplitter) components[0];
  JBScrollPane leftPane = (JBScrollPane) splitter.getFirstComponent();
  JViewport leftView = leftPane.getViewport();
  Tree suggestionTree = (Tree) leftView.getView();

  TreePath webPPath = getTreePathWithString(suggestionTree, webPCategoryData.toString());
  TreeCellRenderer treeCellRenderer = suggestionTree.getCellRenderer();
  Component renderedNode =
      treeCellRenderer.getTreeCellRendererComponent(
          suggestionTree,
          webPPath.getLastPathComponent(),
          false,
          false,
          false,
          suggestionTree.getRowForPath(webPPath),
          false);
  assertThat(renderedNode.toString()).contains("2 recommendations");
  assertThat(renderedNode.toString()).contains("29.30 KB");
}
 
Example 2
Source Project: netbeans   Source File: ResultTreeView.java    License: Apache License 2.0 6 votes vote down vote up
public Component getTreeCellRendererComponent(JTree tree,
                                                 Object value,
                                                 boolean selected,
                                                 boolean expanded,
                                                 boolean leaf,
                                                 int row,
                                                 boolean hasFocus) {
       boolean isResultRootNode =
                       (value instanceof TreeNode)
                       && (((TreeNode) value).getParent() == null);
// render no icon space an empty icon of a callStackFrame
       boolean isCallstackFrame = false;
       if (null != value) {
           isCallstackFrame = (Visualizer.findNode(value) instanceof CallstackFrameNode);
       }

       TreeCellRenderer renderer = (isResultRootNode || isCallstackFrame)
                                   ? noIconTreeCellRenderer
                                   : defaultTreeCellRenderer;
       return renderer.getTreeCellRendererComponent(
               tree, value, selected, expanded, leaf, row, hasFocus);
   }
 
Example 3
Source Project: ramus   Source File: FirstRowCellEditor.java    License: GNU General Public License v3.0 6 votes vote down vote up
public boolean isCellEditable(final EventObject anEvent) {
    if (anEvent instanceof MouseEvent) {
        final MouseEvent event = (MouseEvent) anEvent;
        final int row = treeTable.rowAtPoint(event.getPoint());
        final Rectangle bounds = tree.getRowBounds(row);
        int offset = bounds.x;
        final Object node = tree.getPathForRow(row).getLastPathComponent();
        final boolean leaf = tree.getModel().isLeaf(node);
        final boolean expanded = tree.isExpanded(row);
        final TreeCellRenderer tcr = tree.getCellRenderer();
        final Component treeComponent = tcr.getTreeCellRendererComponent(
                tree, node, true, expanded, leaf, row, false);
        if (treeComponent instanceof JLabel) {
            final JLabel label = (JLabel) treeComponent;

            final Icon icon = label.getIcon();
            if (icon != null) {
                offset += icon.getIconWidth() + label.getIconTextGap();
            }

        }
        if (event.getPoint().x < offset)
            return false;
    }
    return deligate.isCellEditable(anEvent);
}
 
Example 4
Source Project: darklaf   Source File: DarkUIUtil.java    License: MIT License 5 votes vote down vote up
public static boolean isInCell(final Component c) {
    if (getParentOfType(DarkTableHeaderRendererPane.class, c, CELL_SEARCH_DEPTH) != null) return false;
    boolean inCellRenderer = getParentOfType(c, CELL_SEARCH_DEPTH, CellRendererPane.class, CellEditor.class,
                                             TableCellRenderer.class, TableCellEditor.class,
                                             TreeCellRenderer.class, TreeCellEditor.class,
                                             ListCellRenderer.class, CellRenderer.class) != null;
    return inCellRenderer && getParentOfType(JComboBox.class, c) == null;
}
 
Example 5
Source Project: jdk1.8-source-analysis   Source File: SynthTreeUI.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@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;
}
 
Example 6
Source Project: jdk1.8-source-analysis   Source File: SynthTreeUI.java    License: Apache License 2.0 5 votes vote down vote up
private void configureRenderer(SynthContext context) {
    TreeCellRenderer renderer = tree.getCellRenderer();

    if (renderer instanceof DefaultTreeCellRenderer) {
        DefaultTreeCellRenderer r = (DefaultTreeCellRenderer)renderer;
        SynthStyle style = context.getStyle();

        context.setComponentState(ENABLED | SELECTED);
        Color color = r.getTextSelectionColor();
        if (color == null || (color instanceof UIResource)) {
            r.setTextSelectionColor(style.getColor(
                                 context, ColorType.TEXT_FOREGROUND));
        }
        color = r.getBackgroundSelectionColor();
        if (color == null || (color instanceof UIResource)) {
            r.setBackgroundSelectionColor(style.getColor(
                                    context, ColorType.TEXT_BACKGROUND));
        }

        context.setComponentState(ENABLED);
        color = r.getTextNonSelectionColor();
        if (color == null || color instanceof UIResource) {
            r.setTextNonSelectionColor(style.getColorForState(
                                    context, ColorType.TEXT_FOREGROUND));
        }
        color = r.getBackgroundNonSelectionColor();
        if (color == null || color instanceof UIResource) {
            r.setBackgroundNonSelectionColor(style.getColorForState(
                              context, ColorType.TEXT_BACKGROUND));
        }
    }
}
 
Example 7
public CheckTreeCellRenderer(TreeCellRenderer delegate, CheckTreeSelectionModel selectionModel) {
    this.delegate = delegate;
    this.selectionModel = selectionModel;
    setLayout(new BorderLayout());
    setOpaque(false);
    checkBox.setOpaque(false);
}
 
Example 8
Source Project: dragonwell8_jdk   Source File: SynthTreeUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@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;
}
 
Example 9
Source Project: ghidra   Source File: GTreeDragNDropAdapter.java    License: Apache License 2.0 5 votes vote down vote up
/** Paint each of the given nodes that is inside of the clips */
private void paintNodes(List<GTreeNode> nodes, Graphics g) {
	TreeCellRenderer cellRenderer = tree.getCellRenderer();
	Rectangle clip = g.getClipBounds();
	Container parent = tree.getParent();
	int yOffset = 0;

	try {
		for (GTreeNode node : nodes) {

			int row = tree.getRowForPath(node.getTreePath());
			Rectangle rowBounds = tree.getRowBounds(row);
			rowBounds = SwingUtilities.convertRectangle(tree, rowBounds, parent);
			if (clip.y > rowBounds.y + rowBounds.height) {
				continue; // above our clip
			}

			if (clip.y + clip.height < rowBounds.y + rowBounds.height) {
				// painted past the bounds of our clip
				return;
			}

			Component renderer =
				cellRenderer.getTreeCellRendererComponent(tree, node, true, true,
					node.isLeaf(), row, false);
			renderer.setSize(renderer.getPreferredSize());

			// move down the point in our graphics space into which we will paint
			yOffset += rowBounds.height;
			g.translate(0, rowBounds.height);
			renderer.paint(g);
		}
	}
	finally {
		// restore the point into graphics that we will paint
		g.translate(0, -yOffset);
	}
}
 
Example 10
Source Project: TencentKona-8   Source File: SynthTreeUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@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;
}
 
Example 11
Source Project: TencentKona-8   Source File: SynthTreeUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void configureRenderer(SynthContext context) {
    TreeCellRenderer renderer = tree.getCellRenderer();

    if (renderer instanceof DefaultTreeCellRenderer) {
        DefaultTreeCellRenderer r = (DefaultTreeCellRenderer)renderer;
        SynthStyle style = context.getStyle();

        context.setComponentState(ENABLED | SELECTED);
        Color color = r.getTextSelectionColor();
        if (color == null || (color instanceof UIResource)) {
            r.setTextSelectionColor(style.getColor(
                                 context, ColorType.TEXT_FOREGROUND));
        }
        color = r.getBackgroundSelectionColor();
        if (color == null || (color instanceof UIResource)) {
            r.setBackgroundSelectionColor(style.getColor(
                                    context, ColorType.TEXT_BACKGROUND));
        }

        context.setComponentState(ENABLED);
        color = r.getTextNonSelectionColor();
        if (color == null || color instanceof UIResource) {
            r.setTextNonSelectionColor(style.getColorForState(
                                    context, ColorType.TEXT_FOREGROUND));
        }
        color = r.getBackgroundNonSelectionColor();
        if (color == null || color instanceof UIResource) {
            r.setBackgroundNonSelectionColor(style.getColorForState(
                              context, ColorType.TEXT_BACKGROUND));
        }
    }
}
 
Example 12
Source Project: jdk8u60   Source File: SynthTreeUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@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;
}
 
Example 13
Source Project: jdk8u60   Source File: SynthTreeUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void configureRenderer(SynthContext context) {
    TreeCellRenderer renderer = tree.getCellRenderer();

    if (renderer instanceof DefaultTreeCellRenderer) {
        DefaultTreeCellRenderer r = (DefaultTreeCellRenderer)renderer;
        SynthStyle style = context.getStyle();

        context.setComponentState(ENABLED | SELECTED);
        Color color = r.getTextSelectionColor();
        if (color == null || (color instanceof UIResource)) {
            r.setTextSelectionColor(style.getColor(
                                 context, ColorType.TEXT_FOREGROUND));
        }
        color = r.getBackgroundSelectionColor();
        if (color == null || (color instanceof UIResource)) {
            r.setBackgroundSelectionColor(style.getColor(
                                    context, ColorType.TEXT_BACKGROUND));
        }

        context.setComponentState(ENABLED);
        color = r.getTextNonSelectionColor();
        if (color == null || color instanceof UIResource) {
            r.setTextNonSelectionColor(style.getColorForState(
                                    context, ColorType.TEXT_FOREGROUND));
        }
        color = r.getBackgroundNonSelectionColor();
        if (color == null || color instanceof UIResource) {
            r.setBackgroundNonSelectionColor(style.getColorForState(
                              context, ColorType.TEXT_BACKGROUND));
        }
    }
}
 
Example 14
Source Project: openjdk-jdk9   Source File: SynthTreeUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void configureRenderer(SynthContext context) {
    TreeCellRenderer renderer = tree.getCellRenderer();

    if (renderer instanceof DefaultTreeCellRenderer) {
        DefaultTreeCellRenderer r = (DefaultTreeCellRenderer)renderer;
        SynthStyle style = context.getStyle();

        context.setComponentState(ENABLED | SELECTED);
        Color color = r.getTextSelectionColor();
        if (color == null || (color instanceof UIResource)) {
            r.setTextSelectionColor(style.getColor(
                                 context, ColorType.TEXT_FOREGROUND));
        }
        color = r.getBackgroundSelectionColor();
        if (color == null || (color instanceof UIResource)) {
            r.setBackgroundSelectionColor(style.getColor(
                                    context, ColorType.TEXT_BACKGROUND));
        }

        context.setComponentState(ENABLED);
        color = r.getTextNonSelectionColor();
        if (color == null || color instanceof UIResource) {
            r.setTextNonSelectionColor(style.getColorForState(
                                    context, ColorType.TEXT_FOREGROUND));
        }
        color = r.getBackgroundNonSelectionColor();
        if (color == null || color instanceof UIResource) {
            r.setBackgroundNonSelectionColor(style.getColorForState(
                              context, ColorType.TEXT_BACKGROUND));
        }
    }
}
 
Example 15
Source Project: JDKSourceCode1.8   Source File: SynthTreeUI.java    License: MIT License 5 votes vote down vote up
private void configureRenderer(SynthContext context) {
    TreeCellRenderer renderer = tree.getCellRenderer();

    if (renderer instanceof DefaultTreeCellRenderer) {
        DefaultTreeCellRenderer r = (DefaultTreeCellRenderer)renderer;
        SynthStyle style = context.getStyle();

        context.setComponentState(ENABLED | SELECTED);
        Color color = r.getTextSelectionColor();
        if (color == null || (color instanceof UIResource)) {
            r.setTextSelectionColor(style.getColor(
                                 context, ColorType.TEXT_FOREGROUND));
        }
        color = r.getBackgroundSelectionColor();
        if (color == null || (color instanceof UIResource)) {
            r.setBackgroundSelectionColor(style.getColor(
                                    context, ColorType.TEXT_BACKGROUND));
        }

        context.setComponentState(ENABLED);
        color = r.getTextNonSelectionColor();
        if (color == null || color instanceof UIResource) {
            r.setTextNonSelectionColor(style.getColorForState(
                                    context, ColorType.TEXT_FOREGROUND));
        }
        color = r.getBackgroundNonSelectionColor();
        if (color == null || color instanceof UIResource) {
            r.setBackgroundNonSelectionColor(style.getColorForState(
                              context, ColorType.TEXT_BACKGROUND));
        }
    }
}
 
Example 16
Source Project: openjdk-jdk9   Source File: JTreeOperator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JTree.getCellRenderer()} through queue
 */
public TreeCellRenderer getCellRenderer() {
    return (runMapping(new MapAction<TreeCellRenderer>("getCellRenderer") {
        @Override
        public TreeCellRenderer map() {
            return ((JTree) getSource()).getCellRenderer();
        }
    }));
}
 
Example 17
public Component getTableCellEditorComponent(JTable table,
		Object value, boolean isSelected, int r, int c)
{
	Component component = super.getTableCellEditorComponent(table, value, isSelected, r, c);
	//boolean rv = t.isRootVisible();
	//int offsetRow = rv ? r : r - 1;
	int offsetRow = r;
	Rectangle bounds = this.table.getCellRect(offsetRow, 0, false);
	int offset = bounds.x;
	TreeCellRenderer tcr = this.table.getTreeCellRenderer();
	System.out.println("Renderer is a : "+tcr);
	if(tcr instanceof DelegatingRenderer)
		tcr = ((DelegatingRenderer)tcr).getDelegateRenderer();
	System.out.println("After un-delegataion, renderer is a : "+tcr);
	if (tcr instanceof DefaultTreeCellRenderer)
	{
		System.out.println("Renderer is a DefaultTreeCellRenderer");
		Object node = this.table.getPathForRow(offsetRow).getLastPathComponent();
		int depth = this.table.getPathForRow(offsetRow).getPathCount();
		System.out.println("Node's depth is "+depth);
		offset += (depth - 1) * 20;
		Icon icon;
		if (this.table.getTreeTableModel().isLeaf(node))
			icon = ((DefaultTreeCellRenderer) tcr).getLeafIcon();
		else if (this.table.isExpanded(offsetRow))
			icon = ((DefaultTreeCellRenderer) tcr).getOpenIcon();
		else
			icon = ((DefaultTreeCellRenderer) tcr).getClosedIcon();
		if (icon != null)
		{
			offset += ((DefaultTreeCellRenderer) tcr).getIconTextGap()
					+ icon.getIconWidth();
		}
	}
	((PartTypeComboBox) getComponent()).offset = offset;
	((PartTypeComboBox) getComponent()).setSelectedItem(value);
	return component;
}
 
Example 18
Source Project: openjdk-jdk8u   Source File: SynthTreeUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@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;
}
 
Example 19
Source Project: openjdk-jdk8u   Source File: SynthTreeUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void configureRenderer(SynthContext context) {
    TreeCellRenderer renderer = tree.getCellRenderer();

    if (renderer instanceof DefaultTreeCellRenderer) {
        DefaultTreeCellRenderer r = (DefaultTreeCellRenderer)renderer;
        SynthStyle style = context.getStyle();

        context.setComponentState(ENABLED | SELECTED);
        Color color = r.getTextSelectionColor();
        if (color == null || (color instanceof UIResource)) {
            r.setTextSelectionColor(style.getColor(
                                 context, ColorType.TEXT_FOREGROUND));
        }
        color = r.getBackgroundSelectionColor();
        if (color == null || (color instanceof UIResource)) {
            r.setBackgroundSelectionColor(style.getColor(
                                    context, ColorType.TEXT_BACKGROUND));
        }

        context.setComponentState(ENABLED);
        color = r.getTextNonSelectionColor();
        if (color == null || color instanceof UIResource) {
            r.setTextNonSelectionColor(style.getColorForState(
                                    context, ColorType.TEXT_FOREGROUND));
        }
        color = r.getBackgroundNonSelectionColor();
        if (color == null || color instanceof UIResource) {
            r.setBackgroundNonSelectionColor(style.getColorForState(
                              context, ColorType.TEXT_BACKGROUND));
        }
    }
}
 
Example 20
Source Project: marathonv5   Source File: JTreeJavaElement.java    License: Apache License 2.0 5 votes vote down vote up
private String getTextForNodeObject(JTree tree, Object lastPathComponent) {
    TreeCellRenderer renderer = tree.getCellRenderer();
    if (renderer == null) {
        return null;
    }
    Component c = renderer.getTreeCellRendererComponent(tree, lastPathComponent, false, false, false, 0, false);
    if (c != null && c instanceof JLabel) {
        return ((JLabel) c).getText();
    }
    return lastPathComponent.toString();
}
 
Example 21
Source Project: marathonv5   Source File: JTreeNodeJavaElement.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Component getPseudoComponent() {
    return EventQueueWait.exec(new Callable<Component>() {
        @Override
        public Component call() throws Exception {
            validateRow();
            JTree tree = (JTree) parent.getComponent();
            TreeCellRenderer cellRenderer = tree.getCellRenderer();
            TreePath pathForRow = tree.getPathForRow(viewRow);
            Object lastPathComponent = pathForRow.getLastPathComponent();
            return cellRenderer.getTreeCellRendererComponent(tree, lastPathComponent, false, false, false, viewRow, false);
        }
    });
}
 
Example 22
Source Project: marathonv5   Source File: JTreeNodeJavaElement.java    License: Apache License 2.0 5 votes vote down vote up
public static Component getRendererComponent(JTree tree, int row) {
    TreeCellRenderer cellRenderer = tree.getCellRenderer();
    TreePath pathForRow = tree.getPathForRow(row);
    Object lastPathComponent = pathForRow.getLastPathComponent();
    Component rendererComponent = cellRenderer.getTreeCellRendererComponent(tree, lastPathComponent, false, false, false, row,
            false);
    if (rendererComponent == null) {
        return null;
    }
    if (rendererComponent instanceof JComponent) {
        ((JComponent) rendererComponent).putClientProperty("jtree", (JTree) tree);
        ((JComponent) rendererComponent).putClientProperty("row", row);
    }
    return rendererComponent;
}
 
Example 23
Source Project: marathonv5   Source File: RTree.java    License: Apache License 2.0 5 votes vote down vote up
private String getTextForNodeObject(JTree tree, Object lastPathComponent) {
    TreeCellRenderer renderer = tree.getCellRenderer();
    if (renderer == null) {
        return null;
    }
    Component c = renderer.getTreeCellRendererComponent(tree, lastPathComponent, false, false, false, 0, false);
    if (c != null && c instanceof JLabel) {
        return ((JLabel) c).getText();
    }
    return lastPathComponent.toString();
}
 
Example 24
Source Project: openjdk-jdk9   Source File: JTreeOperator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JTree.setCellRenderer(TreeCellRenderer)} through queue
 */
public void setCellRenderer(final TreeCellRenderer treeCellRenderer) {
    runMapping(new MapVoidAction("setCellRenderer") {
        @Override
        public void map() {
            ((JTree) getSource()).setCellRenderer(treeCellRenderer);
        }
    });
}
 
Example 25
Source Project: netbeans   Source File: BindingCustomizer.java    License: Apache License 2.0 5 votes vote down vote up
private void initExpressionCombo() {
    TreeCellRenderer renderer = new TreeComboRenderer(FormUtils.getBundleString("MSG_BindingCustomizer_NullExpression")); // NOI18N
    expressionCombo = new ComboBoxWithTree(expressionModel, renderer, new Converter(expressionModel));
    expressionCombo.setSelectedItem("null"); // NOI18N

    renderer = new TreeComboRenderer(FormUtils.getBundleString("MSG_BindingCustomizer_NullDisplayExpression")); // NOI18N
    displayExpressionCombo = new ComboBoxWithTree(displayExpressionModel, renderer, new Converter(displayExpressionModel));
    displayExpressionCombo.setSelectedItem("null"); // NOI18N
}
 
Example 26
Source Project: netbeans   Source File: DomPanel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a cell renderer for the DOM tree.
 * 
 * @param delegate delegating/original tree renderer.
 * @return call renderer for the DOM tree.
 */
private TreeCellRenderer createTreeCellRenderer(final TreeCellRenderer delegate) {
    Color origColor = UIManager.getColor("Tree.selectionBackground"); // NOI18N
    Color color = origColor.brighter().brighter();
    if (color.equals(Color.WHITE)) { // Issue 217127
        color = origColor.darker();
    }
    // Color used for hovering highlight
    final Color hoverColor = color;
    final boolean nimbus = "Nimbus".equals(UIManager.getLookAndFeel().getID()); // NOI18N
    final JPanel nimbusPanel = nimbus ? new JPanel(new BorderLayout()) : null;
    return new DefaultTreeCellRenderer() {
        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            JComponent component;
            if (!selected && isHighlighted(value)) {
                component = (JComponent)delegate.getTreeCellRendererComponent(tree, value, true, expanded, leaf, row, hasFocus);
                if (nimbus) {
                    nimbusPanel.removeAll();
                    nimbusPanel.add(component);
                    component = nimbusPanel;
                }
                component.setBackground(hoverColor);
                component.setOpaque(true);
            } else {
                component = (JLabel)delegate.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
            }
            return component;
        }
    };
}
 
Example 27
Source Project: jdk8u-jdk   Source File: SynthTreeUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@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;
}
 
Example 28
Source Project: netbeans   Source File: DocumentViewPanel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a cell renderer for the tree view.
 *
 * @param delegate delegating/original tree renderer.
 * @return call renderer for the tree view.
 */
private TreeCellRenderer createTreeCellRenderer(final TreeCellRenderer delegate) {
    return new DefaultTreeCellRenderer() {
        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            return delegate.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
        }
    };
}
 
Example 29
Source Project: jdk8u-jdk   Source File: SynthTreeUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void configureRenderer(SynthContext context) {
    TreeCellRenderer renderer = tree.getCellRenderer();

    if (renderer instanceof DefaultTreeCellRenderer) {
        DefaultTreeCellRenderer r = (DefaultTreeCellRenderer)renderer;
        SynthStyle style = context.getStyle();

        context.setComponentState(ENABLED | SELECTED);
        Color color = r.getTextSelectionColor();
        if (color == null || (color instanceof UIResource)) {
            r.setTextSelectionColor(style.getColor(
                                 context, ColorType.TEXT_FOREGROUND));
        }
        color = r.getBackgroundSelectionColor();
        if (color == null || (color instanceof UIResource)) {
            r.setBackgroundSelectionColor(style.getColor(
                                    context, ColorType.TEXT_BACKGROUND));
        }

        context.setComponentState(ENABLED);
        color = r.getTextNonSelectionColor();
        if (color == null || color instanceof UIResource) {
            r.setTextNonSelectionColor(style.getColorForState(
                                    context, ColorType.TEXT_FOREGROUND));
        }
        color = r.getBackgroundNonSelectionColor();
        if (color == null || color instanceof UIResource) {
            r.setBackgroundNonSelectionColor(style.getColorForState(
                              context, ColorType.TEXT_BACKGROUND));
        }
    }
}
 
Example 30
Source Project: netbeans   Source File: StructureTreeView.java    License: Apache License 2.0 5 votes vote down vote up
public StructureTreeView(TreeCellRenderer r,String lineStyle){
     super();
     tree.setCellRenderer(r);
     tree.putClientProperty("JTree.lineStyle", lineStyle); // NOI18N
     tree.setShowsRootHandles(false);
     //expandAll();
}