scrollbarscrollbarbuttonpainter.java

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

JAVA
364
字号
/*
 * ScrollBarScrollBarButtonPainter.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 ScrollBarScrollBarButtonPainter extends AbstractRegionPainter {
    //package private integers representing the available states that
    //this painter will paint. These are used when creating a new instance
    //of ScrollBarScrollBarButtonPainter to determine which region/state is being painted
    //by that instance.
    static final int FOREGROUND_ENABLED = 1;    static final int FOREGROUND_DISABLED = 2;    static final int FOREGROUND_MOUSEOVER = 3;    static final int FOREGROUND_PRESSED = 4;

    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 ScrollBarScrollBarButtonPainter would be created. For the moment at least,
    //however, all are created for each instance.
    private Color color1 = new Color(255, 200, 0, 255);    private Color color2 = decodeColor("nimbusBlueGrey", -0.01111114f, -0.07763158f, -0.1490196f, 0);    private Color color3 = decodeColor("nimbusBlueGrey", -0.111111104f, -0.10580933f, 0.086274505f, 0);    private Color color4 = decodeColor("nimbusBlueGrey", -0.027777791f, -0.102261856f, 0.20392156f, 0);    private Color color5 = decodeColor("nimbusBlueGrey", -0.039682567f, -0.079276316f, 0.13333333f, 0);    private Color color6 = decodeColor("nimbusBlueGrey", -0.027777791f, -0.07382907f, 0.109803915f, 0);    private Color color7 = decodeColor("nimbusBlueGrey", -0.039682567f, -0.08241387f, 0.23137254f, 0);    private Color color8 = decodeColor("nimbusBlueGrey", -0.055555522f, -0.08443936f, -0.29411766f, -136);    private Color color9 = decodeColor("nimbusBlueGrey", -0.055555522f, -0.09876161f, 0.25490195f, -178);    private Color color10 = decodeColor("nimbusBlueGrey", 0.055555582f, -0.08878718f, -0.5647059f, 0);    private Color color11 = decodeColor("nimbusBlueGrey", -0.027777791f, -0.080223285f, -0.4862745f, 0);    private Color color12 = decodeColor("nimbusBlueGrey", -0.111111104f, -0.09525914f, -0.23137254f, 0);    private Color color13 = decodeColor("nimbusBlueGrey", 0.0f, -0.110526316f, 0.25490195f, -165);    private Color color14 = decodeColor("nimbusBlueGrey", -0.04444444f, -0.080223285f, -0.09803921f, 0);    private Color color15 = decodeColor("nimbusBlueGrey", -0.6111111f, -0.110526316f, 0.10588235f, 0);    private Color color16 = decodeColor("nimbusBlueGrey", 0.0f, -0.110526316f, 0.25490195f, 0);    private Color color17 = decodeColor("nimbusBlueGrey", -0.039682567f, -0.081719734f, 0.20784312f, 0);    private Color color18 = decodeColor("nimbusBlueGrey", -0.027777791f, -0.07677104f, 0.18431371f, 0);    private Color color19 = decodeColor("nimbusBlueGrey", -0.04444444f, -0.080223285f, -0.09803921f, -69);    private Color color20 = decodeColor("nimbusBlueGrey", -0.055555522f, -0.09876161f, 0.25490195f, -39);    private Color color21 = decodeColor("nimbusBlueGrey", 0.055555582f, -0.0951417f, -0.49019608f, 0);    private Color color22 = decodeColor("nimbusBlueGrey", -0.027777791f, -0.086996906f, -0.4117647f, 0);    private Color color23 = decodeColor("nimbusBlueGrey", -0.111111104f, -0.09719298f, -0.15686274f, 0);    private Color color24 = decodeColor("nimbusBlueGrey", -0.037037015f, -0.043859646f, -0.21568626f, 0);    private Color color25 = decodeColor("nimbusBlueGrey", -0.06349206f, -0.07309316f, -0.011764705f, 0);    private Color color26 = decodeColor("nimbusBlueGrey", -0.048611104f, -0.07296763f, 0.09019607f, 0);    private Color color27 = decodeColor("nimbusBlueGrey", -0.03535354f, -0.05497076f, 0.031372547f, 0);    private Color color28 = decodeColor("nimbusBlueGrey", -0.034188032f, -0.043168806f, 0.011764705f, 0);    private Color color29 = decodeColor("nimbusBlueGrey", -0.03535354f, -0.0600676f, 0.109803915f, 0);    private Color color30 = decodeColor("nimbusBlueGrey", -0.037037015f, -0.043859646f, -0.21568626f, -44);    private Color color31 = decodeColor("nimbusBlueGrey", -0.6111111f, -0.110526316f, -0.74509805f, 0);

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

    public ScrollBarScrollBarButtonPainter(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 FOREGROUND_ENABLED: paintForegroundEnabled(g); break;            case FOREGROUND_DISABLED: paintForegroundDisabled(g); break;            case FOREGROUND_MOUSEOVER: paintForegroundMouseOver(g); break;            case FOREGROUND_PRESSED: paintForegroundPressed(g); break;
        }
    }
        


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

    private void paintForegroundEnabled(Graphics2D g) {        path = decodePath1();        g.setPaint(color1);        g.fill(path);        path = decodePath2();        g.setPaint(decodeGradient1(path));        g.fill(path);        path = decodePath3();        g.setPaint(decodeGradient2(path));        g.fill(path);        path = decodePath4();        g.setPaint(decodeGradient3(path));        g.fill(path);        path = decodePath5();        g.setPaint(color13);        g.fill(path);    }    private void paintForegroundDisabled(Graphics2D g) {        path = decodePath1();        g.setPaint(color1);        g.fill(path);    }    private void paintForegroundMouseOver(Graphics2D g) {        path = decodePath1();        g.setPaint(color1);        g.fill(path);        path = decodePath2();        g.setPaint(decodeGradient4(path));        g.fill(path);        path = decodePath3();        g.setPaint(decodeGradient5(path));        g.fill(path);        path = decodePath4();        g.setPaint(decodeGradient6(path));        g.fill(path);        path = decodePath5();        g.setPaint(color13);        g.fill(path);    }    private void paintForegroundPressed(Graphics2D g) {        path = decodePath1();        g.setPaint(color1);        g.fill(path);        path = decodePath2();        g.setPaint(decodeGradient7(path));        g.fill(path);        path = decodePath3();        g.setPaint(decodeGradient8(path));        g.fill(path);        path = decodePath4();        g.setPaint(color31);        g.fill(path);        path = decodePath5();        g.setPaint(color13);        g.fill(path);    }

    private Path2D decodePath1() {        path.reset();        path.moveTo(decodeX(3.0f), decodeY(3.0f));        path.lineTo(decodeX(3.0f), decodeY(3.0f));        path.closePath();        return path;    }    private Path2D decodePath2() {        path.reset();        path.moveTo(decodeX(0.0f), decodeY(0.0f));        path.lineTo(decodeX(1.6956522f), decodeY(0.0f));        path.curveTo(decodeAnchorX(1.6956522464752197f, 0.0f), decodeAnchorY(0.0f, 0.0f), decodeAnchorX(1.6956522464752197f, -0.7058823529411633f), decodeAnchorY(1.307692289352417f, -3.0294117647058822f), decodeX(1.6956522f), decodeY(1.3076923f));

⌨️ 快捷键说明

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