1 | /**
|
---|
2 | * DefaultFrameReader.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 |
|
---|
19 | package org.expeditee.io;
|
---|
20 |
|
---|
21 | import java.io.BufferedReader;
|
---|
22 | import java.io.FileInputStream;
|
---|
23 | import java.io.IOException;
|
---|
24 | import java.io.InputStreamReader;
|
---|
25 | import java.io.Reader;
|
---|
26 | import java.lang.reflect.Method;
|
---|
27 | import java.util.LinkedHashMap;
|
---|
28 | import java.util.List;
|
---|
29 | import java.util.LinkedList;
|
---|
30 |
|
---|
31 | import org.expeditee.core.Colour;
|
---|
32 | import org.expeditee.core.Font;
|
---|
33 | import org.expeditee.core.Point;
|
---|
34 | import org.expeditee.gui.Frame;
|
---|
35 | import org.expeditee.items.Constraint;
|
---|
36 | import org.expeditee.items.Dot;
|
---|
37 | import org.expeditee.items.DotType;
|
---|
38 | import org.expeditee.items.Item;
|
---|
39 | import org.expeditee.items.Justification;
|
---|
40 | import org.expeditee.items.Line;
|
---|
41 | import org.expeditee.items.PermissionPair;
|
---|
42 | import org.expeditee.items.Text;
|
---|
43 |
|
---|
44 | public abstract class DefaultFrameReader implements FrameReader {
|
---|
45 |
|
---|
46 | protected static LinkedHashMap<Character, Method> _ItemTags = null;
|
---|
47 |
|
---|
48 | protected static List<Character> _DelayedItemTags = null;
|
---|
49 |
|
---|
50 | protected static LinkedHashMap<Character, Method> _FrameTags = null;
|
---|
51 |
|
---|
52 | protected static Class[] pString = { String.class };
|
---|
53 | protected static Class[] pInt = { int.class };
|
---|
54 | protected static Class[] pIntO = { Integer.class };
|
---|
55 | protected static Class[] pFloat = { float.class };
|
---|
56 | protected static Class[] pFloatO = { Float.class };
|
---|
57 | protected static Class[] pDouble = { double.class };
|
---|
58 | protected static Class[] pColor = { Colour.class };
|
---|
59 | protected static Class[] pBool = { boolean.class };
|
---|
60 | protected static Class[] pFont = { Font.class };
|
---|
61 | protected static Class[] pPoint = { Point.class };
|
---|
62 | protected static Class[] pArrow = { float.class, double.class, double.class };
|
---|
63 | protected static Class[] pList = { List.class };
|
---|
64 | protected static Class[] pIntArray = { int[].class };
|
---|
65 | protected static Class[] pItem = { Item.class };
|
---|
66 | protected static Class[] pJustification = { Justification.class };
|
---|
67 | protected static Class[] pPermission = { PermissionPair.class };
|
---|
68 | protected static Class[] pDotType = { DotType.class };
|
---|
69 |
|
---|
70 | public DefaultFrameReader(){
|
---|
71 | if (_ItemTags != null && _FrameTags != null)
|
---|
72 | return;
|
---|
73 |
|
---|
74 | _ItemTags = new LinkedHashMap<Character, Method>();
|
---|
75 | _FrameTags = new LinkedHashMap<Character, Method>();
|
---|
76 | _DelayedItemTags = new LinkedList<Character>();
|
---|
77 |
|
---|
78 | try {
|
---|
79 | _FrameTags.put('A', Frame.class.getMethod("setName", pString));
|
---|
80 | _FrameTags.put('V', Frame.class.getMethod("setVersion", pInt));
|
---|
81 | _FrameTags
|
---|
82 | .put('p', Frame.class.getMethod("setPermission", pPermission));
|
---|
83 | _FrameTags.put('U', Frame.class.getMethod("setOwner", pString));
|
---|
84 | _FrameTags.put('D', Frame.class
|
---|
85 | .getMethod("setDateCreated", pString));
|
---|
86 | _FrameTags.put('M', Frame.class.getMethod("setLastModifyUser",
|
---|
87 | pString));
|
---|
88 | _FrameTags.put('d', Frame.class.getMethod("setLastModifyDate",
|
---|
89 | pString));
|
---|
90 | _FrameTags
|
---|
91 | .put('F', Frame.class.getMethod("setFrozenDate", pString));
|
---|
92 |
|
---|
93 | _FrameTags.put('O', Frame.class.getMethod("setForegroundColor",
|
---|
94 | pColor));
|
---|
95 | _FrameTags.put('B', Frame.class.getMethod("setBackgroundColor",
|
---|
96 | pColor));
|
---|
97 |
|
---|
98 | _ItemTags.put('S', Item.class.getMethod("setID", pInt));
|
---|
99 | _ItemTags.put('s', Item.class.getMethod("setDateCreated", pString));
|
---|
100 | _ItemTags.put('d', Item.class.getMethod("setColor", pColor));
|
---|
101 | _ItemTags.put('G', Item.class.getMethod("setBackgroundColor",
|
---|
102 | pColor));
|
---|
103 | _ItemTags.put('K', Item.class.getMethod("setBorderColor",
|
---|
104 | pColor));
|
---|
105 |
|
---|
106 | _ItemTags.put('R', Item.class.getMethod("setAnchorLeft", pIntO));
|
---|
107 | _ItemTags.put('H', Item.class.getMethod("setAnchorRight", pIntO));
|
---|
108 | _ItemTags.put('N', Item.class.getMethod("setAnchorTop", pIntO));
|
---|
109 | _ItemTags.put('I', Item.class.getMethod("setAnchorBottom", pIntO));
|
---|
110 |
|
---|
111 | _ItemTags.put('P', Item.class.getMethod("setPosition", pPoint));
|
---|
112 | _ItemTags.put('F', Item.class.getMethod("setLink", pString));
|
---|
113 | _ItemTags.put('J', Item.class.getMethod("setFormula", pString));
|
---|
114 |
|
---|
115 | _ItemTags.put('X', Item.class.getMethod("setActions", pList));
|
---|
116 | _ItemTags.put('x', Item.class.getMethod("setActionMark", pBool));
|
---|
117 | _ItemTags.put('U', Item.class.getMethod("setActionCursorEnter",
|
---|
118 | pList));
|
---|
119 | _ItemTags.put('V', Item.class.getMethod("setActionCursorLeave",
|
---|
120 | pList));
|
---|
121 | _ItemTags.put('W', Item.class.getMethod("setActionEnterFrame",
|
---|
122 | pList));
|
---|
123 | _ItemTags.put('Y', Item.class.getMethod("setActionLeaveFrame",
|
---|
124 | pList));
|
---|
125 | _ItemTags.put('D', Item.class.getMethod("addToData", pString));
|
---|
126 | _ItemTags.put('u', Item.class.getMethod("setHighlight", pBool));
|
---|
127 | _ItemTags.put('e', Item.class.getMethod("setFillColor", pColor));
|
---|
128 | _ItemTags.put('E', Item.class.getMethod("setGradientColor", pColor));
|
---|
129 | _ItemTags.put('Q', Item.class.getMethod("setGradientAngle", pDouble));
|
---|
130 |
|
---|
131 | _ItemTags.put('i', Item.class.getMethod("setFillPattern", pString));
|
---|
132 | _ItemTags.put('o', Item.class.getMethod("setOwner", pString));
|
---|
133 | _ItemTags.put('n', Item.class.getMethod("setLinkMark", pBool));
|
---|
134 | _ItemTags
|
---|
135 | .put('q', Item.class.getMethod("setLinkFrameset", pString));
|
---|
136 | _ItemTags
|
---|
137 | .put('y', Item.class.getMethod("setLinkTemplate", pString));
|
---|
138 | _ItemTags.put('g', Item.class.getMethod("setLinePattern", pIntArray));
|
---|
139 |
|
---|
140 | _ItemTags.put('j', Item.class.getMethod("setArrow", pArrow));
|
---|
141 |
|
---|
142 | _ItemTags.put('v', Dot.class.getMethod("setDotType", pDotType));
|
---|
143 | _ItemTags.put('z', Dot.class.getMethod("setFilled", pBool));
|
---|
144 |
|
---|
145 | _ItemTags.put('f', Text.class.getMethod("setFont", pFont));
|
---|
146 | _ItemTags.put('t', Text.class.getMethod("setSpacing", pFloat));
|
---|
147 | _ItemTags.put('T', Text.class.getMethod("appendLine", pString));
|
---|
148 | _ItemTags.put('a', Text.class.getMethod("setWordSpacing", pInt));
|
---|
149 | _ItemTags.put('b', Text.class.getMethod("setLetterSpacing", pFloat));
|
---|
150 | _ItemTags.put('m', Text.class.getMethod("setInitialSpacing", pFloat));
|
---|
151 | _ItemTags.put('w', Text.class.getMethod("setWidth", pIntO));
|
---|
152 | _ItemTags.put('k', Text.class.getMethod("setJustification", pJustification));
|
---|
153 | _ItemTags.put('r', Text.class.getMethod("setAutoWrap", pBool));
|
---|
154 |
|
---|
155 | _ItemTags.put('h', Item.class.getMethod("setThickness", pFloat));
|
---|
156 | _ItemTags.put('l', Item.class.getMethod("setLineIDs", pString));
|
---|
157 | _ItemTags.put('c', Item.class.getMethod("setConstraintIDs", pString));
|
---|
158 |
|
---|
159 | _ItemTags.put('A', Item.class.getMethod("setTooltip", pString));
|
---|
160 | _ItemTags.put('B', Item.class.getMethod("setLinkHistory", pBool));
|
---|
161 |
|
---|
162 | _ItemTags.put('p', Item.class.getMethod("setPermission", pPermission));
|
---|
163 |
|
---|
164 | // Lines and constraints are created differently
|
---|
165 | _ItemTags.put('L', Line.class.getMethod("setStartItem", pItem));
|
---|
166 | _ItemTags.put('C', Constraint.class.getMethod("getID", (Class[]) null));
|
---|
167 |
|
---|
168 | _ItemTags.put('[', Item.class.getMethod("setMagnetizedItemLeft", pInt));
|
---|
169 | _DelayedItemTags.add('[');
|
---|
170 | _ItemTags.put(']', Item.class.getMethod("setMagnetizedItemRight", pInt));
|
---|
171 | _DelayedItemTags.add(']');
|
---|
172 | _ItemTags.put('^', Item.class.getMethod("setMagnetizedItemTop", pInt));
|
---|
173 | _DelayedItemTags.add('^');
|
---|
174 | _ItemTags.put('_', Item.class.getMethod("setMagnetizedItemBottom", pInt));
|
---|
175 | _DelayedItemTags.add('_');
|
---|
176 | } catch (Exception e) {
|
---|
177 | e.printStackTrace();
|
---|
178 | }
|
---|
179 |
|
---|
180 | }
|
---|
181 |
|
---|
182 | public Frame readFrame(String fullPath) throws IOException {
|
---|
183 | Reader in = new InputStreamReader(new FileInputStream(fullPath), "UTF-8");
|
---|
184 | return readFrame(new BufferedReader(in));
|
---|
185 | }
|
---|
186 | }
|
---|