1 | package org.expeditee.agents;
|
---|
2 |
|
---|
3 | import java.util.Collection;
|
---|
4 |
|
---|
5 | import org.expeditee.gui.Frame;
|
---|
6 | import org.expeditee.gui.FrameIO;
|
---|
7 | import org.expeditee.gui.FrameKeyboardActions;
|
---|
8 | import org.expeditee.gui.Vector;
|
---|
9 | import org.expeditee.items.Item;
|
---|
10 | import org.expeditee.items.Line;
|
---|
11 | import org.expeditee.items.UserAppliedPermission;
|
---|
12 |
|
---|
13 | public class ScaleFrameset extends DefaultAgent {
|
---|
14 | private int _firstFrame = 1;
|
---|
15 |
|
---|
16 | private float _scale = 1F;
|
---|
17 |
|
---|
18 | private int _maxFrame = Integer.MAX_VALUE;
|
---|
19 |
|
---|
20 | public ScaleFrameset(float scale, int firstFrame, int maxFrame) {
|
---|
21 | super();
|
---|
22 | _firstFrame = firstFrame;
|
---|
23 | _maxFrame = maxFrame;
|
---|
24 | _scale = scale;
|
---|
25 | }
|
---|
26 |
|
---|
27 | public ScaleFrameset(float scale) {
|
---|
28 | this(scale, 1, Integer.MAX_VALUE);
|
---|
29 | }
|
---|
30 |
|
---|
31 | @Override
|
---|
32 | protected Frame process(Frame frame) {
|
---|
33 | String framesetName = frame.getFramesetName();
|
---|
34 |
|
---|
35 | _maxFrame = Math.min(FrameIO.getLastNumber(framesetName), _maxFrame);
|
---|
36 |
|
---|
37 | // Scale each of the frames
|
---|
38 | for (int i = _firstFrame; i <= _maxFrame; i++) {
|
---|
39 | scaleFrame(FrameIO.LoadFrame(framesetName + i), _scale);
|
---|
40 | }
|
---|
41 | // TODO fix this so it actually works properly!!
|
---|
42 | // TODO figure out why it doesnt repaint correctly sometimes
|
---|
43 |
|
---|
44 | // TODO make this thread safe!
|
---|
45 | FrameKeyboardActions.Refresh();
|
---|
46 |
|
---|
47 | return null;
|
---|
48 | }
|
---|
49 |
|
---|
50 | public static void scaleFrame(Frame frame, float scaleFactor) {
|
---|
51 |
|
---|
52 | if (frame == null) {
|
---|
53 | return;
|
---|
54 | }
|
---|
55 |
|
---|
56 | for (Vector v : frame.getVectors()) {
|
---|
57 | v.Source.scale(scaleFactor, 0, 0);
|
---|
58 | }
|
---|
59 |
|
---|
60 | Collection<Item> items = frame.getVisibleItems();
|
---|
61 |
|
---|
62 | for (Item item : items) {
|
---|
63 | // This line is only needed for circles!!
|
---|
64 | // Need to really fix up the way this works!!
|
---|
65 | if (item.hasEnclosures())
|
---|
66 | continue;
|
---|
67 | if (!item.hasPermission(UserAppliedPermission.full))
|
---|
68 | continue;
|
---|
69 | item.invalidateAll();
|
---|
70 | if (!(item instanceof Line)) {
|
---|
71 | item.scale(scaleFactor, 0, 0);
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 | for (Item item : items) {
|
---|
76 | if (!item.hasPermission(UserAppliedPermission.full))
|
---|
77 | continue;
|
---|
78 | // if (!(item instanceof Line))
|
---|
79 | item.updatePolygon();
|
---|
80 |
|
---|
81 | if (item instanceof Line) {
|
---|
82 | ((Line) item).refreshStroke(item.getThickness());
|
---|
83 | }
|
---|
84 |
|
---|
85 | item.invalidateAll();
|
---|
86 | }
|
---|
87 | }
|
---|
88 | }
|
---|