blueprintengine.java

来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,139 行 · 第 1/3 页

JAVA
1,139
字号
        super.paintExpander(context, g, state, expanderStyle, info, x, y, w,h);    }    public void paintCheck(SynthContext context, Graphics g, int state,                           int shadowType, String info, int x, int y,                           int w, int h) {        if (!paintSimpleImage(context, g, x, y, w, h, true,                ((BlueprintStyle)context.getStyle()).                        getInfo("CHECK", info, state, shadowType, UNDEFINED,                                UNDEFINED, UNDEFINED, null))) {            super.paintCheck(context, g, state, shadowType, info, x, y, w, h);        }    }    public void paintExtension(SynthContext context, Graphics g, int state,                               int shadowType, String info, int x, int y,                               int w, int h, int placement, int tabIndex) {        if (!paintSimpleImage(context, g, x, y, w, h, true,                ((BlueprintStyle)context.getStyle()).                         getInfo("EXTENSION", info, state, shadowType,                                 UNDEFINED, placement, UNDEFINED, null))) {            super.paintExtension(context, g, state, shadowType, info, x, y,                                 w, h, placement, tabIndex);        }    }    public void paintFlatBox(SynthContext context, Graphics g, int state,                             String key, int x, int y, int w, int h) {        if (key == "checkbutton" && state == SynthConstants.MOUSE_OVER) {            return;        }        Component c = context.getComponent();        String parentType = null;        c = c.getParent();        if (c instanceof CellRendererPane) {            // Skip the CellRendererPane            c = c.getParent();        }        if (c != null && c instanceof JComponent) {            parentType = getComponentType((JComponent)c);        }        if (!paintSimpleImage(context, g, x, y, w, h, true,                ((BlueprintStyle)context.getStyle()).                         getInfo("FLAT_BOX", key, state, UNDEFINED, UNDEFINED,                                 UNDEFINED, UNDEFINED, parentType))) {            super.paintFlatBox(context, g, state, key, x, y, w, h);        }    }    void paintBackground(SynthContext context, Graphics g, int state,            Color color, int x, int y, int w, int h) {        JComponent c = context.getComponent();        if (c instanceof JPopupMenu) {            if (paintSimpleImage(context, g, x, y, w, h, true,                ((BlueprintStyle)context.getStyle()).                         getInfo("BACKGROUND", null, state, UNDEFINED,                             UNDEFINED, UNDEFINED, UNDEFINED, null))) {                return;            }        }        super.paintBackground(context, g, state, color, x, y, w, h);    }    /**     * Paints a gap image. This renders the image into a portion of     * the passed in region that is dictated     * by the <code>gapSide</code> and <code>size</code> arguments. For     * example, if <code>gapSide</code> is <code>GTKConstants.TOP</code>,     * this will render the image into the space:     * <table>     * <tr><td>x origin<td> <code>x</code> + <code>gapStart</code>     * <tr><td>y origin<td>  <code>y</code>     * <tr><td>width<td> <code>gapSize</code>     * <tr><td>height<td> <code>size</code>     * </table>     *     * @param context Context used to retrieve style information.     * @param info Blueprint style info     * @param g Graphics object to paint to     * @param x X origin     * @param y Y origin     * @param w Width to draw to     * @param h Height to draw to     * @param drawCenter Whether or not the center is drawn.     * @param gapSide Side the gap is on, one of GTKConstants.LEFT,     *        GTKConstants.RIGHT, GTKConstants.TOP or GTKConstants.BOTTOM     * @param gapStart Starting location of the gap. The axis the gap is     *        on is dictated by the gapSide     * @param gapSize size of the gap     */    private void paintGapImage(SynthContext context, BlueprintStyle.Info info,                               Graphics g, int x, int y, int w, int h,                               boolean drawCenter, int gapSide, int gapStart,                               int gapSize) {                Rectangle r1 = new Rectangle();        Rectangle r2 = new Rectangle();        Rectangle r3 = new Rectangle();        int size = 0;        int componentMask = COMPONENT_ALL;        Image startImage = info.getGapStartImage();        Image image = info.getGapImage();        Image endImage = info.getGapEndImage();        if (!drawCenter) {            componentMask |= COMPONENT_CENTER;        }        // Blueprint doesn't look at each individual image for size, just the        // starting image.        if (startImage != null) {            if (gapSide == TOP || gapSize == BOTTOM) {                size = startImage.getHeight(null);            } else {                size = startImage.getWidth(null);            }        } else {            if (gapSide == TOP || gapSize == BOTTOM) {                size = ((BlueprintStyle)context.getStyle()).getYThickness();            } else {                size = ((BlueprintStyle)context.getStyle()).getXThickness();            }        }        if (gapSize > 0) {            switch(gapSide) {            case TOP:                if (!drawCenter) {                    componentMask |= COMPONENT_NORTH_WEST | COMPONENT_NORTH |                        COMPONENT_NORTH_EAST;                }                // gap start                r1.x = x;                r1.y = y;                r1.width = gapStart;                r1.height = size;                // gap                r2.x = x + gapStart;                r2.y = y;                r2.width = gapSize;                r2.height = size;                // gap end                r3.x = x + gapStart + gapSize;                r3.y = y;                r3.width = w - (gapStart + gapSize);                r3.height = size;                break;            case BOTTOM:                if (!drawCenter) {                    componentMask |= COMPONENT_SOUTH_WEST | COMPONENT_SOUTH |                        COMPONENT_SOUTH_EAST;                }                // gap start                r1.x = x;                r1.y = y + h - size;                r1.width = gapStart;                r1.height = size;                // gap                r2.x = x + gapStart;                r2.y = y + h - size;                r2.width = gapSize;                r2.height = size;                // gap end                r3.x = x + gapStart + gapSize;                r3.y = y + h - size;                r3.width = w - (gapStart + gapSize);                r3.height = size;                break;            case LEFT:                if (!drawCenter) {                    componentMask |= COMPONENT_NORTH_WEST | COMPONENT_WEST |                        COMPONENT_SOUTH_WEST;                }                // gap start                r1.x = x;                r1.y = y;                r1.width = size;                r1.height = gapStart;                // gap                r2.x = x;                r2.y = y + gapStart;                r2.width = size;                r2.height = gapSize;                // gap end                r3.x = x;                r3.y = y + gapStart + gapSize;                r3.width = size;                r3.height = h - (gapStart + gapSize);                break;            case RIGHT:                if (!drawCenter) {                    componentMask |= COMPONENT_NORTH_EAST | COMPONENT_EAST |                        COMPONENT_SOUTH_EAST;                }                // gap start                r1.x = x + w - size;                r1.y = y;                r1.width = size;                r1.height = gapStart;                // gap                r2.x = x + w - size;                r2.y = y + gapStart;                r2.width = size;                r2.height = gapSize;                // gap end                r3.x = x + w - size;                r3.y = y + gapStart + gapSize;                r3.width = size;                r3.height = h - (gapStart + gapSize);                break;            }            themeBlueprintRender(context, g, x, y, w, h, info.getImage(),                    info.getImageInsets(), componentMask, true, false,                    info.isBkgMask(), info.isRecolorable(),                    info.getColorizeColor());            // NOTE:            // stretch should be queried from the info, but there is currently            // no support for that field for gap images in BlueprintStyle.Info.            if (startImage != null) {                themeBlueprintRender(context, g, r1.x, r1.y, r1.width, r1.height,                        startImage, info.getGapStartInsets(), COMPONENT_ALL,                        true, false, false, false, null);            }            if (image != null) {                themeBlueprintRender(context, g, r2.x, r2.y, r2.width, r2.height,                        image, info.getGapInsets(), COMPONENT_ALL,                        true, false, false, false, null);            }            if (endImage != null) {                themeBlueprintRender(context, g, r3.x, r3.y, r3.width, r3.height,                        endImage, info.getGapEndInsets(), COMPONENT_ALL,                        true, false, false, false, null);            }        }    }    /**     * Paints the image and overlay image from the passed in style.     *     * @param g Graphics object to paint to     * @param x X origin     * @param y Y origin     * @param w Width to draw to     * @param h Height to draw to     * @param drawCenter Whether the center of the image should be drawn     * @param info Used to fetch image, insets and overlay image from     */    private boolean paintSimpleImage(SynthContext context, Graphics g, int x, int y,            int w, int h, boolean drawCenter, BlueprintStyle.Info info) {        if (info != null) {            Rectangle clip = g.getClipBounds();            _clipX1 = clip.x;            _clipY1 = clip.y;            _clipX2 = _clipX1 + clip.width;            _clipY2 = _clipY1 + clip.height;            themeBlueprintRender(context, g, x, y, w, h, info.getImage(),                    info.getImageInsets(), drawCenter ? COMPONENT_ALL :                    COMPONENT_ALL | COMPONENT_CENTER, info.getStretch(),                    false, info.isBkgMask(), info.isRecolorable(),                    info.getColorizeColor());            if (drawCenter) {                themeBlueprintRender(context, g, x, y, w, h,                        info.getOverlayImage(), info.getOverlayInsets(),                        COMPONENT_ALL, info.getOverlayStretch(), true,                        false, false, null);            }            return true;        }        return false;    }    /**     * Paints the image in the specified region.     *     * @param g Graphics object to paint to     * @param x X origin     * @param y Y origin     * @param w Width to draw to     * @param h Height to draw to     * @param image Image to render     * @param insets Insets used to determine portion of image that is fixed.     * @param componentMask Mask defining the areas of the image to draw.     * @param stretch Stretch the image to fit the drawing area.     * @param center Centers the image to the middle of the drawing area.     * @param isBkgMask Whether or not the image is a background mask.     * @param isRecolorable If the image is recolorable.     * @param colorizeColor Color to use if image is recolorable.     */    private void themeBlueprintRender(SynthContext context, Graphics g,                                      int x, int y, int w, int h, Image image,                                      Insets insets, int componentMask,                                      boolean stretch, boolean center,                                      boolean isBkgMask, boolean isRecolorable,                                      Color colorizeColor) {        if (image == null) {            return;        }        if (insets == null) {            insets = GTKPainter.EMPTY_INSETS;        }        int iw = image.getWidth(null);        int ih = image.getHeight(null);         if (isBkgMask) {            // Colorize mask using the colorizeColor from info.            BufferedImage i = new BufferedImage(iw, ih,                                                BufferedImage.TYPE_INT_ARGB);            Graphics2D g3 = i.createGraphics();                         boolean topParentReached = false;            int steps = 0;             Component compParent = context.getComponent();             while (!topParentReached && steps <= 2) {                compParent = compParent.getParent ();                steps ++;                 if (compParent != null) {                    Color color = compParent.getBackground ();                    if (color != null) {                        if (!color.equals (colorizeColor) &&                             !color.equals (Color.black) &&                             !(compParent instanceof JFileChooser)) {                            colorizeColor = color;                            topParentReached = true;                        }                    }                } else {                    topParentReached = true;                }            }             if (colorizeColor == null) {                colorizeColor = ((GTKStyle)context.getStyle()).                    getGTKColor(context.getComponent(), context.getRegion(),                                context.getComponentState(),                                ColorType.BACKGROUND);            }            g3.setColor(colorizeColor);            g3.fillRect(0, 0, iw, ih);            g3.setComposite(AlphaComposite.DstIn);            g3.drawImage(image, 0, 0, null);            g3.dispose();            image = i;        } else if (isRecolorable) {            // Create a copy of the image to manipulate the pixels.            BufferedImage i = new BufferedImage(iw, ih,                    BufferedImage.TYPE_INT_ARGB);            Graphics2D g3 = i.createGraphics();            g3.setComposite(AlphaComposite.Src);            g3.drawImage(image, 0, 0, null);            g3.dispose();            int red = colorizeColor.getRed();            int green = colorizeColor.getGreen();            int blue = colorizeColor.getBlue();            int alpha = colorizeColor.getAlpha();            Color color = RGBtoHLS(red, green, blue);            int hue = color.getRed();            int lum = color.getGreen();            int sat = color.getBlue();            int[] pixels = null;            // Get the pixel data from the image.            pixels = i.getRaster().getPixels(0, 0, iw, ih, pixels);            // Colorize the pixels.            for (int index = 0; index < pixels.length; index+=4) {                red = pixels[index];                green = pixels[index + 1];                blue = pixels[index + 2];

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?