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

项目:incubator-netbeans    文件:ResultTreeView.java   
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);
   }
项目:ramus    文件:FirstRowCellEditor.java   
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);
}
项目: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"));
    }
}
项目: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"));
        }
    }
项目: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"));
    }
}
项目:javify    文件:BasicTreeUI.java   
/**
 * Sets the TreeCellRenderer to <code>tcr</code>. This invokes
 * <code>updateRenderer</code>.
 *
 * @param tcr is the new TreeCellRenderer.
 */
protected void setCellRenderer(TreeCellRenderer tcr)
{
  // Finish editing before changing the renderer.
  completeEditing();

  // The renderer is set in updateRenderer.
  updateRenderer();

  // Refresh the layout if necessary.
  if (treeState != null)
    {
      treeState.invalidateSizes();
      updateSize();
    }
}
项目:javify    文件:BasicTreeUI.java   
/**
 * Paints the renderer part of a row. The receiver should NOT modify
 * clipBounds, or insets.
 *
 * @param g - the graphics configuration
 * @param clipBounds -
 * @param insets -
 * @param bounds - bounds of expand control
 * @param path - path to draw control for
 * @param row - row to draw control for
 * @param isExpanded - is the row expanded
 * @param hasBeenExpanded - has the row already been expanded
 * @param isLeaf - is the path a leaf
 */
protected void paintRow(Graphics g, Rectangle clipBounds, Insets insets,
                        Rectangle bounds, TreePath path, int row,
                        boolean isExpanded, boolean hasBeenExpanded,
                        boolean isLeaf)
{
  boolean selected = tree.isPathSelected(path);
  boolean hasIcons = false;
  Object node = path.getLastPathComponent();

  paintExpandControl(g, clipBounds, insets, bounds, path, row, isExpanded,
                     hasBeenExpanded, isLeaf);

  TreeCellRenderer dtcr = currentCellRenderer;

  boolean focused = false;
  if (treeSelectionModel != null)
    focused = treeSelectionModel.getLeadSelectionRow() == row
              && tree.isFocusOwner();

  Component c = dtcr.getTreeCellRendererComponent(tree, node, selected,
                                                  isExpanded, isLeaf, row,
                                                  focused);

  rendererPane.paintComponent(g, c, c.getParent(), bounds);
}
项目:intellij-ce-playground    文件:TreeTableView.java   
public TreeTableView(ListTreeTableModelOnColumns treeTableModel) {
  super(treeTableModel);
  setRootVisible(false);

  setTreeCellRenderer(new TreeCellRenderer() {
    private final TreeCellRenderer myBaseRenderer = new HighlightableCellRenderer();
    public Component getTreeCellRendererComponent(JTree tree1,
                                                  Object value,
                                                  boolean selected,
                                                  boolean expanded,
                                                  boolean leaf,
                                                  int row,
                                                  boolean hasFocus) {
      JComponent result = (JComponent)myBaseRenderer.getTreeCellRendererComponent(tree1, value, selected, expanded, leaf, row, hasFocus);
      result.setOpaque(!selected);
      return result;
    }
  });

  setSizes();
}
项目:intellij-ce-playground    文件:TreeExpandableItemsHandler.java   
@Override
protected Pair<Component, Rectangle> getCellRendererAndBounds(Integer key) {
  int rowIndex = key.intValue();

  TreePath path = myComponent.getPathForRow(rowIndex);
  if (path == null) return null;

  Rectangle bounds = myComponent.getPathBounds(path);
  if (bounds == null) return null;

  TreeCellRenderer renderer = myComponent.getCellRenderer();
  if (renderer == null) return null;

  Object node = path.getLastPathComponent();
  Component rendererComponent = renderer.getTreeCellRendererComponent(
    myComponent,
    node,
    myComponent.isRowSelected(rowIndex),
    myComponent.isExpanded(rowIndex),
    myComponent.getModel().isLeaf(node),
    rowIndex,
    myComponent.hasFocus()
  );
  return Pair.create(rendererComponent, bounds);
}
项目:jvm-stm    文件:BasicTreeUI.java   
/**
  * Sets the TreeCellRenderer to <code>tcr</code>. This invokes
  * <code>updateRenderer</code>.
  * 
  * @param tcr is the new TreeCellRenderer.
  */
 protected void setCellRenderer(TreeCellRenderer tcr)
 {
   // Finish editing before changing the renderer.
   completeEditing();

   // The renderer is set in updateRenderer.
   updateRenderer();

   // Refresh the layout if necessary.
   if (treeState != null)
     {
treeState.invalidateSizes();
updateSize();
     }
 }
项目:jvm-stm    文件:BasicTreeUI.java   
/**
 * Paints the renderer part of a row. The receiver should NOT modify
 * clipBounds, or insets.
 * 
 * @param g - the graphics configuration
 * @param clipBounds -
 * @param insets -
 * @param bounds - bounds of expand control
 * @param path - path to draw control for
 * @param row - row to draw control for
 * @param isExpanded - is the row expanded
 * @param hasBeenExpanded - has the row already been expanded
 * @param isLeaf - is the path a leaf
 */
protected void paintRow(Graphics g, Rectangle clipBounds, Insets insets,
                        Rectangle bounds, TreePath path, int row,
                        boolean isExpanded, boolean hasBeenExpanded,
                        boolean isLeaf)
{
  boolean selected = tree.isPathSelected(path);
  boolean hasIcons = false;
  Object node = path.getLastPathComponent();

  paintExpandControl(g, clipBounds, insets, bounds, path, row, isExpanded,
                     hasBeenExpanded, isLeaf);

  TreeCellRenderer dtcr = currentCellRenderer;

  boolean focused = false;
  if (treeSelectionModel != null)
    focused = treeSelectionModel.getLeadSelectionRow() == row
              && tree.isFocusOwner();

  Component c = dtcr.getTreeCellRendererComponent(tree, node, selected,
                                                  isExpanded, isLeaf, row,
                                                  focused);

  rendererPane.paintComponent(g, c, c.getParent(), bounds);
}
项目: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    文件:TreeRolloverController.java   
@Override
protected RolloverRenderer getRolloverRenderer(Point location, boolean prepare) {
    TreeCellRenderer renderer = component.getCellRenderer();
    RolloverRenderer rollover = renderer instanceof RolloverRenderer 
        ? (RolloverRenderer) renderer : null;
    if ((rollover != null) && !rollover.isEnabled()) {
        rollover = null;
    }
    if ((rollover != null) && prepare) {
        TreePath path = component.getPathForRow(location.y);
        Object element = path != null ? path.getLastPathComponent() : null;
        renderer.getTreeCellRendererComponent(component, element, false, 
                false, false, 
                location.y, false);
    }
    return rollover;
}
项目:swingx    文件:TreeTableCellEditor.java   
/**
     * @param row
     * @param isSelected
     */
    protected void initEditorOffset(JTable table, int row, int column,
            boolean isSelected) {
        if (tree == null)
            return;
//        Rectangle bounds = tree.getRowBounds(row);
//        int offset = bounds.x;
        Object node = tree.getPathForRow(row).getLastPathComponent();
        boolean leaf = tree.getModel().isLeaf(node);
        boolean expanded = tree.isExpanded(row);
        TreeCellRenderer tcr = tree.getCellRenderer();
        Component editorComponent = tcr.getTreeCellRendererComponent(tree, node,
                isSelected, expanded, leaf, row, false);

        ((TreeTableTextField) getComponent()).init(row,
                column, table, tree, editorComponent);
    }
项目:swingx    文件:JXTreeUnitTest.java   
/**
 * Issue #817-swingx: Delegating renderer must create list's default.
 * Delegating has default from list initially, here: custom default.
 */
@Test
public void testDelegatingRendererUseCustomDefaultSetNull() {
    JXTree list = new JXTree() {

        @Override
        protected TreeCellRenderer createDefaultCellRenderer() {
            return new CustomDefaultRenderer();
        }

    };
    TreeCellRenderer defaultRenderer = list.createDefaultCellRenderer();
    DelegatingRenderer renderer = (DelegatingRenderer) list.getCellRenderer();
    list.setCellRenderer(null);
    assertEquals("wrapping renderer must use list's default on null",
            defaultRenderer.getClass(), renderer.getDelegateRenderer().getClass());
}
项目:swingx    文件:JXTreeUnitTest.java   
/**
 * Issue #817-swingx: Delegating renderer must create list's default.
 * Delegating has default from list initially, here: custom default.
 */
@Test
public void testDelegatingRendererUseCustomDefault() {
    JXTree list = new JXTree() {

        @Override
        protected TreeCellRenderer createDefaultCellRenderer() {
            return new CustomDefaultRenderer();
        }

    };
    TreeCellRenderer defaultRenderer = list.createDefaultCellRenderer();
    assertEquals("sanity: creates custom", CustomDefaultRenderer.class, 
            defaultRenderer.getClass());
    DelegatingRenderer renderer = (DelegatingRenderer) list.getCellRenderer();
    assertEquals(defaultRenderer.getClass(), renderer.getDelegateRenderer().getClass());
}
项目:swingx    文件:RendererVisualCheck.java   
/**
 * xtable/xlist using the same custom component controller.<p>
 * 
 */
public void interactiveTableAndTreeCustomColorRenderingController() {
    TableModel tableModel = new AncientSwingTeam();
    ComponentProvider<JLabel> controller = createColorRenderingLabelController();
    JXTable xtable = new JXTable(tableModel);
    xtable.setDefaultRenderer(Color.class, new DefaultTableRenderer(controller));
    TreeModel model = createTreeColorModel();
    JTree tree = new JTree(model);
    ComponentProvider<?> wrapper = new WrappingProvider(controller); //;createColorRenderingLabelController());
    TreeCellRenderer renderer = new DefaultTreeRenderer(wrapper);
    tree.setCellRenderer(renderer);
    JXFrame frame = wrapWithScrollingInFrame(xtable, tree, "JXTable/JXTree: Custom color renderer - sharing the component controller");
    addMessage(frame, "share provider in table and in wrappingProvider does not work?");
    frame.pack();
    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;
}
项目: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"));
    }
}
项目: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"));
    }
}
项目:aTunes    文件:FileSelectionDialog.java   
private void setTreeRenderer() {
    fileSystemTree.setCellRenderer(new TreeCellRenderer() {
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;

            if (node.getUserObject() instanceof String)
                return new JLabel();

            Directory content = (Directory) node.getUserObject();
            JLabel icon = new JLabel(value.toString());
            icon.setIcon(fsView.getSystemIcon(content.file));

            return icon;
        }
    });
}
项目:aibench-project    文件: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"));
    }
}
项目:aibench-project    文件:TreeRolloverController.java   
@Override
protected RolloverRenderer getRolloverRenderer(Point location, boolean prepare) {
    TreeCellRenderer renderer = component.getCellRenderer();
    RolloverRenderer rollover = renderer instanceof RolloverRenderer 
        ? (RolloverRenderer) renderer : null;
    if ((rollover != null) && !rollover.isEnabled()) {
        rollover = null;
    }
    if ((rollover != null) && prepare) {
        TreePath path = component.getPathForRow(location.y);
        Object element = path != null ? path.getLastPathComponent() : null;
        renderer.getTreeCellRendererComponent(component, element, false, 
                false, false, 
                location.y, false);
    }
    return rollover;
}
项目: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"));
    }
}
项目:jtv    文件:Jtv.java   
void handleNormalize(KeyEvent e){
    if( (e.getModifiers() & KeyEvent.CTRL_MASK) != 0 ){
        e.consume();
        resetSize();
    }else if( (e.getModifiers() & KeyEvent.ALT_MASK) != 0 ){

        TreeCellRenderer cellRenderer = tree.getCellRenderer();

        if( cellRenderer instanceof DefaultTreeCellRenderer ){

            e.consume();

            DefaultTreeCellRenderer dCellRenderer =
                (DefaultTreeCellRenderer) cellRenderer;

            Font font = dCellRenderer.getFont();
            Font next = new Font(font.getName(), font.getStyle(), 12);
            dCellRenderer.setFont( next );
            cmdInput.storeCaretPos();
            cmdInput.setFont( next );
            SwingUtilities.updateComponentTreeUI(topFrame);
            cmdInput.restoreCaretPos();
        }
    }
}
项目:cn1    文件:BasicTreeUI.java   
public void propertyChange(final PropertyChangeEvent e) {
    String changedProperty = e.getPropertyName();
    if (JTree.CELL_RENDERER_PROPERTY.equals(changedProperty)) {
        setCellRenderer((TreeCellRenderer)e.getNewValue());
    } else if (JTree.CELL_EDITOR_PROPERTY.equals(changedProperty)) {
        setCellEditor((TreeCellEditor)e.getNewValue());
    } else if (JTree.TREE_MODEL_PROPERTY.equals(changedProperty)) {
        setModel((TreeModel)e.getNewValue());
    } else if (JTree.ROOT_VISIBLE_PROPERTY.equals(changedProperty)) {
        setRootVisible(((Boolean)e.getNewValue()).booleanValue());
    } else if (JTree.SHOWS_ROOT_HANDLES_PROPERTY.equals(changedProperty)) {
        setShowsRootHandles(((Boolean)e.getNewValue()).booleanValue());
    } else if (JTree.ROW_HEIGHT_PROPERTY.equals(changedProperty)) {
        setRowHeight(((Integer)e.getNewValue()).intValue());
    } else if (JTree.EDITABLE_PROPERTY.equals(changedProperty)) {
        setEditable(((Boolean)e.getNewValue()).booleanValue());
    } else if (JTree.LARGE_MODEL_PROPERTY.equals(changedProperty)) {
        setLargeModel(((Boolean)e.getNewValue()).booleanValue());
    } else if (JTree.SELECTION_MODEL_PROPERTY.equals(changedProperty)) {
        setSelectionModel((TreeSelectionModel)e.getNewValue());
    } else if (JTree.LEAD_SELECTION_PATH_PROPERTY.equals(changedProperty)) {
        TreePath leadPath = (TreePath)e.getNewValue();
        lastSelectedRow = leadPath != null ? tree.getRowForPath(leadPath) : -1;
    }
}
项目:cn1    文件:JTreeTest.java   
public void testSetCellRenderer() {
    PropertyChangeController listener = new PropertyChangeController();
    TreeCellRenderer renderer1 = new DefaultTreeCellRenderer();
    TreeCellRenderer renderer2 = new DefaultTreeCellRenderer();
    tree.addPropertyChangeListener(listener);
    TreeCellRenderer oldRenderer = tree.getCellRenderer();
    tree.setCellRenderer(renderer1);
    listener.checkPropertyFired(tree, "cellRenderer", oldRenderer, renderer1);
    assertEquals("cellRenderer", renderer1, tree.getCellRenderer());
    listener.reset();
    tree.setCellRenderer(renderer2);
    listener.checkPropertyFired(tree, "cellRenderer", renderer1, renderer2);
    assertEquals("cellRenderer", renderer2, tree.getCellRenderer());
    listener.reset();
    tree.setCellRenderer(renderer2);
    assertFalse("event's not been fired ", listener.isChanged());
    listener.reset();
    tree.setCellRenderer(null);
    listener.checkPropertyFired(tree, "cellRenderer", renderer2, null);
    // it's being controlled by UI via listener
    assertNotNull("cellRenderer", tree.getCellRenderer());
    assertNotSame("cellRenderer", oldRenderer, tree.getCellRenderer());
    assertNotSame("cellRenderer", renderer2, tree.getCellRenderer());
    listener.reset();
}
项目:JamVM-PH    文件:BasicTreeUI.java   
/**
  * Sets the TreeCellRenderer to <code>tcr</code>. This invokes
  * <code>updateRenderer</code>.
  * 
  * @param tcr is the new TreeCellRenderer.
  */
 protected void setCellRenderer(TreeCellRenderer tcr)
 {
   // Finish editing before changing the renderer.
   completeEditing();

   // The renderer is set in updateRenderer.
   updateRenderer();

   // Refresh the layout if necessary.
   if (treeState != null)
     {
treeState.invalidateSizes();
updateSize();
     }
 }
项目:JamVM-PH    文件:BasicTreeUI.java   
/**
 * Paints the renderer part of a row. The receiver should NOT modify
 * clipBounds, or insets.
 * 
 * @param g - the graphics configuration
 * @param clipBounds -
 * @param insets -
 * @param bounds - bounds of expand control
 * @param path - path to draw control for
 * @param row - row to draw control for
 * @param isExpanded - is the row expanded
 * @param hasBeenExpanded - has the row already been expanded
 * @param isLeaf - is the path a leaf
 */
protected void paintRow(Graphics g, Rectangle clipBounds, Insets insets,
                        Rectangle bounds, TreePath path, int row,
                        boolean isExpanded, boolean hasBeenExpanded,
                        boolean isLeaf)
{
  boolean selected = tree.isPathSelected(path);
  boolean hasIcons = false;
  Object node = path.getLastPathComponent();

  paintExpandControl(g, clipBounds, insets, bounds, path, row, isExpanded,
                     hasBeenExpanded, isLeaf);

  TreeCellRenderer dtcr = currentCellRenderer;

  boolean focused = false;
  if (treeSelectionModel != null)
    focused = treeSelectionModel.getLeadSelectionRow() == row
              && tree.isFocusOwner();

  Component c = dtcr.getTreeCellRendererComponent(tree, node, selected,
                                                  isExpanded, isLeaf, row,
                                                  focused);

  rendererPane.paintComponent(g, c, c.getParent(), bounds);
}
项目:libreveris    文件: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"));
    }
}
项目:tools-idea    文件:TreeTableView.java   
public TreeTableView(ListTreeTableModelOnColumns treeTableModel) {
  super(treeTableModel);
  setRootVisible(false);

  setTreeCellRenderer(new TreeCellRenderer() {
    private final TreeCellRenderer myBaseRenderer = new HighlightableCellRenderer();
    public Component getTreeCellRendererComponent(JTree tree1,
                                                  Object value,
                                                  boolean selected,
                                                  boolean expanded,
                                                  boolean leaf,
                                                  int row,
                                                  boolean hasFocus) {
      JComponent result = (JComponent)myBaseRenderer.getTreeCellRendererComponent(tree1, value, selected, expanded, leaf, row, hasFocus);
      result.setOpaque(!selected);
      return result;
    }
  });

  setSizes();
}
项目:tools-idea    文件:TreeExpandableItemsHandler.java   
protected Pair<Component, Rectangle> getCellRendererAndBounds(Integer key) {
  int rowIndex = key.intValue();

  TreePath path = myComponent.getPathForRow(rowIndex);
  if (path == null) return null;

  Rectangle bounds = myComponent.getPathBounds(path);
  if (bounds == null) return null;

  TreeCellRenderer renderer = myComponent.getCellRenderer();
  if (renderer == null) return null;

  Object node = path.getLastPathComponent();
  Component rendererComponent = renderer.getTreeCellRendererComponent(
    myComponent,
    node,
    myComponent.isRowSelected(rowIndex),
    myComponent.isExpanded(rowIndex),
    myComponent.getModel().isLeaf(node),
    rowIndex,
    myComponent.hasFocus()
  );
  return Pair.create(rendererComponent, bounds);
}
项目:classpath    文件:BasicTreeUI.java   
/**
 * Sets the TreeCellRenderer to <code>tcr</code>. This invokes
 * <code>updateRenderer</code>.
 *
 * @param tcr is the new TreeCellRenderer.
 */
protected void setCellRenderer(TreeCellRenderer tcr)
{
  // Finish editing before changing the renderer.
  completeEditing();

  // The renderer is set in updateRenderer.
  updateRenderer();

  // Refresh the layout if necessary.
  if (treeState != null)
    {
      treeState.invalidateSizes();
      updateSize();
    }
}
项目:classpath    文件:BasicTreeUI.java   
/**
 * Paints the renderer part of a row. The receiver should NOT modify
 * clipBounds, or insets.
 *
 * @param g - the graphics configuration
 * @param clipBounds -
 * @param insets -
 * @param bounds - bounds of expand control
 * @param path - path to draw control for
 * @param row - row to draw control for
 * @param isExpanded - is the row expanded
 * @param hasBeenExpanded - has the row already been expanded
 * @param isLeaf - is the path a leaf
 */
protected void paintRow(Graphics g, Rectangle clipBounds, Insets insets,
                        Rectangle bounds, TreePath path, int row,
                        boolean isExpanded, boolean hasBeenExpanded,
                        boolean isLeaf)
{
  boolean selected = tree.isPathSelected(path);
  boolean hasIcons = false;
  Object node = path.getLastPathComponent();

  paintExpandControl(g, clipBounds, insets, bounds, path, row, isExpanded,
                     hasBeenExpanded, isLeaf);

  TreeCellRenderer dtcr = currentCellRenderer;

  boolean focused = false;
  if (treeSelectionModel != null)
    focused = treeSelectionModel.getLeadSelectionRow() == row
              && tree.isFocusOwner();

  Component c = dtcr.getTreeCellRendererComponent(tree, node, selected,
                                                  isExpanded, isLeaf, row,
                                                  focused);

  rendererPane.paintComponent(g, c, c.getParent(), bounds);
}
项目:freeVM    文件:BasicTreeUI.java   
public void propertyChange(final PropertyChangeEvent e) {
    String changedProperty = e.getPropertyName();
    if (JTree.CELL_RENDERER_PROPERTY.equals(changedProperty)) {
        setCellRenderer((TreeCellRenderer)e.getNewValue());
    } else if (JTree.CELL_EDITOR_PROPERTY.equals(changedProperty)) {
        setCellEditor((TreeCellEditor)e.getNewValue());
    } else if (JTree.TREE_MODEL_PROPERTY.equals(changedProperty)) {
        setModel((TreeModel)e.getNewValue());
    } else if (JTree.ROOT_VISIBLE_PROPERTY.equals(changedProperty)) {
        setRootVisible(((Boolean)e.getNewValue()).booleanValue());
    } else if (JTree.SHOWS_ROOT_HANDLES_PROPERTY.equals(changedProperty)) {
        setShowsRootHandles(((Boolean)e.getNewValue()).booleanValue());
    } else if (JTree.ROW_HEIGHT_PROPERTY.equals(changedProperty)) {
        setRowHeight(((Integer)e.getNewValue()).intValue());
    } else if (JTree.EDITABLE_PROPERTY.equals(changedProperty)) {
        setEditable(((Boolean)e.getNewValue()).booleanValue());
    } else if (JTree.LARGE_MODEL_PROPERTY.equals(changedProperty)) {
        setLargeModel(((Boolean)e.getNewValue()).booleanValue());
    } else if (JTree.SELECTION_MODEL_PROPERTY.equals(changedProperty)) {
        setSelectionModel((TreeSelectionModel)e.getNewValue());
    } else if (JTree.LEAD_SELECTION_PATH_PROPERTY.equals(changedProperty)) {
        TreePath leadPath = (TreePath)e.getNewValue();
        lastSelectedRow = leadPath != null ? tree.getRowForPath(leadPath) : -1;
    }
}
项目:freeVM    文件:JTreeTest.java   
public void testSetCellRenderer() {
    PropertyChangeController listener = new PropertyChangeController();
    TreeCellRenderer renderer1 = new DefaultTreeCellRenderer();
    TreeCellRenderer renderer2 = new DefaultTreeCellRenderer();
    tree.addPropertyChangeListener(listener);
    TreeCellRenderer oldRenderer = tree.getCellRenderer();
    tree.setCellRenderer(renderer1);
    listener.checkPropertyFired(tree, "cellRenderer", oldRenderer, renderer1);
    assertEquals("cellRenderer", renderer1, tree.getCellRenderer());
    listener.reset();
    tree.setCellRenderer(renderer2);
    listener.checkPropertyFired(tree, "cellRenderer", renderer1, renderer2);
    assertEquals("cellRenderer", renderer2, tree.getCellRenderer());
    listener.reset();
    tree.setCellRenderer(renderer2);
    assertFalse("event's not been fired ", listener.isChanged());
    listener.reset();
    tree.setCellRenderer(null);
    listener.checkPropertyFired(tree, "cellRenderer", renderer2, null);
    // it's being controlled by UI via listener
    assertNotNull("cellRenderer", tree.getCellRenderer());
    assertNotSame("cellRenderer", oldRenderer, tree.getCellRenderer());
    assertNotSame("cellRenderer", renderer2, tree.getCellRenderer());
    listener.reset();
}