Changeset 67 for trunk/src/org/expeditee/io/KMSWriter.java
- Timestamp:
- 05/19/08 12:03:18 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/io/KMSWriter.java
r50 r67 7 7 import java.lang.reflect.Method; 8 8 import java.util.Iterator; 9 import java.util.LinkedHashMap;10 9 import java.util.LinkedList; 11 10 import java.util.List; … … 17 16 import org.expeditee.items.Line; 18 17 import org.expeditee.items.Picture; 19 import org.expeditee.items.Text;20 18 import org.expeditee.stats.SessionStats; 21 19 … … 32 30 private StringBuilder _stringWriter = null; 33 31 34 // keep track of methods that are put on the same line35 private static LinkedHashMap<String, Method> _ItemTags = null;36 37 private static LinkedHashMap<String, Method> _FrameTags = null;38 39 private static LinkedHashMap<String, Method> _BodyTags = null;40 41 32 private static final char TERMINATOR = 'Z'; 42 33 … … 44 35 45 36 public KMSWriter() { 46 if (_ItemTags != null && _FrameTags != null) 47 return; 48 49 _ItemTags = new LinkedHashMap<String, Method>(); 50 _FrameTags = new LinkedHashMap<String, Method>(); 51 _BodyTags = new LinkedHashMap<String, Method>(); 52 53 Class[] param = {}; 54 55 try { 56 _FrameTags.put("A", Frame.class.getMethod("getFrameName", param)); 57 _FrameTags.put("V", Frame.class.getMethod("getVersion", param)); 58 _FrameTags.put("v", Frame.class 59 .getMethod("getFormatVersion", param)); 60 _FrameTags.put("p", Frame.class.getMethod("getProtection", param)); 61 _FrameTags.put("U", Frame.class.getMethod("getOwner", param)); 62 _FrameTags.put("D", Frame.class.getMethod("getDateCreated", param)); 63 _FrameTags.put("M", Frame.class.getMethod("getLastModifyUser", 64 param)); 65 _FrameTags.put("d", Frame.class.getMethod("getLastModifyDate", 66 param)); 67 _FrameTags.put("F", Frame.class.getMethod("getFrozenDate", param)); 68 69 _BodyTags.put("O", Frame.class.getMethod("getForegroundColor", 70 param)); 71 _BodyTags.put("B", Frame.class.getMethod("getBackgroundColor", 72 param)); 73 _BodyTags 74 .put("v", Frame.class.getMethod("getFormatVersion", param)); 75 76 _ItemTags.put("S", Item.class.getMethod("getID", param)); 77 _ItemTags.put("s", Item.class.getMethod("getDateCreated", param)); 78 _ItemTags.put("d", Item.class.getMethod("getColor", param)); 79 _ItemTags.put("G", Item.class 80 .getMethod("getBackgroundColor", param)); 81 _ItemTags.put("P", Item.class.getMethod("getPosition", param)); 82 _ItemTags.put("F", Item.class.getMethod("getLink", param)); 83 _ItemTags.put("X", Item.class.getMethod("getAction", param)); 84 _ItemTags.put("x", Item.class.getMethod("getActionMark", param)); 85 _ItemTags.put("U", Item.class.getMethod("getActionCursorEnter", 86 param)); 87 _ItemTags.put("V", Item.class.getMethod("getActionCursorLeave", 88 param)); 89 _ItemTags.put("W", Item.class.getMethod("getActionEnterFrame", 90 param)); 91 _ItemTags.put("Y", Item.class.getMethod("getActionLeaveFrame", 92 param)); 93 _ItemTags.put("D", Item.class.getMethod("getData", param)); 94 _ItemTags.put("u", Item.class.getMethod("getHighlight", param)); 95 _ItemTags.put("e", Item.class.getMethod("getFillColor", param)); 96 _ItemTags.put("i", Item.class.getMethod("getFillPattern", param)); 97 _ItemTags.put("o", Item.class.getMethod("getOwner", param)); 98 _ItemTags.put("n", Item.class.getMethod("getLinkMark", param)); 99 _ItemTags.put("q", Item.class.getMethod("getLinkFrameset", param)); 100 _ItemTags.put("y", Item.class.getMethod("getLinkTemplate", param)); 101 _ItemTags.put("g", Item.class.getMethod("getLinePattern", param)); 102 103 _ItemTags.put("j", Item.class.getMethod("getArrow", param)); 104 105 _ItemTags.put("f", Text.class.getMethod("getFont", param)); 106 _ItemTags.put("t", Text.class.getMethod("getSpacing", param)); 107 _ItemTags.put("T", Text.class.getMethod("getText", param)); 108 109 _ItemTags.put("a", Text.class.getMethod("getWordSpacing", param)); 110 _ItemTags.put("b", Text.class.getMethod("getLetterSpacing", param)); 111 _ItemTags 112 .put("m", Text.class.getMethod("getInitialSpacing", param)); 113 _ItemTags.put("w", Text.class.getMethod("getWidth", param)); 114 _ItemTags.put("k", Text.class.getMethod("getJustification", param)); 115 116 _ItemTags.put("h", Dot.class.getMethod("getThickness", param)); 117 _ItemTags.put("l", Dot.class.getMethod("getLineIDs", param)); 118 _ItemTags.put("c", Dot.class.getMethod("getConstraintIDs", param)); 119 120 // Lines and constraints are created differently 121 /* 122 * _LineTags.put("L", Line.class.getMethod("getID", param)); 123 * _LineTags.put("s", Line.class.getMethod("getLineEnds", param)); 124 * _LineTags.put("g", Line.class.getMethod("getLinePattern", 125 * param)); 126 * 127 * _ConstraintTags.put("C", Constraint.class.getMethod("getID", 128 * (Class[]) null)); _ConstraintTags.put("s", 129 * Constraint.class.getMethod("getLineEnds", (Class[]) null)); 130 */ 131 } catch (SecurityException e) { 132 // TODO Auto-generated catch block 133 e.printStackTrace(); 134 } catch (NoSuchMethodException e) { 135 // TODO Auto-generated catch block 136 e.printStackTrace(); 137 } 37 super(); 138 38 } 139 39 … … 152 52 _writer = new ProxyWriter(new FileWriter(_filename)); 153 53 54 try { 55 _ItemTags.put("S", Item.class.getMethod("getID", new Class[] {})); 56 } catch (Exception e) { 57 58 } 154 59 // _writer = new BufferedWriter(new FileWriter(filepath.toLowerCase() + 155 60 // filename.toLowerCase())); … … 171 76 172 77 writeHeader(frame); 173 // writeBody(frame);174 78 175 79 // write out each Item in the Frame. … … 192 96 Iterator<String> it = _FrameTags.keySet().iterator(); 193 97 Object[] param = {}; 98 99 // Write the version tag 100 writeLine("v", "22"); 194 101 195 102 while (it.hasNext()) { … … 212 119 } 213 120 } 214 215 writeTerminator();216 it = _BodyTags.keySet().iterator();217 218 while (it.hasNext()) {219 String tag = it.next();220 try {221 Object o = _BodyTags.get(tag).invoke(toWrite, param);222 o = Conversion.ConvertToKMS(_BodyTags.get(tag), o);223 if (o != null) {224 writeLine(tag, (String) o);225 }226 } catch (IllegalArgumentException e) {227 // TODO Auto-generated catch block228 e.printStackTrace();229 } catch (IllegalAccessException e) {230 // TODO Auto-generated catch block231 e.printStackTrace();232 } catch (InvocationTargetException e) {233 // TODO Auto-generated catch block234 e.printStackTrace();235 }236 }237 121 } 238 122 … … 267 151 item = ((Picture) item).getText(); 268 152 269 /*270 * if(item instanceof Text) writeClass(item); else if(item instanceof271 * Dot) writeDot((Dot) item);272 */273 153 if (item.getLines().size() > 0) 274 154 writePoint(item); 275 155 else if (!(item instanceof Line)) 276 156 writeClass(item); 277 // lines are saved at the end of the file278 /*279 * else if (item instanceof Line) ;280 */281 157 else 282 158 System.out.println("Unknown Item: " + item.getID()); … … 338 214 if (_points.contains(c.getStart()) 339 215 && _points.contains(c.getEnd())) { 340 writeLine("C", c.getID() + " " 341 + c.getType()); 216 writeLine("C", c.getID() + " " + c.getType()); 342 217 writeLine("s", c.getLineEnds()); 343 218 } … … 348 223 // remove the point from the list 349 224 _points.remove(0); 350 351 225 } 352 226 } … … 354 228 @Override 355 229 protected String finaliseFrame() throws IOException { 356 write Line("" + DELIMITER + TERMINATOR + DELIMITER);230 writeTerminator(); 357 231 358 232 writeLine(SessionStats.getFrameEventList()); … … 399 273 } 400 274 } 401 402 /* 403 * Method[] methods = toWrite.getClass().getMethods(); ArrayList<String> 404 * meths = new ArrayList<String>(); 405 * 406 * for(Method m : methods) meths.add(m.getName()); 407 * 408 * String start = _Tags.get("DelimiterStart"); String end = 409 * _Tags.get("DelimiterEnd"); 410 * 411 * Iterator<String> it = _Tags.keySet().iterator(); 412 * 413 * String term = null; LinkedList<Method> seen = new LinkedList<Method>(); 414 * 415 * while(it.hasNext()){ String name = it.next(); String cName = 416 * className; 417 * 418 * if(writeSuper && name.startsWith(superName)) cName = superName; 419 * 420 * if(name.startsWith(cName)){ String tag = start + _Tags.get(name) + 421 * end; String output = ""; 422 * 423 * //check for other methods that go on this line LinkedList<String> 424 * shared = _SharedLine.get(name); LinkedList<String> runMethods = new 425 * LinkedList<String>(); 426 * 427 * if(shared != null) runMethods.addAll(shared); 428 * 429 * name = name.substring((cName + ".").length()); 430 * runMethods.addFirst(name); 431 * 432 * //loop through all methods and concat their output Iterator 433 * methodIterator = runMethods.iterator(); 434 * 435 * while(methodIterator.hasNext()){ name = "get" + 436 * methodIterator.next(); 437 * 438 * int ind = meths.indexOf(name); 439 * 440 * if(ind >= 0){ Method m = methods[ind]; 441 * 442 * if(!seen.contains(m)){ try { if(m.getParameterTypes().length == 0){ 443 * Object val = m.invoke(toWrite, (Object[]) null); 444 * 445 * if(val instanceof List){ int count = 0; for(Object o : (List) val){ 446 * if(count == 0) output += " " + 447 * KMSConversion.ConvertToKMS(name.substring(3), o); else output += "\n" + 448 * tag + " " + KMSConversion.ConvertToKMS(name.substring(3), o); 449 * 450 * count++; } }else{ String res = 451 * KMSConversion.ConvertToKMS(name.substring(3), val); 452 * 453 * if(res != null) output += " " + res; } } } catch (Exception e) { 454 * Logger.Log(e); } 455 * 456 * seen.add(m); } }else if(name.equals("getTerminator")){ term = start + 457 * _Tags.get(cName + ".Terminator") + end; }else System.out.println("No 458 * method found: " + cName + "." + name); } 459 * 460 * if(output.length() > 0) writeLine(tag + output); } } if(term != null) 461 * writeLine(term); 462 */ 463 } 464 465 /* 466 * private void writeBody(Object toWrite) throws IOException{ 467 * writeClass(toWrite, "Body", " ", false); } 468 */ 275 } 469 276 470 277 /**
Note:
See TracChangeset
for help on using the changeset viewer.