internalframeinternalframetitlepaneinternalframetitlepaneclosebuttonpainter.java

来自「Mobile 应用程序使用 Java Micro Edition (Java M」· Java 代码 · 共 447 行 · 第 1/2 页

JAVA
447
字号
/*
 * InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneCloseButtonPainter.java %E%
 *
 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.sun.java.swing.plaf.nimbus;

import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import javax.swing.*;
import com.sun.java.swing.Painter;

/**
 */
public final class InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneCloseButtonPainter extends AbstractRegionPainter {
    //package private integers representing the available states that
    //this painter will paint. These are used when creating a new instance
    //of InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneCloseButtonPainter to determine which region/state is being painted
    //by that instance.
    static final int BACKGROUND_DISABLED = 1;    static final int BACKGROUND_ENABLED = 2;    static final int BACKGROUND_MOUSEOVER = 3;    static final int BACKGROUND_PRESSED = 4;    static final int BACKGROUND_ENABLED_WINDOWNOTFOCUSED = 5;    static final int BACKGROUND_MOUSEOVER_WINDOWNOTFOCUSED = 6;    static final int BACKGROUND_PRESSED_WINDOWNOTFOCUSED = 7;

    private int state; //refers to one of the static final ints above
    private PaintContext ctx;

    //the following 4 variables are reused during the painting code of the layers
    private Path2D path = new Path2D.Float();
    private Rectangle2D rect = new Rectangle2D.Float(0, 0, 0, 0);
    private RoundRectangle2D roundRect = new RoundRectangle2D.Float(0, 0, 0, 0, 0, 0);
    private Ellipse2D ellipse = new Ellipse2D.Float(0, 0, 0, 0);

    //All Colors used for painting are stored here. Ideally, only those colors being used
    //by a particular instance of InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneCloseButtonPainter would be created. For the moment at least,
    //however, all are created for each instance.
    private Color color1 = decodeColor("nimbusRed", 0.5893519f, -0.75736576f, 0.09411764f, 0);    private Color color2 = decodeColor("nimbusRed", 0.5962963f, -0.71005917f, 0.0f, 0);    private Color color3 = decodeColor("nimbusRed", 0.6005698f, -0.7200287f, -0.015686274f, -122);    private Color color4 = decodeColor("nimbusBlueGrey", 0.0055555105f, -0.062449392f, 0.07058823f, 0);    private Color color5 = decodeColor("nimbusBlueGrey", 0.0055555105f, -0.0029994324f, -0.38039216f, -185);    private Color color6 = decodeColor("nimbusRed", -0.014814814f, 0.20118344f, -0.4431373f, 0);    private Color color7 = decodeColor("nimbusRed", -2.7342606E-4f, 0.13829035f, -0.039215684f, 0);    private Color color8 = decodeColor("nimbusRed", 6.890595E-4f, -0.36665577f, 0.11764705f, 0);    private Color color9 = decodeColor("nimbusRed", -0.001021713f, 0.101804554f, -0.031372547f, 0);    private Color color10 = decodeColor("nimbusRed", -2.7342606E-4f, 0.13243341f, -0.035294116f, 0);    private Color color11 = decodeColor("nimbusRed", -2.7342606E-4f, 0.002258718f, 0.06666666f, 0);    private Color color12 = decodeColor("nimbusRed", 0.0056530247f, 0.0040003657f, -0.38431373f, -122);    private Color color13 = decodeColor("nimbusBlueGrey", 0.0f, -0.110526316f, 0.25490195f, 0);    private Color color14 = decodeColor("nimbusRed", -0.014814814f, 0.20118344f, -0.3882353f, 0);    private Color color15 = decodeColor("nimbusRed", -0.014814814f, 0.20118344f, -0.13333333f, 0);    private Color color16 = decodeColor("nimbusRed", 6.890595E-4f, -0.38929275f, 0.1607843f, 0);    private Color color17 = decodeColor("nimbusRed", 2.537202E-5f, 0.012294531f, 0.043137252f, 0);    private Color color18 = decodeColor("nimbusRed", -2.7342606E-4f, 0.033585668f, 0.039215684f, 0);    private Color color19 = decodeColor("nimbusRed", -2.7342606E-4f, -0.07198727f, 0.14117646f, 0);    private Color color20 = decodeColor("nimbusRed", -0.014814814f, 0.20118344f, 0.0039215684f, -122);    private Color color21 = decodeColor("nimbusBlueGrey", 0.0f, -0.110526316f, 0.25490195f, -140);    private Color color22 = decodeColor("nimbusRed", -0.014814814f, 0.20118344f, -0.49411768f, 0);    private Color color23 = decodeColor("nimbusRed", -0.014814814f, 0.20118344f, -0.20392159f, 0);    private Color color24 = decodeColor("nimbusRed", -0.014814814f, -0.21260965f, 0.019607842f, 0);    private Color color25 = decodeColor("nimbusRed", -0.014814814f, 0.17340565f, -0.09803921f, 0);    private Color color26 = decodeColor("nimbusRed", -0.014814814f, 0.20118344f, -0.10588235f, 0);    private Color color27 = decodeColor("nimbusRed", -0.014814814f, 0.20118344f, -0.04705882f, 0);    private Color color28 = decodeColor("nimbusRed", -0.014814814f, 0.20118344f, -0.31764707f, -122);    private Color color29 = decodeColor("nimbusRed", 0.5962963f, -0.6994788f, -0.07058823f, 0);    private Color color30 = decodeColor("nimbusRed", 0.5962963f, -0.66245294f, -0.23137257f, 0);    private Color color31 = decodeColor("nimbusRed", 0.58518517f, -0.77649516f, 0.21568626f, 0);    private Color color32 = decodeColor("nimbusRed", 0.5962963f, -0.7372781f, 0.10196078f, 0);    private Color color33 = decodeColor("nimbusRed", 0.5962963f, -0.73911506f, 0.12549019f, 0);    private Color color34 = decodeColor("nimbusBlueGrey", 0.0f, -0.027957506f, -0.31764707f, 0);

    //Array of current component colors, updated in each paint call
    private Object[] componentColors;

    public InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneCloseButtonPainter(PaintContext ctx, int state) {
        super();
        this.state = state;
        this.ctx = ctx;
    }

    @Override
    protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object[] extendedCacheKeys) {
        //populate componentColors array with colors calculated in getExtendedCacheKeys call
        componentColors = extendedCacheKeys;
        //generate this entire method. Each state/bg/fg/border combo that has
        //been painted gets its own KEY and paint method.
        switch(state) {
            case BACKGROUND_DISABLED: paintBackgroundDisabled(g); break;            case BACKGROUND_ENABLED: paintBackgroundEnabled(g); break;            case BACKGROUND_MOUSEOVER: paintBackgroundMouseOver(g); break;            case BACKGROUND_PRESSED: paintBackgroundPressed(g); break;            case BACKGROUND_ENABLED_WINDOWNOTFOCUSED: paintBackgroundEnabledAndWindowNotFocused(g); break;            case BACKGROUND_MOUSEOVER_WINDOWNOTFOCUSED: paintBackgroundMouseOverAndWindowNotFocused(g); break;            case BACKGROUND_PRESSED_WINDOWNOTFOCUSED: paintBackgroundPressedAndWindowNotFocused(g); break;
        }
    }
        


    @Override
    protected final PaintContext getPaintContext() {
        return ctx;
    }

    private void paintBackgroundDisabled(Graphics2D g) {        roundRect = decodeRoundRect1();        g.setPaint(decodeGradient1(roundRect));        g.fill(roundRect);        path = decodePath1();        g.setPaint(color3);        g.fill(path);        path = decodePath2();        g.setPaint(color4);        g.fill(path);    }    private void paintBackgroundEnabled(Graphics2D g) {        roundRect = decodeRoundRect2();        g.setPaint(color5);        g.fill(roundRect);        roundRect = decodeRoundRect1();        g.setPaint(decodeGradient2(roundRect));        g.fill(roundRect);        roundRect = decodeRoundRect3();        g.setPaint(decodeGradient3(roundRect));        g.fill(roundRect);        path = decodePath1();        g.setPaint(color12);        g.fill(path);        path = decodePath2();        g.setPaint(color13);        g.fill(path);    }    private void paintBackgroundMouseOver(Graphics2D g) {        roundRect = decodeRoundRect2();        g.setPaint(color5);        g.fill(roundRect);        roundRect = decodeRoundRect1();        g.setPaint(decodeGradient4(roundRect));        g.fill(roundRect);        roundRect = decodeRoundRect4();        g.setPaint(decodeGradient5(roundRect));        g.fill(roundRect);        path = decodePath1();        g.setPaint(color20);        g.fill(path);        path = decodePath2();        g.setPaint(color13);        g.fill(path);    }    private void paintBackgroundPressed(Graphics2D g) {        roundRect = decodeRoundRect2();        g.setPaint(color21);        g.fill(roundRect);        roundRect = decodeRoundRect1();        g.setPaint(decodeGradient6(roundRect));        g.fill(roundRect);        roundRect = decodeRoundRect3();        g.setPaint(decodeGradient7(roundRect));        g.fill(roundRect);        path = decodePath1();        g.setPaint(color28);        g.fill(path);        path = decodePath2();        g.setPaint(color13);        g.fill(path);    }    private void paintBackgroundEnabledAndWindowNotFocused(Graphics2D g) {        roundRect = decodeRoundRect1();        g.setPaint(decodeGradient8(roundRect));        g.fill(roundRect);        roundRect = decodeRoundRect3();        g.setPaint(decodeGradient9(roundRect));        g.fill(roundRect);        path = decodePath2();        g.setPaint(color34);        g.fill(path);    }    private void paintBackgroundMouseOverAndWindowNotFocused(Graphics2D g) {        roundRect = decodeRoundRect2();        g.setPaint(color5);        g.fill(roundRect);        roundRect = decodeRoundRect1();        g.setPaint(decodeGradient4(roundRect));        g.fill(roundRect);        roundRect = decodeRoundRect4();        g.setPaint(decodeGradient5(roundRect));        g.fill(roundRect);        path = decodePath1();        g.setPaint(color20);        g.fill(path);        path = decodePath2();        g.setPaint(color13);        g.fill(path);    }    private void paintBackgroundPressedAndWindowNotFocused(Graphics2D g) {        roundRect = decodeRoundRect2();        g.setPaint(color21);        g.fill(roundRect);        roundRect = decodeRoundRect1();        g.setPaint(decodeGradient6(roundRect));        g.fill(roundRect);        roundRect = decodeRoundRect3();        g.setPaint(decodeGradient7(roundRect));        g.fill(roundRect);

⌨️ 快捷键说明

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