source: trunk/src/org/expeditee/io/FrameReader.java@ 362

Last change on this file since 362 was 362, checked in by ra33, 16 years ago

Added Spell Checker
Added word count stats
Fixed some mail stuff

File size: 5.7 KB
Line 
1package org.expeditee.io;
2
3import java.awt.Color;
4import java.awt.Font;
5import java.awt.Point;
6import java.io.BufferedReader;
7import java.io.FileInputStream;
8import java.io.IOException;
9import java.io.InputStreamReader;
10import java.io.Reader;
11import java.lang.reflect.Method;
12import java.util.LinkedHashMap;
13import java.util.List;
14
15import org.expeditee.gui.Frame;
16import org.expeditee.items.Constraint;
17import org.expeditee.items.Item;
18import org.expeditee.items.Justification;
19import org.expeditee.items.Line;
20import org.expeditee.items.Permission;
21import org.expeditee.items.Text;
22
23public abstract class FrameReader {
24 protected static LinkedHashMap<Character, Method> _ItemTags = null;
25
26 protected static LinkedHashMap<Character, Method> _FrameTags = null;
27
28 protected static Class[] pString = { String.class };
29 protected static Class[] pInt = { int.class };
30 protected static Class[] pFloat = { float.class };
31 protected static Class[] pFloatO = { Float.class };
32 protected static Class[] pColor = { Color.class };
33 protected static Class[] pBool = { boolean.class };
34 protected static Class[] pFont = { Font.class };
35 protected static Class[] pPoint = { Point.class };
36 protected static Class[] pArrow = { float.class, double.class };
37 protected static Class[] pList = { List.class };
38 protected static Class[] pIntArray = { int[].class };
39 protected static Class[] pItem = { Item.class };
40 protected static Class[] pJustification = { Justification.class };
41 protected static Class[] pPermission = { Permission.class };
42
43 public FrameReader(){
44 if (_ItemTags != null && _FrameTags != null)
45 return;
46
47 _ItemTags = new LinkedHashMap<Character, Method>();
48 _FrameTags = new LinkedHashMap<Character, Method>();
49
50 try {
51 _FrameTags.put('A', Frame.class.getMethod("setName", pString));
52 _FrameTags.put('V', Frame.class.getMethod("setVersion", pInt));
53 _FrameTags
54 .put('p', Frame.class.getMethod("setPermission", pPermission));
55 _FrameTags.put('U', Frame.class.getMethod("setOwner", pString));
56 _FrameTags.put('D', Frame.class
57 .getMethod("setDateCreated", pString));
58 _FrameTags.put('M', Frame.class.getMethod("setLastModifyUser",
59 pString));
60 _FrameTags.put('d', Frame.class.getMethod("setLastModifyDate",
61 pString));
62 _FrameTags
63 .put('F', Frame.class.getMethod("setFrozenDate", pString));
64
65 _FrameTags.put('O', Frame.class.getMethod("setForegroundColor",
66 pColor));
67 _FrameTags.put('B', Frame.class.getMethod("setBackgroundColor",
68 pColor));
69
70 _ItemTags.put('S', Item.class.getMethod("setID", pInt));
71 _ItemTags.put('s', Item.class.getMethod("setDateCreated", pString));
72 _ItemTags.put('d', Item.class.getMethod("setColor", pColor));
73 _ItemTags.put('G', Item.class.getMethod("setBackgroundColor",
74 pColor));
75 _ItemTags.put('K', Item.class.getMethod("setBorderColor",
76 pColor));
77 _ItemTags.put('H', Item.class.getMethod("setAnchorRight", pFloatO));
78 _ItemTags.put('I', Item.class.getMethod("setAnchorBottom", pFloatO));
79 _ItemTags.put('P', Item.class.getMethod("setPosition", pPoint));
80 _ItemTags.put('F', Item.class.getMethod("setLink", pString));
81 _ItemTags.put('J', Item.class.getMethod("setFormula", pString));
82
83 _ItemTags.put('X', Item.class.getMethod("setActions", pList));
84 _ItemTags.put('x', Item.class.getMethod("setActionMark", pBool));
85 _ItemTags.put('U', Item.class.getMethod("setActionCursorEnter",
86 pList));
87 _ItemTags.put('V', Item.class.getMethod("setActionCursorLeave",
88 pList));
89 _ItemTags.put('W', Item.class.getMethod("setActionEnterFrame",
90 pList));
91 _ItemTags.put('Y', Item.class.getMethod("setActionLeaveFrame",
92 pList));
93 _ItemTags.put('D', Item.class.getMethod("addToData", pString));
94 _ItemTags.put('u', Item.class.getMethod("setHighlight", pBool));
95 _ItemTags.put('e', Item.class.getMethod("setFillColor", pColor));
96 _ItemTags.put('E', Item.class.getMethod("setGradientColor", pColor));
97 _ItemTags.put('Q', Item.class.getMethod("setGradientAngle", pInt));
98
99 _ItemTags.put('i', Item.class.getMethod("setFillPattern", pString));
100 _ItemTags.put('o', Item.class.getMethod("setOwner", pString));
101 _ItemTags.put('n', Item.class.getMethod("setLinkMark", pBool));
102 _ItemTags
103 .put('q', Item.class.getMethod("setLinkFrameset", pString));
104 _ItemTags
105 .put('y', Item.class.getMethod("setLinkTemplate", pString));
106 _ItemTags.put('g', Item.class
107 .getMethod("setLinePattern", pIntArray));
108
109 _ItemTags.put('j', Item.class.getMethod("setArrow", pArrow));
110
111 _ItemTags.put('f', Text.class.getMethod("setFont", pFont));
112 _ItemTags.put('t', Text.class.getMethod("setSpacing", pInt));
113 _ItemTags.put('T', Text.class.getMethod("appendLine", pString));
114 _ItemTags.put('a', Text.class.getMethod("setWordSpacing", pInt));
115 _ItemTags.put('b', Text.class.getMethod("setLetterSpacing", pInt));
116 _ItemTags.put('m', Text.class.getMethod("setInitialSpacing", pInt));
117 _ItemTags.put('w', Text.class.getMethod("setWidth", pInt));
118 _ItemTags.put('k', Text.class.getMethod("setJustification", pJustification));
119
120 _ItemTags.put('h', Item.class.getMethod("setThickness", pFloat));
121 _ItemTags.put('l', Item.class.getMethod("setLineIDs", pString));
122 _ItemTags.put('c', Item.class
123 .getMethod("setConstraintIDs", pString));
124 // Lines and constraints are created differently
125 _ItemTags.put('L', Line.class.getMethod("setStartItem", pItem));
126 _ItemTags.put('C', Constraint.class.getMethod("getID",
127 (Class[]) null));
128 } catch (Exception e) {
129 e.printStackTrace();
130 }
131
132 }
133
134 public Frame readFrame(String fullPath) throws IOException {
135 Reader in = new InputStreamReader(new FileInputStream(fullPath), "UTF-8");
136 return readFrame(new BufferedReader(in));
137 }
138
139 public abstract Frame readFrame(BufferedReader frameContents) throws IOException;
140}
Note: See TracBrowser for help on using the repository browser.