@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;
    }
  }
示例#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)));
  }
示例#4
0
 private static boolean isTableDecorationSupported() {
   return UIUtil.isUnderAlloyLookAndFeel()
       || UIUtil.isUnderNativeMacLookAndFeel()
       || UIUtil.isUnderQuaquaLookAndFeel()
       || UIUtil.isUnderMetalLookAndFeel()
       || UIUtil.isUnderNimbusLookAndFeel()
       || UIUtil.isUnderWindowsLookAndFeel();
 }
示例#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());
    }
  }
 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;
  }
 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);
         }
       });
 }
示例#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();
  }
示例#11
0
 protected boolean isRetina() {
   return UIUtil.isRetina();
 }
  @PostConstruct
  protected void init() {
    // Button listeners:
    jb_add.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            add();
          }
        });
    jb_addAndClose.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            addAndClose();
          }
        });
    jb_cancel.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            cancel();
          }
        });

    jb_file.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            selectFile();
          }
        });

    // Default button:
    getRootPane().setDefaultButton(jb_add);

    // Layout:
    Container c = getContentPane();
    c.setLayout(new BorderLayout());

    { // Center
      JPanel jp = new JPanel(new BorderLayout());

      JPanel jp_west = new JPanel(new GridLayout(3, 2));
      jp_west.add(new JLabel(" Content type: "));
      jp_west.add(new JLabel(" File name: "));
      jp_west.add(new JLabel(" File: "));
      jp.add(jp_west, BorderLayout.WEST);

      JPanel jp_center = new JPanel(new GridLayout(3, 2));
      jp_center.add(jp_contentType.getComponent());
      jp_center.add(UIUtil.getFlowLayoutPanelLeftAligned(jtf_fileName));
      JPanel jp_file = new JPanel(new FlowLayout(FlowLayout.LEFT));
      jp_file.add(jtf_file);
      jp_file.add(jb_file);
      jp_center.add(jp_file);
      jp.add(jp_center, BorderLayout.CENTER);

      c.add(jp, BorderLayout.CENTER);
    }

    { // South
      JPanel jp = new JPanel();
      jp.setLayout(new FlowLayout(FlowLayout.RIGHT));
      jp.add(jb_cancel);
      jp.add(jb_add);
      jp.add(jb_addAndClose);
      c.add(jp, BorderLayout.SOUTH);
    }

    pack();
  }
/** @author subwiz */
public class AddMultipartFileDialog extends AddMultipartBaseDialog {

  @Inject private ContentTypeCharsetComponent jp_contentType;

  private JTextField jtf_fileName = new JTextField(ContentTypeCharsetComponent.TEXT_FIELD_LENGTH);
  private JTextField jtf_file = new JTextField(ContentTypeCharsetComponent.TEXT_FIELD_LENGTH);

  private JButton jb_file =
      new JButton(UIUtil.getIconFromClasspath(RCFileView.iconBasePath + "load_from_file.png"));

  private JButton jb_add = new JButton("Add");
  private JButton jb_addAndClose = new JButton("Add & close");
  private JButton jb_cancel = new JButton("Cancel");

  @Inject
  public AddMultipartFileDialog(RESTUserInterface rest_ui) {
    super(rest_ui);

    setTitle("Add Multipart File");
  }

  @PostConstruct
  protected void init() {
    // Button listeners:
    jb_add.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            add();
          }
        });
    jb_addAndClose.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            addAndClose();
          }
        });
    jb_cancel.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            cancel();
          }
        });

    jb_file.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            selectFile();
          }
        });

    // Default button:
    getRootPane().setDefaultButton(jb_add);

    // Layout:
    Container c = getContentPane();
    c.setLayout(new BorderLayout());

    { // Center
      JPanel jp = new JPanel(new BorderLayout());

      JPanel jp_west = new JPanel(new GridLayout(3, 2));
      jp_west.add(new JLabel(" Content type: "));
      jp_west.add(new JLabel(" File name: "));
      jp_west.add(new JLabel(" File: "));
      jp.add(jp_west, BorderLayout.WEST);

      JPanel jp_center = new JPanel(new GridLayout(3, 2));
      jp_center.add(jp_contentType.getComponent());
      jp_center.add(UIUtil.getFlowLayoutPanelLeftAligned(jtf_fileName));
      JPanel jp_file = new JPanel(new FlowLayout(FlowLayout.LEFT));
      jp_file.add(jtf_file);
      jp_file.add(jb_file);
      jp_center.add(jp_file);
      jp.add(jp_center, BorderLayout.CENTER);

      c.add(jp, BorderLayout.CENTER);
    }

    { // South
      JPanel jp = new JPanel();
      jp.setLayout(new FlowLayout(FlowLayout.RIGHT));
      jp.add(jb_cancel);
      jp.add(jb_add);
      jp.add(jb_addAndClose);
      c.add(jp, BorderLayout.SOUTH);
    }

    pack();
  }

  private void selectFile() {
    File f = rest_ui.getOpenFile(FileChooserType.OPEN_REQUEST_BODY);
    if (f == null) { // Pressed cancel?
      return;
    }
    if (!f.canRead()) {
      JOptionPane.showMessageDialog(
          rest_ui.getFrame(),
          "File not readable: " + f.getAbsolutePath(),
          "IO Error",
          JOptionPane.ERROR_MESSAGE);
      return;
    }

    // Content type charset correction:
    ContentTypeSelectorOnFile.select(jp_contentType, f, this);

    // Set name:
    if (StringUtil.isEmpty(jtf_fileName.getText())) {
      jtf_fileName.setText(f.getName());
    }

    // Set file:
    jtf_file.setText(f.getAbsolutePath());
  }

  private boolean add() {
    // Validation:
    if (StringUtil.isEmpty(jtf_fileName.getText())) {
      JOptionPane.showMessageDialog(
          this, "Name must be present!", "Validation: name empty!", JOptionPane.ERROR_MESSAGE);
      jtf_fileName.requestFocus();
      return false;
    }

    // Read values:
    final String fileName = jtf_fileName.getText();
    final ContentType ct = jp_contentType.getContentType();
    final File file = new File(jtf_file.getText());
    final ReqEntityFilePart part = new ReqEntityFilePartBean(fileName, ct, file);

    // Trigger all listeners:
    for (AddMultipartPartListener l : listeners) {
      l.addPart(part);
    }

    // Clear:
    clear();

    // Focus:
    jb_file.requestFocus();

    return true;
  }

  private void addAndClose() {
    if (add()) {
      setVisible(false);
    }
  }

  private void cancel() {
    clear();
    setVisible(false);
  }

  @Override
  public void clear() {
    jp_contentType.clear();
    jtf_fileName.setText("");
    jtf_file.setText("");
  }

  @Override
  public void setVisible(boolean boo) {
    jp_contentType.requestFocus();
    super.setVisible(boo);
  }
}
示例#14
0
 public static JBFont miniFont() {
   return label().deriveFont(UIUtil.getFontSize(UIUtil.FontSize.MINI));
 }
示例#15
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);
  }