optionpanepainter.java
来自「Mobile 应用程序使用 Java Micro Edition (Java M」· Java 代码 · 共 567 行 · 第 1/3 页
JAVA
567 行
/*
* OptionPanePainter.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 OptionPanePainter extends AbstractRegionPainter {
//package private integers representing the available states that
//this painter will paint. These are used when creating a new instance
//of OptionPanePainter to determine which region/state is being painted
//by that instance.
static final int BACKGROUND_ENABLED = 1; static final int ERRORICON_ENABLED = 2; static final int INFORMATIONICON_ENABLED = 3; static final int QUESTIONICON_ENABLED = 4; static final int WARNINGICON_ENABLED = 5;
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 OptionPanePainter would be created. For the moment at least,
//however, all are created for each instance.
private Color color1 = decodeColor("nimbusRed", -0.014814814f, 0.18384242f, 0.015686274f, 0); private Color color2 = decodeColor("nimbusRed", -0.014814814f, -0.403261f, 0.21960783f, 0); private Color color3 = decodeColor("nimbusRed", -0.014814814f, -0.07154381f, 0.11372548f, 0); private Color color4 = decodeColor("nimbusRed", -0.014814814f, 0.110274374f, 0.07058823f, 0); private Color color5 = decodeColor("nimbusRed", -0.014814814f, -0.05413574f, 0.2588235f, 0); private Color color6 = new Color(250, 250, 250, 255); private Color color7 = decodeColor("nimbusRed", 0.0f, -0.79881656f, 0.33725488f, -187); private Color color8 = new Color(255, 200, 0, 255); private Color color9 = decodeColor("nimbusInfoBlue", 0.0f, 0.06231594f, -0.054901958f, 0); private Color color10 = decodeColor("nimbusInfoBlue", 3.1620264E-4f, 0.07790506f, -0.19215685f, 0); private Color color11 = decodeColor("nimbusInfoBlue", -8.2296133E-4f, -0.44631243f, 0.19215685f, 0); private Color color12 = decodeColor("nimbusInfoBlue", 0.0012729168f, -0.0739674f, 0.043137252f, 0); private Color color13 = decodeColor("nimbusInfoBlue", 8.354187E-4f, -0.14148629f, 0.19999999f, 0); private Color color14 = decodeColor("nimbusInfoBlue", -0.0014793873f, -0.41456455f, 0.16470587f, 0); private Color color15 = decodeColor("nimbusInfoBlue", 3.437996E-4f, -0.14726585f, 0.043137252f, 0); private Color color16 = decodeColor("nimbusInfoBlue", -4.271865E-4f, -0.0055555105f, 0.0f, 0); private Color color17 = decodeColor("nimbusInfoBlue", 0.0f, 0.0f, 0.0f, 0); private Color color18 = decodeColor("nimbusInfoBlue", -7.866621E-4f, -0.12728173f, 0.17254901f, 0); private Color color19 = new Color(115, 120, 126, 255); private Color color20 = new Color(26, 34, 43, 255); private Color color21 = new Color(168, 173, 178, 255); private Color color22 = new Color(101, 109, 118, 255); private Color color23 = new Color(159, 163, 168, 255); private Color color24 = new Color(116, 122, 130, 255); private Color color25 = new Color(96, 104, 112, 255); private Color color26 = new Color(118, 128, 138, 255); private Color color27 = new Color(255, 255, 255, 255); private Color color28 = decodeColor("nimbusAlertYellow", -4.9102306E-4f, 0.1372549f, -0.15294117f, 0); private Color color29 = decodeColor("nimbusAlertYellow", -0.0015973002f, 0.1372549f, -0.3490196f, 0); private Color color30 = decodeColor("nimbusAlertYellow", 6.530881E-4f, -0.40784314f, 0.0f, 0); private Color color31 = decodeColor("nimbusAlertYellow", -3.9456785E-4f, -0.109803915f, 0.0f, 0); private Color color32 = decodeColor("nimbusAlertYellow", 0.0f, 0.0f, 0.0f, 0); private Color color33 = decodeColor("nimbusAlertYellow", 0.008085668f, -0.04705882f, 0.0f, 0); private Color color34 = decodeColor("nimbusAlertYellow", 0.026515156f, -0.18431371f, 0.0f, 0); private Color color35 = new Color(69, 69, 69, 255); private Color color36 = new Color(0, 0, 0, 255); private Color color37 = new Color(16, 16, 16, 255);
//Array of current component colors, updated in each paint call
private Object[] componentColors;
public OptionPanePainter(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 ERRORICON_ENABLED: painterrorIconEnabled(g); break; case INFORMATIONICON_ENABLED: paintinformationIconEnabled(g); break; case QUESTIONICON_ENABLED: paintquestionIconEnabled(g); break; case WARNINGICON_ENABLED: paintwarningIconEnabled(g); break;
}
}
@Override
protected final PaintContext getPaintContext() {
return ctx;
}
private void painterrorIconEnabled(Graphics2D g) { path = decodePath1(); g.setPaint(color1); g.fill(path); path = decodePath2(); g.setPaint(decodeGradient1(path)); g.fill(path); path = decodePath3(); g.setPaint(color6); g.fill(path); ellipse = decodeEllipse1(); g.setPaint(color6); g.fill(ellipse); path = decodePath4(); g.setPaint(color7); g.fill(path); } private void paintinformationIconEnabled(Graphics2D g) { ellipse = decodeEllipse2(); g.setPaint(color8); g.fill(ellipse); ellipse = decodeEllipse2(); g.setPaint(color8); g.fill(ellipse); ellipse = decodeEllipse2(); g.setPaint(color8); g.fill(ellipse); ellipse = decodeEllipse3(); g.setPaint(decodeGradient2(ellipse)); g.fill(ellipse); ellipse = decodeEllipse4(); g.setPaint(decodeGradient3(ellipse)); g.fill(ellipse); ellipse = decodeEllipse5(); g.setPaint(decodeGradient4(ellipse)); g.fill(ellipse); path = decodePath5(); g.setPaint(color6); g.fill(path); ellipse = decodeEllipse6(); g.setPaint(color6); g.fill(ellipse); } private void paintquestionIconEnabled(Graphics2D g) { ellipse = decodeEllipse3(); g.setPaint(decodeGradient5(ellipse)); g.fill(ellipse); ellipse = decodeEllipse4(); g.setPaint(decodeGradient6(ellipse)); g.fill(ellipse); ellipse = decodeEllipse5(); g.setPaint(decodeGradient7(ellipse)); g.fill(ellipse); path = decodePath6(); g.setPaint(color27); g.fill(path); ellipse = decodeEllipse1(); g.setPaint(color27); g.fill(ellipse); } private void paintwarningIconEnabled(Graphics2D g) { rect = decodeRect1(); g.setPaint(color8); g.fill(rect); path = decodePath7(); g.setPaint(decodeGradient8(path)); g.fill(path); path = decodePath8(); g.setPaint(decodeGradient9(path)); g.fill(path); path = decodePath9(); g.setPaint(decodeGradient10(path)); g.fill(path);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?