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.Graphics2D; |
18 | import java.awt.Rectangle; |
19 | |
20 | abstract public class AbstractPenFreeDrawingAction extends AbstractGraphicsDrawingAction |
21 | { |
22 | protected AbstractPenFreeDrawingAction(int[] x, int[] y) |
23 | { |
24 | _x = x; |
25 | _y = y; |
26 | // Calculate area refreshed |
27 | int minX = Integer.MAX_VALUE; |
28 | int minY = Integer.MAX_VALUE; |
29 | int maxX = Integer.MIN_VALUE; |
30 | int maxY = Integer.MIN_VALUE; |
31 | for (int i = 0; i < _x.length; i++) |
32 | { |
33 | minX = Math.min(minX, _x[i]); |
34 | maxX = Math.max(maxX, _x[i]); |
35 | minY = Math.min(minY, _y[i]); |
36 | maxY = Math.max(maxY, _y[i]); |
37 | } |
38 | |
39 | _area = new Rectangle(minX, minY, maxX - minX, maxY - minY); |
40 | } |
41 | |
42 | @Override protected void draw(Graphics2D graf) |
43 | { |
44 | graf.drawPolyline(_x, _y, _x.length); |
45 | } |
46 | |
47 | final private int[] _x; |
48 | final private int[] _y; |
49 | } |