desktoppanepainter.java
来自「Mobile 应用程序使用 Java Micro Edition (Java M」· Java 代码 · 共 334 行 · 第 1/2 页
JAVA
334 行
/*
* DesktopPanePainter.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 DesktopPanePainter extends AbstractRegionPainter {
//package private integers representing the available states that
//this painter will paint. These are used when creating a new instance
//of DesktopPanePainter to determine which region/state is being painted
//by that instance.
static final int BACKGROUND_ENABLED = 1;
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 DesktopPanePainter would be created. For the moment at least,
//however, all are created for each instance.
private Color color1 = decodeColor("nimbusBase", -0.004577577f, -0.12867206f, 0.007843137f, 0); private Color color2 = decodeColor("nimbusBase", -0.0063245893f, -0.08363098f, -0.17254904f, 0); private Color color3 = decodeColor("nimbusBase", -3.6883354E-4f, -0.056766927f, -0.10196081f, 0); private Color color4 = decodeColor("nimbusBase", -0.008954704f, -0.12645501f, -0.12549022f, 0); private Color color5 = new Color(255, 200, 0, 6); private Color color6 = decodeColor("nimbusBase", -8.028746E-5f, -0.084533215f, -0.05098042f, 0); private Color color7 = decodeColor("nimbusBase", -0.0052053332f, -0.12267083f, -0.09803924f, 0); private Color color8 = decodeColor("nimbusBase", -0.012559712f, -0.13136649f, -0.09803924f, 0); private Color color9 = decodeColor("nimbusBase", -0.009207249f, -0.13984653f, -0.07450983f, 0); private Color color10 = decodeColor("nimbusBase", -0.010750473f, -0.13571429f, -0.12549022f, 0); private Color color11 = decodeColor("nimbusBase", -0.008476257f, -0.1267857f, -0.109803945f, 0); private Color color12 = decodeColor("nimbusBase", -0.0034883022f, -0.042691052f, -0.21176472f, 0); private Color color13 = decodeColor("nimbusBase", -0.012613952f, -0.11610645f, -0.14901963f, 0); private Color color14 = decodeColor("nimbusBase", -0.0038217902f, -0.05238098f, -0.21960786f, 0);
//Array of current component colors, updated in each paint call
private Object[] componentColors;
public DesktopPanePainter(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_ENABLED: paintBackgroundEnabled(g); break;
}
}
@Override
protected final PaintContext getPaintContext() {
return ctx;
}
private void paintBackgroundEnabled(Graphics2D g) { path = decodePath1(); g.setPaint(decodeGradient1(path)); g.fill(path); path = decodePath2(); g.setPaint(decodeGradient2(path)); g.fill(path); path = decodePath3(); g.setPaint(color5); g.fill(path); path = decodePath4(); g.setPaint(decodeGradient3(path)); g.fill(path); path = decodePath5(); g.setPaint(decodeGradient4(path)); g.fill(path); path = decodePath6(); g.setPaint(decodeGradient5(path)); g.fill(path); path = decodePath7(); g.setPaint(decodeGradient6(path)); g.fill(path); path = decodePath8(); g.setPaint(decodeGradient7(path)); g.fill(path); path = decodePath9(); g.setPaint(decodeGradient8(path)); g.fill(path); }
private Path2D decodePath1() { path.reset(); path.moveTo(decodeX(1.2716666f), decodeY(2.0f)); path.curveTo(decodeAnchorX(1.2716666460037231f, 0.0f), decodeAnchorY(2.0f, 0.5f), decodeAnchorX(1.128333330154419f, 0.0f), decodeAnchorY(1.0f, 0.0f), decodeX(1.1283333f), decodeY(1.0f)); path.lineTo(decodeX(1.3516667f), decodeY(1.0f)); path.lineTo(decodeX(1.5866666f), decodeY(1.5754311f)); path.lineTo(decodeX(1.5416667f), decodeY(2.0f)); path.curveTo(decodeAnchorX(1.5416667461395264f, 0.0f), decodeAnchorY(2.0f, 0.0f), decodeAnchorX(1.2716666460037231f, 0.0f), decodeAnchorY(2.0f, -0.5f), decodeX(1.2716666f), decodeY(2.0f)); path.closePath(); return path; } private Path2D decodePath2() { path.reset(); path.moveTo(decodeX(1.7883334f), decodeY(2.0f)); path.curveTo(decodeAnchorX(1.7883334159851074f, 0.0f), decodeAnchorY(2.0f, 0.5f), decodeAnchorX(1.653333306312561f, 0.0f), decodeAnchorY(1.7737069129943848f, 0.0f), decodeX(1.6533333f), decodeY(1.7737069f)); path.lineTo(decodeX(2.0f), decodeY(1.1465517f)); path.curveTo(decodeAnchorX(2.0f, 0.0f), decodeAnchorY(1.1465517282485962f, 0.0f), decodeAnchorX(2.0f, 0.0f), decodeAnchorY(2.0f, -0.5f), decodeX(2.0f), decodeY(2.0f)); path.curveTo(decodeAnchorX(2.0f, 0.5f), decodeAnchorY(2.0f, 0.5f), decodeAnchorX(1.7883334159851074f, 0.0f), decodeAnchorY(2.0f, -0.5f), decodeX(1.7883334f), decodeY(2.0f)); path.closePath(); return path; } private Path2D decodePath3() { path.reset(); path.moveTo(decodeX(1.5666666f), decodeY(1.0f)); path.lineTo(decodeX(1.5666666f), decodeY(1.5689654f)); path.lineTo(decodeX(1.675f), decodeY(1.7715517f)); path.curveTo(decodeAnchorX(1.6749999523162842f, 0.0f), decodeAnchorY(1.7715517282485962f, 0.0f), decodeAnchorX(1.81166672706604f, -23.5f), decodeAnchorY(1.4978448152542114f, 33.5f), decodeX(1.8116667f), decodeY(1.4978448f)); path.curveTo(decodeAnchorX(1.81166672706604f, 23.5f), decodeAnchorY(1.4978448152542114f, -33.5f), decodeAnchorX(2.0f, 0.0f), decodeAnchorY(1.200430989265442f, 0.0f), decodeX(2.0f), decodeY(1.200431f)); path.lineTo(decodeX(2.0f), decodeY(1.0f)); path.lineTo(decodeX(1.5666666f), decodeY(1.0f)); path.closePath(); return path; } private Path2D decodePath4() { path.reset(); path.moveTo(decodeX(1.3383334f), decodeY(1.0f)); path.curveTo(decodeAnchorX(1.3383333683013916f, 0.0f), decodeAnchorY(1.0f, 0.0f), decodeAnchorX(1.441666603088379f, -21.0f), decodeAnchorY(1.3103448152542114f, -37.5f), decodeX(1.4416666f), decodeY(1.3103448f)); path.curveTo(decodeAnchorX(1.441666603088379f, 21.0f), decodeAnchorY(1.3103448152542114f, 37.5f), decodeAnchorX(1.5733332633972168f, 0.0f), decodeAnchorY(1.5840517282485962f, 0.0f), decodeX(1.5733333f), decodeY(1.5840517f)); path.curveTo(decodeAnchorX(1.5733332633972168f, 0.0f), decodeAnchorY(1.5840517282485962f, 0.0f), decodeAnchorX(1.6066666841506958f, 1.5f), decodeAnchorY(1.2413792610168457f, 29.5f), decodeX(1.6066667f), decodeY(1.2413793f)); path.curveTo(decodeAnchorX(1.6066666841506958f, -1.5f), decodeAnchorY(1.2413792610168457f, -29.5f), decodeAnchorX(1.6050000190734863f, 0.0f), decodeAnchorY(1.0f, 0.0f), decodeX(1.605f), decodeY(1.0f)); path.lineTo(decodeX(1.3383334f), decodeY(1.0f)); path.closePath(); return path; } private Path2D decodePath5() { path.reset(); path.moveTo(decodeX(1.5683334f), decodeY(1.5797414f)); path.curveTo(decodeAnchorX(1.568333387374878f, 0.0f), decodeAnchorY(1.579741358757019f, 0.0f), decodeAnchorX(1.5750000476837158f, 0.0f), decodeAnchorY(1.2392241954803467f, 33.0f), decodeX(1.575f), decodeY(1.2392242f)); path.curveTo(decodeAnchorX(1.5750000476837158f, 0.0f), decodeAnchorY(1.2392241954803467f, -33.0f), decodeAnchorX(1.56166672706604f, 0.0f), decodeAnchorY(1.0f, 0.0f), decodeX(1.5616667f), decodeY(1.0f)); path.lineTo(decodeX(2.0f), decodeY(1.0f));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?