source: trunk/src/org/expeditee/io/DefaultFrameReader.java@ 1369

Last change on this file since 1369 was 1369, checked in by bln4, 5 years ago

MaxWidth on text items is now a thing. Use this on text boxes in authentication frameset.

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