filechooserpainter.java

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

JAVA
1,588
字号
/*
 * FileChooserPainter.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 FileChooserPainter extends AbstractRegionPainter {
    //package private integers representing the available states that
    //this painter will paint. These are used when creating a new instance
    //of FileChooserPainter to determine which region/state is being painted
    //by that instance.
    static final int BACKGROUND_ENABLED = 1;    static final int FILEICON_ENABLED = 2;    static final int DIRECTORYICON_ENABLED = 3;    static final int UPFOLDERICON_ENABLED = 4;    static final int NEWFOLDERICON_ENABLED = 5;    static final int COMPUTERICON_ENABLED = 6;    static final int HARDDRIVEICON_ENABLED = 7;    static final int FLOPPYDRIVEICON_ENABLED = 8;    static final int HOMEFOLDERICON_ENABLED = 9;    static final int DETAILSVIEWICON_ENABLED = 10;    static final int LISTVIEWICON_ENABLED = 11;

    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 FileChooserPainter would be created. For the moment at least,
    //however, all are created for each instance.
    private Color color1 = decodeColor("control", 0.0f, 0.0f, 0.0f, 0);    private Color color2 = decodeColor("nimbusBlueGrey", 0.007936537f, -0.065654516f, -0.13333333f, 0);    private Color color3 = new Color(97, 98, 102, 255);    private Color color4 = decodeColor("nimbusBlueGrey", -0.032679737f, -0.043332636f, 0.24705881f, 0);    private Color color5 = decodeColor("nimbusBlueGrey", 0.0f, -0.110526316f, 0.25490195f, 0);    private Color color6 = decodeColor("nimbusBase", 0.0077680945f, -0.51781034f, 0.3490196f, 0);    private Color color7 = decodeColor("nimbusBase", 0.013940871f, -0.599277f, 0.41960782f, 0);    private Color color8 = decodeColor("nimbusBase", 0.004681647f, -0.4198052f, 0.14117646f, 0);    private Color color9 = decodeColor("nimbusBase", 0.0f, -0.6357143f, 0.45098037f, -127);    private Color color10 = decodeColor("nimbusBlueGrey", 0.0f, 0.0f, -0.21f, -99);    private Color color11 = decodeColor("nimbusBase", 2.9569864E-4f, -0.45978838f, 0.2980392f, 0);    private Color color12 = decodeColor("nimbusBase", 0.0015952587f, -0.34848025f, 0.18823528f, 0);    private Color color13 = decodeColor("nimbusBase", 0.0015952587f, -0.30844158f, 0.09803921f, 0);    private Color color14 = decodeColor("nimbusBase", 0.0015952587f, -0.27329817f, 0.035294116f, 0);    private Color color15 = decodeColor("nimbusBase", 0.004681647f, -0.6198413f, 0.43921566f, 0);    private Color color16 = decodeColor("nimbusBase", 0.0f, -0.6357143f, 0.45098037f, -125);    private Color color17 = decodeColor("nimbusBase", 0.0f, -0.6357143f, 0.45098037f, -50);    private Color color18 = decodeColor("nimbusBase", 0.0f, -0.6357143f, 0.45098037f, -100);    private Color color19 = decodeColor("nimbusBase", 0.0012094378f, -0.23571429f, -0.0784314f, 0);    private Color color20 = decodeColor("nimbusBase", 2.9569864E-4f, -0.115166366f, -0.2627451f, 0);    private Color color21 = decodeColor("nimbusBase", 0.0027436614f, -0.335015f, 0.011764705f, 0);    private Color color22 = decodeColor("nimbusBase", 0.0024294257f, -0.3857143f, 0.031372547f, 0);    private Color color23 = decodeColor("nimbusBase", 0.0018081069f, -0.3595238f, -0.13725492f, 0);    private Color color24 = new Color(255, 200, 0, 255);    private Color color25 = decodeColor("nimbusBase", 0.004681647f, -0.44904763f, 0.039215684f, 0);    private Color color26 = decodeColor("nimbusBase", 0.0015952587f, -0.43718487f, -0.015686274f, 0);    private Color color27 = decodeColor("nimbusBase", 2.9569864E-4f, -0.39212453f, -0.24313727f, 0);    private Color color28 = decodeColor("nimbusBase", 0.004681647f, -0.6117143f, 0.43137252f, 0);    private Color color29 = decodeColor("nimbusBase", 0.0012094378f, -0.28015873f, -0.019607842f, 0);    private Color color30 = decodeColor("nimbusBase", 0.00254488f, -0.07049692f, -0.2784314f, 0);    private Color color31 = decodeColor("nimbusBase", 0.0015952587f, -0.28045115f, 0.04705882f, 0);    private Color color32 = decodeColor("nimbusBlueGrey", 0.0f, 5.847961E-4f, -0.21568626f, 0);    private Color color33 = decodeColor("nimbusBase", -0.0061469674f, 0.3642857f, 0.14509803f, 0);    private Color color34 = decodeColor("nimbusBase", 0.0053939223f, 0.3642857f, -0.0901961f, 0);    private Color color35 = decodeColor("nimbusBase", 0.0f, -0.6357143f, 0.45098037f, 0);    private Color color36 = decodeColor("nimbusBase", -0.006044388f, -0.23963585f, 0.45098037f, 0);    private Color color37 = decodeColor("nimbusBase", -0.0063245893f, 0.01592505f, 0.4078431f, 0);    private Color color38 = decodeColor("nimbusBlueGrey", 0.0f, -0.110526316f, 0.25490195f, -170);    private Color color39 = decodeColor("nimbusOrange", -0.032758567f, -0.018273294f, 0.25098038f, 0);    private Color color40 = new Color(255, 255, 255, 255);    private Color color41 = new Color(252, 255, 92, 255);    private Color color42 = new Color(253, 191, 4, 255);    private Color color43 = new Color(160, 161, 163, 255);    private Color color44 = new Color(0, 0, 0, 255);    private Color color45 = new Color(239, 241, 243, 255);    private Color color46 = new Color(197, 201, 205, 255);    private Color color47 = new Color(105, 110, 118, 255);    private Color color48 = new Color(63, 67, 72, 255);    private Color color49 = new Color(56, 51, 25, 255);    private Color color50 = new Color(144, 255, 0, 255);    private Color color51 = new Color(243, 245, 246, 255);    private Color color52 = new Color(208, 212, 216, 255);    private Color color53 = new Color(191, 193, 194, 255);    private Color color54 = new Color(170, 172, 175, 255);    private Color color55 = new Color(152, 155, 158, 255);    private Color color56 = new Color(59, 62, 66, 255);    private Color color57 = new Color(46, 46, 46, 255);    private Color color58 = new Color(64, 64, 64, 255);    private Color color59 = new Color(43, 43, 43, 255);    private Color color60 = new Color(164, 179, 206, 255);    private Color color61 = new Color(97, 123, 170, 255);    private Color color62 = new Color(53, 86, 146, 255);    private Color color63 = new Color(48, 82, 144, 255);    private Color color64 = new Color(71, 99, 150, 255);    private Color color65 = new Color(224, 224, 224, 255);    private Color color66 = new Color(232, 232, 232, 255);    private Color color67 = new Color(231, 234, 237, 255);    private Color color68 = new Color(205, 211, 215, 255);    private Color color69 = new Color(149, 153, 156, 54);    private Color color70 = new Color(255, 122, 101, 255);    private Color color71 = new Color(54, 78, 122, 255);    private Color color72 = new Color(51, 60, 70, 255);    private Color color73 = new Color(228, 232, 237, 255);    private Color color74 = new Color(27, 57, 87, 255);    private Color color75 = new Color(75, 109, 137, 255);    private Color color76 = new Color(77, 133, 185, 255);    private Color color77 = new Color(81, 59, 7, 255);    private Color color78 = new Color(97, 74, 18, 255);    private Color color79 = new Color(137, 115, 60, 255);    private Color color80 = new Color(174, 151, 91, 255);    private Color color81 = new Color(114, 92, 13, 255);    private Color color82 = new Color(64, 48, 0, 255);    private Color color83 = new Color(244, 222, 143, 255);    private Color color84 = new Color(160, 161, 162, 255);    private Color color85 = new Color(226, 230, 233, 255);    private Color color86 = new Color(221, 225, 230, 255);    private Color color87 = decodeColor("nimbusBase", 0.004681647f, -0.48756614f, 0.19215685f, 0);    private Color color88 = decodeColor("nimbusBase", 0.004681647f, -0.48399013f, 0.019607842f, 0);    private Color color89 = decodeColor("nimbusBase", -0.0028941035f, -0.5906323f, 0.4078431f, 0);    private Color color90 = decodeColor("nimbusBase", 0.004681647f, -0.51290727f, 0.34509802f, 0);    private Color color91 = decodeColor("nimbusBase", 0.009583652f, -0.5642857f, 0.3843137f, 0);    private Color color92 = decodeColor("nimbusBase", -0.0072231293f, -0.6074885f, 0.4235294f, 0);    private Color color93 = decodeColor("nimbusBase", 7.13408E-4f, -0.52158386f, 0.17254901f, 0);    private Color color94 = decodeColor("nimbusBase", 0.012257397f, -0.5775132f, 0.19215685f, 0);    private Color color95 = decodeColor("nimbusBase", 0.08801502f, -0.6164835f, -0.14117649f, 0);    private Color color96 = decodeColor("nimbusBase", -0.57865167f, -0.6357143f, -0.5019608f, 0);    private Color color97 = decodeColor("nimbusBase", -0.0036516786f, -0.555393f, 0.42745095f, 0);    private Color color98 = decodeColor("nimbusBase", -0.0010654926f, -0.3634138f, 0.2862745f, 0);    private Color color99 = decodeColor("nimbusBase", -0.57865167f, -0.6357143f, -0.29803923f, 0);    private Color color100 = decodeColor("nimbusBase", -0.57865167f, -0.6357143f, 0.12156862f, 0);    private Color color101 = decodeColor("nimbusBase", -0.57865167f, -0.6357143f, -0.54901963f, 0);    private Color color102 = decodeColor("nimbusBase", -0.57865167f, -0.6357143f, -0.48627454f, 0);    private Color color103 = decodeColor("nimbusBase", -0.57865167f, -0.6357143f, -0.007843137f, 0);    private Color color104 = decodeColor("nimbusBase", -0.0028941035f, -0.5408867f, -0.09411767f, 0);    private Color color105 = decodeColor("nimbusBase", -0.011985004f, -0.54721874f, -0.10588238f, 0);    private Color color106 = decodeColor("nimbusBase", -0.0022627711f, -0.4305861f, -0.0901961f, 0);    private Color color107 = decodeColor("nimbusBase", -0.00573498f, -0.447479f, -0.21568629f, 0);    private Color color108 = decodeColor("nimbusBase", 0.004681647f, -0.53271f, 0.36470586f, 0);    private Color color109 = decodeColor("nimbusBase", 0.004681647f, -0.5276062f, -0.11372551f, 0);    private Color color110 = decodeColor("nimbusBase", -8.738637E-4f, -0.5278006f, -0.0039215684f, 0);    private Color color111 = decodeColor("nimbusBase", -0.0028941035f, -0.5338625f, -0.12549022f, 0);    private Color color112 = decodeColor("nimbusBlueGrey", -0.03535354f, -0.008674465f, -0.32156864f, 0);    private Color color113 = decodeColor("nimbusBlueGrey", -0.027777791f, -0.010526314f, -0.3529412f, 0);    private Color color114 = decodeColor("nimbusBase", -0.0028941035f, -0.5234694f, -0.1647059f, 0);    private Color color115 = decodeColor("nimbusBase", 0.004681647f, -0.53401935f, -0.086274534f, 0);    private Color color116 = decodeColor("nimbusBase", 0.004681647f, -0.52077174f, -0.20784315f, 0);    private Color color117 = new Color(108, 114, 120, 255);    private Color color118 = new Color(77, 82, 87, 255);    private Color color119 = decodeColor("nimbusBase", -0.004577577f, -0.52179027f, -0.2392157f, 0);    private Color color120 = decodeColor("nimbusBase", -0.004577577f, -0.547479f, -0.14901963f, 0);    private Color color121 = new Color(186, 186, 186, 50);    private Color color122 = new Color(186, 186, 186, 40);

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

    public FileChooserPainter(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;            case FILEICON_ENABLED: paintfileIconEnabled(g); break;            case DIRECTORYICON_ENABLED: paintdirectoryIconEnabled(g); break;            case UPFOLDERICON_ENABLED: paintupFolderIconEnabled(g); break;            case NEWFOLDERICON_ENABLED: paintnewFolderIconEnabled(g); break;            case HARDDRIVEICON_ENABLED: painthardDriveIconEnabled(g); break;            case FLOPPYDRIVEICON_ENABLED: paintfloppyDriveIconEnabled(g); break;            case HOMEFOLDERICON_ENABLED: painthomeFolderIconEnabled(g); break;            case DETAILSVIEWICON_ENABLED: paintdetailsViewIconEnabled(g); break;            case LISTVIEWICON_ENABLED: paintlistViewIconEnabled(g); break;
        }
    }
        


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

    private void paintBackgroundEnabled(Graphics2D g) {        rect = decodeRect1();        g.setPaint(color1);        g.fill(rect);    }    private void paintfileIconEnabled(Graphics2D g) {        path = decodePath1();        g.setPaint(color2);        g.fill(path);        rect = decodeRect2();        g.setPaint(color3);        g.fill(rect);        path = decodePath2();        g.setPaint(decodeGradient1(path));        g.fill(path);        path = decodePath3();        g.setPaint(decodeGradient2(path));        g.fill(path);        path = decodePath4();        g.setPaint(color8);        g.fill(path);        path = decodePath5();        g.setPaint(color9);        g.fill(path);    }    private void paintdirectoryIconEnabled(Graphics2D g) {        path = decodePath6();        g.setPaint(color10);        g.fill(path);        path = decodePath7();        g.setPaint(decodeGradient3(path));        g.fill(path);        path = decodePath8();        g.setPaint(decodeGradient4(path));        g.fill(path);        rect = decodeRect3();        g.setPaint(color16);        g.fill(rect);        rect = decodeRect4();        g.setPaint(color17);        g.fill(rect);        rect = decodeRect5();        g.setPaint(color18);        g.fill(rect);        path = decodePath9();        g.setPaint(decodeGradient5(path));        g.fill(path);        path = decodePath10();        g.setPaint(decodeGradient6(path));        g.fill(path);        path = decodePath11();        g.setPaint(color24);        g.fill(path);    }    private void paintupFolderIconEnabled(Graphics2D g) {        path = decodePath12();        g.setPaint(decodeGradient7(path));        g.fill(path);        path = decodePath13();        g.setPaint(decodeGradient8(path));        g.fill(path);        path = decodePath14();        g.setPaint(decodeGradient9(path));        g.fill(path);        path = decodePath15();        g.setPaint(decodeGradient10(path));        g.fill(path);        path = decodePath16();        g.setPaint(color32);        g.fill(path);        path = decodePath17();        g.setPaint(decodeGradient11(path));        g.fill(path);        path = decodePath18();        g.setPaint(color35);        g.fill(path);        path = decodePath19();        g.setPaint(decodeGradient12(path));        g.fill(path);    }    private void paintnewFolderIconEnabled(Graphics2D g) {        path = decodePath6();        g.setPaint(color10);        g.fill(path);        path = decodePath7();        g.setPaint(decodeGradient3(path));        g.fill(path);        path = decodePath8();        g.setPaint(decodeGradient4(path));        g.fill(path);        rect = decodeRect3();        g.setPaint(color16);        g.fill(rect);        rect = decodeRect4();        g.setPaint(color17);        g.fill(rect);        rect = decodeRect5();        g.setPaint(color18);        g.fill(rect);        path = decodePath9();        g.setPaint(decodeGradient5(path));        g.fill(path);        path = decodePath10();

⌨️ 快捷键说明

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