source: trunk/src/org/expeditee/agents/ScaleFrameset.java@ 1102

Last change on this file since 1102 was 1102, checked in by davidb, 6 years ago

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

File size: 3.0 KB
Line 
1/**
2 * ScaleFrameset.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.agents;
20
21import java.util.Collection;
22
23import org.expeditee.gio.gesture.StandardGestureActions;
24import org.expeditee.gui.Frame;
25import org.expeditee.gui.FrameIO;
26import org.expeditee.gui.Vector;
27import org.expeditee.items.Item;
28import org.expeditee.items.Line;
29import org.expeditee.items.Text;
30import org.expeditee.items.UserAppliedPermission;
31
32public class ScaleFrameset extends DefaultAgent {
33 private int _firstFrame = 1;
34
35 private float _scale = 1F;
36
37 private int _maxFrame = Integer.MAX_VALUE;
38
39 public ScaleFrameset(float scale, int firstFrame, int maxFrame) {
40 super();
41 _firstFrame = firstFrame;
42 _maxFrame = maxFrame;
43 _scale = scale;
44 }
45
46 public ScaleFrameset(float scale) {
47 this(scale, 1, Integer.MAX_VALUE);
48 }
49
50 @Override
51 protected Frame process(Frame frame) {
52 String framesetName = frame.getFramesetName();
53
54 _maxFrame = Math.min(FrameIO.getLastNumber(framesetName), _maxFrame);
55
56 // Scale each of the frames
57 for (int i = _firstFrame; i <= _maxFrame; i++) {
58 scaleFrame(FrameIO.LoadFrame(framesetName + i), _scale);
59 }
60 // TODO fix this so it actually works properly!!
61 // TODO figure out why it doesnt repaint correctly sometimes
62
63 // TODO make this thread safe!
64 StandardGestureActions.Refresh();
65
66 return null;
67 }
68
69 public static void scaleFrame(Frame frame, float scaleFactor) {
70
71 if (frame == null) {
72 return;
73 }
74
75 for (Vector v : frame.getVectors()) {
76 v.Source.scale(scaleFactor, 0, 0);
77 }
78
79 Collection<Item> items = frame.getVisibleItems();
80
81 for(Item item : items) {
82 if(item instanceof Text && item.getSize() <= Text.MINIMUM_FONT_SIZE && scaleFactor < 1) {
83 return;
84 }
85 }
86
87 for (Item item : items) {
88 // This line is only needed for circles!!
89 // Need to really fix up the way this works!!
90 if (item.hasEnclosures())
91 continue;
92 if (!item.hasPermission(UserAppliedPermission.full))
93 continue;
94 item.invalidateAll();
95 if (!(item instanceof Line)) {
96 item.scale(scaleFactor, 0, 0);
97 }
98 }
99
100 for (Item item : items) {
101 if (!item.hasPermission(UserAppliedPermission.full))
102 continue;
103 // if (!(item instanceof Line))
104 item.invalidateBounds();
105
106 if (item instanceof Line) {
107 ((Line) item).refreshStroke(item.getThickness());
108 }
109
110 item.invalidateAll();
111 }
112 }
113}
Note: See TracBrowser for help on using the repository browser.