slidersliderthumbpainter.java
来自「Mobile 应用程序使用 Java Micro Edition (Java M」· Java 代码 · 共 638 行 · 第 1/2 页
JAVA
638 行
/*
* SliderSliderThumbPainter.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 SliderSliderThumbPainter extends AbstractRegionPainter {
//package private integers representing the available states that
//this painter will paint. These are used when creating a new instance
//of SliderSliderThumbPainter 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_FOCUSED = 3; static final int BACKGROUND_FOCUSED_MOUSEOVER = 4; static final int BACKGROUND_FOCUSED_PRESSED = 5; static final int BACKGROUND_MOUSEOVER = 6; static final int BACKGROUND_PRESSED = 7; static final int BACKGROUND_ENABLED_ARROWSHAPE = 8; static final int BACKGROUND_DISABLED_ARROWSHAPE = 9; static final int BACKGROUND_MOUSEOVER_ARROWSHAPE = 10; static final int BACKGROUND_PRESSED_ARROWSHAPE = 11; static final int BACKGROUND_FOCUSED_ARROWSHAPE = 12; static final int BACKGROUND_FOCUSED_MOUSEOVER_ARROWSHAPE = 13; static final int BACKGROUND_FOCUSED_PRESSED_ARROWSHAPE = 14;
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 SliderSliderThumbPainter would be created. For the moment at least,
//however, all are created for each instance.
private Color color1 = decodeColor("nimbusBase", 0.021348298f, -0.5625436f, 0.25490195f, 0); private Color color2 = decodeColor("nimbusBase", 0.015098333f, -0.55105823f, 0.19215685f, 0); private Color color3 = decodeColor("nimbusBase", 0.021348298f, -0.5924243f, 0.35686272f, 0); private Color color4 = decodeColor("nimbusBase", 0.021348298f, -0.56722116f, 0.3098039f, 0); private Color color5 = decodeColor("nimbusBase", 0.021348298f, -0.56844974f, 0.32549018f, 0); private Color color6 = decodeColor("nimbusBlueGrey", -0.003968239f, 0.0014736876f, -0.25490198f, -156); private Color color7 = decodeColor("nimbusBase", 5.1498413E-4f, -0.34585923f, -0.007843137f, 0); private Color color8 = decodeColor("nimbusBase", -0.0017285943f, -0.11571431f, -0.25490198f, 0); private Color color9 = decodeColor("nimbusBase", -0.023096085f, -0.6238095f, 0.43921566f, 0); private Color color10 = decodeColor("nimbusBase", 5.1498413E-4f, -0.43866998f, 0.24705881f, 0); private Color color11 = decodeColor("nimbusBase", 5.1498413E-4f, -0.45714286f, 0.32941175f, 0); private Color color12 = decodeColor("nimbusFocus", 0.0f, 0.0f, 0.0f, 0); private Color color13 = decodeColor("nimbusBase", -0.0038217902f, -0.15532213f, -0.14901963f, 0); private Color color14 = decodeColor("nimbusBase", -0.57865167f, -0.6357143f, -0.54509807f, 0); private Color color15 = decodeColor("nimbusBase", 0.004681647f, -0.62780917f, 0.44313723f, 0); private Color color16 = decodeColor("nimbusBase", 2.9569864E-4f, -0.4653107f, 0.32549018f, 0); private Color color17 = decodeColor("nimbusBase", 5.1498413E-4f, -0.4563421f, 0.32549018f, 0); private Color color18 = decodeColor("nimbusBase", -0.0017285943f, -0.4732143f, 0.39215684f, 0); private Color color19 = decodeColor("nimbusBase", 0.0015952587f, -0.04875779f, -0.18823531f, 0); private Color color20 = decodeColor("nimbusBase", 2.9569864E-4f, -0.44943976f, 0.25098038f, 0); private Color color21 = decodeColor("nimbusBase", 0.0f, 0.0f, 0.0f, 0); private Color color22 = decodeColor("nimbusBase", 8.9377165E-4f, -0.121094406f, 0.12156862f, 0); private Color color23 = decodeColor("nimbusBlueGrey", 0.0f, -0.110526316f, 0.25490195f, -121); private Color color24 = new Color(150, 156, 168, 146); private Color color25 = decodeColor("nimbusBase", -0.0033828616f, -0.40608466f, -0.019607842f, 0); private Color color26 = decodeColor("nimbusBase", 5.1498413E-4f, -0.17594418f, -0.20784315f, 0); private Color color27 = decodeColor("nimbusBase", 0.0023007393f, -0.11332625f, -0.28627452f, 0); private Color color28 = decodeColor("nimbusBase", -0.023096085f, -0.62376213f, 0.4352941f, 0); private Color color29 = decodeColor("nimbusBase", 0.004681647f, -0.594392f, 0.39999998f, 0); private Color color30 = decodeColor("nimbusBase", -0.0017285943f, -0.4454704f, 0.25490195f, 0); private Color color31 = decodeColor("nimbusBase", 5.1498413E-4f, -0.4625541f, 0.35686272f, 0); private Color color32 = decodeColor("nimbusBase", 5.1498413E-4f, -0.47442397f, 0.4235294f, 0);
//Array of current component colors, updated in each paint call
private Object[] componentColors;
public SliderSliderThumbPainter(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_FOCUSED: paintBackgroundFocused(g); break; case BACKGROUND_FOCUSED_MOUSEOVER: paintBackgroundFocusedAndMouseOver(g); break; case BACKGROUND_FOCUSED_PRESSED: paintBackgroundFocusedAndPressed(g); break; case BACKGROUND_MOUSEOVER: paintBackgroundMouseOver(g); break; case BACKGROUND_PRESSED: paintBackgroundPressed(g); break; case BACKGROUND_ENABLED_ARROWSHAPE: paintBackgroundEnabledAndArrowShape(g); break; case BACKGROUND_DISABLED_ARROWSHAPE: paintBackgroundDisabledAndArrowShape(g); break; case BACKGROUND_MOUSEOVER_ARROWSHAPE: paintBackgroundMouseOverAndArrowShape(g); break; case BACKGROUND_PRESSED_ARROWSHAPE: paintBackgroundPressedAndArrowShape(g); break; case BACKGROUND_FOCUSED_ARROWSHAPE: paintBackgroundFocusedAndArrowShape(g); break; case BACKGROUND_FOCUSED_MOUSEOVER_ARROWSHAPE: paintBackgroundFocusedAndMouseOverAndArrowShape(g); break; case BACKGROUND_FOCUSED_PRESSED_ARROWSHAPE: paintBackgroundFocusedAndPressedAndArrowShape(g); break;
}
}
@Override
protected final PaintContext getPaintContext() {
return ctx;
}
private void paintBackgroundDisabled(Graphics2D g) { ellipse = decodeEllipse1(); g.setPaint(decodeGradient1(ellipse)); g.fill(ellipse); ellipse = decodeEllipse2(); g.setPaint(decodeGradient2(ellipse)); g.fill(ellipse); } private void paintBackgroundEnabled(Graphics2D g) { ellipse = decodeEllipse3(); g.setPaint(color6); g.fill(ellipse); ellipse = decodeEllipse1(); g.setPaint(decodeGradient3(ellipse)); g.fill(ellipse); ellipse = decodeEllipse2(); g.setPaint(decodeGradient4(ellipse)); g.fill(ellipse); } private void paintBackgroundFocused(Graphics2D g) { ellipse = decodeEllipse4(); g.setPaint(color12); g.fill(ellipse); ellipse = decodeEllipse1(); g.setPaint(decodeGradient3(ellipse)); g.fill(ellipse); ellipse = decodeEllipse2(); g.setPaint(decodeGradient4(ellipse)); g.fill(ellipse); } private void paintBackgroundFocusedAndMouseOver(Graphics2D g) { ellipse = decodeEllipse4(); g.setPaint(color12); g.fill(ellipse); ellipse = decodeEllipse1(); g.setPaint(decodeGradient5(ellipse)); g.fill(ellipse); ellipse = decodeEllipse2(); g.setPaint(decodeGradient6(ellipse)); g.fill(ellipse); } private void paintBackgroundFocusedAndPressed(Graphics2D g) { ellipse = decodeEllipse4(); g.setPaint(color12); g.fill(ellipse); ellipse = decodeEllipse1(); g.setPaint(decodeGradient7(ellipse)); g.fill(ellipse); ellipse = decodeEllipse2(); g.setPaint(decodeGradient8(ellipse)); g.fill(ellipse); } private void paintBackgroundMouseOver(Graphics2D g) { ellipse = decodeEllipse3(); g.setPaint(color6); g.fill(ellipse); ellipse = decodeEllipse1(); g.setPaint(decodeGradient5(ellipse)); g.fill(ellipse); ellipse = decodeEllipse2(); g.setPaint(decodeGradient6(ellipse)); g.fill(ellipse); } private void paintBackgroundPressed(Graphics2D g) { ellipse = decodeEllipse3(); g.setPaint(color23); g.fill(ellipse); ellipse = decodeEllipse1(); g.setPaint(decodeGradient7(ellipse)); g.fill(ellipse); ellipse = decodeEllipse2(); g.setPaint(decodeGradient8(ellipse)); g.fill(ellipse); } private void paintBackgroundEnabledAndArrowShape(Graphics2D g) { path = decodePath1(); g.setPaint(color24); g.fill(path); path = decodePath2(); g.setPaint(decodeGradient9(path)); g.fill(path); path = decodePath3(); g.setPaint(decodeGradient10(path)); g.fill(path); } private void paintBackgroundDisabledAndArrowShape(Graphics2D g) { path = decodePath2(); g.setPaint(decodeGradient11(path)); g.fill(path); path = decodePath3(); g.setPaint(decodeGradient12(path)); g.fill(path); } private void paintBackgroundMouseOverAndArrowShape(Graphics2D g) { path = decodePath1(); g.setPaint(color24); g.fill(path); path = decodePath2(); g.setPaint(decodeGradient13(path)); g.fill(path); path = decodePath3(); g.setPaint(decodeGradient14(path)); g.fill(path); } private void paintBackgroundPressedAndArrowShape(Graphics2D g) { path = decodePath1(); g.setPaint(color24); g.fill(path); path = decodePath2(); g.setPaint(decodeGradient15(path)); g.fill(path); path = decodePath3(); g.setPaint(decodeGradient16(path)); g.fill(path); } private void paintBackgroundFocusedAndArrowShape(Graphics2D g) { path = decodePath4(); g.setPaint(color12); g.fill(path); path = decodePath2(); g.setPaint(decodeGradient9(path)); g.fill(path); path = decodePath3(); g.setPaint(decodeGradient17(path)); g.fill(path); } private void paintBackgroundFocusedAndMouseOverAndArrowShape(Graphics2D g) { path = decodePath4(); g.setPaint(color12); g.fill(path); path = decodePath2(); g.setPaint(decodeGradient13(path)); g.fill(path); path = decodePath3(); g.setPaint(decodeGradient14(path)); g.fill(path); } private void paintBackgroundFocusedAndPressedAndArrowShape(Graphics2D g) { path = decodePath4(); g.setPaint(color12); g.fill(path); path = decodePath2(); g.setPaint(decodeGradient15(path)); g.fill(path); path = decodePath3(); g.setPaint(decodeGradient16(path)); g.fill(path); }
private Ellipse2D decodeEllipse1() { ellipse.setFrame(decodeX(0.4f), //x decodeY(0.4f), //y decodeX(2.6f) - decodeX(0.4f), //width decodeY(2.6f) - decodeY(0.4f)); //height return ellipse; } private Ellipse2D decodeEllipse2() { ellipse.setFrame(decodeX(0.6f), //x decodeY(0.6f), //y decodeX(2.4f) - decodeX(0.6f), //width decodeY(2.4f) - decodeY(0.6f)); //height return ellipse; } private Ellipse2D decodeEllipse3() {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?