Java 类com.intellij.util.ui.tree.WideSelectionTreeUI 实例源码

项目:intellij-ce-playground    文件:EditSourceOnDoubleClickHandler.java   
@Override
public boolean onDoubleClick(MouseEvent e) {
  final TreePath clickPath = myTree.getUI() instanceof WideSelectionTreeUI ? myTree.getClosestPathForLocation(e.getX(), e.getY())
                                                                           : myTree.getPathForLocation(e.getX(), e.getY());
  if (clickPath == null) return false;

  final DataContext dataContext = DataManager.getInstance().getDataContext(myTree);
  final Project project = CommonDataKeys.PROJECT.getData(dataContext);
  if (project == null) return false;

  final TreePath selectionPath = myTree.getSelectionPath();
  if (selectionPath == null || !clickPath.equals(selectionPath)) return false;
  final Object lastPathComponent = selectionPath.getLastPathComponent();
  if (((TreeNode)lastPathComponent).isLeaf() || !expandOnDoubleClick(((TreeNode)lastPathComponent))) {
    //Node expansion for non-leafs has a higher priority
    processDoubleClick(e, dataContext, (TreeNode) lastPathComponent);
    return true;
  }
  return false;
}
项目:intellij-ce-playground    文件:NotificationMessageElement.java   
protected void updateStyle(@NotNull JEditorPane editorPane, @Nullable JTree tree, Object value, boolean selected, boolean hasFocus) {
  final HTMLDocument htmlDocument = (HTMLDocument)editorPane.getDocument();
  final Style style = htmlDocument.getStyleSheet().getStyle(MSG_STYLE);
  if (value instanceof LoadingNode) {
    StyleConstants.setForeground(style, JBColor.GRAY);
  }
  else {
    if (selected) {
      StyleConstants.setForeground(style, hasFocus ? UIUtil.getTreeSelectionForeground() : UIUtil.getTreeTextForeground());
    }
    else {
      StyleConstants.setForeground(style, UIUtil.getTreeTextForeground());
    }
  }

  if (UIUtil.isUnderGTKLookAndFeel() ||
      UIUtil.isUnderNimbusLookAndFeel() && selected && hasFocus ||
      tree != null && tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection()) {
    editorPane.setOpaque(false);
  }
  else {
    editorPane.setOpaque(selected && hasFocus);
  }

  htmlDocument.setCharacterAttributes(0, htmlDocument.getLength(), style, false);
}
项目: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
      }
    }
  }
}
项目:tools-idea    文件:EditSourceOnDoubleClickHandler.java   
@Override
public boolean onDoubleClick(MouseEvent e) {
  final TreePath clickPath = myTree.getUI() instanceof WideSelectionTreeUI ? myTree.getClosestPathForLocation(e.getX(), e.getY())
                                                                           : myTree.getPathForLocation(e.getX(), e.getY());
  if (clickPath == null) return false;

  final DataContext dataContext = DataManager.getInstance().getDataContext(myTree);
  final Project project = PlatformDataKeys.PROJECT.getData(dataContext);
  if (project == null) return false;

  final TreePath selectionPath = myTree.getSelectionPath();
  if (selectionPath == null || !clickPath.equals(selectionPath)) return false;
  final Object lastPathComponent = selectionPath.getLastPathComponent();
  if (((TreeNode)lastPathComponent).isLeaf() || !expandOnDoubleClick(((TreeNode)lastPathComponent))) {
    //Node expansion for non-leafs has a higher priority
    processDoubleClick(e, dataContext, (TreeNode) lastPathComponent);
    return true;
  }
  return false;
}
项目:tools-idea    文件: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
      }
    }
  }
}
项目:consulo    文件:EditSourceOnDoubleClickHandler.java   
@Override
public boolean onDoubleClick(MouseEvent e) {
  final TreePath clickPath = myTree.getUI() instanceof WideSelectionTreeUI ? myTree.getClosestPathForLocation(e.getX(), e.getY())
                                                                           : myTree.getPathForLocation(e.getX(), e.getY());
  if (clickPath == null) return false;

  final DataContext dataContext = DataManager.getInstance().getDataContext(myTree);
  final Project project = dataContext.getData(CommonDataKeys.PROJECT);
  if (project == null) return false;

  final TreePath selectionPath = myTree.getSelectionPath();
  if (selectionPath == null || !clickPath.equals(selectionPath)) return false;
  final Object lastPathComponent = selectionPath.getLastPathComponent();
  if (((TreeNode)lastPathComponent).isLeaf() || !expandOnDoubleClick(((TreeNode)lastPathComponent))) {
    //Node expansion for non-leafs has a higher priority
    processDoubleClick(e, dataContext, (TreeNode) lastPathComponent);
    return true;
  }
  return false;
}
项目:consulo    文件:NotificationMessageElement.java   
protected void updateStyle(@Nonnull JEditorPane editorPane, @javax.annotation.Nullable JTree tree, Object value, boolean selected, boolean hasFocus) {
  final HTMLDocument htmlDocument = (HTMLDocument)editorPane.getDocument();
  final Style style = htmlDocument.getStyleSheet().getStyle(MSG_STYLE);
  if (value instanceof LoadingNode) {
    StyleConstants.setForeground(style, JBColor.GRAY);
  }
  else {
    if (selected) {
      StyleConstants.setForeground(style, hasFocus ? UIUtil.getTreeSelectionForeground() : UIUtil.getTreeTextForeground());
    }
    else {
      StyleConstants.setForeground(style, UIUtil.getTreeTextForeground());
    }
  }

  if (UIUtil.isUnderGTKLookAndFeel() ||
      UIUtil.isUnderNimbusLookAndFeel() && selected && hasFocus ||
      tree != null && tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection()) {
    editorPane.setOpaque(false);
  }
  else {
    editorPane.setOpaque(selected && hasFocus);
  }

  htmlDocument.setCharacterAttributes(0, htmlDocument.getLength(), style, false);
}
项目:consulo    文件:MacUIUtil.java   
public static void doNotFillBackground(@Nonnull final JTree tree, @Nonnull 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
      }
    }
  }
}
项目:SmartQQ4IntelliJ    文件:IMContactView.java   
protected void initTree(Tree tree) {
    tree.setCellRenderer(new ContactTreeCellRenderer());
    tree.setShowsRootHandles(false);
    tree.setRootVisible(false);
    tree.addMouseListener(new IMContactDoubleClicker(getImPanel()));
    tree.setUI(new WideSelectionTreeUI() {

    });
}
项目:intellij-ce-playground    文件:HighlightableCellRenderer.java   
public Component getTreeCellRendererComponent(
  JTree tree,
  Object value,
  boolean selected,
  boolean expanded,
  boolean leaf,
  int row,
  boolean hasFocus
  ) {
  setText(tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus));
  setFont(UIUtil.getTreeFont());
  setIcon(null);

  if (tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection()) {
    setOpaque(false);
    myIsSelected = false;
    myHasFocus = false;
    setDoNotHighlight(selected && hasFocus);
    setForeground(selected && hasFocus ? UIUtil.getTreeSelectionForeground() : UIUtil.getTreeForeground());
  } else {
    setOpaque(true);
    myIsSelected = selected;
    myHasFocus = hasFocus;
    setDoNotHighlight(false);
  }

  myHasFocus = hasFocus;
  return this;
}
项目:intellij-ce-playground    文件:NewErrorTreeEditor.java   
public Component getTreeCellEditorComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row) {
  myPanel.removeAll();
  myPanel.add(myLeft.getTreeCellRendererComponent(tree, value, false, expanded, leaf, row, true), BorderLayout.WEST);
  myPanel.add(myRight.getTreeCellEditorComponent(tree, value, selected, expanded, leaf, row), BorderLayout.EAST);

  if (UIUtil.isFullRowSelectionLAF()) {
    myPanel.setBackground(selected ? UIUtil.getTreeSelectionBackground() : null);
  }
  else if (tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection()) {
    if (selected) {
      myPanel.setBackground(UIUtil.getTreeSelectionBackground());
    }
  }
  else if (selected) {
    myPanel.setBackground(UIUtil.getTreeSelectionBackground());
  }
  else {
    myPanel.setBackground(null);
  }

  if (value instanceof LoadingNode) {
    myPanel.setForeground(JBColor.GRAY);
  }
  else {
    myPanel.setForeground(tree.getForeground());
  }

  if (UIUtil.isUnderGTKLookAndFeel() ||
      UIUtil.isUnderNimbusLookAndFeel() && selected ||
      tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection()) {
    myPanel.setOpaque(false);
  }
  return myPanel;
}
项目:intellij-ce-playground    文件:DnDAwareTree.java   
@Override
public final boolean isOverSelection(final Point point) {
  final TreeUI ui = getUI();
  final TreePath path = ui instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)ui).isWideSelection()
                        ? getClosestPathForLocation(point.x, point.y) : getPathForLocation(point.x, point.y);
  if (path == null) return false;
  return isPathSelected(path);
}
项目:tools-idea    文件:HighlightableCellRenderer.java   
public Component getTreeCellRendererComponent(
  JTree tree,
  Object value,
  boolean selected,
  boolean expanded,
  boolean leaf,
  int row,
  boolean hasFocus
  ) {
  setText(tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus));
  setFont(UIUtil.getTreeFont());
  setIcon(null);

  if (tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection()) {
    setOpaque(false);
    myIsSelected = false;
    myHasFocus = false;
    setDoNotHighlight(selected && hasFocus);
    setForeground(selected && hasFocus ? UIUtil.getTreeSelectionForeground() : UIUtil.getTreeForeground());
  } else {
    setOpaque(true);
    myIsSelected = selected;
    myHasFocus = hasFocus;
    setDoNotHighlight(false);
  }

  myHasFocus = hasFocus;
  return this;
}
项目:tools-idea    文件:ActionsTree.java   
public ActionsTree() {
  myRoot = new DefaultMutableTreeNode(ROOT);

  myTree = new Tree(new MyModel(myRoot)) {
    @Override
    public void paint(Graphics g) {
      super.paint(g);
      Rectangle visibleRect = getVisibleRect();
      Rectangle clip = g.getClipBounds();
      for (int row = 0; row < getRowCount(); row++) {
        Rectangle rowBounds = getRowBounds(row);
        rowBounds.x = 0;
        rowBounds.width = Integer.MAX_VALUE;

        if (rowBounds.intersects(clip)) {
          Object node = getPathForRow(row).getLastPathComponent();

          if (node instanceof DefaultMutableTreeNode) {
            Object data = ((DefaultMutableTreeNode)node).getUserObject();
            Rectangle fullRowRect = new Rectangle(visibleRect.x, rowBounds.y, visibleRect.width, rowBounds.height);
            paintRowData(this, data, fullRowRect, (Graphics2D)g);
          }
        }
      }

    }
  };
  myTree.setRootVisible(false);
  myTree.setShowsRootHandles(true);

  myTree.putClientProperty(WideSelectionTreeUI.STRIPED_CLIENT_PROPERTY, Boolean.TRUE);
  myTree.setCellRenderer(new KeymapsRenderer());

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

  myComponent = ScrollPaneFactory.createScrollPane(myTree,
                                                   ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                                                   ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
}
项目:tools-idea    文件:DnDAwareTree.java   
public final boolean isOverSelection(final Point point) {
  final TreeUI ui = getUI();
  final TreePath path = ui instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)ui).isWideSelection()
                        ? getClosestPathForLocation(point.x, point.y) : getPathForLocation(point.x, point.y);
  if (path == null) return false;
  return isPathSelected(path);
}
项目:consulo    文件:HighlightableCellRenderer.java   
public Component getTreeCellRendererComponent(
  JTree tree,
  Object value,
  boolean selected,
  boolean expanded,
  boolean leaf,
  int row,
  boolean hasFocus
  ) {
  setText(tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus));
  setFont(UIUtil.getTreeFont());
  setIcon(null);

  if (tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection()) {
    setOpaque(false);
    myIsSelected = false;
    myHasFocus = false;
    setDoNotHighlight(selected && hasFocus);
    setForeground(selected && hasFocus ? UIUtil.getTreeSelectionForeground() : UIUtil.getTreeForeground());
  } else {
    setOpaque(true);
    myIsSelected = selected;
    myHasFocus = hasFocus;
    setDoNotHighlight(false);
  }

  myHasFocus = hasFocus;
  return this;
}
项目:consulo    文件:ActionsTree.java   
public ActionsTree() {
  myRoot = new DefaultMutableTreeNode(ROOT);

  myTree = new Tree(new MyModel(myRoot)) {
    @Override
    public void paint(Graphics g) {
      super.paint(g);
      Rectangle visibleRect = getVisibleRect();
      Rectangle clip = g.getClipBounds();
      for (int row = 0; row < getRowCount(); row++) {
        Rectangle rowBounds = getRowBounds(row);
        rowBounds.x = 0;
        rowBounds.width = Integer.MAX_VALUE;

        if (rowBounds.intersects(clip)) {
          Object node = getPathForRow(row).getLastPathComponent();

          if (node instanceof DefaultMutableTreeNode) {
            Object data = ((DefaultMutableTreeNode)node).getUserObject();
            Rectangle fullRowRect = new Rectangle(visibleRect.x, rowBounds.y, visibleRect.width, rowBounds.height);
            paintRowData(this, data, fullRowRect, (Graphics2D)g);
          }
        }
      }

    }
  };
  myTree.setRootVisible(false);
  myTree.setShowsRootHandles(true);

  myTree.putClientProperty(WideSelectionTreeUI.STRIPED_CLIENT_PROPERTY, Boolean.TRUE);
  myTree.setCellRenderer(new KeymapsRenderer());

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

  myComponent = ScrollPaneFactory.createScrollPane(myTree,
                                                   ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                                                   ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
}
项目:consulo    文件:NewErrorTreeEditor.java   
public Component getTreeCellEditorComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row) {
  myPanel.removeAll();
  myPanel.add(myLeft.getTreeCellRendererComponent(tree, value, false, expanded, leaf, row, true), BorderLayout.WEST);
  myPanel.add(myRight.getTreeCellEditorComponent(tree, value, selected, expanded, leaf, row), BorderLayout.EAST);

  if (UIUtil.isFullRowSelectionLAF()) {
    myPanel.setBackground(selected ? UIUtil.getTreeSelectionBackground() : null);
  }
  else if (tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection()) {
    if (selected) {
      myPanel.setBackground(UIUtil.getTreeSelectionBackground());
    }
  }
  else if (selected) {
    myPanel.setBackground(UIUtil.getTreeSelectionBackground());
  }
  else {
    myPanel.setBackground(null);
  }

  if (value instanceof LoadingNode) {
    myPanel.setForeground(JBColor.GRAY);
  }
  else {
    myPanel.setForeground(tree.getForeground());
  }

  if (UIUtil.isUnderGTKLookAndFeel() ||
      UIUtil.isUnderNimbusLookAndFeel() && selected ||
      tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection()) {
    myPanel.setOpaque(false);
  }
  return myPanel;
}
项目:consulo    文件:DnDAwareTree.java   
@Override
public final boolean isOverSelection(final Point point) {
  final TreePath path = WideSelectionTreeUI.isWideSelection(this)
                        ? getClosestPathForLocation(point.x, point.y) : getPathForLocation(point.x, point.y);
  if (path == null) return false;
  return isPathSelected(path);
}
项目:intellij-ce-playground    文件:JBDefaultTreeCellRenderer.java   
public JBDefaultTreeCellRenderer(@NotNull final JTree tree) {
  MacUIUtil.doNotFillBackground(tree, this);
  myMacTreeUI = tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection();
}
项目:intellij-ce-playground    文件:TreeTableTree.java   
public TreeTableTree(TreeModel model, TreeTable treeTable) {
  super(model);
  myTreeTable = treeTable;
  setCellRenderer(getCellRenderer());
  putClientProperty(WideSelectionTreeUI.TREE_TABLE_TREE_KEY, Boolean.TRUE);
}
项目:intellij-ce-playground    文件:ColoredTreeCellRenderer.java   
@Override
public final Component getTreeCellRendererComponent(JTree tree,
                                                    Object value,
                                                    boolean selected,
                                                    boolean expanded,
                                                    boolean leaf,
                                                    int row,
                                                    boolean hasFocus){
  myTree = tree;

  clear();

  mySelected = selected;
  myFocusedCalculated = false;

  // We paint background if and only if tree path is selected and tree has focus.
  // If path is selected and tree is not focused then we just paint focused border.
  if (UIUtil.isFullRowSelectionLAF()) {
    setBackground(selected ? UIUtil.getTreeSelectionBackground() : null);
  }
  else if (tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection()) {
    setPaintFocusBorder(false);
    if (selected) {
      setBackground(hasFocus ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeUnfocusedSelectionBackground());
    }
  }
  else if (selected) {
    setPaintFocusBorder(true);
    if (isFocused()) {
      setBackground(UIUtil.getTreeSelectionBackground());
    }
    else {
      setBackground(null);
    }
  }
  else {
    setBackground(null);
  }

  if (value instanceof LoadingNode) {
    setForeground(JBColor.GRAY);
    setIcon(LOADING_NODE_ICON);
  }
  else {
    setForeground(tree.getForeground());
    setIcon(null);
  }

  if (UIUtil.isUnderGTKLookAndFeel()){
    super.setOpaque(false);  // avoid nasty background
    super.setIconOpaque(false);
  }
  else if (UIUtil.isUnderNimbusLookAndFeel() && selected && hasFocus) {
    super.setOpaque(false);  // avoid erasing Nimbus focus frame
    super.setIconOpaque(false);
  }
  else if (tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection()) {
    super.setOpaque(false);  // avoid erasing Nimbus focus frame
    super.setIconOpaque(false);
  }
  else {
    super.setOpaque(myOpaque || selected && hasFocus || selected && isFocused()); // draw selection background even for non-opaque tree
  }

  if (tree.getUI() instanceof WideSelectionTreeUI && UIUtil.isUnderAquaBasedLookAndFeel()) {
    setMyBorder(null);
    setIpad(new Insets(0, 2,  0, 2));
  }

  customizeCellRenderer(tree, value, selected, expanded, leaf, row, hasFocus);

  return this;
}
项目:intellij-ce-playground    文件:MultilineTreeCellRenderer.java   
public void paint(Graphics g) {
  int height = getHeight();
  int width = getWidth();
  int borderX = myLabelInsets.left - 1;
  int borderY = myLabelInsets.top - 1;
  int borderW = width - borderX - myLabelInsets.right + 2;
  int borderH = height - borderY - myLabelInsets.bottom + 1;

  if (myIcon != null) {
    int verticalIconPosition = (height - myIcon.getIconHeight())/2;
    myIcon.paintIcon(this, g, 0, verticalIconPosition);
    borderX += myIcon.getIconWidth();
    borderW -= myIcon.getIconWidth();
  }

  Color bgColor;
  Color fgColor;
  if (mySelected && myHasFocus){
    bgColor = UIUtil.getTreeSelectionBackground();
    fgColor = UIUtil.getTreeSelectionForeground();
  }
  else{
    bgColor = UIUtil.getTreeTextBackground();
    fgColor = getForeground();
  }

  // fill background
  if (!(myTree.getUI() instanceof WideSelectionTreeUI) || !((WideSelectionTreeUI)myTree.getUI()).isWideSelection()) {
    g.setColor(bgColor);
    g.fillRect(borderX, borderY, borderW, borderH);

    // draw border
    if (mySelected) {
      g.setColor(UIUtil.getTreeSelectionBorderColor());
      UIUtil.drawDottedRectangle(g, borderX, borderY, borderX + borderW - 1, borderY + borderH - 1);
    }
  }

  // paint text
  recalculateWraps();

  if (myTooSmall) { // TODO ???
    return;
  }

  int fontHeight = getCurrFontMetrics().getHeight();
  int currBaseLine = getCurrFontMetrics().getAscent();
  currBaseLine += myTextInsets.top;
  g.setFont(getFont());
  g.setColor(fgColor);
  UISettings.setupAntialiasing(g);

  if (!StringUtil.isEmpty(myPrefix)) {
    g.drawString(myPrefix, myTextInsets.left - myPrefixWidth + 1, currBaseLine);
  }

  for (int i = 0; i < myWraps.size(); i++) {
    String currLine = (String)myWraps.get(i);
    g.drawString(currLine, myTextInsets.left, currBaseLine);
    currBaseLine += fontHeight;  // first is getCurrFontMetrics().getAscent()
  }
}
项目:tools-idea    文件:JBDefaultTreeCellRenderer.java   
public JBDefaultTreeCellRenderer(@NotNull final JTree tree) {
  MacUIUtil.doNotFillBackground(tree, this);
  myMacTreeUI = tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection();
}
项目:tools-idea    文件:ColoredTreeCellRenderer.java   
public final Component getTreeCellRendererComponent(
  JTree tree,
  Object value,
  boolean selected,
  boolean expanded,
  boolean leaf,
  int row,
  boolean hasFocus
){
  myTree = tree;

  clear();

  mySelected = selected;
  myFocusedCalculated = false;

  // We paint background if and only if tree path is selected and tree has focus.
  // If path is selected and tree is not focused then we just paint focused border.
  if (UIUtil.isFullRowSelectionLAF()) {
    setBackground(selected ? UIUtil.getTreeSelectionBackground() : null);
  }
  else if (tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection()) {
    setPaintFocusBorder(false);
    if (selected) {
      setBackground(hasFocus ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeUnfocusedSelectionBackground());
    }
  }
  else {
    if (selected) {
      setPaintFocusBorder(true);
      if (isFocused()) {
        setBackground(UIUtil.getTreeSelectionBackground());
      }
      else {
        setBackground(null);
      }
    }
    else {
      setBackground(null);
    }
  }

  if (value instanceof LoadingNode) {
    setForeground(JBColor.GRAY);
    setIcon(LOADING_NODE_ICON);
  }
  else {
    setForeground(tree.getForeground());
    setIcon(null);
  }

  if (UIUtil.isUnderGTKLookAndFeel()){
    super.setOpaque(false);  // avoid nasty background
    super.setIconOpaque(false);
  }
  else if (UIUtil.isUnderNimbusLookAndFeel() && selected && hasFocus) {
    super.setOpaque(false);  // avoid erasing Nimbus focus frame
    super.setIconOpaque(false);
  }
  else if (tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection()) {
    super.setOpaque(false);  // avoid erasing Nimbus focus frame
    super.setIconOpaque(false);
  }
  else {
    super.setOpaque(myOpaque || selected && hasFocus || selected && isFocused()); // draw selection background even for non-opaque tree
  }

  if (tree.getUI() instanceof WideSelectionTreeUI && UIUtil.isUnderAquaBasedLookAndFeel()) {
    setMyBorder(null);
    setIpad(new Insets(0, 2,  0, 2));
  }

  customizeCellRenderer(tree, value, selected, expanded, leaf, row, hasFocus);

  return this;
}
项目:tools-idea    文件:TreeExpandableItemsHandler.java   
@Override
protected Dimension getImageSize(int width, int height) {
  final TreeUI ui = myComponent.getUI();
  return new Dimension(width, ui instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)ui).isWideSelection() ? height - 1 : height);
}
项目:tools-idea    文件:TreeExpandableItemsHandler.java   
@Override
protected void doFillBackground(final int height, final int width, final Graphics2D g) {
  final TreeUI ui = myComponent.getUI();
  super.doFillBackground(ui instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)ui).isWideSelection() ? height - 1 : height, width, g);
}
项目:tools-idea    文件:MultilineTreeCellRenderer.java   
public void paint(Graphics g) {
  int height = getHeight();
  int width = getWidth();
  int borderX = myLabelInsets.left - 1;
  int borderY = myLabelInsets.top - 1;
  int borderW = width - borderX - myLabelInsets.right + 2;
  int borderH = height - borderY - myLabelInsets.bottom + 1;

  if (myIcon != null) {
    int verticalIconPosition = (height - myIcon.getIconHeight())/2;
    myIcon.paintIcon(this, g, 0, verticalIconPosition);
    borderX += myIcon.getIconWidth();
    borderW -= myIcon.getIconWidth();
  }

  Color bgColor;
  Color fgColor;
  if (mySelected && myHasFocus){
    bgColor = UIUtil.getTreeSelectionBackground();
    fgColor = UIUtil.getTreeSelectionForeground();
  }
  else{
    bgColor = UIUtil.getTreeTextBackground();
    fgColor = getForeground();
  }

  // fill background
  if (!(myTree.getUI() instanceof WideSelectionTreeUI) || !((WideSelectionTreeUI)myTree.getUI()).isWideSelection()) {
    g.setColor(bgColor);
    g.fillRect(borderX, borderY, borderW, borderH);

    // draw border
    if (mySelected) {
      g.setColor(UIUtil.getTreeSelectionBorderColor());
      UIUtil.drawDottedRectangle(g, borderX, borderY, borderX + borderW - 1, borderY + borderH - 1);
    }
  }

  // paint text
  recalculateWraps();

  if (myTooSmall) { // TODO ???
    return;
  }

  int fontHeight = getCurrFontMetrics().getHeight();
  int currBaseLine = getCurrFontMetrics().getAscent();
  currBaseLine += myTextInsets.top;
  g.setFont(getFont());
  g.setColor(fgColor);
  UIUtil.applyRenderingHints(g);

  if (!StringUtil.isEmpty(myPrefix)) {
    g.drawString(myPrefix, myTextInsets.left - myPrefixWidth + 1, currBaseLine);
  }

  for (int i = 0; i < myWraps.size(); i++) {
    String currLine = (String)myWraps.get(i);
    g.drawString(currLine, myTextInsets.left, currBaseLine);
    currBaseLine += fontHeight;  // first is getCurrFontMetrics().getAscent()
  }
}
项目:consulo    文件:JBDefaultTreeCellRenderer.java   
public JBDefaultTreeCellRenderer(@Nonnull final JTree tree) {
  MacUIUtil.doNotFillBackground(tree, this);
  myMacTreeUI = tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection();
}
项目:consulo    文件:TreeTableTree.java   
public TreeTableTree(TreeModel model, TreeTable treeTable) {
  super(model);
  myTreeTable = treeTable;
  setCellRenderer(getCellRenderer());
  putClientProperty(WideSelectionTreeUI.TREE_TABLE_TREE_KEY, treeTable);
}
项目:consulo    文件:ColoredTreeCellRenderer.java   
@Override
@RequiredDispatchThread
public final Component getTreeCellRendererComponent(JTree tree,
                                                    Object value,
                                                    boolean selected,
                                                    boolean expanded,
                                                    boolean leaf,
                                                    int row,
                                                    boolean hasFocus){
  myTree = tree;

  clear();

  mySelected = selected;
  myFocusedCalculated = false;

  // We paint background if and only if tree path is selected and tree has focus.
  // If path is selected and tree is not focused then we just paint focused border.
  if (UIUtil.isFullRowSelectionLAF()) {
    setBackground(selected ? UIUtil.getTreeSelectionBackground() : null);
  }
  else if (tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection()) {
    setPaintFocusBorder(false);
    if (selected) {
      setBackground(hasFocus ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeUnfocusedSelectionBackground());
    }
  }
  else if (selected) {
    setPaintFocusBorder(true);
    if (isFocused()) {
      setBackground(UIUtil.getTreeSelectionBackground());
    }
    else {
      setBackground(null);
    }
  }
  else {
    setBackground(null);
  }

  if (value instanceof LoadingNode) {
    setForeground(JBColor.GRAY);
    setIcon(LOADING_NODE_ICON);
  }
  else {
    setForeground(tree.getForeground());
    setIcon(null);
  }

  if (UIUtil.isUnderGTKLookAndFeel()){
    super.setOpaque(false);  // avoid nasty background
    super.setIconOpaque(false);
  }
  else if (UIUtil.isUnderNimbusLookAndFeel() && selected && hasFocus) {
    super.setOpaque(false);  // avoid erasing Nimbus focus frame
    super.setIconOpaque(false);
  }
  else if (tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection()) {
    super.setOpaque(false);  // avoid erasing Nimbus focus frame
    super.setIconOpaque(false);
  }
  else {
    super.setOpaque(myOpaque || selected && hasFocus || selected && isFocused()); // draw selection background even for non-opaque tree
  }

  if (tree.getUI() instanceof WideSelectionTreeUI && UIUtil.isUnderAquaBasedLookAndFeel()) {
    setMyBorder(null);
    setIpad(new Insets(0, 2,  0, 2));
  }

  customizeCellRenderer(tree, value, selected, expanded, leaf, row, hasFocus);

  return this;
}
项目:consulo    文件:TreeExpandableItemsHandler.java   
@Override
protected Dimension getImageSize(int width, int height) {
  final TreeUI ui = myComponent.getUI();
  return new Dimension(width, ui instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)ui).isWideSelection() ? height - 1 : height);
}
项目:consulo    文件:TreeExpandableItemsHandler.java   
@Override
protected void doFillBackground(final int height, final int width, final Graphics2D g) {
  final TreeUI ui = myComponent.getUI();
  super.doFillBackground(ui instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)ui).isWideSelection() ? height - 1 : height, width, g);
}
项目:consulo    文件:MultilineTreeCellRenderer.java   
public void paint(Graphics g) {
  int height = getHeight();
  int width = getWidth();
  int borderX = myLabelInsets.left - 1;
  int borderY = myLabelInsets.top - 1;
  int borderW = width - borderX - myLabelInsets.right + 2;
  int borderH = height - borderY - myLabelInsets.bottom + 1;

  if (myIcon != null) {
    int verticalIconPosition = (height - myIcon.getIconHeight())/2;
    myIcon.paintIcon(this, g, 0, verticalIconPosition);
    borderX += myIcon.getIconWidth();
    borderW -= myIcon.getIconWidth();
  }

  Color bgColor;
  Color fgColor;
  if (mySelected && myHasFocus){
    bgColor = UIUtil.getTreeSelectionBackground();
    fgColor = UIUtil.getTreeSelectionForeground();
  }
  else{
    bgColor = UIUtil.getTreeTextBackground();
    fgColor = getForeground();
  }

  // fill background
  if (!(myTree.getUI() instanceof WideSelectionTreeUI) || !((WideSelectionTreeUI)myTree.getUI()).isWideSelection()) {
    g.setColor(bgColor);
    g.fillRect(borderX, borderY, borderW, borderH);

    // draw border
    if (mySelected) {
      g.setColor(UIUtil.getTreeSelectionBorderColor());
      UIUtil.drawDottedRectangle(g, borderX, borderY, borderX + borderW - 1, borderY + borderH - 1);
    }
  }

  // paint text
  recalculateWraps();

  if (myTooSmall) { // TODO ???
    return;
  }

  int fontHeight = getCurrFontMetrics().getHeight();
  int currBaseLine = getCurrFontMetrics().getAscent();
  currBaseLine += myTextInsets.top;
  g.setFont(getFont());
  g.setColor(fgColor);
  UIUtil.applyRenderingHints(g);

  if (!StringUtil.isEmpty(myPrefix)) {
    g.drawString(myPrefix, myTextInsets.left - myPrefixWidth + 1, currBaseLine);
  }

  for (int i = 0; i < myWraps.size(); i++) {
    String currLine = (String)myWraps.get(i);
    g.drawString(currLine, myTextInsets.left, currBaseLine);
    currBaseLine += fontHeight;  // first is getCurrFontMetrics().getAscent()
  }
}