1 | // Copyright 2004-2007 Jean-Francois Poilpret |
2 | // |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | // you may not use this file except in compliance with the License. |
5 | // You may obtain a copy of the License at |
6 | // |
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | // |
9 | // Unless required by applicable law or agreed to in writing, software |
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | // See the License for the specific language governing permissions and |
13 | // limitations under the License. |
14 | |
15 | package net.sourceforge.hiveboard.drawing; |
16 | |
17 | import java.awt.BasicStroke; |
18 | import java.awt.Color; |
19 | import java.awt.Graphics2D; |
20 | import java.awt.Rectangle; |
21 | |
22 | public class OvalDrawingAction |
23 | extends AbstractGraphicsDrawingAction |
24 | { |
25 | public OvalDrawingAction( int x1, int y1, int x2, int y2, |
26 | Color penColor, BasicStroke stroke) |
27 | { |
28 | _x = Math.min(x1, x2); |
29 | _width = Math.abs(x2 - x1); |
30 | _y = Math.min(y1, y2); |
31 | _height = Math.abs(y2 - y1); |
32 | _penColor = penColor; |
33 | _stroke = new StrokeHelper(stroke); |
34 | |
35 | int width = (int) (stroke.getLineWidth() * 2.0 + 1.0); |
36 | _area = new Rectangle( _x - width, |
37 | _y - width, |
38 | _x + _width + 2 * width, |
39 | _y + _height + 2 * width); |
40 | } |
41 | |
42 | @Override protected void preDraw(Graphics2D graf) |
43 | { |
44 | graf.setColor(_penColor); |
45 | graf.setStroke(_stroke.getStroke()); |
46 | } |
47 | |
48 | @Override protected void draw(Graphics2D graf) |
49 | { |
50 | graf.drawOval(_x, _y, _width, _height); |
51 | } |
52 | |
53 | final private int _x; |
54 | final private int _y; |
55 | final private int _width; |
56 | final private int _height; |
57 | final private Color _penColor; |
58 | final private StrokeHelper _stroke; |
59 | } |