1 /*
2 * Copyright (c) 2003-2008 by Cosylab d. d.
3 *
4 * This file is part of CosyBeans-Common.
5 *
6 * CosyBeans-Common is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * CosyBeans-Common is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with CosyBeans-Common. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 package com.cosylab.gui.components.ledder;
21 import java.awt.Paint;
22 import java.awt.PaintContext;
23 import java.awt.Rectangle;
24 import java.awt.RenderingHints;
25 import java.awt.geom.AffineTransform;
26 import java.awt.geom.Point2D;
27 import java.awt.geom.Rectangle2D;
28 import java.awt.image.ColorModel;
29
30 /**
31 * This is the implementation of Paint interface tha provides access to
32 * LedPaintContext and is used to render LED icons.
33 *
34 * @author <a href="mailto:ales.pucelj@cosylab.com">Ales Pucelj</a>
35 * @version $id$
36 */
37 public class LedPaint implements Paint {
38
39 // Parameters for LedPaintContext.
40 private LedPaintParameters params;
41 private int centerX;
42 private int centerY;
43
44 /**
45 * Default constructor for LedPaint.
46 *
47 * @param parameters LedPaintParameters
48 */
49 public LedPaint(LedPaintParameters parameters) {
50 this(parameters,parameters.radius+1,parameters.radius+1);
51 }
52
53 /**
54 * Default constructor for LedPaint.
55 *
56 * @param parameters LedPaintParameters
57 */
58 public LedPaint(LedPaintParameters parameters, int centerX, int centerY ) {
59 if (parameters == null) {
60 throw new NullPointerException("Cannot create LedPaint with null parameters");
61 }
62
63 params = parameters;
64 this.centerX=centerX;
65 this.centerY=centerY;
66 }
67
68 /**
69 * @param cm ColorModel
70 * @param deviceBounds Rectangle
71 * @param userBounds Rectangle2D
72 * @param xform AffineTransform
73 * @param hints RenderingHints
74 * @return PaintContext
75 * @see Paint#createContext(ColorModel, Rectangle, Rectangle2D, AffineTransform, RenderingHints)
76 */
77 public PaintContext createContext(
78 ColorModel cm,
79 Rectangle deviceBounds,
80 Rectangle2D userBounds,
81 AffineTransform xform,
82 RenderingHints hints) {
83
84 Point2D center = new Point2D.Double(centerX, centerY);
85
86 Point2D p = xform.transform(center, null);
87
88 return new LedPaintContext((int) p.getX(), (int) p.getY(), params);
89 }
90
91 /**
92 * Always returns OPAQUE.
93 *
94 * @return int
95 * @see java.awt.Transparency#getTransparency()
96 */
97 public int getTransparency() {
98 return OPAQUE;
99 }
100
101 public void setCenter(int x, int y){
102 centerX = x;
103 centerY = y;
104 }
105 }