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 | import java.awt.image.BufferedImage; |
22 | import java.util.ArrayList; |
23 | import java.util.List; |
24 | |
25 | public class CompoundHiliteAction implements HiliteAction |
26 | { |
27 | public boolean addAction(DrawingAction action) |
28 | { |
29 | if (action instanceof HiliteAction) |
30 | { |
31 | _actions.add((HiliteAction) action); |
32 | Rectangle.union(_area, action.getActionArea(), _area); |
33 | return true; |
34 | } |
35 | else |
36 | { |
37 | return false; |
38 | } |
39 | } |
40 | |
41 | public void clear() |
42 | { |
43 | _actions.clear(); |
44 | _area.setBounds(0, 0, 0, 0); |
45 | } |
46 | |
47 | public boolean isEmpty() |
48 | { |
49 | return _actions.isEmpty(); |
50 | } |
51 | |
52 | public void perform(Graphics2D graf) |
53 | { |
54 | graf.setStroke(_stroke); |
55 | graf.setColor(_color); |
56 | for (HiliteAction action: _actions) |
57 | { |
58 | action.perform(graf); |
59 | } |
60 | } |
61 | |
62 | public void perform(BufferedImage image) |
63 | { |
64 | Graphics2D graf = image.createGraphics(); |
65 | perform(graf); |
66 | graf.dispose(); |
67 | } |
68 | |
69 | public void setHiliteStroke(BasicStroke stroke) |
70 | { |
71 | _stroke = stroke; |
72 | } |
73 | |
74 | public void setHiliteColor(Color color) |
75 | { |
76 | _color = color; |
77 | } |
78 | |
79 | public Rectangle getActionArea() |
80 | { |
81 | return _area; |
82 | } |
83 | |
84 | private Rectangle _area = new Rectangle(); |
85 | private List<HiliteAction> _actions = new ArrayList<HiliteAction>(); |
86 | transient private BasicStroke _stroke; |
87 | transient private Color _color; |
88 | } |