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

Last change on this file since 1513 was 1513, checked in by bnemhaus, 4 years ago

You now have the ability to anchor Items to the center of the frame. AnchorCenterX: 0 will anchor a item directly to the vertical center of the frame. AnchorCenterY: 0 to the horizontal center of the frame. Negative numbers go left/up from the center, positive numbers right/down.

More work to come to deal with connected items such as rectangles made up on connected dots.

File size: 11.3 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.PermissionTriple;
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 = { PermissionTriple.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 /// C H I J L N P Q R S W X Y Z
86 /// a b c f g h i j l m n o q r s t u v w x y z
87 // Standard frame tags
88 _FrameTags.put('A', Frame.class.getMethod("setName", pString));
89 _FrameTags.put('V', Frame.class.getMethod("setVersion", pInt));
90 _FrameTags.put('p', Frame.class.getMethod("setPermission", pPermission));
91 _FrameTags.put('U', Frame.class.getMethod("setOwner", pString));
92 _FrameTags.put('D', Frame.class.getMethod("setDateCreated", pString));
93 _FrameTags.put('M', Frame.class.getMethod("setLastModifyUser", pString));
94 _FrameTags.put('d', Frame.class.getMethod("setLastModifyDate", pString));
95 _FrameTags.put('F', Frame.class.getMethod("setFrozenDate", pString));
96 _FrameTags.put('O', Frame.class.getMethod("setForegroundColor", pColor));
97 _FrameTags.put('B', Frame.class.getMethod("setBackgroundColor", pColor));
98 _FrameTags.put('T', Frame.class.getMethod("addToData", pString));
99 _FrameTags.put('G', Frame.class.getMethod("setGroup", pString));
100
101 // Encryption frame tags
102 _FrameTags.put('K', Frame.class.getMethod("setFrameEncryptionLabelOnLoad", pString));
103 _FrameTags.put('E', Frame.class.getMethod("setFrameEncryptionPermission", pEncPermission));
104 _FrameTags.put('k', Frame.class.getMethod("setHomogeneousEncryptionLabelOnLoad", pString));
105 _FrameTags.put('e', Frame.class.getMethod("setEncryptionPermission", pEncPermission));
106 _FrameTags.put('a', Frame.class.getMethod("addToHetrogeneousFrameOwnerLabels", pString));
107
108 // Note: As of 26/11/18 there are no unused letter item tags. Use other characters.
109 _ItemTags.put(DefaultFrameWriter.TYPE_AND_ID, Item.class.getMethod("setID", pInt));
110 _ItemTags.put(DefaultFrameWriter.DATE_CREATED, Item.class.getMethod("setDateCreated", pString));
111 _ItemTags.put(DefaultFrameWriter.COLOR, Item.class.getMethod("setColor", pColor));
112 _ItemTags.put(DefaultFrameWriter.BACKGROUND_COLOR, Item.class.getMethod("setBackgroundColor",
113 pColor));
114 _ItemTags.put(DefaultFrameWriter.BORDER_COLOR, Item.class.getMethod("setBorderColor",
115 pColor));
116
117 _ItemTags.put(DefaultFrameWriter.ANCHOR_LEFT, Item.class.getMethod("setAnchorLeft", pIntO));
118 _ItemTags.put(DefaultFrameWriter.ANCHOR_RIGHT, Item.class.getMethod("setAnchorRight", pIntO));
119 _ItemTags.put(DefaultFrameWriter.ANCHOR_TOP, Item.class.getMethod("setAnchorTop", pIntO));
120 _ItemTags.put(DefaultFrameWriter.ANCHOR_BOTTOM, Item.class.getMethod("setAnchorBottom", pIntO));
121
122 _ItemTags.put(DefaultFrameWriter.POSITION, Item.class.getMethod("setPosition", pPoint));
123 _ItemTags.put(DefaultFrameWriter.LINK, Item.class.getMethod("setLink", pString));
124 _ItemTags.put(DefaultFrameWriter.FORMULA, Item.class.getMethod("setFormula", pString));
125
126 _ItemTags.put(DefaultFrameWriter.ACTION, Item.class.getMethod("setActions", pList));
127 _ItemTags.put(DefaultFrameWriter.ACTION_MARK, Item.class.getMethod("setActionMark", pBool));
128 _ItemTags.put(DefaultFrameWriter.ACTION_CURSOR_ENTER, Item.class.getMethod("setActionCursorEnter",
129 pList));
130 _ItemTags.put(DefaultFrameWriter.ACTION_CURSOR_LEAVE, Item.class.getMethod("setActionCursorLeave",
131 pList));
132 _ItemTags.put(DefaultFrameWriter.ACTION_ENTER_FRAME, Item.class.getMethod("setActionEnterFrame",
133 pList));
134 _ItemTags.put(DefaultFrameWriter.ACTION_LEAVE_FRAME, Item.class.getMethod("setActionLeaveFrame",
135 pList));
136 _ItemTags.put(DefaultFrameWriter.DATA, Item.class.getMethod("addToData", pString));
137 _ItemTags.put(DefaultFrameWriter.HIGHLIGHT, Item.class.getMethod("setHighlight", pBool));
138 _ItemTags.put(DefaultFrameWriter.FILL_COLOR, Item.class.getMethod("setFillColor", pColor));
139 _ItemTags.put(DefaultFrameWriter.GRADIENT_COLOR, Item.class.getMethod("setGradientColor", pColor));
140 _ItemTags.put(DefaultFrameWriter.GRADIENT_ANGLE, Item.class.getMethod("setGradientAngle", pDouble));
141
142 _ItemTags.put(DefaultFrameWriter.FILL_PATTERN, Item.class.getMethod("setFillPattern", pString));
143 _ItemTags.put(DefaultFrameWriter.OWNER, Item.class.getMethod("setOwner", pString));
144 _ItemTags.put(DefaultFrameWriter.LINK_MARK, Item.class.getMethod("setLinkMark", pBool));
145 _ItemTags
146 .put(DefaultFrameWriter.LINK_FRAMESET, Item.class.getMethod("setLinkFrameset", pString));
147 _ItemTags
148 .put(DefaultFrameWriter.LINK_TEMPLATE, Item.class.getMethod("setLinkTemplate", pString));
149 _ItemTags.put(DefaultFrameWriter.LINE_PATTERN, Item.class.getMethod("setLinePattern", pIntArray));
150
151 _ItemTags.put(DefaultFrameWriter.ARROW, Item.class.getMethod("setArrow", pArrow));
152
153 _ItemTags.put(DefaultFrameWriter.DOT_TYPE, Dot.class.getMethod("setDotType", pDotType));
154 _ItemTags.put(DefaultFrameWriter.FILLED, Dot.class.getMethod("setFilled", pBool));
155
156 _ItemTags.put(DefaultFrameWriter.FONT, Text.class.getMethod("setFont", pFont));
157 _ItemTags.put(DefaultFrameWriter.SPACING, Text.class.getMethod("setSpacing", pFloat));
158 _ItemTags.put(DefaultFrameWriter.TEXT, Text.class.getMethod("appendLine", pString));
159 _ItemTags.put(DefaultFrameWriter.WORD_SPACING, Text.class.getMethod("setWordSpacing", pInt));
160 _ItemTags.put(DefaultFrameWriter.LETTER_SPACING, Text.class.getMethod("setLetterSpacing", pFloat));
161 _ItemTags.put(DefaultFrameWriter.INITIAL_SPACING, Text.class.getMethod("setInitialSpacing", pFloat));
162 _ItemTags.put(DefaultFrameWriter.WIDTH_TO_SAVE, Text.class.getMethod("setWidth", pIntO));
163 _ItemTags.put(DefaultFrameWriter.MIN_WIDTH_TO_SAVE, Text.class.getMethod("setMinWidth", pIntO));
164 _ItemTags.put(DefaultFrameWriter.JUSTIFICATION, Text.class.getMethod("setJustification", pJustification));
165 _ItemTags.put(DefaultFrameWriter.AUTO_WRAP_TO_SAVE, Text.class.getMethod("setAutoWrap", pBool));
166
167 _ItemTags.put(DefaultFrameWriter.THICKNESS, Item.class.getMethod("setThickness", pFloat));
168 _ItemTags.put(DefaultFrameWriter.LINE_IDS, Item.class.getMethod("setLineIDs", pString));
169 _ItemTags.put(DefaultFrameWriter.CONSTRAINT_IDS, Item.class.getMethod("setConstraintIDs", pString));
170
171 _ItemTags.put(DefaultFrameWriter.TOOLTIP, Item.class.getMethod("setTooltip", pString));
172 _ItemTags.put(DefaultFrameWriter.LINK_HISTORY, Item.class.getMethod("setLinkHistory", pBool));
173
174 _ItemTags.put(DefaultFrameWriter.PERMISSION, Item.class.getMethod("setPermission", pPermission));
175
176 _ItemTags.put(DefaultFrameWriter.MASK, Text.class.getMethod("setMask", pIntO));
177
178 // Lines and constraints are created differently
179 _ItemTags.put('L', Line.class.getMethod("setStartItem", pItem));
180 _ItemTags.put('C', Constraint.class.getMethod("getID", (Class[]) null));
181
182 _ItemTags.put(DefaultFrameWriter.MAGNETIZED_ITEM_LEFT, Item.class.getMethod("setMagnetizedItemLeft", pInt));
183 _DelayedItemTags.add('[');
184 _ItemTags.put(DefaultFrameWriter.MAGNETIZED_ITEM_RIGHT, Item.class.getMethod("setMagnetizedItemRight", pInt));
185 _DelayedItemTags.add(']');
186 _ItemTags.put(DefaultFrameWriter.MAGNETIZED_ITEM_TOP, Item.class.getMethod("setMagnetizedItemTop", pInt));
187 _DelayedItemTags.add('^');
188 _ItemTags.put(DefaultFrameWriter.MAGNETIZED_ITEM_BOTTOM, Item.class.getMethod("setMagnetizedItemBottom", pInt));
189 _DelayedItemTags.add('/');
190
191 _ItemTagsExt.put(DefaultFrameWriter.ENCRYPTION_LABEL_STR, Item.class.getMethod("setEncryptionLabelOnLoad", pString));
192
193 _ItemTagsExt.put(DefaultFrameWriter.PLACEHOLDER_STR, Text.class.getMethod("setPlaceholder", pString));
194 _ItemTagsExt.put(DefaultFrameWriter.SINGLE_LINE_ONLY_STR, Text.class.getMethod("setSingleLineOnly", pBool));
195 _ItemTagsExt.put(DefaultFrameWriter.TAB_INDEX_STR, Text.class.getMethod("setTabIndex", pInt));
196 _ItemTagsExt.put(DefaultFrameWriter.ACCEPTS_ENTER, Item.class.getMethod("setAcceptsEnter", pBool));
197 _ItemTagsExt.put(DefaultFrameWriter.ANCHOR_CENTERX_STR, Item.class.getMethod("setAnchorCenterX", pIntO));
198 } catch (Exception e) {
199 e.printStackTrace();
200 }
201
202 }
203
204 public Frame readFrame(String fullPath) throws IOException {
205 File f = new File(fullPath);
206 Reader in = new InputStreamReader(new FileInputStream(fullPath), "UTF-8");
207 Frame frame = readFrame(new BufferedReader(in));
208 frame.setLastModifyDate(frame.getLastModifyDate(), f.lastModified());
209 return frame;
210 }
211}
Note: See TracBrowser for help on using the repository browser.