Java 类javax.swing.tree.DefaultTreeCellRenderer 实例源码

项目:MFM    文件:SwingUtils.java   
public static void updateIcons(JTree tree) {
    Font defaultFont = UIManager.getFont("Tree.font");
    Font currentFont = tree.getFont();

    double newScale = (double)
            currentFont.getSize2D() / defaultFont.getSize2D();

    DefaultTreeCellRenderer renderer =
            (DefaultTreeCellRenderer) tree.getCellRenderer();
    renderer.setOpenIcon(
            scale(UIManager.getIcon("Tree.openIcon"), newScale, tree));
    renderer.setClosedIcon(
            scale(UIManager.getIcon("Tree.closedIcon"), newScale, tree));
    renderer.setLeafIcon(
            scale(UIManager.getIcon("Tree.leafIcon"), newScale, tree));

    Collection<Integer> iconSizes = Arrays.asList(
            renderer.getOpenIcon().getIconHeight(),
            renderer.getClosedIcon().getIconHeight(),
            renderer.getLeafIcon().getIconHeight());

    // Convert points to pixels
    Point2D p = new Point2D.Float(0, currentFont.getSize2D());
    FontRenderContext context =
            tree.getFontMetrics(currentFont).getFontRenderContext();
    context.getTransform().transform(p, p);
    int fontSizeInPixels = (int) Math.ceil(p.getY());

    tree.setRowHeight(
            Math.max(fontSizeInPixels, Collections.max(iconSizes) + 2));
}
项目:rapidminer    文件:ExtendedCheckTreeCellRenderer.java   
@Override
public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
        boolean leaf, int row, boolean hasFocus) {
    Component renderer = delegate.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
    ((DefaultTreeCellRenderer) renderer).setLeafIcon(null);
    ((DefaultTreeCellRenderer) renderer).setIcon(null);
    ((DefaultTreeCellRenderer) renderer).setOpenIcon(null);
    ((DefaultTreeCellRenderer) renderer).setClosedIcon(null);

    TreePath path = tree.getPathForRow(row);
    if (path != null) {
        if (selectionModel.isPathSelected(path, true)) {
            checkBox.setState(Boolean.TRUE);
        } else {
            checkBox.setState(selectionModel.isPartiallySelected(path) ? null : Boolean.FALSE);
        }
    }
    removeAll();
    add(checkBox, BorderLayout.WEST);
    add(renderer, BorderLayout.CENTER);
    return this;
}
项目:JavaGraph    文件:CheckboxTree.java   
/**
 * Empty constructor with the correct visibility.
 * @param tree the enclosing checkbox tree
 */
CellRenderer(CheckboxTree tree) {
    this.tree = tree;
    this.jLabel = new DefaultTreeCellRenderer();
    this.jLabel.setOpenIcon(null);
    this.jLabel.setLeafIcon(null);
    this.jLabel.setClosedIcon(null);
    this.jLabel.setBorder(INSET_BORDER);
    this.checkbox = new JCheckBox();
    this.checkbox.setOpaque(false);
    setLayout(new BorderLayout());
    add(this.jLabel, BorderLayout.CENTER);
    add(this.checkbox, CheckboxTree.CHECKBOX_ORIENTATION);
    setBorder(new EmptyBorder(0, 2, 0, 0));
    setComponentOrientation(this.tree.getComponentOrientation());
    setOpaque(false);
}
项目:openjdk-jdk10    文件:UpdateUIRecursionTest.java   
public UpdateUIRecursionTest() {
    super("UpdateUIRecursionTest");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(400, 400);

    String[] listData = {
        "First", "Second", "Third", "Fourth", "Fifth", "Sixth"
    };

    tree = new JTree(listData);
    renderer = new DefaultTreeCellRenderer();
    getContentPane().add(new JScrollPane(tree), BorderLayout.CENTER);
    tree.setCellRenderer(this);

    setVisible(true);
}
项目:audiveris    文件:JTreeTable.java   
/**
 * 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.
    TreeCellRenderer tcr = getCellRenderer();

    if (tcr instanceof DefaultTreeCellRenderer) {
        DefaultTreeCellRenderer dtcr = ((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.
        dtcr.setBorderSelectionColor(null);
        dtcr.setTextSelectionColor(UIManager.getColor("Table.selectionForeground"));
        dtcr.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground"));
    }
}
项目:bisis-v4    文件:RecordTreeCellEditor.java   
public RecordTreeCellEditor(RecordTree tree,DefaultTreeCellRenderer renderer) {
    super(tree,renderer);       
    cellEditor = new JTextArea();
    codedCellEditor = new JTextField();
    label = new JLabel();   
    coder = new JButton(new ImageIcon(getClass().getResource(
       "/com/gint/app/bisis4/client/images/coder.gif")));
    lookup = new CharacterLookup(BisisApp.getMainFrame());
    editingContainer = new Container();
    this.ownerTree = tree;
    regDlg = new RegistryDlg(BisisApp.getMainFrame());
    codedCellEditor.addKeyListener(new CellEditorKeyListener());            
    cellEditor.addKeyListener(new CellEditorKeyListener());
    coder.addKeyListener(new CellEditorKeyListener());
    coder.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e) {                        
            handleOpenCoder();              
        }           
    });
}
项目:checkstyle-backport-jre6    文件:TreeTableCellRenderer.java   
/**
 * 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"));
    }
}
项目:spring16project-Modula-2    文件:JTreeTable.java   
/**
 * updateUI is overridden to set the colors of the Tree's renderer to
 * match that of the table.
 */
public void updateUI() {
    super.updateUI();
    // Make the tree's cell renderer use the table's cell selection
    // colors.
    TreeCellRenderer tcr = getCellRenderer();
    if (tcr instanceof DefaultTreeCellRenderer) {
        DefaultTreeCellRenderer dtcr = ((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.
        // dtcr.setBorderSelectionColor(null);
        dtcr.setTextSelectionColor(UIManager
                .getColor("Table.selectionForeground"));
        dtcr.setBackgroundSelectionColor(UIManager
                .getColor("Table.selectionBackground"));
        ((DefaultTreeCellRenderer)this.getCellRenderer()).setLeafIcon(null);
        ((DefaultTreeCellRenderer)this.getCellRenderer()).setOpenIcon(null);
        ((DefaultTreeCellRenderer)this.getCellRenderer()).setClosedIcon(null);
    }
}
项目:spring16project-Modula-2    文件:TaskTable.java   
/**
     * updateUI is overridden to set the colors of the Tree's renderer to
     * match that of the table.
     */
    public void updateUI() {
        super.updateUI();

        // Make the tree's cell renderer use the table's cell selection
        // colors.
        TreeCellRenderer tcr = getCellRenderer();
        if (tcr instanceof DefaultTreeCellRenderer) {
            DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);

dtcr.setBorderSelectionColor(null);
            dtcr.setTextSelectionColor(UIManager
                    .getColor("Table.selectionForeground"));
            dtcr.setBackgroundSelectionColor(UIManager
                    .getColor("Table.selectionBackground"));
        }
    }
项目:spring16project-Modula-2    文件:DefectTable.java   
/**
     * updateUI is overridden to set the colors of the Tree's renderer to
     * match that of the table.
     */
    public void updateUI() {
        super.updateUI();

        // Make the tree's cell renderer use the table's cell selection
        // colors.
        TreeCellRenderer tcr = getCellRenderer();
        if (tcr instanceof DefaultTreeCellRenderer) {
            DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);

dtcr.setBorderSelectionColor(null);
            dtcr.setTextSelectionColor(UIManager
                    .getColor("Table.selectionForeground"));
            dtcr.setBackgroundSelectionColor(UIManager
                    .getColor("Table.selectionBackground"));
        }
    }
项目:JHelioviewer-SWHV    文件:EventPanel.java   
public EventPanel(SWEKGroup _group) {
    group = _group;
    setLayout(new BorderLayout());
    SWEKTreeModel.addSWEKTreeModelListener(this);

    JTree eventTypeTree = new JTree(new EventPanelModel(group));
    eventTypeTree.setEditable(true);
    eventTypeTree.setShowsRootHandles(true);
    eventTypeTree.setSelectionModel(null);
    eventTypeTree.setCellRenderer(new SWEKEventTreeRenderer(eventTypeTree));
    eventTypeTree.setCellEditor(new MyTreeCellEditor(eventTypeTree, (DefaultTreeCellRenderer) eventTypeTree.getCellRenderer()));

    // workaround for Win HiDpi
    if (System.getProperty("jhv.os").equals("windows")) {
        eventTypeTree.setRowHeight(new JCheckBox("J").getPreferredSize().height);
    }

    add(eventTypeTree, BorderLayout.CENTER);

    JPanel busyPanel = new JPanel();
    busyPanel.setBackground(eventTypeTree.getBackground());
    busyPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2));
    busyPanel.add(over);
    add(busyPanel, BorderLayout.LINE_END);
}
项目:spring16project-Fortran    文件:JTreeTable.java   
/**
 * 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.
    TreeCellRenderer tcr = getCellRenderer();
    if (tcr instanceof DefaultTreeCellRenderer) {
        DefaultTreeCellRenderer dtcr = ((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.
        // dtcr.setBorderSelectionColor(null);
        dtcr.setTextSelectionColor(UIManager.getColor("Table.selectionForeground"));
        dtcr.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground"));
        ((DefaultTreeCellRenderer) this.getCellRenderer()).setLeafIcon(null);
        ((DefaultTreeCellRenderer) this.getCellRenderer()).setOpenIcon(null);
        ((DefaultTreeCellRenderer) this.getCellRenderer()).setClosedIcon(null);
    }
}
项目:spring16project-Fortran    文件:TaskTable.java   
/**
 * 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.
    TreeCellRenderer tcr = getCellRenderer();
    if (tcr instanceof DefaultTreeCellRenderer) {
        DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);

        dtcr.setBorderSelectionColor(null);
        dtcr.setTextSelectionColor(UIManager.getColor("Table.selectionForeground"));
        dtcr.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground"));
    }
}
项目:intellij-ce-playground    文件:MacUIUtil.java   
public static void doNotFillBackground(@NotNull final JTree tree, @NotNull final DefaultTreeCellRenderer renderer) {
  TreeUI ui = tree.getUI();
  if (ui instanceof WideSelectionTreeUI) {
    if (((WideSelectionTreeUI)ui).isWideSelection()) {
      renderer.setOpaque(false);
      try {
        final Field fillBackground = DefaultTreeCellRenderer.class.getDeclaredField("fillBackground");
        fillBackground.setAccessible(true);
        fillBackground.set(renderer, false);
      }
      catch (Exception e) {
        // nothing
      }
    }
  }
}
项目:rapidminer-studio    文件:ExtendedCheckTreeCellRenderer.java   
@Override
public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
        boolean leaf, int row, boolean hasFocus) {
    Component renderer = delegate.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
    ((DefaultTreeCellRenderer) renderer).setLeafIcon(null);
    ((DefaultTreeCellRenderer) renderer).setIcon(null);
    ((DefaultTreeCellRenderer) renderer).setOpenIcon(null);
    ((DefaultTreeCellRenderer) renderer).setClosedIcon(null);

    TreePath path = tree.getPathForRow(row);
    if (path != null) {
        if (selectionModel.isPathSelected(path, true)) {
            checkBox.setState(Boolean.TRUE);
        } else {
            checkBox.setState(selectionModel.isPartiallySelected(path) ? null : Boolean.FALSE);
        }
    }
    removeAll();
    add(checkBox, BorderLayout.WEST);
    add(renderer, BorderLayout.CENTER);
    return this;
}
项目:amos-ss15-proj3    文件:Tree_Renderer.java   
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,
                                              boolean sel,
                                              boolean expanded,
                                              boolean leaf, int row,
                                              boolean hasFocus) {
    //DefaultTreeCellRenderer.getTreeCellRendererComponent() returns itself
    JLabel element = (DefaultTreeCellRenderer) new DefaultTreeCellRenderer().getTreeCellRendererComponent(
                    tree, value, selected, expanded, leaf, row, hasFocus);

    //content of a node, could be a Path (if just directory) or a CommitFile
    Object content = ((DefaultMutableTreeNode) value).getUserObject();

    //if path, default .toString() method is called
    element.setOpaque(true);

    //if a CommitFile
    if (content instanceof Presenter) {
        element = ((Presenter)content).present(element);
    }

    return element;
}
项目:binnavi    文件:CTagFilterTree.java   
/**
 * Creates a new filter tree object.
 * 
 * @param tagManager Provides the tags the user can select.
 */
public CTagFilterTree(final ITagManager tagManager) {
  super(new CFilterTreeModel(tagManager.getRootTag()));

  m_tagManager = tagManager;

  setDigIn(false);

  final DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
  renderer.setOpenIcon(ICON_CONTAINER_TAG);
  renderer.setClosedIcon(ICON_CONTAINER_TAG);
  renderer.setLeafIcon(ICON_TAG);
  setCellRenderer(renderer);

  setRootVisible(false);
  TreeHelpers.expandAll(this, true);

  tagManager.addListener(m_tagManagerListener);
}
项目:swingx    文件:JXTreeTable.java   
/**
 * 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.
    // TODO JW: need to revisit...
    // a) the "real" of a JXTree is always wrapped into a DelegatingRenderer
    //  consequently the if-block never executes
    // b) even if it does it probably (?) should not 
    // unconditionally overwrite custom selection colors. 
    // Check for UIResources instead. 
    TreeCellRenderer tcr = getCellRenderer();
    if (tcr instanceof DefaultTreeCellRenderer) {
        DefaultTreeCellRenderer dtcr = ((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.
        dtcr.setBorderSelectionColor(null);
        dtcr.setTextSelectionColor(
            UIManager.getColor("Table.selectionForeground"));
        dtcr.setBackgroundSelectionColor(
            UIManager.getColor("Table.selectionBackground"));
    }
}
项目:swingx    文件:JXTreeTableIssues.java   
/**
 * Custom renderer colors of core DefaultTreeCellRenderer not respected.
 * This is intentional: treeTable's highlighters must rule, so the
 * renderer colors are used to force the treecellrenderer to use the 
 * correct values.
 */
public void interactiveCoreRendererCustomColor() {
    JXTreeTable treeTable = new JXTreeTable(new FileSystemModel());
    treeTable.addHighlighter(HighlighterFactory.createSimpleStriping());
    DefaultTreeCellRenderer legacy = createBackgroundTreeRenderer();
    // in a treetable this has no effect: treetable.applyRenderer 
    // internally resets them to the same colors as tree itself
    // (configured by the table's highlighters
    legacy.setBackgroundNonSelectionColor(Color.YELLOW);
    legacy.setBackgroundSelectionColor(Color.RED);
    treeTable.setTreeCellRenderer(legacy);
    JTree tree = new JXTree(treeTable.getTreeTableModel());
    DefaultTreeCellRenderer other = createBackgroundTreeRenderer();
    other.setBackgroundNonSelectionColor(Color.YELLOW);
    other.setBackgroundSelectionColor(Color.RED);
    tree.setCellRenderer(other);
    JXFrame frame = wrapWithScrollingInFrame(treeTable, tree, "legacy renderers - highlight complete cell");
    frame.setVisible(true);  
}
项目:swingx    文件:TreeRendererTest.java   
/**
 * Custom tree colors in JTree. Compare core default renderer with Swingx
 * default renderer.
 * 
 */
public void interactiveCompareTreeExtTreeColors() {
    JTree xtree = new JTree();
    Color background = Color.MAGENTA;
    Color foreground = Color.YELLOW;
    xtree.setBackground(background);
    xtree.setForeground(foreground);
    DefaultTreeCellRenderer coreTreeCellRenderer = new DefaultTreeCellRenderer();
    // to get a uniform color on both tree and node
    // the core default renderer needs to be configured
    coreTreeCellRenderer.setBackgroundNonSelectionColor(background);
    coreTreeCellRenderer.setTextNonSelectionColor(foreground);
    xtree.setCellRenderer(coreTreeCellRenderer);
    JTree tree = new JTree();
    tree.setBackground(background);
    tree.setForeground(foreground);
    // swingx renderer uses tree colors
    tree.setCellRenderer(xTreeRenderer);
    final JXFrame frame = wrapWithScrollingInFrame(xtree, tree,
            "custom tree colors - core vs. ext renderer");
    frame.setVisible(true);
}
项目:swingx    文件:JXTreeTableVisualCheck.java   
/**
 * Creates and returns a core default tree cell renderer with tooltip.
 * @return
 */
private TreeCellRenderer createTreeRenderer() {
    final TreeCellRenderer delegate = new DefaultTreeCellRenderer();
    TreeCellRenderer renderer = new TreeCellRenderer() {

        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, 
                boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            Component result = delegate.getTreeCellRendererComponent(tree, value, 
                    selected, expanded, leaf, row, hasFocus);
            ((JComponent) result).setToolTipText(String.valueOf(tree.getPathForRow(row)));
             return result;
        }

    };
    return renderer;
}
项目:youscope    文件:Workspace.java   
/**
 * Constructor
 */
Workspace()
{
    super(new BorderLayout());
    add(new JScrollPane(variablesTree), BorderLayout.CENTER);
    setPreferredSize(new Dimension(200, 300));
    variablesTree.setRootVisible(false);
    variablesTree.setShowsRootHandles(true);

    // Customize icons
    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
    Icon leafIcon = ImageLoadingTools.getResourceIcon("icons/sticky-note-pin.png", "document");
    if(leafIcon != null)
        renderer.setLeafIcon(leafIcon);
    Icon openIcon = ImageLoadingTools.getResourceIcon("icons/wooden-box.png", "opened folder");
    if(openIcon != null)
        renderer.setOpenIcon(openIcon);
    Icon closedIcon = ImageLoadingTools.getResourceIcon("icons/wooden-box.png", "closed folder");
    if(closedIcon != null)
        renderer.setClosedIcon(closedIcon);
    variablesTree.setCellRenderer(renderer);

    setBorder(new TitledBorder("Workspace"));
}
项目:mindraider    文件:JTreeTable.java   
/**
 * updateUI is overridden to set the colors of the Tree's renderer to
 * match that of the table.
 */
public void updateUI() {
    super.updateUI();
    // Make the tree's cell renderer use the table's cell selection
    // colors.
    TreeCellRenderer tcr = getCellRenderer();
    if (tcr instanceof DefaultTreeCellRenderer) {
        DefaultTreeCellRenderer dtcr = ((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.
        // dtcr.setBorderSelectionColor(null);
        dtcr.setTextSelectionColor(UIManager
                .getColor("Table.selectionForeground"));
        dtcr.setBackgroundSelectionColor(UIManager
                .getColor("Table.selectionBackground"));
    }
}
项目:humo    文件:CallStackParserListener.java   
public void init(String filename, StringBuilder sourcecode, boolean createComponents)
   {
usedProductionsStack= new Stack<DefaultMutableTreeNode>();
usedProductionsStackRoot= new StacktraceTreeNode("Call stack of: " + filename, currentFrame);
usedProductionsStack.push(usedProductionsStackRoot);
if (createComponents)
{
    stacktraceTree= new JTree();
    DefaultTreeCellRenderer renderer= new DefaultTreeCellRenderer();
    Icon customOpenIcon= new ImageIcon(HumoTester.class.getResource("/images/stckframe.gif"));
    Icon customClosedIcon= new ImageIcon(HumoTester.class.getResource("/images/stckframe.gif"));
    renderer.setOpenIcon(customOpenIcon);
    renderer.setClosedIcon(customClosedIcon);
    stacktraceTree.setCellRenderer(renderer);
}

stacktraceTree.setModel(new DefaultTreeModel(usedProductionsStackRoot));
currentFrame= null;
   }
项目:MeteoInfoLib    文件:CheckTreeCellRenderer.java   
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    Component renderer = delegate.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
    ((DefaultTreeCellRenderer)this.delegate).setIcon(null);

    TreePath path = tree.getPathForRow(row);
    if (path != null) {
        System.out.println(path);
        if (selectionModel.isPathSelected(path, true)) {
            checkBox.setSelected(true);
        } else {
            //System.out.println(selectionModel.isPartiallySelected(path));
            checkBox.setSelected(selectionModel.isPartiallySelected(path) ? true : false);
        }
    }
    removeAll();
    add(checkBox, BorderLayout.WEST);
    add(renderer, BorderLayout.CENTER);
    return this;
}
项目:viewer    文件:JTreeTable.java   
/**
 * updateUI is overridden to set the colors of the Tree's renderer
 * to match that of the table.
 */
public void updateUI() {
    super.updateUI();
    // Make the tree's cell renderer use the table's cell selection
    // colors.
    TreeCellRenderer tcr = getCellRenderer();
    if (tcr instanceof DefaultTreeCellRenderer) {
    DefaultTreeCellRenderer dtcr = ((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.
    // dtcr.setBorderSelectionColor(null);
    dtcr.setTextSelectionColor(UIManager.getColor
                   ("Table.selectionForeground"));
    dtcr.setBackgroundSelectionColor(UIManager.getColor
                    ("Table.selectionBackground"));
    }
}
项目:humo    文件:ExecutionParserListener.java   
public void init(String filename, boolean createComponents, CharSequence sourcecode)
   {
nodes= new Stack<DefaultMutableTreeNode>();
root= new DefaultMutableTreeNode("Execution of: " + filename);
nodes.push(root);
if (createComponents)
{
    executionTree= new JTree();
    DefaultTreeCellRenderer renderer= new DefaultTreeCellRenderer();
    Icon customOpenIcon= new ImageIcon(HumoTester.class.getResource("/images/ebrkpnt_green.gif"));
    Icon customClosedIcon= new ImageIcon(HumoTester.class.getResource("/images/ebrkpnt.gif"));
    renderer.setOpenIcon(customOpenIcon);
    renderer.setClosedIcon(customClosedIcon);
    executionTree.setCellRenderer(renderer);

}

executionTree.setModel(new DefaultTreeModel(root));
   }
项目:aceview    文件:ACEExplanationViewComponent.java   
@Override
protected void initialiseOWLView() throws Exception {
    treeExplanations = new JTree(model);
    treeExplanations.setRowHeight(-1);
    treeExplanations.setRootVisible(true);
    treeExplanations.setShowsRootHandles(true);

    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
    renderer.setOpenIcon(null);
    renderer.setClosedIcon(null);
    renderer.setLeafIcon(null);
    treeExplanations.setCellRenderer(renderer);

    setLayout(new BorderLayout());
    add(BorderLayout.CENTER, new JScrollPane(treeExplanations));

    treeExplanations.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    treeExplanations.addTreeSelectionListener(treeSelectionListener);
    ACETextManager.addSnippetListener(snippetListener);
}
项目:jcrBrowser    文件:BrowserUI.java   
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    if (comp instanceof JLabel) {
        JLabel lbl = (JLabel) comp;
        DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();

        Icon leafIcon = renderer.getDefaultLeafIcon();
        // Icon openIcon = renderer.getDefaultOpenIcon( );
        Icon closedIcon = renderer.getDefaultClosedIcon();
        if (((BOContent) value).isFolder()) {
            lbl.setIcon(closedIcon);
        } else {
            lbl.setIcon(leafIcon);
        }

    }
    return comp;
}
项目:wabit    文件:WorkspaceTreeCellRenderer.java   
private void setupForChart(DefaultTreeCellRenderer r, Chart chart) {
    ChartType chartType = chart.getType();
    if (chartType == null) {
        r.setIcon(CHART_ICON);
    } else if (chartType.equals(ChartType.BAR)) {
        r.setIcon(CHART_BAR_ICON);
    } else if (chartType.equals(ChartType.PIE)) {
        r.setIcon(CHART_PIE_ICON);
    } else if (chartType.equals(ChartType.CATEGORY_LINE)) {
        r.setIcon(CHART_LINE_ICON);
    } else if (chartType.equals(ChartType.SCATTER)) {
        r.setIcon(CHART_SCATTER_ICON);
    } else if (chartType.equals(ChartType.LINE)) {
        r.setIcon(CHART_LINE_ICON);
    } else {
        logger.warn("Using generic icon for unknown chart type " + chartType);
        r.setIcon(CHART_ICON); 
    }
    r.setText(chart.getName());
}
项目:humo    文件:ProductionsParserListener.java   
public void init(String filename, boolean createComponents)
   {
nodes= new HashMap<CharSequence, DefaultMutableTreeNode>();
this.root= new DefaultMutableTreeNode("Productions of: " + filename);

if (createComponents)
{
    productionsTree= new JTree(root);
    DefaultTreeCellRenderer renderer= new DefaultTreeCellRenderer();
    Icon customOpenIcon= new ImageIcon(HumoTester.class.getResource("/images/scalarvar.gif"));
    Icon customClosedIcon= new ImageIcon(HumoTester.class.getResource("/images/genericvariable.gif"));
    renderer.setOpenIcon(customOpenIcon);
    renderer.setClosedIcon(customClosedIcon);
    productionsTree.setCellRenderer(renderer);
}

productionsTree.setModel(new DefaultTreeModel(root));
   }
项目:incubator-taverna-workbench    文件:JTreeTable.java   
/**
 * updateUI is overridden to set the colors of the Tree's renderer to
 * match that of the table.
 */
public void updateUI() {
    super.updateUI();
    // Make the tree's cell renderer use the table's cell selection
    // colors.
    TreeCellRenderer tcr = getCellRenderer();
    if (tcr instanceof DefaultTreeCellRenderer) {
        //DefaultTreeCellRenderer dtcr = ((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.
        // dtcr.setBorderSelectionColor(null);
        // dtcr.setTextSelectionColor(UIManager.getColor
        // ("Table.selectionForeground"));
        // dtcr.setBackgroundSelectionColor(UIManager.getColor
        // ("Table.selectionBackground"));
    }
}
项目:incubator-netbeans    文件:DocumentViewPanel.java   
/**
 * 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);
        }
    };
}
项目:incubator-netbeans    文件:TreeViewCellEditor.java   
/** Construct a cell editor.
* @param tree the tree
*/
public TreeViewCellEditor(JTree tree) {
    //Use a dummy DefaultTreeCellEditor - we'll set up the correct
    //icon when we fetch the editor component (see EOF).  Not sure
    //it's wildly vaulable to subclass DefaultTreeCellEditor here - 
    //we override most everything
    super(tree, new DefaultTreeCellRenderer());

    // deal with selection if already exists
    if (tree.getSelectionCount() == 1) {
        lastPath = tree.getSelectionPath();
    }

    addCellEditorListener(this);
}
项目:incubator-netbeans    文件:CheckTreeCellRenderer.java   
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf,
                                              int row, boolean hasFocus) {
    // Get CheckTreeNode from current Node
    CheckTreeNode treeNode = (value instanceof CheckTreeNode) ? (CheckTreeNode) value : null;

    // Update UI
    if (treeRendererComponent != null) {
        remove(treeRendererComponent);
    }

    if (treeNode != null) {
        checkBox.setVisible(!persistentRenderer);
        setupCellRendererIcon((DefaultTreeCellRenderer) treeRenderer, treeNode.getIcon());
    } else {
        checkBox.setVisible(false);
        setupCellRendererIcon((DefaultTreeCellRenderer) treeRenderer, null);
    }

    treeRendererComponent = treeRenderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
    add(treeRendererComponent, BorderLayout.CENTER);

    // Return if no path or not a CheckTreeNode
    if (treeNode == null) {
        return this;
    }

    // If tree model supports checking (uses CheckTreeNodes), setup CheckBox
    if (treeNode.isFullyChecked()) {
        setupCheckBox(Boolean.TRUE);
    } else {
        setupCheckBox(treeNode.isPartiallyChecked() ? null : Boolean.FALSE);
    }

    return this;
}
项目:rapidminer    文件:ExtendedCheckTreeMouseSelectionManager.java   
public ExtendedCheckTreeMouseSelectionManager(JTree tree, boolean selectAll) {
    this.tree = tree;
    selectionModel = new ExtendedCheckTreeSelectionModel(tree.getModel());

    if (selectAll) {
        selectionModel.addSelectionPath(tree.getPathForRow(0));
    }

    tree.setCellRenderer(new ExtendedCheckTreeCellRenderer(new DefaultTreeCellRenderer(), selectionModel));
    tree.addMouseListener(this);
    selectionModel.addTreeSelectionListener(this);
}
项目:rapidminer    文件:ClusterTreeVisualization.java   
/**
 * Ensure white background for this tree.
 */
private void setBackgroundWhite() {
    setBackground(Colors.WHITE);
    setCellRenderer(new DefaultTreeCellRenderer() {

        private static final long serialVersionUID = 1L;

        @Override
        public Color getBackgroundNonSelectionColor() {
            return Colors.WHITE;
        }
    });
}
项目:marathonv5    文件:DefaultContextMenu.java   
public AssertionTreeNodeRenderer() {
    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
    fgSel = renderer.getTextSelectionColor();
    fgNonSel = renderer.getTextNonSelectionColor();
    bgSel = renderer.getBackgroundSelectionColor();
    bgNonSel = renderer.getBackgroundNonSelectionColor();
    valueStyle = new SimpleAttributeSet();
    StyleConstants.setForeground(valueStyle, valueForegroundColor);
    propertyStyle = new SimpleAttributeSet();
    if (fgNonSel != null) {
        StyleConstants.setForeground(propertyStyle, fgNonSel);
    }
}
项目:marathonv5    文件:GenealogyTree.java   
public GenealogyTree(Person graphNode) {
    super(new GenealogyModel(graphNode));
    getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
    Icon personIcon = null;
    renderer.setLeafIcon(personIcon);
    renderer.setClosedIcon(personIcon);
    renderer.setOpenIcon(personIcon);
    setCellRenderer(renderer);
}
项目:VASSAL-src    文件:Inventory.java   
protected TreeCellRenderer initTreeCellRenderer() {
  return new DefaultTreeCellRenderer() {

    private static final long serialVersionUID = -250332615261355856L;

    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
      super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf && !foldersOnly, row, hasFocus);
      if (value instanceof CounterNode) {
        final GamePiece piece = ((CounterNode) value).getCounter().getPiece();
        if (piece != null) {
          final Rectangle r = piece.getShape().getBounds();
          r.x = (int) Math.round(r.x * pieceZoom);
          r.y = (int) Math.round(r.y * pieceZoom);
          r.width = (int) Math.round(r.width * pieceZoom);
          r.height = (int) Math.round(r.height * pieceZoom);
          setIcon(drawPieces ? new Icon() {

            public int getIconHeight() {
              return r.height;
            }

            public int getIconWidth() {
              return r.width;
            }

            public void paintIcon(Component c, Graphics g, int x, int y) {
              piece.draw(g, -r.x, -r.y, c, pieceZoom);
            }

          } : null);
        }
      }
      return this;
    }

  };
}