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

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

Reimplementation of the functionality that limits a text item to one line by reducing font size. The user must now specify inject a width property (eg Width: 300) and inject the property 'SingleLineOnly: true' to cause the functionality to happen. This new version of the functionality also now works with pasting large amounts of content rather than adding a single character at the time. Also, this new version dynamically returns to the larger font size as the length of the text item decreases.

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