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

Last change on this file since 919 was 919, checked in by jts21, 10 years ago

Added license headers to all files, added full GPL3 license file, moved license header generator script to dev/bin/scripts

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