@Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    if (UIUtil.isUnderAquaLookAndFeel()) {
      return;
    }

    switch (getState()) {
      case DONT_CARE:
        Icon icon = getIcon();
        if (icon == null) {
          icon = UIManager.getIcon("CheckBox.icon");
        }
        if (UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF()) {
          icon = EmptyIcon.create(20, 18);
        }
        if (icon != null) {
          final Insets i = getInsets();
          final Rectangle r = getBounds();
          final Rectangle r1 = new Rectangle();
          r1.x = i.left;
          r1.y = i.top;
          r1.width = r.width - (i.right + r1.x);
          r1.height = r.height - (i.bottom + r1.y);

          final Rectangle r2 = new Rectangle();
          final Rectangle r3 = new Rectangle();
          SwingUtilities.layoutCompoundLabel(
              this,
              getFontMetrics(getFont()),
              getText(),
              icon,
              getVerticalAlignment(),
              getHorizontalAlignment(),
              getVerticalTextPosition(),
              getHorizontalTextPosition(),
              r1,
              r2,
              r3,
              getText() == null ? 0 : getIconTextGap());

          // selected table cell: do not paint white on white
          g.setColor(UIUtil.getTreeForeground());
          int height = r2.height / 10;
          int width = r2.width / 3;
          g.fillRect(
              r2.x + r2.width / 2 - width / 2, r2.y + r2.height / 2 - height / 2, width, height);
        }
        break;
      default:
        break;
    }
  }
Esempio n. 2
0
  @Override
  public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
    final Component result = super.prepareRenderer(renderer, row, column);
    final boolean selected =
        myExpandableItemsHandler.getExpandedItems().contains(new TableCell(row, column));

    // Fix GTK background
    if (UIUtil.isUnderGTKLookAndFeel()) {
      UIUtil.changeBackGround(this, UIUtil.getTreeTextBackground());
    }

    if (isTableDecorationSupported() && isStriped() && result instanceof JComponent) {
      final Color bg = row % 2 == 1 ? getBackground() : DECORATED_ROW_BG_COLOR;
      final JComponent c = (JComponent) result;
      final boolean cellSelected = isCellSelected(row, column);
      if (!cellSelected || (!hasFocus() && !getSelectionBackground().equals(c.getBackground()))) {
        c.setOpaque(true);
        c.setBackground(bg);
        for (Component child : c.getComponents()) {
          child.setBackground(bg);
        }
      }
    }

    if (!selected) return result;

    return new JComponent() {
      {
        add(result);
        setOpaque(false);
        setLayout(
            new AbstractLayoutManager() {
              @Override
              public Dimension preferredLayoutSize(Container parent) {
                return result.getPreferredSize();
              }

              @Override
              public void layoutContainer(Container parent) {
                Dimension size = parent.getSize();
                Insets i = parent.getInsets();
                Dimension pref = result.getPreferredSize();
                result.setBounds(
                    i.left,
                    i.top,
                    Math.max(pref.width, size.width - i.left - i.right),
                    size.height - i.top - i.bottom);
              }
            });
      }
    };
  }
  protected void buildOptions(JPanel searchOptions) {
    super.buildOptions(searchOptions);
    searchOptions.add(
        UIUtil.createOptionLine(
            shortenFQN =
                new JCheckBox(SSRBundle.message("shorten.fully.qualified.names.checkbox"), true)));

    searchOptions.add(
        UIUtil.createOptionLine(
            formatAccordingToStyle =
                new JCheckBox(
                    CodeInsightBundle.message(
                        "dialog.edit.template.checkbox.reformat.according.to.style"),
                    true)));

    searchOptions.add(
        UIUtil.createOptionLine(
            useStaticImport =
                new JCheckBox(
                    CodeInsightBundle.message("dialog.edit.template.checkbox.use.static.import"),
                    true)));
  }
Esempio n. 4
0
 private static boolean isTableDecorationSupported() {
   return UIUtil.isUnderAlloyLookAndFeel()
       || UIUtil.isUnderNativeMacLookAndFeel()
       || UIUtil.isUnderQuaquaLookAndFeel()
       || UIUtil.isUnderMetalLookAndFeel()
       || UIUtil.isUnderNimbusLookAndFeel()
       || UIUtil.isUnderWindowsLookAndFeel();
 }
Esempio n. 5
0
  private static float calculateScaleFactor() {
    if (SystemInfo.isMac) {
      return 1.0f;
    }

    if (SystemProperties.has("hidpi") && !SystemProperties.is("hidpi")) {
      return 1.0f;
    }

    // On Linux: rely on DPI
    if (SystemInfo.isLinux) {
      final int dpi = getSystemDPI();
      if (dpi < 120) return 1f;
      if (dpi < 144) return 1.25f;
      if (dpi < 168) return 1.5f;
      if (dpi < 192) return 1.75f;
      return 2f;
    }

    int size = -1;

    // On Windows: rely on default system font
    if (SystemInfo.isWindows) {
      UIUtil.initSystemFontData();
      Pair<String, Integer> fdata = UIUtil.getSystemFontData();
      if (fdata != null) size = fdata.getSecond();
    }
    if (size == -1) {
      size = Fonts.label().getSize();
    }
    if (size <= 13) return 1.0f;
    if (size <= 16) return 1.25f;
    if (size <= 18) return 1.5f;
    if (size < 24) return 1.75f;

    return 2.0f;
  }
  public void setValuesFromConfig(Configuration configuration) {
    // replaceCriteriaEdit.putUserData(SubstitutionShortInfoHandler.CURRENT_CONFIGURATION_KEY,
    // configuration);

    if (configuration instanceof ReplaceConfiguration) {
      final ReplaceConfiguration config = (ReplaceConfiguration) configuration;
      final ReplaceOptions options = config.getOptions();
      super.setValuesFromConfig(config);

      UIUtil.setContent(
          replaceCriteriaEdit,
          config.getOptions().getReplacement(),
          0,
          replaceCriteriaEdit.getDocument().getTextLength(),
          searchContext.getProject());

      shortenFQN.setSelected(options.isToShortenFQN());
      formatAccordingToStyle.setSelected(options.isToReformatAccordingToStyle());
      useStaticImport.setSelected(options.isToUseStaticImport());

      ReplaceOptions newReplaceOptions = ((ReplaceConfiguration) model.getConfig()).getOptions();
      newReplaceOptions.clearVariableDefinitions();

      for (ReplacementVariableDefinition def : options.getReplacementVariableDefinitions()) {
        newReplaceOptions.addVariableDefinition((ReplacementVariableDefinition) def.clone());
      }
    } else {
      super.setValuesFromConfig(configuration);

      UIUtil.setContent(
          replaceCriteriaEdit,
          configuration.getMatchOptions().getSearchPattern(),
          0,
          replaceCriteriaEdit.getDocument().getTextLength(),
          searchContext.getProject());
    }
  }
Esempio n. 7
0
 private void handle(MouseEvent e) {
   if (UIUtil.isActionClick(e, MouseEvent.MOUSE_PRESSED)) {
     if (!myPopup.isShowing()) {
       openProcessPopup(true);
     } else {
       hideProcessPopup();
     }
   } else if (e.isPopupTrigger()) {
     ActionGroup group = (ActionGroup) ActionManager.getInstance().getAction("BackgroundTasks");
     ActionManager.getInstance()
         .createActionPopupMenu(ActionPlaces.UNKNOWN, group)
         .getComponent()
         .show(e.getComponent(), e.getX(), e.getY());
   }
 }
  public StatusText() {
    myClickListener =
        new ClickListener() {
          @Override
          public boolean onClick(@NotNull MouseEvent e, int clickCount) {
            if (e.getButton() == MouseEvent.BUTTON1 && clickCount == 1) {
              ActionListener actionListener = findActionListenerAt(e.getPoint());
              if (actionListener != null) {
                actionListener.actionPerformed(new ActionEvent(this, 0, ""));
                return true;
              }
            }
            return false;
          }
        };

    myMouseMotionListener =
        new MouseAdapter() {

          private Cursor myOriginalCursor;

          @Override
          public void mouseMoved(final MouseEvent e) {
            if (isStatusVisible()) {
              if (findActionListenerAt(e.getPoint()) != null) {
                if (myOriginalCursor == null) {
                  myOriginalCursor = myMouseTarget.getCursor();
                  myMouseTarget.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                }
              } else if (myOriginalCursor != null) {
                myMouseTarget.setCursor(myOriginalCursor);
                myOriginalCursor = null;
              }
            }
          }
        };

    myComponent.setOpaque(false);
    myComponent.setFont(UIUtil.getLabelFont());
    setText(DEFAULT_EMPTY_TEXT, DEFAULT_ATTRIBUTES);
    myIsDefaultText = true;
  }
Esempio n. 9
0
 public void setRefreshVisible(final boolean visible) {
   UIUtil.invokeLaterIfNeeded(
       new Runnable() {
         @Override
         public void run() {
           myRefreshAlarm.cancelAllRequests();
           myRefreshAlarm.addRequest(
               new Runnable() {
                 @Override
                 public void run() {
                   if (visible) {
                     myRefreshIcon.resume();
                   } else {
                     myRefreshIcon.suspend();
                   }
                   myRefreshIcon.revalidate();
                   myRefreshIcon.repaint();
                 }
               },
               visible ? 100 : 300);
         }
       });
 }
Esempio n. 10
0
  private void buildInProcessCount() {
    removeAll();
    setLayout(new BorderLayout());

    final JPanel progressCountPanel = new JPanel(new BorderLayout(0, 0));
    progressCountPanel.setOpaque(false);
    String processWord = myOriginals.size() == 1 ? " process" : " processes";
    final LinkLabel label =
        new LinkLabel(
            myOriginals.size() + processWord + " running...",
            null,
            new LinkListener() {
              @Override
              public void linkSelected(final LinkLabel aSource, final Object aLinkData) {
                triggerPopupShowing();
              }
            });

    if (SystemInfo.isMac) label.setFont(UIUtil.getLabelFont().deriveFont(11.0f));

    label.setOpaque(false);

    final Wrapper labelComp = new Wrapper(label);
    labelComp.setOpaque(false);
    progressCountPanel.add(labelComp, BorderLayout.CENTER);

    // myProgressIcon.setBorder(new IdeStatusBarImpl.MacStatusBarWidgetBorder());
    progressCountPanel.add(myProgressIcon, BorderLayout.WEST);

    add(myRefreshAndInfoPanel, BorderLayout.CENTER);

    progressCountPanel.setBorder(new EmptyBorder(0, 0, 0, 4));
    add(progressCountPanel, BorderLayout.EAST);

    revalidate();
    repaint();
  }
Esempio n. 11
0
 protected boolean isRetina() {
   return UIUtil.isRetina();
 }
Esempio n. 12
0
 public static JBFont miniFont() {
   return label().deriveFont(UIUtil.getFontSize(UIUtil.FontSize.MINI));
 }
Esempio n. 13
0
 public static JBFont smallFont() {
   return label().deriveFont(UIUtil.getFontSize(UIUtil.FontSize.SMALL));
 }
  public void paintComponent(Graphics g) {
    if (getFrame() != null) {
      setState(getFrame().getExtendedState());
    }
    JRootPane rootPane = getRootPane();
    Window window = getWindow();
    boolean leftToRight =
        (window == null)
            ? rootPane.getComponentOrientation().isLeftToRight()
            : window.getComponentOrientation().isLeftToRight();
    boolean isSelected = (window == null) ? true : window.isActive();
    int width = getWidth();
    int height = getHeight();

    Color background;
    Color foreground;
    Color darkShadow;

    if (isSelected) {
      background = UIUtil.getPanelBackground(); // myActiveBackground;
      foreground = myActiveForeground;
      darkShadow = Gray._73; // myActiveShadow;
    } else {
      background = UIUtil.getPanelBackground(); // myInactiveBackground;
      foreground = myInactiveForeground;
      darkShadow = myInactiveShadow;
    }

    g.setColor(background);
    g.fillRect(0, 0, width, height);

    // g.setColor(darkShadow);
    // g.drawLine(0, height - 1, width, height - 1);
    // g.drawLine(0, 0, 0, 0);
    // g.drawLine(width - 1, 0, width - 1, 0);

    int xOffset = leftToRight ? 5 : width - 5;

    if (getWindowDecorationStyle() == JRootPane.FRAME) {
      xOffset += leftToRight ? IMAGE_WIDTH + 5 : -IMAGE_WIDTH - 5;
    }

    String theTitle = getTitle();
    if (theTitle != null) {
      FontMetrics fm = SwingUtilities2.getFontMetrics(rootPane, g);

      g.setColor(foreground);

      int yOffset = ((height - fm.getHeight()) / 2) + fm.getAscent();

      Rectangle rect = new Rectangle(0, 0, 0, 0);
      if (myIconifyButton != null && myIconifyButton.getParent() != null) {
        rect = myIconifyButton.getBounds();
      }
      int titleW;

      if (leftToRight) {
        if (rect.x == 0) {
          rect.x = window.getWidth() - window.getInsets().right - 2;
        }
        titleW = rect.x - xOffset - 4;
        theTitle = SwingUtilities2.clipStringIfNecessary(rootPane, fm, theTitle, titleW);
      } else {
        titleW = xOffset - rect.x - rect.width - 4;
        theTitle = SwingUtilities2.clipStringIfNecessary(rootPane, fm, theTitle, titleW);
        xOffset -= SwingUtilities2.stringWidth(rootPane, fm, theTitle);
      }
      int titleLength = SwingUtilities2.stringWidth(rootPane, fm, theTitle);
      if (myIdeMenu == null) {
        SwingUtilities2.drawString(rootPane, g, theTitle, xOffset, yOffset);
        xOffset += leftToRight ? titleLength + 5 : -5;
      }
    }

    int w = width;
    int h = height;
    h--;
    g.setColor(UIManager.getColor("MenuBar.darcula.borderColor"));
    g.drawLine(0, h, w, h);
    h--;
    g.setColor(UIManager.getColor("MenuBar.darcula.borderShadowColor"));
    g.drawLine(0, h, w, h);
  }