private void establishFontMetrics() { final BufferedImage img = createBufferedImage(1, 1); final Graphics2D graphics = img.createGraphics(); graphics.setFont(myNormalFont); final float lineSpace = mySettingsProvider.getLineSpace(); final FontMetrics fo = graphics.getFontMetrics(); myDescent = fo.getDescent(); myCharSize.width = fo.charWidth('W'); myCharSize.height = fo.getHeight() + (int) (lineSpace * 2); myDescent += lineSpace; myMonospaced = isMonospaced(fo); if (!myMonospaced) { LOG.info("WARNING: Font " + myNormalFont.getName() + " is non-monospaced"); } img.flush(); graphics.dispose(); }
@Override public void paintIcon(Component c, Graphics g, int x, int y) { Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.translate(x, y); g2.setStroke(new BasicStroke(BORDER_WIDTH)); g2.setPaint(LINE_COLOR); g2.draw(BORDER); g2.setStroke(new BasicStroke(SLIT_WIDTH)); g2.setColor(UIManager.getColor("Panel.background")); int n = SLIT_NUM + 1; int v = ICON_SIZE / n; int m = n * v; for (int i = 1; i < n; i++) { int a = i * v; g2.drawLine(a, 0, a, m); g2.drawLine(0, a, m, a); } // g2.drawLine(1 * v, 0 * v, 1 * v, 4 * v); // g2.drawLine(2 * v, 0 * v, 2 * v, 4 * v); // g2.drawLine(3 * v, 0 * v, 3 * v, 4 * v); // g2.drawLine(0 * v, 1 * v, 4 * v, 1 * v); // g2.drawLine(0 * v, 2 * v, 4 * v, 2 * v); // g2.drawLine(0 * v, 3 * v, 4 * v, 3 * v); g2.setPaint(LINE_COLOR); Rectangle2D b = ARROW.getBounds(); Point2D p = new Point2D.Double(b.getX() + b.getWidth() / 2d, b.getY() + b.getHeight() / 2d); AffineTransform toCenterAT = AffineTransform.getTranslateInstance(ICON_SIZE / 2d - p.getX(), ICON_SIZE / 2d - p.getY()); g2.fill(toCenterAT.createTransformedShape(ARROW)); g2.dispose(); }