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

The following examples show how to use com.intellij.util.ui.UIUtil#isUnderGTKLookAndFeel() . 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: GTKPlusUIUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
protected Boolean compute() {
  if (!UIUtil.isUnderGTKLookAndFeel()) {
    return false;
  }

  JTextArea dummyArea = new JTextArea();
  dummyArea.updateUI();

  SynthContext synthContext = getSynthContext(dummyArea.getUI(), dummyArea);

  Color colorBack = synthContext.getStyle().getColor(synthContext, ColorType.TEXT_BACKGROUND);
  Color colorFore = synthContext.getStyle().getColor(synthContext, ColorType.TEXT_FOREGROUND);

  double textAvg = colorFore.getRed() / 256. + colorFore.getGreen() / 256. + colorFore.getBlue() / 256.;
  double bgAvg = colorBack.getRed() / 256. + colorBack.getGreen() / 256. + colorBack.getBlue() / 256.;
  return textAvg > bgAvg;
}
 
Example 2
Source File: LafManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void fixPopupSize(final Popup popup, final Component contents) {
  if (!UIUtil.isUnderGTKLookAndFeel() || !(contents instanceof JPopupMenu)) return;

  for (Class<?> aClass = popup.getClass(); aClass != null && Popup.class.isAssignableFrom(aClass); aClass = aClass.getSuperclass()) {
    try {
      final Method getComponent = aClass.getDeclaredMethod("getComponent");
      getComponent.setAccessible(true);
      final Object component = getComponent.invoke(popup);
      if (component instanceof JWindow) {
        ((JWindow)component).setSize(new Dimension(0, 0));
      }
      break;
    }
    catch (Exception ignored) {
    }
  }
}
 
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: IgnoredSettingsPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
  if (UIUtil.isUnderGTKLookAndFeel()) {
    final Color background = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
    UIUtil.changeBackGround(this, background);
  }

  IgnoredFileBean bean = (IgnoredFileBean)value;
  final String path = bean.getPath();
  if (path != null) {
    if (path.endsWith("/")) {
      append(VcsBundle.message("ignored.configure.item.directory", path), SimpleTextAttributes.REGULAR_ATTRIBUTES);
    }
    else {
      append(VcsBundle.message("ignored.configure.item.file", path), SimpleTextAttributes.REGULAR_ATTRIBUTES);
    }
  }
  else if (bean.getMask() != null) {
    append(VcsBundle.message("ignored.configure.item.mask", bean.getMask()), SimpleTextAttributes.REGULAR_ATTRIBUTES);
  }
}
 
Example 5
Source File: ContentChooser.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
  setIcon(myListEntryIcon);
  if (myUseIdeaEditor) {
    int max = list.getModel().getSize();
    String indexString = String.valueOf(index + 1);
    int count = String.valueOf(max).length() - indexString.length();
    char[] spaces = new char[count];
    Arrays.fill(spaces, ' ');
    String prefix = indexString + new String(spaces) + "  ";
    append(prefix, SimpleTextAttributes.GRAYED_ATTRIBUTES);
  }
  else if (UIUtil.isUnderGTKLookAndFeel()) {
    // Fix GTK background
    Color background = selected ? UIUtil.getListSelectionBackground() : UIUtil.getListBackground();
    UIUtil.changeBackGround(this, background);
  }
  String text = ((Item)value).shortText;

  FontMetrics metrics = list.getFontMetrics(list.getFont());
  int charWidth = metrics.charWidth('m');
  int maxLength = list.getParent().getParent().getWidth() * 3 / charWidth / 2;
  text = StringUtil.first(text, maxLength, true); // do not paint long strings
  append(text, SimpleTextAttributes.REGULAR_ATTRIBUTES);
}
 
Example 6
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 7
Source File: LafManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Popup getPopup(final Component owner, final Component contents, final int x, final int y) throws IllegalArgumentException {
  final Point point = fixPopupLocation(contents, x, y);

  final int popupType = UIUtil.isUnderGTKLookAndFeel() ? WEIGHT_HEAVY : PopupUtil.getPopupType(this);
  if (popupType >= 0) {
    PopupUtil.setPopupType(myDelegate, popupType);
  }

  final Popup popup = myDelegate.getPopup(owner, contents, point.x, point.y);
  fixPopupSize(popup, contents);
  return popup;
}
 
Example 8
Source File: LafManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void patchOptionPaneIcons(final UIDefaults defaults) {
  if (UIUtil.isUnderGTKLookAndFeel() && defaults.get(ourOptionPaneIconKeys[0]) == null) {
    // GTK+ L&F keeps icons hidden in style
    final SynthStyle style = SynthLookAndFeel.getStyle(new JOptionPane(""), Region.DESKTOP_ICON);
    if (style != null) {
      for (final String key : ourOptionPaneIconKeys) {
        final Object icon = style.get(null, key);
        if (icon != null) defaults.put(key, icon);
      }
    }
  }
}
 
Example 9
Source File: LafManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void fixGtkPopupStyle() {
  if (!UIUtil.isUnderGTKLookAndFeel()) return;

  // it must be instance of com.sun.java.swing.plaf.gtk.GTKStyleFactory, but class package-local
  if (SystemInfo.isJavaVersionAtLeast(10, 0, 0)) {
    return;
  }

  final SynthStyleFactory original = SynthLookAndFeel.getStyleFactory();

  SynthLookAndFeel.setStyleFactory(new SynthStyleFactory() {
    @Override
    public SynthStyle getStyle(final JComponent c, final Region id) {
      final SynthStyle style = original.getStyle(c, id);
      if (id == Region.POPUP_MENU) {
        final Integer x = ReflectionUtil.getField(style.getClass(), style, int.class, "xThickness");
        if (x != null && x == 0) {
          // workaround for Sun bug #6636964
          ReflectionUtil.setField(style.getClass(), style, int.class, "xThickness", 1);
          ReflectionUtil.setField(style.getClass(), style, int.class, "yThickness", 3);
        }
      }
      return style;
    }
  });

  new JBPopupMenu();  // invokes updateUI() -> updateStyle()

  SynthLookAndFeel.setStyleFactory(original);
}
 
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: XDebuggerFramesList.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void customizeCellRenderer(@Nonnull final JList list,
                                     final Object value,
                                     final int index,
                                     final boolean selected,
                                     final boolean hasFocus) {
  // Fix GTK background
  if (UIUtil.isUnderGTKLookAndFeel()){
    final Color background = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
    UIUtil.changeBackGround(this, background);
  }
  if (value == null) {
    append(XDebuggerBundle.message("stack.frame.loading.text"), SimpleTextAttributes.GRAY_ATTRIBUTES);
    return;
  }
  if (value instanceof String) {
    append((String)value, SimpleTextAttributes.ERROR_ATTRIBUTES);
    return;
  }

  XStackFrame stackFrame = (XStackFrame)value;
  if (!selected) {
    Color c = getFrameBgColor(stackFrame);
    if (c != null) {
      setBackground(c);
    }
  }
  stackFrame.customizePresentation(this);
}
 
Example 12
Source File: ActionMenu.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void updateUI() {
  boolean isAmbiance = UIUtil.isUnderGTKLookAndFeel() && "Ambiance".equalsIgnoreCase(UIUtil.getGtkThemeName());
  if (myTopLevel && !isAmbiance && UIUtil.GTK_AMBIANCE_TEXT_COLOR.equals(getForeground())) {
    setForeground(null);
  }

  super.updateUI();

  if (myTopLevel && isAmbiance) {
    setForeground(UIUtil.GTK_AMBIANCE_TEXT_COLOR);
  }

  if (myTopLevel && UIUtil.isUnderGTKLookAndFeel()) {
    Insets insets = getInsets();
    Insets newInsets = new Insets(insets.top, insets.left, insets.bottom, insets.right);
    if (insets.top + insets.bottom < 6) {
      newInsets.top = newInsets.bottom = 3;
    }
    if (insets.left + insets.right < 12) {
      newInsets.left = newInsets.right = 6;
    }
    if (!newInsets.equals(insets)) {
      setBorder(BorderFactory.createEmptyBorder(newInsets.top, newInsets.left, newInsets.bottom, newInsets.right));
    }
  }
}
 
Example 13
Source File: ListCellRendererWrapper.java    From consulo with Apache License 2.0 5 votes vote down vote up
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
  mySeparator = false;
  myIcon = null;
  myText = null;
  myForeground = null;
  myBackground = null;
  myFont = null;
  myToolTipText = null;
  myProperties = FList.emptyList();

  @SuppressWarnings("unchecked") final T t = (T)value;
  customize(list, t, index, isSelected, cellHasFocus);

  if (mySeparator) {
    final TitledSeparator separator = new TitledSeparator(myText);
    separator.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0));
    if (!UIUtil.isUnderGTKLookAndFeel()) {
      separator.setOpaque(false);
      separator.setBackground(UIUtil.TRANSPARENT_COLOR);
      separator.getLabel().setOpaque(false);
      separator.getLabel().setBackground(UIUtil.TRANSPARENT_COLOR);
    }
    return separator;
  }

  @SuppressWarnings("unchecked") final Component component = myDefaultRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
  if (component instanceof JLabel) {
    final JLabel label = (JLabel)component;
    label.setIcon(myIcon);
    if (myText != null) label.setText(myText);
    if (myForeground != null) label.setForeground(myForeground);
    if (myBackground != null && !isSelected) label.setBackground(myBackground);
    if (myFont != null) label.setFont(myFont);
    label.setToolTipText(myToolTipText);
    for (Pair<Object, Object> pair : myProperties) {
      label.putClientProperty(pair.first, pair.second);
    }
  }
  return component;
}
 
Example 14
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 15
Source File: ColoredListCellRenderer.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList<? extends T> list, T value, int index, boolean selected, boolean hasFocus) {
  clear();
  mySeparator = false;
  mySeparatorText = null;

  if (myComboBox != null) {
    setEnabled(myComboBox.isEnabled());
  }

  setFont(list.getFont());

  mySelected = selected;
  myForeground = isEnabled() ? list.getForeground() : UIManager.getColor("Label.disabledForeground");
  mySelectionForeground = list.getSelectionForeground();

  if (index == -1) {
    setOpaque(false);
    mySelected = false;
  }
  else {
    setOpaque(true);
    setBackground(selected ? list.getSelectionBackground() : null);
  }

  setPaintFocusBorder(hasFocus);

  customizeCellRenderer(list, value, index, selected, hasFocus);

  if (mySeparator) {
    final TitledSeparator separator = new TitledSeparator(mySeparatorText);
    separator.setBorder(JBUI.Borders.empty(0, 2, 0, 0));

    if (!UIUtil.isUnderGTKLookAndFeel()) {
      separator.setOpaque(false);
      separator.setBackground(UIUtil.TRANSPARENT_COLOR);
      separator.getLabel().setOpaque(false);
      separator.getLabel().setBackground(UIUtil.TRANSPARENT_COLOR);
    }
    return separator;
  }

  if (myDefaultGtkRenderer != null && list.getModel() instanceof ComboBoxModel) {
    final Component component = myDefaultGtkRenderer.getListCellRendererComponent(list, value, index, selected, hasFocus);
    if (component instanceof JLabel) {
      return formatToLabel((JLabel)component);
    }
  }
  return this;
}
 
Example 16
Source File: ActionMenuItem.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void setUI(final MenuItemUI ui) {
  final MenuItemUI newUi = UIUtil.isUnderGTKLookAndFeel() && GtkMenuItemUI.isUiAcceptable(ui) ? new GtkMenuItemUI(ui) : ui;
  super.setUI(newUi);
}
 
Example 17
Source File: ActionMenu.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void setUI(final MenuItemUI ui) {
  final MenuItemUI newUi = !myTopLevel && UIUtil.isUnderGTKLookAndFeel() && GtkMenuUI.isUiAcceptable(ui) ? new GtkMenuUI(ui) : ui;
  super.setUI(newUi);
}
 
Example 18
Source File: NavBarUIManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static NavBarUI getUI() {
  if (UIUtil.isUnderAquaLookAndFeel()) return AQUA;
  if (UIUtil.isUnderGTKLookAndFeel())  return GTK;
  if (UIUtil.isUnderDarcula())         return DARCULA;
  return COMMON;
}
 
Example 19
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 20
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();
}