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

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

Adding networking stuff for peer to peer sharing of frames

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