Ignore:
Timestamp:
05/19/08 12:03:18 (16 years ago)
Author:
ra33
Message:

Fixed a bunch of problems with rectangles and resizing the window, as well as adding some more unit tests etc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/io/KMSWriter.java

    r50 r67  
    77import java.lang.reflect.Method;
    88import java.util.Iterator;
    9 import java.util.LinkedHashMap;
    109import java.util.LinkedList;
    1110import java.util.List;
     
    1716import org.expeditee.items.Line;
    1817import org.expeditee.items.Picture;
    19 import org.expeditee.items.Text;
    2018import org.expeditee.stats.SessionStats;
    2119
     
    3230        private StringBuilder _stringWriter = null;
    3331
    34         // keep track of methods that are put on the same line
    35         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 
    4132        private static final char TERMINATOR = 'Z';
    4233
     
    4435
    4536        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();
    13838        }
    13939
     
    15252                        _writer = new ProxyWriter(new FileWriter(_filename));
    15353
     54                try {
     55                        _ItemTags.put("S", Item.class.getMethod("getID", new Class[] {}));
     56                } catch (Exception e) {
     57
     58                }
    15459                // _writer = new BufferedWriter(new FileWriter(filepath.toLowerCase() +
    15560                // filename.toLowerCase()));
     
    17176
    17277                writeHeader(frame);
    173                 // writeBody(frame);
    17478
    17579                // write out each Item in the Frame.
     
    19296                Iterator<String> it = _FrameTags.keySet().iterator();
    19397                Object[] param = {};
     98
     99                // Write the version tag
     100                writeLine("v", "22");
    194101
    195102                while (it.hasNext()) {
     
    212119                        }
    213120                }
    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 block
    228                                 e.printStackTrace();
    229                         } catch (IllegalAccessException e) {
    230                                 // TODO Auto-generated catch block
    231                                 e.printStackTrace();
    232                         } catch (InvocationTargetException e) {
    233                                 // TODO Auto-generated catch block
    234                                 e.printStackTrace();
    235                         }
    236                 }
    237121        }
    238122
     
    267151                        item = ((Picture) item).getText();
    268152
    269                 /*
    270                  * if(item instanceof Text) writeClass(item); else if(item instanceof
    271                  * Dot) writeDot((Dot) item);
    272                  */
    273153                if (item.getLines().size() > 0)
    274154                        writePoint(item);
    275155                else if (!(item instanceof Line))
    276156                        writeClass(item);
    277                 // lines are saved at the end of the file
    278                 /*
    279                  * else if (item instanceof Line) ;
    280                  */
    281157                else
    282158                        System.out.println("Unknown Item: " + item.getID());
     
    338214                                                if (_points.contains(c.getStart())
    339215                                                                && _points.contains(c.getEnd())) {
    340                                                         writeLine("C", c.getID() + " "
    341                                                                         + c.getType());
     216                                                        writeLine("C", c.getID() + " " + c.getType());
    342217                                                        writeLine("s", c.getLineEnds());
    343218                                                }
     
    348223                        // remove the point from the list
    349224                        _points.remove(0);
    350 
    351225                }
    352226        }
     
    354228        @Override
    355229        protected String finaliseFrame() throws IOException {
    356                 writeLine("" + DELIMITER + TERMINATOR + DELIMITER);
     230                writeTerminator();
    357231
    358232                writeLine(SessionStats.getFrameEventList());
     
    399273                        }
    400274                }
    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        }
    469276
    470277        /**
Note: See TracChangeset for help on using the changeset viewer.