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

The following examples show how to use com.intellij.util.ui.UIUtil#isRetina() . 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: ColorChooserButton.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
private static ImageIcon makeColorIconForColor(final Color color) {
  final int size = UIUtil.isRetina() ? 8 : 16;
  final int halfSize = size / 2;

  final int offsetX = 8;
  final Image img = UIUtil.createImage(size + offsetX, size, BufferedImage.TYPE_INT_ARGB);
  final Graphics gfx = img.getGraphics();
  try {
    if (color == null) {
      gfx.setColor(IdeaUtils.isDarkTheme() ? Color.darkGray : Color.white);
      gfx.fillRect(offsetX, 0, size, size);
      gfx.setColor(IdeaUtils.isDarkTheme() ? Color.yellow : Color.black);
      gfx.drawRect(offsetX, 0, size - 1, size - 1);
      gfx.drawLine(offsetX, 0, offsetX + size - 1, size - 1);
    } else if (color == DIFF_COLORS) {
      gfx.setColor(Color.red);
      gfx.fillRect(offsetX, 0, halfSize, halfSize);
      gfx.setColor(Color.green);
      gfx.fillRect(offsetX + halfSize, 0, halfSize, halfSize);
      gfx.setColor(Color.yellow);
      gfx.fillRect(offsetX, halfSize, halfSize, halfSize);
      gfx.setColor(Color.blue);
      gfx.fillRect(offsetX + halfSize, halfSize, halfSize, halfSize);
      gfx.setColor(Color.black);
      gfx.drawRect(offsetX, 0, size - 1, size - 1);
    } else {
      gfx.setColor(color);
      gfx.fillRect(offsetX, 0, size, size);
      gfx.setColor(Color.black);
      gfx.drawRect(offsetX, 0, size - 1, size - 1);
    }
  } finally {
    gfx.dispose();
  }
  return new ImageIcon(img);
}
 
Example 2
Source File: MacIntelliJTextBorder.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) {
  if (TextFieldWithPopupHandlerUI.isSearchField(c)) {
    return;
  }

  Graphics2D g2 = (Graphics2D)g.create();
  try {
    g2.translate(x, y);

    Path2D border = new Path2D.Double(Path2D.WIND_EVEN_ODD);
    double lw = UIUtil.isRetina(g2) ? 0.5 : 1.0;
    border.append(new Rectangle2D.Double(JBUI.scale(3), JBUI.scale(3),
                                         c.getWidth() - JBUI.scale(6),
                                         c.getHeight() - JBUI.scale(6)), false);
    border.append(new Rectangle2D.Double(JBUI.scale(3) + lw, JBUI.scale(3) + lw,
                                         c.getWidth() - JBUI.scale(6) - lw * 2,
                                         c.getHeight() - JBUI.scale(6) - lw * 2), false);
    g2.setColor(Gray.xBC);
    g2.fill(border);

    if (c.getParent() instanceof JComboBox) return;

    paint(c, g2, width, height, 0);
  } finally {
    g2.dispose();
  }
}
 
Example 3
Source File: MacIntelliJTextBorder.java    From consulo with Apache License 2.0 5 votes vote down vote up
void clipForBorder(Component c, Graphics2D g2, int width, int height) {
  Area area = new Area(new Rectangle2D.Double(0, 0, width, height));
  double lw = UIUtil.isRetina(g2) ? 0.5 : 1.0;
  area.subtract(new Area(new Rectangle2D.Double(JBUI.scale(3) + lw, JBUI.scale(3) + lw,
                                                width - JBUI.scale(6) - lw * 2,
                                                height - JBUI.scale(6) - lw * 2)));
  area.intersect(new Area(g2.getClip()));
  g2.setClip(area);
}
 
Example 4
Source File: MacIntelliJTextFieldUI.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void paintAquaSearchFocusRing(Graphics2D g, Rectangle r, Component c) {
  Graphics2D g2 = (Graphics2D)g.create();
  try {
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, MacUIUtil.USE_QUARTZ ? RenderingHints.VALUE_STROKE_PURE : RenderingHints.VALUE_STROKE_NORMALIZE);
    g2.translate(r.x, r.y);

    int arc = JBUI.scale(6);
    double lw = UIUtil.isRetina(g2) ? 0.5 : 1.0;
    Shape outerShape = new RoundRectangle2D.Double(JBUI.scale(3), JBUI.scale(3),
                                                   r.width - JBUI.scale(6),
                                                   r.height - JBUI.scale(6),
                                                   arc, arc);
    g2.setColor(c.getBackground());
    g2.fill(outerShape);

    Path2D path = new Path2D.Double(Path2D.WIND_EVEN_ODD);
    path.append(outerShape, false);
    path.append(new RoundRectangle2D.Double(JBUI.scale(3) + lw, JBUI.scale(3) + lw,
                                            r.width - JBUI.scale(6) - lw*2,
                                            r.height - JBUI.scale(6) - lw*2,
                                            arc-lw, arc-lw), false);

    g2.setColor(Gray.xBC);
    g2.fill(path);

    if (c.hasFocus()) {
      DarculaUIUtilPart.paintFocusBorder(g2, r.width, r.height, arc, true);
    }
  }
  finally {
    g2.dispose();
  }
}
 
Example 5
Source File: DarculaUIUtilPart.java    From consulo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("SuspiciousNameCombination")
private static void doPaint(Graphics2D g, int width, int height, int arc, boolean symmetric) {
  double bw = UIUtil.isRetina(g) ? 0.5 : 1.0;
  double lw = JBUI.scale(UIUtil.isUnderDefaultMacTheme() ? 3 : 2);

  g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, MacUIUtil.USE_QUARTZ ? RenderingHints.VALUE_STROKE_PURE : RenderingHints.VALUE_STROKE_NORMALIZE);

  double outerArc = arc > 0 ? arc + lw - JBUI.scale(2) : lw;
  double rightOuterArc = symmetric ? outerArc : JBUI.scale(6);
  Path2D outerRect = new Path2D.Double(Path2D.WIND_EVEN_ODD);
  outerRect.moveTo(width - rightOuterArc, 0);
  outerRect.quadTo(width, 0, width, rightOuterArc);
  outerRect.lineTo(width, height - rightOuterArc);
  outerRect.quadTo(width, height, width - rightOuterArc, height);
  outerRect.lineTo(outerArc, height);
  outerRect.quadTo(0, height, 0, height - outerArc);
  outerRect.lineTo(0, outerArc);
  outerRect.quadTo(0, 0, outerArc, 0);
  outerRect.closePath();

  lw += bw;
  double rightInnerArc = symmetric ? outerArc : JBUI.scale(7);
  Path2D innerRect = new Path2D.Double(Path2D.WIND_EVEN_ODD);
  innerRect.moveTo(width - rightInnerArc, lw);
  innerRect.quadTo(width - lw, lw, width - lw, rightInnerArc);
  innerRect.lineTo(width - lw, height - rightInnerArc);
  innerRect.quadTo(width - lw, height - lw, width - rightInnerArc, height - lw);
  innerRect.lineTo(outerArc, height - lw);
  innerRect.quadTo(lw, height - lw, lw, height - outerArc);
  innerRect.lineTo(lw, outerArc);
  innerRect.quadTo(lw, lw, outerArc, lw);
  innerRect.closePath();

  Path2D path = new Path2D.Double(Path2D.WIND_EVEN_ODD);
  path.append(outerRect, false);
  path.append(innerRect, false);
  g.fill(path);
}
 
Example 6
Source File: SendFeedbackDialog.java    From freeline with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static String getDescription() {
    StringBuilder sb = new StringBuilder();
    String javaVersion = System.getProperty("java.runtime.version", System.getProperty("java.version", "unknown"));
    sb.append(javaVersion);
    String archDataModel = System.getProperty("sun.arch.data.model");
    if(archDataModel != null) {
        sb.append("x").append(archDataModel);
    }

    String javaVendor = System.getProperty("java.vm.vendor");
    if(javaVendor != null) {
        sb.append(" ").append(javaVendor);
    }

    sb.append(", ").append(System.getProperty("os.name"));
    String osArch = System.getProperty("os.arch");
    if(osArch != null) {
        sb.append("(").append(osArch).append(")");
    }

    String osVersion = System.getProperty("os.version");
    String osPatchLevel = System.getProperty("sun.os.patch.level");
    if(osVersion != null) {
        sb.append(" v").append(osVersion);
        if(osPatchLevel != null) {
            sb.append(" ").append(osPatchLevel);
        }
    }

    if(!GraphicsEnvironment.isHeadless()) {
        GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
        sb.append(" (");

        for(int i = 0; i < devices.length; ++i) {
            if(i > 0) {
                sb.append(", ");
            }

            GraphicsDevice device = devices[i];
            Rectangle bounds = device.getDefaultConfiguration().getBounds();
            sb.append(bounds.width).append("x").append(bounds.height);
        }

        if(UIUtil.isRetina()) {
            sb.append(" R");
        }

        sb.append(")");
    }

    return sb.toString();
}
 
Example 7
Source File: MacIntelliJTextFieldUI.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected void paintSearchField(Graphics2D g, JTextComponent c, Rectangle r) {
  Graphics2D g2 = (Graphics2D)g.create();
  try {
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, MacUIUtil.USE_QUARTZ ? RenderingHints.VALUE_STROKE_PURE : RenderingHints.VALUE_STROKE_NORMALIZE);
    g2.translate(r.x, r.y);

    int arc = JBUI.scale(6);
    double lw = UIUtil.isRetina(g2) ? 0.5 : 1.0;
    Shape outerShape = new RoundRectangle2D.Double(JBUI.scale(3), JBUI.scale(3),
                                                   r.width - JBUI.scale(6),
                                                   r.height - JBUI.scale(6),
                                                   arc, arc);
    g2.setColor(c.getBackground());
    g2.fill(outerShape);

    Path2D path = new Path2D.Double(Path2D.WIND_EVEN_ODD);
    path.append(outerShape, false);
    path.append(new RoundRectangle2D.Double(JBUI.scale(3) + lw, JBUI.scale(3) + lw,
                                            r.width - JBUI.scale(6) - lw*2,
                                            r.height - JBUI.scale(6) - lw*2,
                                            arc-lw, arc-lw), false);

    g2.setColor(Gray.xBC);
    g2.fill(path);

    if (c.hasFocus() && c.getClientProperty("JTextField.Search.noBorderRing") != Boolean.TRUE) {
      DarculaUIUtilPart.paintFocusBorder(g2, r.width, r.height, arc, true);
    }

    g2.translate(-r.x, -r.y);

    boolean withHistoryPopup = isSearchFieldWithHistoryPopup(c);
    Icon label = getSearchIcon(c);
    boolean isEmpty = !hasText();
    Point point = getSearchIconCoord();
    if (isEmpty && !c.hasFocus() && !withHistoryPopup) {
      label.paintIcon(c, g2, point.x, point.y);
    } else {
      Graphics ig = g2.create(0, 0, c.getWidth(), c.getHeight());

      Area area = new Area(new Rectangle2D.Double(point.x, point.y, isEmpty ? label.getIconWidth() : 16, label.getIconHeight()));
      area.intersect(new Area(ig.getClip()));
      ig.setClip(area);
      label.paintIcon(c, ig, point.x, point.y);
      ig.dispose();
    }

    if (!isEmpty) {
      Point ic = getClearIconCoord();
      MacIntelliJIconCache.getIcon("searchFieldClear").paintIcon(c, g2, ic.x, ic.y);
    }

    AbstractAction newLineAction = getNewLineAction(c);
    if (newLineAction != null) {
      Icon newLineIcon = (Icon)newLineAction.getValue(Action.SMALL_ICON);
      if (newLineIcon != null) {
        newLineIcon.paintIcon(c, g2, getAddNewLineIconCoord().x, r.y);
      }
    }
  } finally {
    g2.dispose();
  }
}