Java Code Examples for com.intellij.util.ui.UIUtil#isUnderNimbusLookAndFeel()

The following examples show how to use com.intellij.util.ui.UIUtil#isUnderNimbusLookAndFeel() . 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 File: StringElementListCellRenderer.java    From android-strings-search-plugin with Apache License 2.0 6 votes vote down vote up
private void customize(Object value, boolean selected) {
    if (value instanceof StringElement) {
        StringElement element = (StringElement) value;

        // TODO Change icon to each countries flags.
        setIcon(AllIcons.Modules.SourceFolder);
        setText(element.getParentDirName());

        setBorder(BorderFactory.createEmptyBorder(0, 0, 0, UIUtil.getListCellHPadding()));
        setHorizontalTextPosition(2);
        setBackground(selected ? UIUtil.getListSelectionBackground() : UIUtil.getListBackground());
        setForeground(selected ? UIUtil.getListSelectionForeground() : UIUtil.getInactiveTextColor());

        if (UIUtil.isUnderNimbusLookAndFeel()) {
            setOpaque(false);
        }
    }
}
 
Example 2
Source File: BooleanTableCellRenderer.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSel, boolean hasFocus, int row, int column) {
  final Color bg = UIUtil.isUnderNimbusLookAndFeel() && row % 2 == 1 ? UIUtil.TRANSPARENT_COLOR : table.getBackground();
  final Color fg = table.getForeground();
  final Color selBg = table.getSelectionBackground();
  final Color selFg = table.getSelectionForeground();

  if (value == null) {
    myPanel.setBackground(isSel ? selBg : bg);
    return myPanel;
  }

  setForeground(isSel ? selFg : fg);
  setBackground(isSel ? selBg : bg);

  if (value instanceof String) {
    setSelected(Boolean.parseBoolean((String)value));
  }
  else {
    setSelected(((Boolean)value).booleanValue());
  }
  setEnabled(table.isCellEditable(row, column));
  return this;
}
 
Example 3
Source File: NotificationMessageElement.java    From consulo with 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 4
Source File: ThreeStateCheckBoxRenderer.java    From consulo with Apache License 2.0 6 votes vote down vote up
private JCheckBox tune(final Object value, final boolean isSelected, final int row, final JTable table) {
  final Color bg = UIUtil.isUnderNimbusLookAndFeel() && row % 2 == 1 ? UIUtil.TRANSPARENT_COLOR : table.getBackground();
  final Color fg = table.getForeground();
  final Color selBg = table.getSelectionBackground();
  final Color selFg = table.getSelectionForeground();

  setForeground(isSelected ? selFg : fg);
  setBackground(isSelected ? selBg : bg);

  if (value == null) {
    setState(State.DONT_CARE);
  } else {
    setSelected((Boolean) value);
  }
  return this;
}
 
Example 5
Source File: MultiSelectDialog.java    From AndroidStringsOneTabTranslation with Apache License 2.0 5 votes vote down vote up
@NotNull
public static JTextPane configureMessagePaneUi(JTextPane messageComponent,
                                               String message,
                                               final boolean addBrowserHyperlinkListener) {
    messageComponent.setFont(UIUtil.getLabelFont());
    if (BasicHTML.isHTMLString(message)) {
        final HTMLEditorKit editorKit = new HTMLEditorKit();
        editorKit.getStyleSheet().addRule(UIUtil.displayPropertiesToCSS(UIUtil.getLabelFont(), UIUtil.getLabelForeground()));
        messageComponent.setEditorKit(editorKit);
        messageComponent.setContentType(UIUtil.HTML_MIME);
        if (addBrowserHyperlinkListener) {
            messageComponent.addHyperlinkListener(BrowserHyperlinkListener.INSTANCE);
        }
    }
    messageComponent.setText(message);
    messageComponent.setEditable(false);
    if (messageComponent.getCaret() != null) {
        messageComponent.setCaretPosition(0);
    }

    if (UIUtil.isUnderNimbusLookAndFeel()) {
        messageComponent.setOpaque(false);
        messageComponent.setBackground(UIUtil.TRANSPARENT_COLOR);
    } else {
        messageComponent.setBackground(UIUtil.getOptionPaneBackground());
    }

    messageComponent.setForeground(UIUtil.getLabelForeground());
    return messageComponent;
}
 
Example 6
Source File: Messages.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static JTextPane configureMessagePaneUi(@Nonnull JTextPane messageComponent, @Nullable String message, @Nullable UIUtil.FontSize fontSize) {
  UIUtil.FontSize fixedFontSize = fontSize == null ? UIUtil.FontSize.NORMAL : fontSize;
  messageComponent.setFont(UIUtil.getLabelFont(fixedFontSize));
  if (BasicHTML.isHTMLString(message)) {
    HTMLEditorKit editorKit = new HTMLEditorKit();
    Font font = UIUtil.getLabelFont(fixedFontSize);
    editorKit.getStyleSheet().addRule(UIUtil.displayPropertiesToCSS(font, UIUtil.getLabelForeground()));
    messageComponent.setEditorKit(editorKit);
    messageComponent.setContentType(UIUtil.HTML_MIME);
  }
  messageComponent.setText(message);
  messageComponent.setEditable(false);
  if (messageComponent.getCaret() != null) {
    messageComponent.setCaretPosition(0);
  }

  if (UIUtil.isUnderNimbusLookAndFeel()) {
    messageComponent.setOpaque(false);
    messageComponent.setBackground(UIUtil.TRANSPARENT_COLOR);
  }
  else {
    messageComponent.setBackground(UIUtil.getOptionPaneBackground());
  }

  messageComponent.setForeground(UIUtil.getLabelForeground());
  return messageComponent;
}
 
Example 7
Source File: CheckboxTreeNoPolicy.java    From consulo with Apache License 2.0 5 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) {
  invalidate();
  if (value instanceof CheckedTreeNode) {
    CheckedTreeNode node = (CheckedTreeNode)value;

    NodeState state = getNodeStatus(node);
    myCheckbox.setVisible(true);
    myCheckbox.setSelected(state != NodeState.CLEAR);
    myCheckbox.setEnabled(node.isEnabled() && state != NodeState.PARTIAL);
    myCheckbox.setOpaque(false);
    myCheckbox.setBackground(null);
    setBackground(null);
  }
  else {
    myCheckbox.setVisible(false);
  }
  myTextRenderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);

  if (UIUtil.isUnderGTKLookAndFeel()) {
    final Color background = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
    UIUtil.changeBackGround(this, background);
  }
  else if (UIUtil.isUnderNimbusLookAndFeel()) {
    UIUtil.changeBackGround(this, UIUtil.TRANSPARENT_COLOR);
  }
  customizeRenderer(tree, value, selected, expanded, leaf, row, hasFocus);
  revalidate();

  return this;
}
 
Example 8
Source File: NonOpaquePanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void setOpaque(boolean isOpaque) {
  super.setOpaque(isOpaque);
  setDoubleBuffered(false);

  if (!isOpaque && UIUtil.isUnderNimbusLookAndFeel()) {
    if (UIUtil.isUnderNimbusLookAndFeel()) {
      setBackground(UIUtil.TRANSPARENT_COLOR);
    }
  }
}
 
Example 9
Source File: NewErrorTreeEditor.java    From consulo with 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 10
Source File: ChangesTreeList.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Component getTreeCellRendererComponent(JTree tree,
                                              Object value,
                                              boolean selected,
                                              boolean expanded,
                                              boolean leaf,
                                              int row,
                                              boolean hasFocus) {

  if (UIUtil.isUnderGTKLookAndFeel() || UIUtil.isUnderNimbusLookAndFeel()) {
    NonOpaquePanel.setTransparent(this);
    NonOpaquePanel.setTransparent(myCheckBox);
  } else {
    setBackground(null);
    myCheckBox.setBackground(null);
    myCheckBox.setOpaque(false);
  }

  myTextRenderer.setOpaque(false);
  myTextRenderer.setTransparentIconBackground(true);
  myTextRenderer.setToolTipText(null);
  myTextRenderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
  if (myShowCheckboxes) {
    @SuppressWarnings("unchecked")
    CheckboxTree.NodeState state = getNodeStatus((ChangesBrowserNode)value);
    myCheckBox.setSelected(state != CheckboxTree.NodeState.CLEAR);
    //noinspection unchecked
    myCheckBox.setEnabled(tree.isEnabled() && isNodeEnabled((ChangesBrowserNode)value));
    revalidate();

    return this;
  }
  else {
    return myTextRenderer;
  }
}
 
Example 11
Source File: PsiElementModuleRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void customizeCellRenderer(
  Object value,
  int index,
  boolean selected,
  boolean hasFocus
) {
  myText = "";
  if (value instanceof PsiElement) {
    PsiElement element = (PsiElement)value;
    if (element.isValid()) {
      PsiFile psiFile = element.getContainingFile();
      Module module = ModuleUtil.findModuleForPsiElement(element);
      final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(element.getProject()).getFileIndex();
      boolean isInLibraries = false;
      if (psiFile != null) {
        VirtualFile vFile = psiFile.getVirtualFile();
        if (vFile != null) {
          isInLibraries = fileIndex.isInLibrarySource(vFile) || fileIndex.isInLibraryClasses(vFile);
          if (isInLibraries){
            showLibraryLocation(fileIndex, vFile);
          }
        }
      }
      if (module != null && !isInLibraries) {
        showProjectLocation(psiFile, module, fileIndex);
      }
    }
  }

  setText(myText);
  setBorder(BorderFactory.createEmptyBorder(0, 0, 0, UIUtil.getListCellHPadding()));
  setHorizontalTextPosition(SwingConstants.LEFT);
  setBackground(selected ? UIUtil.getListSelectionBackground() : UIUtil.getListBackground());
  setForeground(selected ? UIUtil.getListSelectionForeground() : UIUtil.getInactiveTextColor());

  if (UIUtil.isUnderNimbusLookAndFeel()) {
    setOpaque(false);
  }
}
 
Example 12
Source File: SearchTextField.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected boolean hasIconsOutsideOfTextField() {
  return UIUtil.isUnderGTKLookAndFeel() || UIUtil.isUnderNimbusLookAndFeel();
}
 
Example 13
Source File: CheckBoxList.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
  JCheckBox checkbox = (JCheckBox)value;

  Color textColor = getForeground(isSelected);
  Color backgroundColor = getBackground(isSelected);
  Font font = getFont();

  boolean shouldAdjustColors = !UIUtil.isUnderNimbusLookAndFeel();

  if (shouldAdjustColors) {
    checkbox.setBackground(backgroundColor);
    checkbox.setForeground(textColor);
  }

  checkbox.setEnabled(isEnabled());
  checkbox.setFont(font);
  checkbox.setFocusPainted(false);
  checkbox.setBorderPainted(false);
  checkbox.setOpaque(true);
  String auxText = getSecondaryText(index);

  JComponent rootComponent;
  if (auxText != null) {
    JPanel panel = new JPanel(new BorderLayout());

    panel.add(checkbox, BorderLayout.LINE_START);

    JLabel infoLabel = new JLabel(auxText, SwingConstants.RIGHT);
    infoLabel.setBorder(new EmptyBorder(0, 0, 0, checkbox.getInsets().left));
    infoLabel.setFont(UIUtil.getFont(UIUtil.FontSize.SMALL, font));
    panel.add(infoLabel, BorderLayout.CENTER);

    if (shouldAdjustColors) {
      panel.setBackground(backgroundColor);
      infoLabel.setForeground(isSelected ? textColor : JBColor.GRAY);
      infoLabel.setBackground(backgroundColor);
    }

    rootComponent = panel;
  }
  else {
    rootComponent = checkbox;
  }

  rootComponent.setBorder(isSelected ? mySelectedBorder : myBorder);

  rootComponent = adjustRendering(rootComponent, checkbox, index, isSelected, cellHasFocus);

  return rootComponent;
}
 
Example 14
Source File: ColoredTreeCellRenderer.java    From consulo with 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 15
Source File: NonOpaquePanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void setTransparent(JComponent c) {
  c.setOpaque(false);
  if (UIUtil.isUnderNimbusLookAndFeel()) {
    c.setBackground(UIUtil.TRANSPARENT_COLOR);
  }
}
 
Example 16
Source File: ConfigurationErrorsComponent.java    From consulo with Apache License 2.0 4 votes vote down vote up
private ErrorListRenderer(@Nonnull final JList list) {
  setLayout(new BorderLayout());
  setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
  setOpaque(false);

  myList = list;

  myText = new JTextPane();

  myButtonsPanel = new JPanel(new BorderLayout());
  myButtonsPanel.setBorder(BorderFactory.createEmptyBorder(5, 3, 5, 3));
  myButtonsPanel.setOpaque(false);
  final JPanel buttons = new JPanel();
  buttons.setOpaque(false);
  buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
  myButtonsPanel.add(buttons, BorderLayout.NORTH);
  add(myButtonsPanel, BorderLayout.EAST);

  myFixGroup = new JPanel();
  myFixGroup.setOpaque(false);
  myFixGroup.setLayout(new BoxLayout(myFixGroup, BoxLayout.Y_AXIS));

  myFixGroup.add(new ToolbarAlikeButton(AllIcons.Actions.QuickfixBulb, FIX_ACTION_NAME) {
  });
  myFixGroup.add(Box.createHorizontalStrut(3));
  buttons.add(myFixGroup);

  buttons.add(new ToolbarAlikeButton(AllIcons.General.AutoscrollToSource, NAVIGATE_ACTION_NAME) {
  });
  buttons.add(Box.createHorizontalStrut(3));

  buttons.add(new ToolbarAlikeButton(AllIcons.Actions.Cancel, "IGNORE") {
  });

  myFakeTextPane = new JTextPane();
  myText.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
  myFakeTextPane.setBorder(BorderFactory.createEmptyBorder(3, 0, 3, 0));
  myText.setOpaque(false);
  if (UIUtil.isUnderNimbusLookAndFeel()) {
    myText.setBackground(UIUtil.TRANSPARENT_COLOR);
  }

  myText.setEditable(false);
  myFakeTextPane.setEditable(false);
  myText.setEditorKit(UIUtil.getHTMLEditorKit());
  myFakeTextPane.setEditorKit(UIUtil.getHTMLEditorKit());

  myFakeViewport = new JViewport();
  myFakeViewport.setView(myFakeTextPane);

  add(myText, BorderLayout.CENTER);
}