com.intellij.util.ui.JBUI Java Examples

The following examples show how to use com.intellij.util.ui.JBUI. 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: UsageViewImpl.java    From consulo with 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 #2
Source File: ServiceAuthConfiguration.java    From consulo with 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 #3
Source File: PoppedIcon.java    From consulo with 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 File: LookupCellRenderer.java    From consulo with 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 #5
Source File: MacIntelliJTextFieldUI.java    From consulo with 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 #6
Source File: NavBarRootPaneExtension.java    From consulo with 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 #7
Source File: VcsLogGraphTable.java    From consulo with 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 #8
Source File: DaemonTooltipWithActionRenderer.java    From consulo with 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 #9
Source File: MultilinePopupBuilder.java    From consulo with 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 #10
Source File: DesktopStripeButton.java    From consulo with 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 #11
Source File: IdeRootPane.java    From consulo with 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 #12
Source File: ParameterInfoComponent.java    From consulo with 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 #13
Source File: PluginsTableRenderer.java    From consulo with 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 #14
Source File: BranchActionGroupPopup.java    From consulo with 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 #15
Source File: HectorComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void layoutVertical(final JPanel panel) {
  for (Map.Entry<Language, JSlider> entry : mySliders.entrySet()) {
    Language language = entry.getKey();
    JSlider slider = entry.getValue();

    JPanel borderPanel = new JPanel(new BorderLayout());
    slider.setPreferredSize(JBUI.size(100, 100));
    borderPanel.add(new JLabel(language.getDisplayName()), BorderLayout.NORTH);
    borderPanel.add(slider, BorderLayout.CENTER);
    panel.add(borderPanel, new GridBagConstraints(GridBagConstraints.RELATIVE, 1, 1, 1, 0, 1, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, JBUI.insets(0, 5, 0, 5), 0, 0));
  }
}
 
Example #16
Source File: BaseGroupPanel.java    From EasyCode with 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 #17
Source File: SlideComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void processMouse(MouseEvent e) {
  int pointerValue = myVertical ? e.getY() : e.getX();
  pointerValue = pointerValue < getPointerOffset() ? getPointerOffset() : pointerValue;
  int size = myVertical ? getHeight() : getWidth();
  pointerValue = pointerValue > (size - JBUI.scale(12)) ? size - JBUI.scale(12) : pointerValue;

  myPointerValue = pointerValue;

  myValue = pointerValueToValue(myPointerValue);

  repaint();
  fireValueChanged();
}
 
Example #18
Source File: OptionTableWithPreviewPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void init() {
  super.init();

  myPanel.setLayout(new GridBagLayout());
  initTables();

  myTreeTable = createOptionsTree(getSettings());
  myTreeTable.setBackground(UIUtil.getPanelBackground());
  myTreeTable.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
  JBScrollPane scrollPane = new JBScrollPane(myTreeTable) {
    @Override
    public Dimension getMinimumSize() {
      return super.getPreferredSize();
    }
  };
  myPanel.add(scrollPane, new GridBagConstraints(0, 0, 1, 1, 0, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, JBUI.emptyInsets(), 0, 0));

  final JPanel previewPanel = createPreviewPanel();
  myPanel.add(previewPanel, new GridBagConstraints(1, 0, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, JBUI.emptyInsets(), 0, 0));

  installPreviewPanel(previewPanel);
  addPanelToWatch(myPanel);

  isFirstUpdate = false;
  customizeSettings();
}
 
Example #19
Source File: FileSystemViewDelegate.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static Icon getIcon(@Nonnull File file) {
  if (ourShellFolderMethod == null) {
    return getDefaultIcon(file);
  }

  try {
    Object object = ourShellFolderMethod.invoke(FileSystemView.getFileSystemView(), file);
    if (!(object instanceof ShellFolder)) {
      return getDefaultIcon(file);
    }

    if (SystemInfo.isWindows) {
      if(!JBUI.isHiDPI()) {
        return getIconFromShellFolder(file, (ShellFolder)object);
      }

      // on HiDPI monitors, ShellFolder return 32x32 only icons, and cut base icon
      // it ignore scale, for 2.5 scale return icon with 32x32 (and cut only 25% of icon, not resize)
      // that why - return default icon
    }
    else {
      return getIconFromShellFolder(file, (ShellFolder)object);
    }
  }
  catch (IllegalAccessException | InvocationTargetException ignored) {
  }
  return getDefaultIcon(file);
}
 
Example #20
Source File: BookmarksFavoriteListProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void customizeRenderer(ColoredTreeCellRenderer renderer,
                              JTree tree,
                              @Nonnull Object value,
                              boolean selected,
                              boolean expanded,
                              boolean leaf,
                              int row,
                              boolean hasFocus) {
  renderer.clear();
  renderer.setIcon(Bookmark.getDefaultIcon());
  if (value instanceof Bookmark) {
    Bookmark bookmark = (Bookmark)value;
    BookmarkItem.setupRenderer(renderer, myProject, bookmark, selected);
    if (renderer.getIcon() != null) {
      RowIcon icon = new RowIcon(3, RowIcon.Alignment.CENTER);
      icon.setIcon(TargetAWT.to(bookmark.getIcon()), 0);
      icon.setIcon(JBUI.scale(EmptyIcon.create(1)), 1);
      icon.setIcon(renderer.getIcon(), 2);
      renderer.setIcon(icon);
    }
    else {
      renderer.setIcon(bookmark.getIcon());
    }
  }
  else {
    renderer.append(getListName(myProject));
  }
}
 
Example #21
Source File: UiInspectorAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void drawInsets(Graphics2D g2d, FontMetrics fm, String name, Insets insets, int offset, int fontHeight, int innerX, int innerY, int innerWidth, int innerHeight) {
  g2d.setColor(JBColor.BLACK);
  g2d.drawString(name, innerX - offset + JBUI.scale(5), innerY - offset + fontHeight);

  g2d.setColor(JBColor.GRAY);

  int outerX = innerX - offset;
  int outerWidth = innerWidth + offset * 2;
  int outerY = innerY - offset;
  int outerHeight = innerHeight + offset * 2;

  final String top = insets != null ? Integer.toString(insets.top) : "-";
  final String bottom = insets != null ? Integer.toString(insets.bottom) : "-";
  final String left = insets != null ? Integer.toString(insets.left) : "-";
  final String right = insets != null ? Integer.toString(insets.right) : "-";

  int shift = JBUI.scale(7);
  drawCenteredString(g2d, fm, fontHeight, top,
                     outerX + outerWidth / 2,
                     outerY + shift);
  drawCenteredString(g2d, fm, fontHeight, bottom,
                     outerX + outerWidth / 2,
                     outerY + outerHeight - shift);
  drawCenteredString(g2d, fm, fontHeight, left,
                     outerX + shift,
                     outerY + outerHeight / 2);
  drawCenteredString(g2d, fm, fontHeight, right,
                     outerX + outerWidth - shift,
                     outerY + outerHeight / 2);
}
 
Example #22
Source File: RunAnythingMore.java    From consulo with Apache License 2.0 5 votes vote down vote up
static RunAnythingMore get(boolean isSelected) {
  instance.setBackground(UIUtil.getListBackground(isSelected, true));
  instance.label.setForeground(UIUtil.getLabelDisabledForeground());
  instance.label.setFont(RunAnythingUtil.getTitleFont());
  instance.label.setBackground(UIUtil.getListBackground(isSelected, true));
  instance.label.setBorder(JBUI.Borders.emptyLeft(1));
  return instance;
}
 
Example #23
Source File: LineStatusMarkerRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static Rectangle getMarkerArea(@Nonnull Editor editor, @Nonnull Rectangle r, int line1, int line2) {
  EditorGutterComponentEx gutter = ((EditorEx)editor).getGutterComponentEx();
  int x = r.x + JBUI.scale(1); // leave 1px for brace highlighters
  int endX = gutter.getWhitespaceSeparatorOffset();
  int y = lineToY(editor, line1);
  int endY = lineToY(editor, line2);
  return new Rectangle(x, y, endX - x, endY - y);
}
 
Example #24
Source File: TestTreeRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public Dimension getPreferredSize() {
  final Dimension preferredSize = super.getPreferredSize();
  return myDurationWidth < 0 || ((TestTreeView)myTree).isExpandableHandlerVisibleForCurrentRow(myRow)
         ? preferredSize
         : JBUI.size(preferredSize.width + myDurationWidth, preferredSize.height);
}
 
Example #25
Source File: ModernButtonBorderPainter.java    From consulo with 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 #26
Source File: PRTreeNodeForm.java    From azure-devops-intellij with 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());
}
 
Example #27
Source File: BegMenuItemUI.java    From consulo with 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 #28
Source File: InlineProgressIndicator.java    From consulo with 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 #29
Source File: TimeTrackerWidget.java    From DarkyenusTimeTracker with 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 File: DarculaSpinnerBorder.java    From consulo with 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();
}