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/KMSReader.java

    r4 r67  
    11package org.expeditee.io;
    22
    3 import java.awt.Color;
    4 import java.awt.Font;
    5 import java.awt.Point;
    63import java.io.BufferedReader;
    74import java.io.FileReader;
     
    1310import java.util.Iterator;
    1411import java.util.LinkedHashMap;
    15 import java.util.List;
    1612
    1713import org.expeditee.gui.Frame;
     
    3026 *
    3127 */
    32 public class KMSReader implements FrameReader {
     28public class KMSReader extends FrameReader {
    3329
    3430        private BufferedReader _reader = null;
     
    4844                _FrameTags = new LinkedHashMap<String, Method>();
    4945
    50                 Class[] pString = { String.class };
    51                 Class[] pInt = { int.class };
    52                 Class[] pFloat = { float.class };
    53                 Class[] pColor = { Color.class };
    54                 Class[] pBool = { boolean.class };
    55                 Class[] pFont = { Font.class };
    56                 Class[] pPoint = { Point.class };
    57                 Class[] pArrow = { int.class, double.class };
    58                 Class[] pList = { List.class };
    59                 Class[] pIntArray = { int[].class };
    60                 Class[] pItem = { Item.class };
    61 
    6246                try {
    6347                        _FrameTags.put("A", Frame.class.getMethod("setFrameName", pString));
    6448                        _FrameTags.put("V", Frame.class.getMethod("setVersion", pInt));
    65                         _FrameTags
    66                                         .put("v", Frame.class.getMethod("setFormatVersion", pInt));
    6749                        _FrameTags
    6850                                        .put("p", Frame.class.getMethod("setProtection", pString));
     
    152134         * @return true if s begins with a KMS tag
    153135         */
    154         private boolean isValidLine(String s) {
     136        private static boolean isValidLine(String s) {
    155137                return s.length() >= 3 && s.charAt(0) == '+' && s.charAt(2) == '+'
    156138                                && Character.isLetter(s.charAt(1));
     
    332314        }
    333315
    334         private String getTag(String line) {
     316        private static String getTag(String line) {
    335317                assert (line.charAt(0) == '+');
    336318                assert (line.length() > 2);
     
    338320        }
    339321
    340         private String getValue(String line) {
     322        private static String getValue(String line) {
    341323                assert (line.charAt(0) == '+');
    342324                if (line.length() > 4)
     
    365347
    366348                if (_FrameTags.get(tag) == null) {
    367                         if (!tag.equals("t"))
     349                        if (!tag.equals("t") && !tag.equals("v") )
    368350                                FrameGraphics.ErrorMessage("Tag '" + tag + "' in '" + line
    369351                                                + "' is not supported.");
     
    530512                return toMake;
    531513        }
     514       
     515        public static int getVersion(String fullpath) {
     516                try {
     517                        BufferedReader reader = new BufferedReader(new FileReader(fullpath));
     518                        String next = "";
     519                        // First read the header lines until we get the version number
     520                        while (reader.ready() && (next = reader.readLine())!= null) {
     521                                if (isValidLine(next)) {
     522                                        char tag = getTag(next).charAt(0);
     523                                        String value = getValue(next);
     524                                        if (tag == 'V')
     525                                                return Integer.parseInt(value);
     526                                        else if(tag == 'Z')
     527                                                return 0;
     528                                }
     529                        }
     530                } catch (Exception e) {
     531                }
     532                return 0;
     533        }
    532534}
Note: See TracChangeset for help on using the changeset viewer.