Java Code Examples for com.intellij.util.ui.tree.WideSelectionTreeUI

The following examples show how to use com.intellij.util.ui.tree.WideSelectionTreeUI. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: consulo   Source File: EditSourceOnDoubleClickHandler.java    License: Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source Project: consulo   Source File: NotificationMessageElement.java    License: Apache License 2.0 6 votes vote down vote up
protected void updateStyle(@Nonnull 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);
}
 
Example 3
Source Project: SmartIM4IntelliJ   Source File: IMContactView.java    License: Apache License 2.0 5 votes vote down vote up
protected void initTree(Tree tree) {
    tree.setCellRenderer(getContactRenderer());
    tree.setShowsRootHandles(false);
    tree.setRootVisible(false);
    tree.addMouseListener(new IMContactDoubleClicker(getImPanel()));
    tree.setUI(new WideSelectionTreeUI() {

    });
}
 
Example 4
Source Project: consulo   Source File: HighlightableCellRenderer.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 5
Source Project: consulo   Source File: ActionsTree.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 6
Source Project: consulo   Source File: NewErrorTreeEditor.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 7
Source Project: consulo   Source File: DnDAwareTree.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 8
@Override
public final Component getTreeCellRendererComponent(JTree tree,
                                                    Object value,
                                                    boolean selected,
                                                    boolean expanded,
                                                    boolean leaf,
                                                    int row,
                                                    boolean hasFocus) {
  myTree = tree;

  clear();

  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 (WideSelectionTreeUI.isWideSelection(tree)) {
    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);
  }
  else {
    setForeground(tree.getForeground());
    setIcon(null);
  }

  super.setOpaque(myOpaque || selected && hasFocus || selected && isFocused()); // draw selection background even for non-opaque tree


  if (tree.getUI() instanceof InspectorTreeUI && UIUtil.isUnderAquaBasedLookAndFeel()) {
    setMyBorder(null);
    setIpad(JBUI.insets(0, 2));
  }

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

  return this;
}
 
Example 9
@Override
public final Component getTreeCellRendererComponent(JTree tree,
                                                    Object value,
                                                    boolean selected,
                                                    boolean expanded,
                                                    boolean leaf,
                                                    int row,
                                                    boolean hasFocus) {
  myTree = tree;

  clear();

  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 (WideSelectionTreeUI.isWideSelection(tree)) {
    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);
  }
  else {
    setForeground(tree.getForeground());
    setIcon(null);
  }

  super.setOpaque(myOpaque || selected && hasFocus || selected && isFocused()); // draw selection background even for non-opaque tree


  if (tree.getUI() instanceof InspectorTreeUI && UIUtil.isUnderAquaBasedLookAndFeel()) {
    setMyBorder(null);
    setIpad(JBUI.insets(0, 2));
  }

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

  return this;
}
 
Example 10
Source Project: consulo   Source File: JBDefaultTreeCellRenderer.java    License: Apache License 2.0 4 votes vote down vote up
public JBDefaultTreeCellRenderer(@Nonnull final JTree tree) {
  myMacTreeUI = tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection();
}
 
Example 11
Source Project: consulo   Source File: TreeTableTree.java    License: Apache License 2.0 4 votes vote down vote up
public TreeTableTree(TreeModel model, TreeTable treeTable) {
  super(model);
  myTreeTable = treeTable;
  setCellRenderer(getCellRenderer());
  putClientProperty(WideSelectionTreeUI.TREE_TABLE_TREE_KEY, treeTable);
}
 
Example 12
Source Project: consulo   Source File: ColoredTreeCellRenderer.java    License: Apache License 2.0 4 votes vote down vote up
@Override
@RequiredUIAccess
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;
}
 
Example 13
Source Project: consulo   Source File: TreeExpandableItemsHandler.java    License: Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example 14
Source Project: consulo   Source File: TreeExpandableItemsHandler.java    License: Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example 15
Source Project: consulo   Source File: MultilineTreeCellRenderer.java    License: Apache License 2.0 4 votes vote down vote up
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()
  }
}