make/jdk/src/classes/build/tools/generatenimbus/PainterGenerator.java
author vlivanov
Thu, 18 Jan 2018 02:25:18 +0300
changeset 48596 860326263d1f
parent 47216 71c04702a3d5
permissions -rw-r--r--
8194963: SystemDictionary::link_method_handle_constant() can't link MethodHandle.invoke()/invokeExact() Reviewed-by: kvn, psandoz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3742
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21805
diff changeset
     2
 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
3742
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
     4
 *
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3742
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
3742
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3742
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
3742
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    10
 *
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    15
 * accompanied this code).
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    16
 *
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3742
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3742
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3742
diff changeset
    23
 * questions.
3742
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    24
 */
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    25
package build.tools.generatenimbus;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    26
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    27
import java.awt.geom.Point2D;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    28
import java.util.ArrayList;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    29
import java.util.HashMap;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    30
import java.util.LinkedHashMap;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    31
import java.util.List;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    32
import java.util.Map;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    33
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    34
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    35
/**
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    36
 * PainterGenerator - Class for generating Painter class java source from a Canvas
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    37
 *
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    38
 * Following in the general theory that is used to generate a Painter file.
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    39
 *
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    40
 * Each Painter file represents a Region. So there is one painter file per region. In
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    41
 * skin.laf we support Icon subregions, which are really just hacked versions of the
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    42
 * parent region.
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    43
 *
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    44
 * In order to generate the most compact and efficient bytecode possible for the
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    45
 * Painters, we actually perform the generation sequence in two steps. The first
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    46
 * step is the analysis phase, where we walk through the SynthModel for the region
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    47
 * and discover commonality among the different states in the region. For example,
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    48
 * do they have common paths? Do they have common colors? Gradients? Is the painting
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    49
 * code for the different states identical other than for colors?
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    50
 *
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    51
 * We gather this information up. On the second pass, we use this data to determine the
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    52
 * methods that need to be generated, and the class variables that need to be generated.
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    53
 * We try to keep the actual bytecode count as small as possible so that we may reduce
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    54
 * the overall size of the look and feel significantly.
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    55
 *
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    56
 * @author  Richard Bair
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    57
 * @author  Jasper Potts
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    58
 */
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    59
public class PainterGenerator {
25097
147ac5785a84 8016451: Scary messages emitted by build.tools.generatenimbus.PainterGenerator during build
prr
parents: 23010
diff changeset
    60
147ac5785a84 8016451: Scary messages emitted by build.tools.generatenimbus.PainterGenerator during build
prr
parents: 23010
diff changeset
    61
    private static final boolean debug = false;
147ac5785a84 8016451: Scary messages emitted by build.tools.generatenimbus.PainterGenerator during build
prr
parents: 23010
diff changeset
    62
3742
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    63
    //a handful of counters, incremented whenever the associated object type is encounted.
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    64
    //These counters form the basis of the field and method suffixes.
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    65
    //These are all 1 based, because I felt like it :-)
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    66
    private int colorCounter = 1;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    67
    private int gradientCounter = 1;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    68
    private int radialCounter = 1;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    69
    private int pathCounter = 1;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    70
    private int rectCounter = 1;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    71
    private int roundRectCounter = 1;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    72
    private int ellipseCounter = 1;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    73
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    74
    private int stateTypeCounter = 1;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    75
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    76
    //during the first pass, we will construct these maps
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    77
    private Map<String, String> colors = new HashMap<String, String>();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    78
    /**
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    79
     * Code=>method name.
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    80
     */
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    81
    private Map<String, String> methods = new HashMap<String, String>();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    82
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    83
    //these variables hold the generated code
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    84
    /**
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    85
     * The source code in this variable will be used to define the various state types
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    86
     */
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    87
    private StringBuilder stateTypeCode = new StringBuilder();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    88
    /**
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    89
     * The source code in this variable will be used to define the switch statement for painting
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    90
     */
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    91
    private StringBuilder switchCode = new StringBuilder();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    92
    /**
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    93
     * The source code in this variable will be used to define the methods for painting each state
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    94
     */
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    95
    private StringBuilder paintingCode = new StringBuilder();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    96
    /**
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    97
     * The source code in this variable will be used to add getExtendedCacheKeys
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    98
     * implementation if needed.
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
    99
     */
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   100
    private StringBuilder getExtendedCacheKeysCode = new StringBuilder();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   101
    /**
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   102
     * The source code in this variable will be used to define the methods for decoding gradients
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   103
     * and shapes.
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   104
     */
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   105
    private StringBuilder gradientsCode = new StringBuilder();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   106
    private StringBuilder colorCode = new StringBuilder();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   107
    private StringBuilder shapesCode = new StringBuilder();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   108
    /**
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   109
     * Map of component colors keyed by state constant name
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   110
     */
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   111
    private Map<String, List<ComponentColor>> componentColorsMap =
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   112
            new LinkedHashMap<String, List<ComponentColor>>();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   113
    /**
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   114
     * For the current state the list of all component colors used by this
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   115
     * painter, the index in this list is also the index in the runtime array
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   116
     * of defaults and keys.
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   117
     */
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   118
    private List<ComponentColor> componentColors = null;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   119
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   120
    PainterGenerator(UIRegion r) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   121
        generate(r);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   122
    }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   123
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   124
    private void generate(UIRegion r) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   125
        for (UIState state : r.getBackgroundStates()) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   126
            Canvas canvas = state.getCanvas();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   127
            String type = (r instanceof UIIconRegion ? r.getKey() : "Background");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   128
            generate(state, canvas, type);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   129
        }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   130
        for (UIState state : r.getForegroundStates()) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   131
            Canvas canvas = state.getCanvas();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   132
            generate(state, canvas, "Foreground");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   133
        }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   134
        for (UIState state : r.getBorderStates()) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   135
            Canvas canvas = state.getCanvas();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   136
            generate(state, canvas, "Border");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   137
        }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   138
        //now check for any uiIconRegions, since these are collapsed together.
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   139
        for (UIRegion sub : r.getSubRegions()) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   140
            if (sub instanceof UIIconRegion) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   141
                generate(sub);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   142
            }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   143
        }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   144
        //generate all the code for component colors
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   145
        if (!componentColorsMap.isEmpty()) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   146
            getExtendedCacheKeysCode
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   147
                    .append("    protected Object[] getExtendedCacheKeys(JComponent c) {\n")
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   148
                    .append("        Object[] extendedCacheKeys = null;\n")
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   149
                    .append("        switch(state) {\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   150
            for (Map.Entry<String, List<ComponentColor>> entry : componentColorsMap.entrySet()) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   151
                getExtendedCacheKeysCode
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   152
                    .append("            case ")
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   153
                    .append(entry.getKey()).append(":\n")
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   154
                    .append("                extendedCacheKeys = new Object[] {\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   155
                for (int i=0; i<entry.getValue().size(); i++) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   156
                    ComponentColor cc = entry.getValue().get(i);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   157
                    cc.write(getExtendedCacheKeysCode);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   158
                    if (i + 1 < entry.getValue().size()) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   159
                        getExtendedCacheKeysCode.append("),\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   160
                    } else {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   161
                        getExtendedCacheKeysCode.append(")");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   162
                    }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   163
                }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   164
                getExtendedCacheKeysCode.append("};\n")
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   165
                    .append("                break;\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   166
            }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   167
            getExtendedCacheKeysCode
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   168
                    .append("        }\n")
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   169
                    .append("        return extendedCacheKeys;\n")
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   170
                    .append("    }");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   171
        }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   172
    }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   173
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   174
    //type is background, foreground, border, upArrowIcon, etc.
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   175
    private void generate(UIState state, Canvas canvas, String type) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   176
        String states = state.getStateKeys();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   177
        String stateType = Utils.statesToConstantName(type + "_" + states);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   178
        String paintMethodName = "paint" + type + Utils.statesToClassName(states);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   179
        //create new array for component colors for this state
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   180
        componentColors = new ArrayList<ComponentColor>();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   181
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   182
        stateTypeCode.append("    static final int ").append(stateType).append(" = ").append(stateTypeCounter++).append(";\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   183
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   184
        if (canvas.isBlank()) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   185
            return;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   186
        }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   187
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   188
        switchCode.append("            case ").append(stateType).append(": ").append(paintMethodName).append("(g); break;\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   189
        paintingCode.append("    private void ").append(paintMethodName).append("(Graphics2D g) {\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   190
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   191
        //start by setting up common info needed to encode the control points
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   192
        Insets in = canvas.getStretchingInsets();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   193
        float a = in.left;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   194
        float b = canvas.getSize().width - in.right;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   195
        float c = in.top;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   196
        float d = canvas.getSize().height - in.bottom;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   197
        float width = canvas.getSize().width;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   198
        float height = canvas.getSize().height;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   199
        float cw = b - a;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   200
        float ch = d - c;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   201
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   202
        Layer[] layers = canvas.getLayers().toArray(new Layer[0]);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   203
        for (int index=layers.length-1; index >= 0; index--) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   204
            Layer layer = layers[index];
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   205
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   206
            //shapes must be painted in reverse order
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   207
            List<Shape> shapes = layer.getShapes();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   208
            for (int i=shapes.size()-1; i>=0; i--) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   209
                Shape shape = shapes.get(i);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   210
                Paint paint = shape.getPaint();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   211
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   212
                /*
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   213
                    We attempt to write the minimal number of bytecodes as possible when
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   214
                    generating code. Due to the inherit complexities in determining what
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   215
                    is extraneous, we use the following system:
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   216
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   217
                    We first generate the code for the shape. Then, we check to see if
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   218
                    this shape has already been generated. If so, then we defer to an
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   219
                    existing method. If not, then we will create a new methods, stick
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   220
                    the code in it, and refer to that method.
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   221
                */
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   222
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   223
                String shapeMethodName = null; // will contain the name of the method which creates the shape
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   224
                String shapeVariable = null; // will be one of rect, roundRect, ellipse, or path.
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   225
                String shapeMethodBody = null;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   226
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   227
                if (shape instanceof Rectangle) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   228
                    Rectangle rshape = (Rectangle) shape;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   229
                    float x1 = encode((float)rshape.getX1(), a, b, width);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   230
                    float y1 = encode((float)rshape.getY1(), c, d, height);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   231
                    float x2 = encode((float)rshape.getX2(), a, b, width);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   232
                    float y2 = encode((float)rshape.getY2(), c, d, height);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   233
                    if (rshape.isRounded()) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   234
                        //it is a rounded rectangle
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   235
                        float rounding = (float)rshape.getRounding();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   236
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   237
                        shapeMethodBody =
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   238
                                "        roundRect.setRoundRect(" +
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   239
                                writeDecodeX(x1) + ", //x\n" +
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   240
                                "                               " + writeDecodeY(y1) + ", //y\n" +
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   241
                                "                               " + writeDecodeX(x2) + " - " + writeDecodeX(x1) + ", //width\n" +
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   242
                                "                               " + writeDecodeY(y2) + " - " + writeDecodeY(y1) + ", //height\n" +
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   243
                                "                               " + rounding + "f, " + rounding + "f); //rounding";
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   244
                        shapeVariable = "roundRect";
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   245
                    } else {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   246
                        shapeMethodBody =
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   247
                                "            rect.setRect(" +
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   248
                                writeDecodeX(x1) + ", //x\n" +
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   249
                                "                         " + writeDecodeY(y1) + ", //y\n" +
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   250
                                "                         " + writeDecodeX(x2) + " - " + writeDecodeX(x1) + ", //width\n" +
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   251
                                "                         " + writeDecodeY(y2) + " - " + writeDecodeY(y1) + "); //height";
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   252
                        shapeVariable = "rect";
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   253
                    }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   254
                } else if (shape instanceof Ellipse) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   255
                    Ellipse eshape = (Ellipse) shape;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   256
                    float x1 = encode((float)eshape.getX1(), a, b, width);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   257
                    float y1 = encode((float)eshape.getY1(), c, d, height);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   258
                    float x2 = encode((float)eshape.getX2(), a, b, width);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   259
                    float y2 = encode((float)eshape.getY2(), c, d, height);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   260
                    shapeMethodBody =
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   261
                            "        ellipse.setFrame(" +
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   262
                            writeDecodeX(x1) + ", //x\n" +
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   263
                            "                         " + writeDecodeY(y1) + ", //y\n" +
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   264
                            "                         " + writeDecodeX(x2) + " - " + writeDecodeX(x1) + ", //width\n" +
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   265
                            "                         " + writeDecodeY(y2) + " - " + writeDecodeY(y1) + "); //height";
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   266
                    shapeVariable = "ellipse";
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   267
                } else if (shape instanceof Path) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   268
                    Path pshape = (Path) shape;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   269
                    List<Point> controlPoints = pshape.getControlPoints();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   270
                    Point first, last;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   271
                    first = last = controlPoints.get(0);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   272
                    StringBuilder buffer = new StringBuilder();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   273
                    buffer.append("        path.reset();\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   274
                    buffer.append("        path.moveTo(" + writeDecodeX(encode((float)first.getX(), a, b, width)) + ", " + writeDecodeY(encode((float)first.getY(), c, d, height)) + ");\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   275
                    for (int j=1; j<controlPoints.size(); j++) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   276
                        Point cp = controlPoints.get(j);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   277
                        if (last.isP2Sharp() && cp.isP1Sharp()) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   278
                            float x = encode((float)cp.getX(), a, b, width);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   279
                            float y = encode((float)cp.getY(), c, d, height);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   280
                            buffer.append("        path.lineTo(" + writeDecodeX(x) + ", " + writeDecodeY(y) + ");\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   281
                        } else {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   282
                            float x1 = encode((float)last.getX(), a, b, width);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   283
                            float y1 = encode((float)last.getY(), c, d, height);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   284
                            float x2 = encode((float)cp.getX(), a, b, width);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   285
                            float y2 = encode((float)cp.getY(), c, d, height);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   286
                            buffer.append(
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   287
                                    "        path.curveTo(" + writeDecodeBezierX(x1, last.getX(), last.getCp2X()) + ", "
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   288
                                                            + writeDecodeBezierY(y1, last.getY(), last.getCp2Y()) + ", "
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   289
                                                            + writeDecodeBezierX(x2, cp.getX(), cp.getCp1X()) + ", "
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   290
                                                            + writeDecodeBezierY(y2, cp.getY(), cp.getCp1Y()) + ", "
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   291
                                                            + writeDecodeX(x2) + ", " + writeDecodeY(y2) + ");\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   292
                        }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   293
                        last = cp;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   294
                    }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   295
                    if (last.isP2Sharp() && first.isP1Sharp()) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   296
                        float x = encode((float)first.getX(), a, b, width);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   297
                        float y = encode((float)first.getY(), c, d, height);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   298
                        buffer.append("        path.lineTo(" + writeDecodeX(x) + ", " + writeDecodeY(y) + ");\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   299
                    } else {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   300
                        float x1 = encode((float)last.getX(), a, b, width);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   301
                        float y1 = encode((float)last.getY(), c, d, height);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   302
                        float x2 = encode((float)first.getX(), a, b, width);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   303
                        float y2 = encode((float)first.getY(), c, d, height);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   304
                        buffer.append(
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   305
                                "        path.curveTo(" + writeDecodeBezierX(x1, last.getX(), last.getCp2X()) + ", "
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   306
                                                        + writeDecodeBezierY(y1, last.getY(), last.getCp2Y()) + ", "
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   307
                                                        + writeDecodeBezierX(x2, first.getX(), first.getCp1X()) + ", "
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   308
                                                        + writeDecodeBezierY(y2, first.getY(), first.getCp1Y()) + ", "
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   309
                                                        + writeDecodeX(x2) + ", " + writeDecodeY(y2) + ");\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   310
                    }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   311
                    buffer.append("        path.closePath();");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   312
                    shapeMethodBody = buffer.toString();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   313
                    shapeVariable = "path";
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   314
                } else {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   315
                    throw new RuntimeException("Cannot happen unless a new Shape has been defined");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   316
                }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   317
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   318
                //now that we have the shape defined in shapeMethodBody, and a shapeVariable name,
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   319
                //look to see if such a body has been previously defined.
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   320
                shapeMethodName = methods.get(shapeMethodBody);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   321
                String returnType = null;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   322
                if (shapeMethodName == null) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   323
                    if ("rect".equals(shapeVariable)) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   324
                        shapeMethodName = "decodeRect" + rectCounter++;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   325
                        returnType = "Rectangle2D";
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   326
                    } else if ("roundRect".equals(shapeVariable)) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   327
                        shapeMethodName = "decodeRoundRect" + roundRectCounter++;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   328
                        returnType = "RoundRectangle2D";
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   329
                    } else if ("ellipse".equals(shapeVariable)) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   330
                        shapeMethodName = "decodeEllipse" + ellipseCounter++;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   331
                        returnType = "Ellipse2D";
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   332
                    } else {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   333
                        shapeMethodName = "decodePath" + pathCounter++;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   334
                        returnType = "Path2D";
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   335
                    }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   336
                    methods.put(shapeMethodBody, shapeMethodName);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   337
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   338
                    //since the method wasn't previously defined, time to define it
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   339
                    shapesCode.append("    private ").append(returnType).append(" ").append(shapeMethodName).append("() {\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   340
                    shapesCode.append(shapeMethodBody);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   341
                    shapesCode.append("\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   342
                    shapesCode.append("        return " + shapeVariable + ";\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   343
                    shapesCode.append("    }\n\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   344
                }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   345
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   346
                //now that the method has been defined, I can go on and decode the
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   347
                //paint. After the paint is decoded, I can write the g.fill() method call,
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   348
                //using the result of the shapeMethodName. Yay!
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   349
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   350
//            if (shapeVariable != null) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   351
            //first, calculate the bounds of the shape being painted and store in variables
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   352
                paintingCode.append("        ").append(shapeVariable).append(" = ").append(shapeMethodName).append("();\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   353
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   354
                if (paint instanceof Matte) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   355
                    String colorVariable = encodeMatte((Matte)paint);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   356
                    paintingCode.append("        g.setPaint(").append(colorVariable).append(");\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   357
                } else if (paint instanceof Gradient) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   358
                    String gradientMethodName = encodeGradient(shape, (Gradient)paint);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   359
                    paintingCode.append("        g.setPaint(").append(gradientMethodName).append("(").append(shapeVariable).append("));\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   360
                } else if (paint instanceof RadialGradient) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   361
                    String radialMethodName = encodeRadial(shape, (RadialGradient)paint);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   362
                    paintingCode.append("        g.setPaint(").append(radialMethodName).append("(").append(shapeVariable).append("));\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   363
                }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   364
                paintingCode.append("        g.fill(").append(shapeVariable).append(");\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   365
            }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   366
        }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   367
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   368
        paintingCode.append("\n    }\n\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   369
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   370
        //collect component colors
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   371
        if (!componentColors.isEmpty()) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   372
            componentColorsMap.put(stateType, componentColors);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   373
            componentColors = null;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   374
        }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   375
    }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   376
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   377
    private float encode(float x, float a, float b, float w) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   378
        float r = 0;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   379
        if (x < a) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   380
            r = (x / a);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   381
        } else if (x > b) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   382
            r = 2 + ((x - b) / (w - b));
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   383
        } else if (x == a && x == b) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   384
            return 1.5f;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   385
        } else {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   386
            r = 1 + ((x - a) / (b - a));
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   387
        }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   388
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   389
        if (Float.isNaN(r)) {
25097
147ac5785a84 8016451: Scary messages emitted by build.tools.generatenimbus.PainterGenerator during build
prr
parents: 23010
diff changeset
   390
            if (debug) {
147ac5785a84 8016451: Scary messages emitted by build.tools.generatenimbus.PainterGenerator during build
prr
parents: 23010
diff changeset
   391
                System.err.println("[Error] Encountered NaN: encode(" + x + ", " + a + ", " + b + ", " + w + ")");
147ac5785a84 8016451: Scary messages emitted by build.tools.generatenimbus.PainterGenerator during build
prr
parents: 23010
diff changeset
   392
            }
3742
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   393
            return 0;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   394
        } else if (Float.isInfinite(r)) {
25097
147ac5785a84 8016451: Scary messages emitted by build.tools.generatenimbus.PainterGenerator during build
prr
parents: 23010
diff changeset
   395
            if (debug) {
147ac5785a84 8016451: Scary messages emitted by build.tools.generatenimbus.PainterGenerator during build
prr
parents: 23010
diff changeset
   396
                System.err.println("[Error] Encountered Infinity: encode(" + x + ", " + a + ", " + b + ", " + w + ")");
147ac5785a84 8016451: Scary messages emitted by build.tools.generatenimbus.PainterGenerator during build
prr
parents: 23010
diff changeset
   397
            }
3742
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   398
            return 0;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   399
        } else if (r < 0) {
25097
147ac5785a84 8016451: Scary messages emitted by build.tools.generatenimbus.PainterGenerator during build
prr
parents: 23010
diff changeset
   400
            if (debug) {
147ac5785a84 8016451: Scary messages emitted by build.tools.generatenimbus.PainterGenerator during build
prr
parents: 23010
diff changeset
   401
                System.err.println("[Error] encoded value was less than 0: encode(" + x + ", " + a + ", " + b + ", " + w + ")");
147ac5785a84 8016451: Scary messages emitted by build.tools.generatenimbus.PainterGenerator during build
prr
parents: 23010
diff changeset
   402
            }
3742
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   403
            return 0;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   404
        } else if (r > 3) {
25097
147ac5785a84 8016451: Scary messages emitted by build.tools.generatenimbus.PainterGenerator during build
prr
parents: 23010
diff changeset
   405
            if (debug) {
147ac5785a84 8016451: Scary messages emitted by build.tools.generatenimbus.PainterGenerator during build
prr
parents: 23010
diff changeset
   406
                System.err.println("[Error] encoded value was greater than 3: encode(" + x + ", " + a + ", " + b + ", " + w + ")");
147ac5785a84 8016451: Scary messages emitted by build.tools.generatenimbus.PainterGenerator during build
prr
parents: 23010
diff changeset
   407
            }
3742
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   408
            return 3;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   409
        } else {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   410
            return r;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   411
        }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   412
    }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   413
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   414
    private String writeDecodeX(float encodedX) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   415
        return "decodeX(" + encodedX + "f)";
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   416
    }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   417
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   418
    private String writeDecodeY(float encodedY) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   419
        return "decodeY(" + encodedY + "f)";
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   420
    }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   421
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   422
    /**
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   423
     *
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   424
     * @param ex encoded x value
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   425
     * @param x unencoded x value
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   426
     * @param cpx unencoded cpx value
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   427
     * @return
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   428
     */
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   429
    private static String writeDecodeBezierX(double ex, double x, double cpx) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   430
        return "decodeAnchorX(" + ex + "f, " + (cpx - x) + "f)";
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   431
    }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   432
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   433
    /**
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   434
     *
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   435
     * @param ey encoded y value
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   436
     * @param y unencoded y value
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   437
     * @param cpy unencoded cpy value
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   438
     * @return
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   439
     */
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   440
    private static String writeDecodeBezierY(double ey, double y, double cpy) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   441
        return "decodeAnchorY(" + ey + "f, " + (cpy - y) + "f)";
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   442
    }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   443
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   444
    private String encodeMatte(Matte m) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   445
        String declaration = m.getDeclaration();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   446
        String variableName = colors.get(declaration);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   447
        if (variableName == null) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   448
            variableName = "color" + colorCounter++;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   449
            colors.put(declaration, variableName);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   450
            colorCode.append(String.format("    private Color %s = %s;\n",
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   451
                                           variableName, declaration));
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   452
        }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   453
        // handle component colors
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   454
        if (m.getComponentPropertyName() != null) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   455
            ComponentColor cc = m.createComponentColor(variableName);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   456
            int index = componentColors.indexOf(cc);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   457
            if (index == -1) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   458
                index = componentColors.size();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   459
                componentColors.add(cc);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   460
            }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   461
            return "(Color)componentColors[" + index + "]";
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   462
        } else {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   463
            return variableName;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   464
        }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   465
    }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   466
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   467
    private String encodeGradient(Shape ps, Gradient g) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   468
        StringBuilder b = new StringBuilder();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   469
        float x1 = (float)ps.getPaintX1();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   470
        float y1 = (float)ps.getPaintY1();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   471
        float x2 = (float)ps.getPaintX2();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   472
        float y2 = (float)ps.getPaintY2();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   473
        b.append("        return decodeGradient((");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   474
        b.append(x1);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   475
        b.append("f * w) + x, (");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   476
        b.append(y1);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   477
        b.append("f * h) + y, (");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   478
        b.append(x2);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   479
        b.append("f * w) + x, (");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   480
        b.append(y2);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   481
        b.append("f * h) + y,\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   482
        encodeGradientColorsAndFractions(g,b);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   483
        b.append(");");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   484
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   485
        String methodBody = b.toString();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   486
        String methodName = methods.get(methodBody);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   487
        if (methodName == null) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   488
            methodName = "decodeGradient" + gradientCounter++;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   489
            gradientsCode.append("    private Paint ").append(methodName).append("(Shape s) {\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   490
            gradientsCode.append("        Rectangle2D bounds = s.getBounds2D();\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   491
            gradientsCode.append("        float x = (float)bounds.getX();\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   492
            gradientsCode.append("        float y = (float)bounds.getY();\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   493
            gradientsCode.append("        float w = (float)bounds.getWidth();\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   494
            gradientsCode.append("        float h = (float)bounds.getHeight();\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   495
            gradientsCode.append(methodBody);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   496
            gradientsCode.append("\n    }\n\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   497
            methods.put(methodBody, methodName);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   498
        }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   499
        return methodName;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   500
    }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   501
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   502
    /**
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   503
     * Takes a abstract gradient and creates the code for the fractions float
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   504
     * array and the colors array that can be used in the constructors of linear
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   505
     * and radial gradients.
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   506
     *
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   507
     * @param g The abstract gradient to get stops from
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   508
     * @param b Append code string of the form "new float[]{...},
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   509
     *          new Color[]{...}" to this StringBuilder
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   510
     */
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   511
    private void encodeGradientColorsAndFractions(AbstractGradient g,
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   512
                                                    StringBuilder b) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   513
        List<GradientStop> stops = g.getStops();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   514
        // there are stops.size() number of main stops. Between each is a
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   515
        // fractional stop. Thus, there are: stops.size() + stops.size() - 1
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   516
        // number of fractions and colors.
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   517
        float[] fractions = new float[stops.size() + stops.size() - 1];
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   518
        String[] colors = new String[fractions.length];
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   519
        //for each stop, create the stop and it's associated fraction
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   520
        int index = 0; // the index into fractions and colors
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   521
        for (int i = 0; i < stops.size(); i++) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   522
            GradientStop s = stops.get(i);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   523
            //copy over the stop's data
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   524
            colors[index] = encodeMatte(s.getColor());
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   525
            fractions[index] = s.getPosition();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   526
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   527
            //If this isn't the last stop, then add in the fraction
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   528
            if (index < fractions.length - 1) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   529
                float f1 = s.getPosition();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   530
                float f2 = stops.get(i + 1).getPosition();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   531
                index++;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   532
                fractions[index] = f1 + (f2 - f1) * s.getMidpoint();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   533
                colors[index] = "decodeColor("+
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   534
                        colors[index - 1]+","+
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   535
                        encodeMatte(stops.get(i + 1).getColor())+",0.5f)";
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   536
            }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   537
            index++;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   538
        }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   539
        // Check boundry conditions
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   540
        for (int i = 1; i < fractions.length; i++) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   541
            //to avoid an error with LinearGradientPaint where two fractions
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   542
            //are identical, bump up the fraction value by a miniscule amount
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   543
            //if it is identical to the previous one
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   544
            //NOTE: The <= is critical because the previous value may already
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   545
            //have been bumped up
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   546
            if (fractions[i] <= fractions[i - 1]) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   547
                fractions[i] = fractions[i - 1] + .000001f;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   548
            }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   549
        }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   550
        //another boundary condition where multiple stops are all at the end. The
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   551
        //previous loop bumped all but one of these past 1.0, which is bad.
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   552
        //so remove any fractions (and their colors!) that are beyond 1.0
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   553
        int outOfBoundsIndex = -1;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   554
        for (int i = 0; i < fractions.length; i++) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   555
            if (fractions[i] > 1) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   556
                outOfBoundsIndex = i;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   557
                break;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   558
            }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   559
        }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   560
        if (outOfBoundsIndex >= 0) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   561
            float[] f = fractions;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   562
            String[] c = colors;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   563
            fractions = new float[outOfBoundsIndex];
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   564
            colors = new String[outOfBoundsIndex];
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   565
            System.arraycopy(f, 0, fractions, 0, outOfBoundsIndex);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   566
            System.arraycopy(c, 0, colors, 0, outOfBoundsIndex);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   567
        }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   568
        // build string
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   569
        b.append("                new float[] { ");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   570
        for (int i = 0; i < fractions.length; i++) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   571
            if (i>0)b.append(',');
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   572
            b.append(fractions[i]);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   573
            b.append('f');
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   574
        }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   575
        b.append(" },\n                new Color[] { ");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   576
        for (int i = 0; i < colors.length; i++) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   577
            if (i>0) b.append(",\n                            ");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   578
            b.append(colors[i]);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   579
        }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   580
        b.append("}");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   581
    }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   582
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   583
    private String encodeRadial(Shape ps, RadialGradient g) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   584
        float centerX1 = (float)ps.getPaintX1();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   585
        float centerY1 = (float)ps.getPaintY1();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   586
        float x2 = (float)ps.getPaintX2();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   587
        float y2 = (float)ps.getPaintY2();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   588
        float radius = (float)Point2D.distance(centerX1, centerY1, x2, y2);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   589
        StringBuilder b = new StringBuilder();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   590
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   591
        b.append("        return decodeRadialGradient((");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   592
        b.append(centerX1);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   593
        b.append("f * w) + x, (");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   594
        b.append(centerY1);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   595
        b.append("f * h) + y, ");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   596
        b.append(radius);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   597
        b.append("f,\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   598
        encodeGradientColorsAndFractions(g,b);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   599
        b.append(");");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   600
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   601
        String methodBody = b.toString();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   602
        String methodName = methods.get(methodBody);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   603
        if (methodName == null) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   604
            methodName = "decodeRadial" + radialCounter++;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   605
            gradientsCode.append("    private Paint ").append(methodName).append("(Shape s) {\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   606
            gradientsCode.append("        Rectangle2D bounds = s.getBounds2D();\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   607
            gradientsCode.append("        float x = (float)bounds.getX();\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   608
            gradientsCode.append("        float y = (float)bounds.getY();\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   609
            gradientsCode.append("        float w = (float)bounds.getWidth();\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   610
            gradientsCode.append("        float h = (float)bounds.getHeight();\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   611
            gradientsCode.append(methodBody);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   612
            gradientsCode.append("\n    }\n\n");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   613
            methods.put(methodBody, methodName);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   614
        }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   615
        return methodName;
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   616
    }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   617
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   618
    //note that this method is not thread-safe. In fact, none of this class is.
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   619
    public static void writePainter(UIRegion r, String painterName) {
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   620
        //Need only write out the stuff for this region, don't need to worry about subregions
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   621
        //since this method will be called for each of those (and they go in their own file, anyway).
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   622
        //The only subregion that we compound into this is the one for icons.
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   623
        PainterGenerator gen = new PainterGenerator(r);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   624
        System.out.println("Generating source file: " + painterName + ".java");
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   625
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   626
        Map<String, String> variables = Generator.getVariables();
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   627
        variables.put("PAINTER_NAME", painterName);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   628
        variables.put("STATIC_DECL", gen.stateTypeCode.toString());
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   629
        variables.put("COLORS_DECL", gen.colorCode.toString());
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   630
        variables.put("DO_PAINT_SWITCH_BODY", gen.switchCode.toString());
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   631
        variables.put("PAINTING_DECL", gen.paintingCode.toString());
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   632
        variables.put("GET_EXTENDED_CACHE_KEYS", gen.getExtendedCacheKeysCode.toString());
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   633
        variables.put("SHAPES_DECL", gen.shapesCode.toString());
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   634
        variables.put("GRADIENTS_DECL", gen.gradientsCode.toString());
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   635
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   636
        Generator.writeSrcFile("PainterImpl", variables, painterName);
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   637
    }
5e1b8bc3cb1a 6844267: Nimbus generator depends on JIBX
peterz
parents:
diff changeset
   638
}