toolbartogglebuttonpainter.java
来自「Mobile 应用程序使用 Java Micro Edition (Java M」· Java 代码 · 共 519 行 · 第 1/2 页
JAVA
519 行
/*
* ToolBarToggleButtonPainter.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 ToolBarToggleButtonPainter extends AbstractRegionPainter {
//package private integers representing the available states that
//this painter will paint. These are used when creating a new instance
//of ToolBarToggleButtonPainter to determine which region/state is being painted
//by that instance.
static final int BACKGROUND_ENABLED = 1; static final int BACKGROUND_FOCUSED = 2; static final int BACKGROUND_MOUSEOVER = 3; static final int BACKGROUND_MOUSEOVER_FOCUSED = 4; static final int BACKGROUND_PRESSED = 5; static final int BACKGROUND_PRESSED_FOCUSED = 6; static final int BACKGROUND_SELECTED = 7; static final int BACKGROUND_SELECTED_FOCUSED = 8; static final int BACKGROUND_PRESSED_SELECTED = 9; static final int BACKGROUND_PRESSED_SELECTED_FOCUSED = 10; static final int BACKGROUND_MOUSEOVER_SELECTED = 11; static final int BACKGROUND_MOUSEOVER_SELECTED_FOCUSED = 12; static final int BACKGROUND_DISABLED_SELECTED = 13;
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 ToolBarToggleButtonPainter would be created. For the moment at least,
//however, all are created for each instance.
private Color color1 = decodeColor("nimbusFocus", 0.0f, 0.0f, 0.0f, 0); private Color color2 = decodeColor("nimbusBlueGrey", -0.027777791f, -0.06885965f, -0.36862746f, -153); private Color color3 = decodeColor("nimbusBlueGrey", 0.0f, -0.020974077f, -0.21960783f, 0); private Color color4 = decodeColor("nimbusBlueGrey", 0.0f, 0.11169591f, -0.53333336f, 0); private Color color5 = decodeColor("nimbusBlueGrey", 0.055555582f, -0.10658931f, 0.25098038f, 0); private Color color6 = decodeColor("nimbusBlueGrey", 0.0f, -0.098526314f, 0.2352941f, 0); private Color color7 = decodeColor("nimbusBlueGrey", 0.0f, -0.07333623f, 0.20392156f, 0); private Color color8 = decodeColor("nimbusBlueGrey", 0.0f, -0.110526316f, 0.25490195f, 0); private Color color9 = decodeColor("nimbusBlueGrey", 0.0f, -0.110526316f, 0.25490195f, -86); private Color color10 = decodeColor("nimbusBlueGrey", -0.01111114f, -0.060526315f, -0.3529412f, 0); private Color color11 = decodeColor("nimbusBlueGrey", 0.0f, -0.064372465f, -0.2352941f, 0); private Color color12 = decodeColor("nimbusBlueGrey", -0.006944418f, -0.0595709f, -0.12941176f, 0); private Color color13 = decodeColor("nimbusBlueGrey", 0.0f, -0.061075766f, -0.031372547f, 0); private Color color14 = decodeColor("nimbusBlueGrey", 0.0f, -0.06080256f, -0.035294116f, 0); private Color color15 = decodeColor("nimbusBlueGrey", 0.0f, -0.06472479f, -0.23137254f, 0); private Color color16 = decodeColor("nimbusBlueGrey", 0.007936537f, -0.06959064f, -0.0745098f, 0); private Color color17 = decodeColor("nimbusBlueGrey", 0.0138888955f, -0.06401469f, -0.07058823f, 0); private Color color18 = decodeColor("nimbusBlueGrey", 0.0f, -0.06530018f, 0.035294116f, 0); private Color color19 = decodeColor("nimbusBlueGrey", 0.0f, -0.06507177f, 0.031372547f, 0); private Color color20 = decodeColor("nimbusBlueGrey", -0.027777791f, -0.05338346f, -0.47058824f, 0); private Color color21 = decodeColor("nimbusBlueGrey", 0.0f, -0.049301825f, -0.36078432f, 0); private Color color22 = decodeColor("nimbusBlueGrey", -0.018518567f, -0.03909774f, -0.2509804f, 0); private Color color23 = decodeColor("nimbusBlueGrey", -0.00505054f, -0.040013492f, -0.13333333f, 0); private Color color24 = decodeColor("nimbusBlueGrey", 0.01010108f, -0.039558575f, -0.1372549f, 0); private Color color25 = decodeColor("nimbusBlueGrey", 0.0f, -0.110526316f, 0.25490195f, -220); private Color color26 = decodeColor("nimbusBlueGrey", 0.0f, -0.066408664f, 0.054901958f, 0); private Color color27 = decodeColor("nimbusBlueGrey", 0.0f, -0.06807348f, 0.086274505f, 0); private Color color28 = decodeColor("nimbusBlueGrey", 0.0f, -0.06924191f, 0.109803915f, 0);
//Array of current component colors, updated in each paint call
private Object[] componentColors;
public ToolBarToggleButtonPainter(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_FOCUSED: paintBackgroundFocused(g); break; case BACKGROUND_MOUSEOVER: paintBackgroundMouseOver(g); break; case BACKGROUND_MOUSEOVER_FOCUSED: paintBackgroundMouseOverAndFocused(g); break; case BACKGROUND_PRESSED: paintBackgroundPressed(g); break; case BACKGROUND_PRESSED_FOCUSED: paintBackgroundPressedAndFocused(g); break; case BACKGROUND_SELECTED: paintBackgroundSelected(g); break; case BACKGROUND_SELECTED_FOCUSED: paintBackgroundSelectedAndFocused(g); break; case BACKGROUND_PRESSED_SELECTED: paintBackgroundPressedAndSelected(g); break; case BACKGROUND_PRESSED_SELECTED_FOCUSED: paintBackgroundPressedAndSelectedAndFocused(g); break; case BACKGROUND_MOUSEOVER_SELECTED: paintBackgroundMouseOverAndSelected(g); break; case BACKGROUND_MOUSEOVER_SELECTED_FOCUSED: paintBackgroundMouseOverAndSelectedAndFocused(g); break; case BACKGROUND_DISABLED_SELECTED: paintBackgroundDisabledAndSelected(g); break;
}
}
@Override
protected final PaintContext getPaintContext() {
return ctx;
}
private void paintBackgroundFocused(Graphics2D g) { path = decodePath1(); g.setPaint(color1); g.fill(path); } private void paintBackgroundMouseOver(Graphics2D g) { roundRect = decodeRoundRect1(); g.setPaint(color2); g.fill(roundRect); roundRect = decodeRoundRect2(); g.setPaint(decodeGradient1(roundRect)); g.fill(roundRect); roundRect = decodeRoundRect3(); g.setPaint(decodeGradient2(roundRect)); g.fill(roundRect); } private void paintBackgroundMouseOverAndFocused(Graphics2D g) { roundRect = decodeRoundRect4(); g.setPaint(color1); g.fill(roundRect); roundRect = decodeRoundRect2(); g.setPaint(decodeGradient1(roundRect)); g.fill(roundRect); roundRect = decodeRoundRect3(); g.setPaint(decodeGradient2(roundRect)); g.fill(roundRect); } private void paintBackgroundPressed(Graphics2D g) { roundRect = decodeRoundRect5(); g.setPaint(color9); g.fill(roundRect); roundRect = decodeRoundRect6(); g.setPaint(decodeGradient3(roundRect)); g.fill(roundRect); roundRect = decodeRoundRect7(); g.setPaint(decodeGradient4(roundRect)); g.fill(roundRect); } private void paintBackgroundPressedAndFocused(Graphics2D g) { roundRect = decodeRoundRect8(); g.setPaint(color1); g.fill(roundRect); roundRect = decodeRoundRect6(); g.setPaint(decodeGradient3(roundRect)); g.fill(roundRect); roundRect = decodeRoundRect7(); g.setPaint(decodeGradient4(roundRect)); g.fill(roundRect); } private void paintBackgroundSelected(Graphics2D g) { roundRect = decodeRoundRect5(); g.setPaint(color9); g.fill(roundRect); roundRect = decodeRoundRect6(); g.setPaint(decodeGradient5(roundRect)); g.fill(roundRect); roundRect = decodeRoundRect7(); g.setPaint(decodeGradient6(roundRect)); g.fill(roundRect); } private void paintBackgroundSelectedAndFocused(Graphics2D g) { roundRect = decodeRoundRect8(); g.setPaint(color1); g.fill(roundRect); roundRect = decodeRoundRect6(); g.setPaint(decodeGradient5(roundRect)); g.fill(roundRect); roundRect = decodeRoundRect7(); g.setPaint(decodeGradient6(roundRect)); g.fill(roundRect); } private void paintBackgroundPressedAndSelected(Graphics2D g) { roundRect = decodeRoundRect5(); g.setPaint(color9); g.fill(roundRect); roundRect = decodeRoundRect6(); g.setPaint(decodeGradient7(roundRect)); g.fill(roundRect); roundRect = decodeRoundRect7(); g.setPaint(decodeGradient8(roundRect)); g.fill(roundRect); } private void paintBackgroundPressedAndSelectedAndFocused(Graphics2D g) { roundRect = decodeRoundRect8(); g.setPaint(color1); g.fill(roundRect); roundRect = decodeRoundRect6(); g.setPaint(decodeGradient7(roundRect)); g.fill(roundRect); roundRect = decodeRoundRect7(); g.setPaint(decodeGradient8(roundRect)); g.fill(roundRect); } private void paintBackgroundMouseOverAndSelected(Graphics2D g) { roundRect = decodeRoundRect5(); g.setPaint(color9); g.fill(roundRect); roundRect = decodeRoundRect6(); g.setPaint(decodeGradient3(roundRect)); g.fill(roundRect); roundRect = decodeRoundRect7(); g.setPaint(decodeGradient4(roundRect)); g.fill(roundRect); } private void paintBackgroundMouseOverAndSelectedAndFocused(Graphics2D g) { roundRect = decodeRoundRect8(); g.setPaint(color1); g.fill(roundRect); roundRect = decodeRoundRect6(); g.setPaint(decodeGradient3(roundRect)); g.fill(roundRect); roundRect = decodeRoundRect7(); g.setPaint(decodeGradient4(roundRect)); g.fill(roundRect); } private void paintBackgroundDisabledAndSelected(Graphics2D g) { roundRect = decodeRoundRect5(); g.setPaint(color25); g.fill(roundRect); roundRect = decodeRoundRect6(); g.setPaint(decodeGradient9(roundRect));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?