Java Code Examples for com.intellij.util.ui.JBUI

The following examples show how to use com.intellij.util.ui.JBUI. 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: PluginsTableRenderer.java    License: Apache License 2.0 6 votes vote down vote up
public PluginsTableRenderer(PluginDescriptor pluginDescriptor, boolean availableRender) {
  myPluginDescriptor = pluginDescriptor;

  final Font smallFont;
  if (SystemInfo.isMac) {
    smallFont = UIUtil.getLabelFont(UIUtil.FontSize.MINI);
  }
  else {
    smallFont = UIUtil.getLabelFont().deriveFont(Math.max(UISettings.getInstance().getFontSize() - JBUI.scale(3), JBUI.scaleFontSize(10)));
  }
  myName.setFont(UIUtil.getLabelFont().deriveFont(UISettings.getInstance().getFontSize()));
  myStatus.setFont(smallFont);
  myCategory.setFont(smallFont);
  myDownloads.setFont(smallFont);
  myStatus.setText("");
  myCategory.setText("");
  myLastUpdated.setFont(smallFont);
  if (!availableRender || !(pluginDescriptor instanceof PluginNode)) {
    myPanel.remove(myRightPanel);
  }

  myPanel.setBorder(UIUtil.isJreHiDPI(myPanel) ? JBUI.Borders.empty(4, 3) : JBUI.Borders.empty(2, 3));
}
 
Example 2
Source Project: consulo   Source File: DesktopStripeButton.java    License: Apache License 2.0 6 votes vote down vote up
private void init() {
  setFocusable(false);
  setBackground(ourBackgroundColor);
  final Border border = JBUI.Borders.empty(5, 5, 0, 5);
  setBorder(border);
  updatePresentation();
  apply(myDecorator.getWindowInfo());
  addActionListener(this);
  addMouseListener(new MyPopupHandler());
  setRolloverEnabled(true);
  setOpaque(false);

  enableEvents(AWTEvent.MOUSE_EVENT_MASK);

  addMouseMotionListener(new MouseMotionAdapter() {
    @Override
    public void mouseDragged(final MouseEvent e) {
      processDrag(e);
    }
  });
  KeymapManager.getInstance().addKeymapManagerListener(myKeymapListener, this);
}
 
Example 3
Source Project: consulo   Source File: PoppedIcon.java    License: Apache License 2.0 6 votes vote down vote up
private static void paintBackground(Graphics g, Dimension size, int state) {
  if (UIUtil.isUnderAquaLookAndFeel()) {
    if (state == ActionButtonComponent.PUSHED) {
      ((Graphics2D)g).setPaint(UIUtil.getGradientPaint(0, 0, ALPHA_40, size.width, size.height, ALPHA_20));
      g.fillRect(0, 0, size.width - 1, size.height - 1);

      g.setColor(ALPHA_120);
      g.drawLine(0, 0, 0, size.height - 2);
      g.drawLine(1, 0, size.width - 2, 0);

      g.setColor(ALPHA_30);
      g.drawRect(1, 1, size.width - 3, size.height - 3);
    }
    else if (state == ActionButtonComponent.POPPED) {
      ((Graphics2D)g).setPaint(UIUtil.getGradientPaint(0, 0, Gray._235, 0, size.height, Gray._200));
      g.fillRect(1, 1, size.width - 3, size.height - 3);
    }
  }
  else {
    final Color bg = UIUtil.getPanelBackground();
    final boolean dark = UIUtil.isUnderDarcula();
    g.setColor(state == ActionButtonComponent.PUSHED ? ColorUtil.shift(bg, dark ? 1d / 0.7d : 0.7d) : dark ? Gray._255.withAlpha(40) : ALPHA_40);
    g.fillRect(JBUI.scale(1), JBUI.scale(1), size.width - JBUI.scale(2), size.height - JBUI.scale(2));
  }
}
 
Example 4
Source Project: consulo   Source File: VcsLogGraphTable.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void paintComponent(Graphics g) {
  setFont(UIManager.getFont("Table.font"));
  g.setColor(myColor);

  int width = getWidth();

  if (isNarrow) {
    g.fillRect(0, 0, width - JBUI.scale(ROOT_INDICATOR_WHITE_WIDTH), myUi.getTable().getRowHeight());
    g.setColor(myBorderColor);
    g.fillRect(width - JBUI.scale(ROOT_INDICATOR_WHITE_WIDTH), 0, JBUI.scale(ROOT_INDICATOR_WHITE_WIDTH),
               myUi.getTable().getRowHeight());
  }
  else {
    g.fillRect(0, 0, width, myUi.getTable().getRowHeight());
  }

  super.paintComponent(g);
}
 
Example 5
Source Project: consulo   Source File: IdeRootPane.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Dimension preferredLayoutSize(Container parent) {
  Dimension rd;
  Insets i = getInsets();

  if (contentPane != null) {
    rd = contentPane.getPreferredSize();
  }
  else {
    rd = parent.getSize();
  }
  Dimension mbd;
  if (menuBar != null && menuBar.isVisible() && !myFullScreen) {
    mbd = menuBar.getPreferredSize();
  }
  else {
    mbd = JBUI.emptySize();
  }
  return new Dimension(Math.max(rd.width, mbd.width) + i.left + i.right,
                       rd.height + mbd.height + i.top + i.bottom);
}
 
Example 6
Source Project: consulo   Source File: BranchActionGroupPopup.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected JComponent createItemComponent() {
  myTextLabel = new ErrorLabel();
  myTextLabel.setOpaque(true);
  myTextLabel.setBorder(JBUI.Borders.empty(1));

  myInfoLabel = new ErrorLabel();
  myInfoLabel.setOpaque(true);
  myInfoLabel.setBorder(JBUI.Borders.empty(1, DEFAULT_HGAP, 1, 1));
  myInfoLabel.setFont(FontUtil.minusOne(myInfoLabel.getFont()));

  JPanel compoundPanel = new OpaquePanel(new BorderLayout(), JBColor.WHITE);
  myIconLabel = new IconComponent();
  myInfoLabel.setHorizontalAlignment(SwingConstants.RIGHT);
  JPanel compoundTextPanel = new OpaquePanel(new BorderLayout(), compoundPanel.getBackground());
  JPanel textPanel = new OpaquePanel(new BorderLayout(), compoundPanel.getBackground());
  compoundPanel.add(myIconLabel, BorderLayout.WEST);
  textPanel.add(myTextLabel, BorderLayout.WEST);
  textPanel.add(myInfoLabel, BorderLayout.CENTER);
  compoundTextPanel.add(textPanel, BorderLayout.CENTER);
  compoundPanel.add(compoundTextPanel, BorderLayout.CENTER);
  return layoutComponent(compoundPanel);
}
 
Example 7
Source Project: consulo   Source File: UsageViewImpl.java    License: Apache License 2.0 6 votes vote down vote up
private void addButtonAction(int index, @Nonnull Action action) {
  JButton button = new JButton(action);
  add(button, index);
  DialogUtil.registerMnemonic(button);

  if (getBorder() == null) setBorder(IdeBorderFactory.createBorder(SideBorder.TOP));
  update();
  Object s = action.getValue(Action.LONG_DESCRIPTION);
  if (s instanceof String) {
    JBLabel label = new JBLabel((String)s);
    label.setEnabled(false);
    label.setFont(JBUI.Fonts.smallFont());
    add(JBUI.Borders.emptyLeft(-1).wrap(label));
  }
  s = action.getValue(Action.SHORT_DESCRIPTION);
  if (s instanceof String) {
    button.setToolTipText((String)s);
  }
  invalidate();
  if (getParent() != null) {
    getParent().validate();
  }
}
 
Example 8
Source Project: consulo   Source File: ParameterInfoComponent.java    License: Apache License 2.0 6 votes vote down vote up
private void setShortcutLabel() {
  if (myShortcutLabel != null) remove(myShortcutLabel);

  String upShortcut = KeymapUtil.getFirstKeyboardShortcutText(IdeActions.ACTION_METHOD_OVERLOAD_SWITCH_UP);
  String downShortcut = KeymapUtil.getFirstKeyboardShortcutText(IdeActions.ACTION_METHOD_OVERLOAD_SWITCH_DOWN);
  if (!myAllowSwitchLabel || myObjects.length <= 1 || !myHandler.supportsOverloadSwitching() || upShortcut.isEmpty() && downShortcut.isEmpty()) {
    myShortcutLabel = null;
  }
  else {
    myShortcutLabel = new JLabel(upShortcut.isEmpty() || downShortcut.isEmpty()
                                 ? CodeInsightBundle.message("parameter.info.switch.overload.shortcuts.single", upShortcut.isEmpty() ? downShortcut : upShortcut)
                                 : CodeInsightBundle.message("parameter.info.switch.overload.shortcuts", upShortcut, downShortcut));
    myShortcutLabel.setForeground(CONTEXT_HELP_FOREGROUND);
    Font labelFont = UIUtil.getLabelFont();
    myShortcutLabel.setFont(labelFont.deriveFont(labelFont.getSize2D() - (SystemInfo.isWindows ? 1 : 2)));
    myShortcutLabel.setBorder(JBUI.Borders.empty(6, 10, 0, 10));
    add(myShortcutLabel, BorderLayout.SOUTH);
  }
}
 
Example 9
Source Project: consulo   Source File: NavBarRootPaneExtension.java    License: Apache License 2.0 6 votes vote down vote up
private void toggleRunPanel(final boolean show) {
  if (show && myRunPanel == null && runToolbarExists()) {
    final ActionManager manager = ActionManager.getInstance();
    AnAction toolbarRunGroup = CustomActionsSchema.getInstance().getCorrectedAction("NavBarToolBar");
    if (toolbarRunGroup instanceof ActionGroup) {
      final boolean needGap = isNeedGap(toolbarRunGroup);
      final ActionToolbar actionToolbar = manager.createActionToolbar(ActionPlaces.NAVIGATION_BAR_TOOLBAR, (ActionGroup)toolbarRunGroup, true);
      final JComponent component = actionToolbar.getComponent();
      myRunPanel = new JPanel(new BorderLayout()) {
        @Override
        public void doLayout() {
          alignVertically(this);
        }
      };
      myRunPanel.setOpaque(false);
      myRunPanel.add(component, BorderLayout.CENTER);
      myRunPanel.setBorder(JBUI.Borders.empty(0, needGap ? 5 : 1, 0, 0));
      myWrapperPanel.add(myRunPanel, BorderLayout.EAST);
    }
  }
  else if (!show && myRunPanel != null) {
    myWrapperPanel.remove(myRunPanel);
    myRunPanel = null;
  }
}
 
Example 10
Source Project: consulo   Source File: ServiceAuthConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
public void updateIcon() {
  myUserIcon = null;

  String email = myState.email;
  if (email == null) {
    myState.iconBytes = null;
    return;
  }

  // get node size
  int size = (int)Math.ceil(AllIcons.Actions.Find.getIconHeight() * JBUI.sysScale());
  Application.get().executeOnPooledThread(() -> {
    String emailHash = DigestUtils.md5Hex(email.toLowerCase().trim());

    try {
      byte[] bytes = HttpRequests.request("https://www.gravatar.com/avatar/" + emailHash + ".png?s=" + size + "&d=identicon").readBytes(null);

      myState.iconBytes = Base64.getEncoder().encodeToString(bytes);
    }
    catch (IOException e) {
      LOGGER.error(e);
    }
  });
}
 
Example 11
Source Project: consulo   Source File: LookupCellRenderer.java    License: Apache License 2.0 6 votes vote down vote up
public LookupCellRenderer(LookupImpl lookup) {
  EditorColorsScheme scheme = lookup.getTopLevelEditor().getColorsScheme();
  myNormalFont = scheme.getFont(EditorFontType.PLAIN);
  myBoldFont = scheme.getFont(EditorFontType.BOLD);

  myLookup = lookup;
  myNameComponent = new MySimpleColoredComponent();
  myNameComponent.setIpad(JBUI.insetsLeft(2));
  myNameComponent.setMyBorder(null);

  myTailComponent = new MySimpleColoredComponent();
  myTailComponent.setIpad(JBUI.emptyInsets());
  myTailComponent.setBorder(JBUI.Borders.emptyRight(10));

  myTypeLabel = new MySimpleColoredComponent();
  myTypeLabel.setIpad(JBUI.emptyInsets());
  myTypeLabel.setBorder(JBUI.Borders.emptyRight(6));

  myPanel = new LookupPanel();
  myPanel.add(myNameComponent, BorderLayout.WEST);
  myPanel.add(myTailComponent, BorderLayout.CENTER);
  myPanel.add(myTypeLabel, BorderLayout.EAST);

  myNormalMetrics = myLookup.getTopLevelEditor().getComponent().getFontMetrics(myNormalFont);
  myBoldMetrics = myLookup.getTopLevelEditor().getComponent().getFontMetrics(myBoldFont);
}
 
Example 12
Source Project: consulo   Source File: MacIntelliJTextFieldUI.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void paintBackground(Graphics graphics) {
  Graphics2D g = (Graphics2D)graphics;
  final JTextComponent c = getComponent();
  final Container parent = c.getParent();
  final Rectangle r = getDrawingRect();
  if (c.isOpaque() && parent != null) {
    g.setColor(parent.getBackground());
    g.fillRect(0, 0, c.getWidth(), c.getHeight());
  }

  if (isSearchField(c)) {
    paintSearchField(g, c, r);
  }
  else {
    if (c.getBorder() instanceof MacIntelliJTextBorder) {
      g.setColor(c.getBackground());
      g.fillRect(JBUI.scale(3), JBUI.scale(3), c.getWidth() - JBUI.scale(6), c.getHeight() - JBUI.scale(6));
    }
    else {
      super.paintBackground(g);
    }
  }
}
 
Example 13
Source Project: consulo   Source File: DaemonTooltipWithActionRenderer.java    License: Apache License 2.0 6 votes vote down vote up
private Font getActionFont() {
  Font toolTipFont = UIUtil.getToolTipFont();
  if (toolTipFont == null || SystemInfo.isWindows) return toolTipFont;

  //if font was changed from default we dont have a good heuristic to customize it
  if (JBUI.Fonts.label() != toolTipFont || UISettings.getInstance().OVERRIDE_NONIDEA_LAF_FONTS) return toolTipFont;

  if (SystemInfo.isMac) {
    return toolTipFont.deriveFont(toolTipFont.getSize() - 1f);
  }

  if (SystemInfo.isLinux) {
    return toolTipFont.deriveFont(toolTipFont.getSize() - 1f);
  }
  return toolTipFont;
}
 
Example 14
Source Project: consulo   Source File: MultilinePopupBuilder.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
private static EditorTextField createTextField(@Nonnull Project project,
                                               Collection<String> values,
                                               boolean supportsNegativeValues,
                                               @Nonnull String initialValue) {
  TextFieldWithCompletion textField =
          new TextFieldWithCompletion(project, new MyCompletionProvider(values, supportsNegativeValues), initialValue, false, true, false) {
            @Override
            protected EditorEx createEditor() {
              EditorEx editor = super.createEditor();
              SoftWrapsEditorCustomization.ENABLED.customize(editor);
              return editor;
            }
          };
  textField.setBorder(new CompoundBorder(JBUI.Borders.empty(2), textField.getBorder()));
  return textField;
}
 
Example 15
Source Project: EasyCode   Source File: BaseGroupPanel.java    License: MIT License 5 votes vote down vote up
/**
 * 初始化方法
 *
 * @param defaultGroupName 默认选中分组
 */
private void init(String defaultGroupName) {
    // 创建一个内容面板
    JPanel contentPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    ComboBoxModel<String> comboBoxModel = new CollectionComboBoxModel<>(groupNameList);
    this.comboBox = new ComboBox<>(comboBoxModel);

    // 添加下拉框
    contentPanel.add(new Label("Group Name:"));
    contentPanel.add(this.comboBox);

    // 添加事件按钮
    DefaultActionGroup actionGroup = createActionGroup();

    // 添加分组选中事件
    this.comboBox.addItemListener(e -> changeGroup((String) comboBox.getSelectedItem()));

    // 选择默认分组
    this.comboBox.setSelectedItem(defaultGroupName);


    ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar("Group Toolbar", actionGroup, true);

    contentPanel.add(actionToolbar.getComponent());

    contentPanel.setPreferredSize(JBUI.size(600, 40));

    // 将内容面板添加至主面板左边(西边)
    this.add(contentPanel, BorderLayout.WEST);
}
 
Example 16
Source Project: consulo   Source File: DesktopToolWindowHeader.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
public static JPanel wrapAndFillVertical(JComponent owner) {
  JPanel panel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.MIDDLE, 0, JBUI.scale(5), false, true));
  panel.add(owner);
  panel.setOpaque(false);
  return panel;
}
 
Example 17
Source Project: consulo   Source File: UnifiedDiffPanel.java    License: Apache License 2.0 5 votes vote down vote up
public UnifiedDiffPanel(@javax.annotation.Nullable Project project,
                        @Nonnull UnifiedContentPanel content,
                        @Nonnull DataProvider provider,
                        @Nonnull DiffContext context) {
  super(project, provider, context);
  myBusyIcon = new AsyncProcessIcon.Big("UnifiedDiff");
  JPanel centerPanel = JBUI.Panels.simplePanel(content).addToTop(myNotificationsPanel);
  myContentPanel.add(centerPanel, GOOD_CONTENT);
  myContentPanel.add(myBusyIcon, LOADING_CONTENT);
  myContentPanel.add(createMessagePanel("Can not calculate diff. " + DiffTooBigException.MESSAGE), TOO_BIG_CONTENT);
  myContentPanel.add(createMessagePanel("Can not calculate diff. Operation canceled."), OPERATION_CANCELED_CONTENT);
  myContentPanel.add(createMessagePanel("Error"), ERROR_CONTENT);

  setCurrentCard(LOADING_CONTENT, false);
}
 
Example 18
public MultiIconSimpleColoredComponent() {
  myFragments = new ArrayList<>(3);
  myLayouts = new ArrayList<>(3);
  myAttributes = new ArrayList<>(3);
  myIcons = new ArrayList<>(3);
  myIpad = new JBInsets(1, 2, 1, 2);
  myIconTextGap = JBUI.scale(2);
  myBorder = new MyBorder();
  myFragmentPadding = new TIntIntHashMap(10);
  myFragmentAlignment = new TIntIntHashMap(10);
  setOpaque(true);
  updateUI();
}
 
Example 19
Source Project: consulo   Source File: ProgressStripeIcon.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
public static AsyncProcessIcon generateIcon(@Nonnull JComponent component) {
  List<Icon> result = ContainerUtil.newArrayList();
  if (UIUtil.isUnderAquaBasedLookAndFeel() && !UIUtil.isUnderDarcula()) {
    for (int i = 0; i < 2 * JBUI.scale(GradientIcon.GRADIENT); i += JBUI.scale(TRANSLATE)) {
      result.add(new GradientIcon(component, i));
    }
  }
  else {
    for (int i = 0; i < JBUI.scale(StripeIcon.WIDTH); i += JBUI.scale(TRANSLATE)) {
      result.add(new StripeIcon(component, i));
    }
    result = ContainerUtil.reverse(result);
  }

  Icon passive = result.get(0);
  AsyncProcessIcon icon = new AsyncProcessIcon("ProgressWithStripes", result.toArray(new Icon[result.size()]), passive) {
    @Override
    public Dimension getPreferredSize() {
      return new Dimension(component.getWidth(), passive.getIconHeight());
    }
  };
  component.addComponentListener(new ComponentAdapter() {
    @Override
    public void componentResized(ComponentEvent e) {
      super.componentResized(e);
      icon.revalidate();
    }
  });
  return icon;
}
 
Example 20
Source Project: consulo   Source File: DesktopFontImpl.java    License: Apache License 2.0 5 votes vote down vote up
public DesktopFontImpl(@Nonnull String fontName, int fontSize, int fontStyle) {
  myFontStyle = fontStyle;

  int style = 0;
  style = BitUtil.set(style, java.awt.Font.PLAIN, BitUtil.isSet(fontStyle, Font.STYLE_PLAIN));
  style = BitUtil.set(style, java.awt.Font.BOLD, BitUtil.isSet(fontStyle, Font.STYLE_BOLD));
  style = BitUtil.set(style, java.awt.Font.ITALIC, BitUtil.isSet(fontStyle, Font.STYLE_ITALIC));

  myFont = new java.awt.Font(fontName, style, JBUI.scaleFontSize(fontSize));
}
 
Example 21
Source Project: consulo   Source File: DarculaButtonPainter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
  final Graphics2D g2d = (Graphics2D)g;
  final Insets ins = getBorderInsets(c);
  final int yOff = (ins.top + ins.bottom) / 4;
  final boolean square = DarculaButtonUI.isSquare(c);
  int offset = JBUI.scale(square ? 1 : getOffset());
  int w = c.getWidth();
  int h = c.getHeight();
  int diam = JBUI.scale(22);

  if (c.hasFocus()) {
    if (DarculaButtonUI.isHelpButton((JComponent)c)) {
      DarculaUIUtil.paintFocusOval(g2d, (w - diam) / 2, (h - diam) / 2, diam, diam);
    } else {
      DarculaUIUtil.paintFocusRing(g2d, new Rectangle(offset, yOff, width - 2 * offset, height - 2 * yOff));
    }
  } else {
    final GraphicsConfig config = new GraphicsConfig(g);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
    g2d.setPaint(UIUtil.getGradientPaint(width / 2, y + yOff + JBUI.scale(1), Gray._80.withAlpha(90), width / 2, height - 2 * yOff, Gray._90.withAlpha(90)));
    //g.drawRoundRect(x + offset + 1, y + yOff + 1, width - 2 * offset, height - 2*yOff, 5, 5);
    ((Graphics2D)g).setPaint(getBorderColor());
    if (DarculaButtonUI.isHelpButton((JComponent)c)) {
      g.drawOval((w - diam) / 2, (h - diam) / 2, diam, diam);
    } else {
      g.translate(x,y);
      int r = JBUI.scale(square ? 3 : 5);
      g.drawRoundRect(offset, yOff, width - 2 * offset, height - 2 * yOff, r, r);
      g.translate(-x,-y);
    }

    config.restore();
  }
}
 
Example 22
Source Project: consulo   Source File: RecentLocationsRenderer.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
private static JComponent createTitleComponent(@Nonnull Project project,
                                               @Nonnull JList<? extends RecentLocationItem> list,
                                               @Nonnull SpeedSearch speedSearch,
                                               @Nullable String breadcrumb,
                                               @Nonnull IdeDocumentHistoryImpl.PlaceInfo placeInfo,
                                               @Nonnull EditorColorsScheme colorsScheme,
                                               boolean selected) {
  JComponent title = JBUI.Panels.simplePanel().withBorder(JBUI.Borders.empty()).addToLeft(createTitleTextComponent(project, list, speedSearch, placeInfo, colorsScheme, breadcrumb, selected));

  title.setBorder(JBUI.Borders.empty(8, 6, 5, 0));
  title.setBackground(getBackgroundColor(colorsScheme, selected));

  return title;
}
 
Example 23
Source Project: consulo   Source File: DarculaSpinnerUI.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Component createPreviousButton() {
  JButton button = createArrow(SwingConstants.SOUTH);
  button.setName("Spinner.previousButton");
  button.setBorder(JBUI.Borders.empty(1, 1, 1, 1));
  installPreviousButtonListeners(button);
  return button;
}
 
Example 24
Source Project: consulo   Source File: FileSystemViewDelegate.java    License: Apache License 2.0 5 votes vote down vote up
private static Icon getIconFromShellFolder(File file, ShellFolder sf) {
  Image icon = sf.getIcon(JBUI.isHiDPI());
  if (icon != null) {
    return new ImageIcon(icon, sf.getFolderType());
  }
  return getDefaultIcon(file);
}
 
Example 25
Source Project: consulo   Source File: BegMenuItemUI.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void installDefaults() {
  super.installDefaults();
  final String propertyPrefix = getPropertyPrefix();
  Integer integer = UIUtil.getPropertyMaxGutterIconWidth(propertyPrefix);
  if (integer != null) {
    myMaxGutterIconWidth = JBUI.scale(integer.intValue());
  }
}
 
Example 26
Source Project: consulo   Source File: InlineProgressIndicator.java    License: Apache License 2.0 5 votes vote down vote up
protected void createCompactTextAndProgress() {
  JPanel textAndProgress = new NonOpaquePanel(new BorderLayout());
  textAndProgress.add(myText, BorderLayout.CENTER);

  final NonOpaquePanel progressWrapper = new NonOpaquePanel(new BorderLayout());
  progressWrapper.setBorder(JBUI.Borders.empty(0, 4));
  progressWrapper.add(myProgress, BorderLayout.CENTER);

  textAndProgress.add(progressWrapper, BorderLayout.EAST);
  myComponent.add(textAndProgress, BorderLayout.CENTER);
}
 
Example 27
Source Project: consulo   Source File: DarculaSpinnerBorder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
  final JSpinner spinner = (JSpinner)c;
  final JFormattedTextField editor = UIUtil.findComponentOfType(spinner, JFormattedTextField.class);
  final int x1 = x + JBUI.scale(3);
  final int y1 = y + JBUI.scale(3);
  final int width1 = width - JBUI.scale(8);
  final int height1 = height - JBUI.scale(6);
  final boolean focused = c.isEnabled() && c.isVisible() && editor != null && editor.hasFocus();
  final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);

  if (c.isOpaque()) {
    g.setColor(UIUtil.getPanelBackground());
    g.fillRect(x, y, width, height);
  }

  g.setColor(UIUtil.getTextFieldBackground());
  g.fillRoundRect(x1, y1, width1, height1, JBUI.scale(5), JBUI.scale(5));
  g.setColor(UIUtil.getPanelBackground());
  if (editor != null) {
    final int off = editor.getBounds().x + editor.getWidth() + ((JSpinner)c).getInsets().left + JBUI.scale(1);
    g.fillRect(off, y1, JBUI.scale(17), height1);
    g.setColor(Gray._100);
    g.drawLine(off, y1, off, height1 + JBUI.scale(2));
  }

  if (!c.isEnabled()) {
    ((Graphics2D)g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
  }

  if (focused) {
    DarculaUIUtil.paintFocusRing(g, new Rectangle(x1, y1, width1, height1));
  }
  else {
    g.setColor(Gray._100);
    g.drawRoundRect(x1, y1, width1, height1, JBUI.scale(5), JBUI.scale(5));
  }
  config.restore();
}
 
Example 28
Source Project: consulo   Source File: ModernButtonBorderPainter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Insets getBorderInsets(Component c) {
  if (DarculaButtonUI.isSquare(c)) {
    return JBUI.insets(2, 0).asUIResource();
  }
  return JBUI.insets(8, 16).asUIResource();
}
 
Example 29
Source Project: DarkyenusTimeTracker   Source File: TimeTrackerWidget.java    License: The Unlicense 5 votes vote down vote up
@Override
public Dimension getPreferredSize() {
    final Font widgetFont = WIDGET_FONT;
    final FontMetrics fontMetrics = getFontMetrics(widgetFont);
    final TimePattern pattern = currentShowTimePattern();
    final int stringWidth;

    if (widgetFont.equals(getPreferredSize_lastFont) && pattern.equals(getPreferredSize_lastPattern)) {
        stringWidth = getPreferredSize_lastWidth;
    } else {
        int maxWidth = 0;
        // Size may decrease with growing time, so we try different second boundaries
        for (int seconds : PREFERRED_SIZE_SECOND_QUERIES) {
            maxWidth = Math.max(maxWidth, fontMetrics.stringWidth(pattern.secondsToString(seconds - 1)));
        }
        getPreferredSize_lastPattern = pattern;
        getPreferredSize_lastFont = widgetFont;
        getPreferredSize_lastWidth = maxWidth;
        stringWidth = maxWidth;
    }


    final Insets insets = getInsets();
    int width = stringWidth + insets.left + insets.right + JBUI.scale(2);
    int height = fontMetrics.getHeight() + insets.top + insets.bottom + JBUI.scale(2);
    return new Dimension(width, height);
}
 
Example 30
Source Project: azure-devops-intellij   Source File: PRTreeNodeForm.java    License: MIT License 5 votes vote down vote up
public PRTreeNodeForm(final boolean selected, final boolean hasFocus) {
    SwingHelper.setMargin(panel, JBUI.scale(5));
    panel.setBackground(selected ?
            (hasFocus ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeUnfocusedSelectionBackground())
            : UIUtil.getTreeBackground());

    titleLabel.setForeground(selected && hasFocus ? UIUtil.getTreeSelectionForeground() : UIUtil.getTreeTextForeground());
    summaryLabel.setForeground(selected && hasFocus ? UIUtil.getTreeSelectionForeground() : SimpleTextAttributes.GRAY_ATTRIBUTES.getFgColor());
}