comparison src/share/classes/javax/swing/plaf/nimbus/PainterImpl.template @ 1173:7f45fcc04f8e

6591875: Nimbus Swing Look and Feel Reviewed-by: jasper, ohair
author peterz
date Sat, 25 Apr 2009 21:17:50 +0400
parents
children 743021a4938c
comparison
equal deleted inserted replaced
-1:000000000000 0:0bb807f5e5a1
1 /*
2 * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25 package ${PACKAGE};
26
27 import java.awt.*;
28 import java.awt.geom.*;
29 import java.awt.image.*;
30 import javax.swing.*;
31 import javax.swing.Painter;
32
33
34 public final class ${PAINTER_NAME} extends AbstractRegionPainter {
35 //package private integers representing the available states that
36 //this painter will paint. These are used when creating a new instance
37 //of ${PAINTER_NAME} to determine which region/state is being painted
38 //by that instance.
39 ${STATIC_DECL}
40
41 private int state; //refers to one of the static final ints above
42 private PaintContext ctx;
43
44 //the following 4 variables are reused during the painting code of the layers
45 private Path2D path = new Path2D.Float();
46 private Rectangle2D rect = new Rectangle2D.Float(0, 0, 0, 0);
47 private RoundRectangle2D roundRect = new RoundRectangle2D.Float(0, 0, 0, 0, 0, 0);
48 private Ellipse2D ellipse = new Ellipse2D.Float(0, 0, 0, 0);
49
50 //All Colors used for painting are stored here. Ideally, only those colors being used
51 //by a particular instance of ${PAINTER_NAME} would be created. For the moment at least,
52 //however, all are created for each instance.
53 ${COLORS_DECL}
54
55 //Array of current component colors, updated in each paint call
56 private Object[] componentColors;
57
58 public ${PAINTER_NAME}(PaintContext ctx, int state) {
59 super();
60 this.state = state;
61 this.ctx = ctx;
62 }
63
64 @Override
65 protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object[] extendedCacheKeys) {
66 //populate componentColors array with colors calculated in getExtendedCacheKeys call
67 componentColors = extendedCacheKeys;
68 //generate this entire method. Each state/bg/fg/border combo that has
69 //been painted gets its own KEY and paint method.
70 switch(state) {
71 ${DO_PAINT_SWITCH_BODY}
72 }
73 }
74
75 ${GET_EXTENDED_CACHE_KEYS}
76
77 @Override
78 protected final PaintContext getPaintContext() {
79 return ctx;
80 }
81
82 ${PAINTING_DECL}
83
84 ${SHAPES_DECL}
85
86 ${GRADIENTS_DECL}
87 }