📄 metalutils.java
字号:
// otherwise it's the height. private static final int IMAGE_SIZE = 64; /** * This is the actual width we're painting in, or last painted to. */ private int w; /** * This is the actual height we're painting in, or last painted to */ private int h; GradientPainter(int count) { super(count); } public void paint(Component c, Graphics2D g, java.util.List gradient, int x, int y, int w, int h, boolean isVertical) { int imageWidth; int imageHeight; if (isVertical) { imageWidth = IMAGE_SIZE; imageHeight = h; } else { imageWidth = w; imageHeight = IMAGE_SIZE; } synchronized(c.getTreeLock()) { this.w = w; this.h = h; paint(c, g, x, y, imageWidth, imageHeight, gradient, isVertical); } } protected void paintToImage(Component c, Image image, Graphics g, int w, int h, Object[] args) { Graphics2D g2 = (Graphics2D)g; java.util.List gradient = (java.util.List)args[0]; boolean isVertical = ((Boolean)args[1]).booleanValue(); // Render to the VolatileImage if (isVertical) { drawVerticalGradient(g2, ((Number)gradient.get(0)).floatValue(), ((Number)gradient.get(1)).floatValue(), (Color)gradient.get(2), (Color)gradient.get(3), (Color)gradient.get(4), w, h); } else { drawHorizontalGradient(g2, ((Number)gradient.get(0)).floatValue(), ((Number)gradient.get(1)).floatValue(), (Color)gradient.get(2), (Color)gradient.get(3), (Color)gradient.get(4), w, h); } } protected void paintImage(Component c, Graphics g, int x, int y, int imageW, int imageH, Image image, Object[] args) { boolean isVertical = ((Boolean)args[1]).booleanValue(); // Render to the screen g.translate(x, y); if (isVertical) { for (int counter = 0; counter < w; counter += IMAGE_SIZE) { int tileSize = Math.min(IMAGE_SIZE, w - counter); g.drawImage(image, counter, 0, counter + tileSize, h, 0, 0, tileSize, h, null); } } else { for (int counter = 0; counter < h; counter += IMAGE_SIZE) { int tileSize = Math.min(IMAGE_SIZE, h - counter); g.drawImage(image, 0, counter, w, counter + tileSize, 0, 0, w, tileSize, null); } } g.translate(-x, -y); } private void drawVerticalGradient(Graphics2D g, float ratio1, float ratio2, Color c1,Color c2, Color c3, int w, int h) { int mid = (int)(ratio1 * h); int mid2 = (int)(ratio2 * h); if (mid > 0) { g.setPaint(getGradient((float)0, (float)0, c1, (float)0, (float)mid, c2)); g.fillRect(0, 0, w, mid); } if (mid2 > 0) { g.setColor(c2); g.fillRect(0, mid, w, mid2); } if (mid > 0) { g.setPaint(getGradient((float)0, (float)mid + mid2, c2, (float)0, (float)mid * 2 + mid2, c1)); g.fillRect(0, mid + mid2, w, mid); } if (h - mid * 2 - mid2 > 0) { g.setPaint(getGradient((float)0, (float)mid * 2 + mid2, c1, (float)0, (float)h, c3)); g.fillRect(0, mid * 2 + mid2, w, h - mid * 2 - mid2); } } private void drawHorizontalGradient(Graphics2D g, float ratio1, float ratio2, Color c1,Color c2, Color c3, int w, int h) { int mid = (int)(ratio1 * w); int mid2 = (int)(ratio2 * w); if (mid > 0) { g.setPaint(getGradient((float)0, (float)0, c1, (float)mid, (float)0, c2)); g.fillRect(0, 0, mid, h); } if (mid2 > 0) { g.setColor(c2); g.fillRect(mid, 0, mid2, h); } if (mid > 0) { g.setPaint(getGradient((float)mid + mid2, (float)0, c2, (float)mid * 2 + mid2, (float)0, c1)); g.fillRect(mid + mid2, 0, mid, h); } if (w - mid * 2 - mid2 > 0) { g.setPaint(getGradient((float)mid * 2 + mid2, (float)0, c1, w, (float)0, c3)); g.fillRect(mid * 2 + mid2, 0, w - mid * 2 - mid2, h); } } private GradientPaint getGradient(float x1, float y1, Color c1, float x2, float y2, Color c2) { return new GradientPaint(x1, y1, c1, x2, y2, c2, true); } } /** * Returns true if the specified widget is in a toolbar. */ static boolean isToolBarButton(JComponent c) { return (c.getParent() instanceof JToolBar); } static Icon getOceanToolBarIcon(Image i) { ImageProducer prod = new FilteredImageSource(i.getSource(), new OceanToolBarImageFilter()); return new ImageIconUIResource(Toolkit.getDefaultToolkit().createImage(prod)); } static Icon getOceanDisabledButtonIcon(Image image) { Object[] range = (Object[])UIManager.get("Button.disabledGrayRange"); int min = 180; int max = 215; if (range != null) { min = ((Integer)range[0]).intValue(); max = ((Integer)range[1]).intValue(); } ImageProducer prod = new FilteredImageSource(image.getSource(), new OceanDisabledButtonImageFilter(min , max)); return new ImageIconUIResource(Toolkit.getDefaultToolkit().createImage(prod)); } /** * Used to create a disabled Icon with the ocean look. */ private static class OceanDisabledButtonImageFilter extends RGBImageFilter{ private float min; private float factor; OceanDisabledButtonImageFilter(int min, int max) { canFilterIndexColorModel = true; this.min = (float)min; this.factor = (max - min) / 255f; } public int filterRGB(int x, int y, int rgb) { // Coefficients are from the sRGB color space: int gray = Math.min(255, (int)(((0.2125f * ((rgb >> 16) & 0xFF)) + (0.7154f * ((rgb >> 8) & 0xFF)) + (0.0721f * (rgb & 0xFF)) + .5f) * factor + min)); return (rgb & 0xff000000) | (gray << 16) | (gray << 8) | (gray << 0); } } /** * Used to create the rollover icons with the ocean look. */ private static class OceanToolBarImageFilter extends RGBImageFilter { OceanToolBarImageFilter() { canFilterIndexColorModel = true; } public int filterRGB(int x, int y, int rgb) { int r = ((rgb >> 16) & 0xff); int g = ((rgb >> 8) & 0xff); int b = (rgb & 0xff); int gray = Math.max(Math.max(r, g), b); return (rgb & 0xff000000) | (gray << 16) | (gray << 8) | (gray << 0); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -