Changeset 601


Ignore:
Timestamp:
12/10/13 17:58:08 (10 years ago)
Author:
jts21
Message:

Switch back to EXP format, revert changes to Picture class

Location:
trunk/src/org/expeditee
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/actions/Misc.java

    r595 r601  
    13621362                System.out.println(text.getText());
    13631363        }
    1364        
    1365         public static void testWriter(Frame frame) {
    1366                 try {
    1367                         FrameWriter fw = new ExaWriter();
    1368                         fw.writeFrame(frame);
    1369                         String contents = fw.getFileContents();
    1370                         Frame newFrame;
    1371                         try {
    1372                                 String nextName = frame.getFramesetName() + FrameIO.ReadINF(FrameIO.LoadFrame(frame.getFramesetName() + "0").getPath(), frame.getFramesetName(), true);
    1373                                 System.out.println(nextName);
    1374                                 newFrame = new ExaReader(nextName).readFrame(new BufferedReader(new StringReader(contents)));
    1375                                 newFrame.setChanged(true);
    1376                                 newFrame.setPath(frame.getPath());
    1377                                 FrameIO.SaveFrame(newFrame);
    1378                                 Text text = new Text(DisplayIO.getCurrentFrame().getNextItemID(), "New frame");
    1379                                 text.setPosition(FrameMouseActions.MouseX, FrameMouseActions.MouseY);
    1380                                 text.setLink(newFrame.getName());
    1381                                 FrameMouseActions.pickup(text);
    1382                                
    1383                         } catch (Exception e) {
    1384                                 e.printStackTrace();
    1385                         }
    1386 
    1387         } catch (Exception e) {
    1388                 e.printStackTrace();
    1389         }
    1390         }
    1391        
    1392         public static Item testPicture() {
    1393                 // return new Picture(string, DisplayIO.getCurrentFrame());
    1394                 Picture p = new Picture("/home/jts21/wallpaper.png", DisplayIO.getCurrentFrame());
    1395                 p.setPosition(149, 189);
    1396                 p.setCropStart(new Point(100, 100));
    1397                 p.setCropEnd(new Point(200, 200));
    1398                 p.setWidth(100);
    1399                 // p.setPosition(100, 100);
    1400                 // p.scale(0.1F, (int)FrameMouseActions.MouseX, (int)FrameMouseActions.MouseY);
    1401                
    1402                 // p.setImageSource(string);
    1403                 return p;
    1404         }
    1405        
    1406         public static void getAllItems(Frame frame) {
    1407                 System.out.println(frame.getAllItems());
    1408         }
    1409        
    1410         public static void getItemsToSave(Frame frame) {
    1411                 System.out.println(frame.getItemsToSave());
    1412         }
    14131364}
  • trunk/src/org/expeditee/gui/AttributeUtils.java

    r595 r601  
    2929public class AttributeUtils {
    3030
    31         // private static final int GET_LENGTH = "get".length();
    32 
    33         //private static int SET_LENGTH = "set".length();
    34 
    3531        public static final class Attribute {
    3632                public final String displayName;
     
    4844               
    4945                // the internal hashmap
    50                 private final HashMap<String, Attribute> map = new HashMap<String, Attribute>(256);
     46                private final HashMap<String, Attribute> map;
    5147                // a list of keys in the order they were added (used to make attribute extraction consistent)
    52                 public final List<String> keys = new LinkedList<String>();
    53                
    54                 // put an item at the end of the list
     48                public final List<String> keys;
     49               
     50                public AttributeSet(int size) {
     51                        map = new HashMap<String, Attribute>(size);
     52                        keys = new LinkedList<String>();
     53                }
     54               
    5555                public void put(String attributeName, Method getter, Method setter) {
    5656                        if(map.containsKey(attributeName.toLowerCase())) {
     
    6363                }
    6464               
    65                 // put an item at the start of the list
    66                 public void ins(String attributeName, Method getter, Method setter) {
    67                         if(map.containsKey(attributeName.toLowerCase())) {
    68                                 System.err.println(this + " already contains key '" + attributeName + "', overwriting value!");
    69                                 keys.remove(attributeName.toLowerCase());
    70                         }
    71                         // we keep an ordered list of attributes for extraction
    72                         keys.add(0, attributeName.toLowerCase());
    73                         map.put(attributeName.toLowerCase(), new Attribute(attributeName, getter, setter));
    74                 }
    75                
    76                 /**
    77                  * Create a second reference the the same Attribute, using a different name
    78                  * Does not modify the list of keys
    79                  */
     65                // Create a second reference the the same Attribute, using a different name
     66                // Does not modify the list of keys
    8067                public void alias(String alias, String name) {
    8168                        if(map.containsKey(name.toLowerCase())) {
     
    8673                }
    8774               
    88                 public void putAll(AttributeSet toAdd) {
    89                         keys.addAll(toAdd.keys);
    90                         map.putAll(toAdd.map);
    91                 }
    92                
    93                 public Attribute remove(String name) {
    94                         keys.remove(name);
    95                         return map.remove(name);
    96                 }
    97                
    9875                public boolean containsKey(String key) {
    9976                        return map.containsKey(key);
     
    10582        }
    10683       
    107        
    108         // Frames
    109         // Common list of attributes
    110         public static final AttributeSet _FrameAttrib = new AttributeSet();
    111         // List of attributes that may be set
    112         public static final AttributeSet _FrameAttribSet = new AttributeSet();
    113         // List of attributes that should be saved
    114         public static final AttributeSet _FrameAttribSave = new AttributeSet();
    115         // Items
    116         // Common list of attributes
    117         public static final AttributeSet _Attrib = new AttributeSet();
    118         // List of attributes that may be set
    119         public static final AttributeSet _AttribSet = new AttributeSet();
    120         // List of attributes that should be saved
    121         public static final AttributeSet _AttribSave = new AttributeSet();
    122        
    123         // List of method names to ignore when searching for a match
    124         // private static List<Method> _GetMethods = null;
    125 
    126         // private static HashMap<String, Method> _SetMethods = null;
     84        public static final AttributeSet _Attrib = new AttributeSet(128);
     85        public static final AttributeSet _FrameAttrib = new AttributeSet(16);
     86
    12787
    12888        // List of attributes which are ignored when extracting attributes
     
    210170                                                            Frame.class.getMethod("setOwner", pString));
    211171                        _FrameAttrib.put("DateCreated",     Frame.class.getMethod("getDateCreated"),
    212                                                             Frame.class.getMethod("setDateCreated", pString));
     172                                                            null);
    213173                        _FrameAttrib.put("LastModifyUser",  Frame.class.getMethod("getLastModifyUser"),
    214                                                             Frame.class.getMethod("setLastModifyUser", pString));
     174                                                            null);
    215175                        _FrameAttrib.put("LastModifyDate",  Frame.class.getMethod("getLastModifyDate"),
    216                                                             Frame.class.getMethod("setLastModifyDate", pString));
     176                                                            null);
    217177                        _FrameAttrib.put("ForegroundColor", Frame.class.getMethod("getForegroundColor"),
    218178                                                            Frame.class.getMethod("setForegroundColor", pColor));
     
    220180                                                            Frame.class.getMethod("setBackgroundColor", pColor));
    221181                       
    222                         // FrameAttribSet has some stuff removed (so users can't set the creation date), and some aliases
    223                         _FrameAttribSet.putAll(_FrameAttrib);
    224                         _FrameAttribSet.remove("DateCreated");
    225                         _FrameAttribSet.remove("LastModifyUser");
    226                         _FrameAttribSet.remove("LastModifyDate");
    227                         _FrameAttribSet.alias("fgc",        "foregroundcolor");
    228                         _FrameAttribSet.alias("bgc",        "backgroundcolor");
    229                         _FrameAttribSet.alias("p",          "permission");
    230                        
    231                         // FrameAttribSave has some extra stuff
    232                         _FrameAttribSave.putAll(_FrameAttrib);
    233                         _FrameAttribSave.ins("Version",Frame.class.getMethod("getVersion"),
    234                                                             Frame.class.getMethod("setVersion", pInt));
    235                         _FrameAttribSave.put("FrozenDate",  Frame.class.getMethod("getFrozenDate"),
    236                                                             Frame.class.getMethod("setFrozenDate", pString));
     182                        // aliases for attribute setting
     183                        _FrameAttrib.alias("fgc",        "foregroundcolor");
     184                        _FrameAttrib.alias("bgc",        "backgroundcolor");
     185                        _FrameAttrib.alias("p",          "permission");
     186                       
    237187                       
    238188                        // Generic Items
     
    309259                        _Attrib.put("Width",                Item.class.getMethod("getWidthToSave"),
    310260                                                            Item.class.getMethod("setWidth", pIntO));
     261                        _Attrib.put("X",                    null,
     262                                                            Item.class.getMethod("setX", pFloat));
     263                        _Attrib.put("Y",                    null,
     264                                                            Item.class.getMethod("setY", pFloat));
    311265                       
    312266                        // Text Items
     
    318272                                                            Text.class.getMethod("setJustification", pJustification));
    319273                       
    320                         // Picture Items
    321                         _Attrib.put("Scale",                Picture.class.getMethod("getScaleToSave"),
    322                                                             Picture.class.getMethod("setScale", pFloat));
    323                         _Attrib.ins("CropStart",            Picture.class.getMethod("getCropStart"),
    324                                                             Picture.class.getMethod("setCropStart", pPoint));
    325                         _Attrib.ins("CropEnd",              Picture.class.getMethod("getCropEnd"),
    326                                                             Picture.class.getMethod("setCropEnd", pPoint));
    327                         _Attrib.ins("Image",                Picture.class.getMethod("getImageSource"),
    328                                                             Picture.class.getMethod("setImageSource", pString));
    329                        
    330                        
    331                         // AttribSet has some extra stuff and some aliases
    332                         _AttribSet.putAll(_Attrib);
    333                         _AttribSet.put("X",                 null,
    334                                                             Item.class.getMethod("setX", pFloat));
    335                         _AttribSet.put("Y",                 null,
    336                                                             Item.class.getMethod("setY", pFloat));
    337                         _AttribSet.alias("pos",             "position");
    338                         _AttribSet.alias("p",               "position");
    339                         _AttribSet.alias("xy",              "position");
    340                         _AttribSet.alias("a",               "action");
    341                         _AttribSet.alias("d",               "data");
    342                         _AttribSet.alias("f",               "formula");
    343                         _AttribSet.alias("s",               "size");
    344                         _AttribSet.alias("l",               "link");
    345                         _AttribSet.alias("ab",              "anchorbottom");
    346                         _AttribSet.alias("ar",              "anchorright");
    347                         _AttribSet.alias("t",               "thickness");
    348                         // _SetAttrib.alias("c",               "color"); // breaks circle creation
    349                         _AttribSet.alias("bgc",             "backgroundcolor");
    350                         _AttribSet.alias("bc",              "bordercolor");
    351                         _AttribSet.alias("fc",              "fillcolor");
    352                         _AttribSet.alias("gc",              "gradientcolor");
    353                         _AttribSet.alias("ga",              "gradientangle");
    354                         _AttribSet.alias("fp",              "fillpattern");
    355                         _AttribSet.alias("lm",              "linkmark");
    356                         _AttribSet.alias("am",              "actionmark");
    357                         _AttribSet.alias("dt",              "dottype");
    358                         _AttribSet.alias("fill",            "filled");
    359                         _AttribSet.alias("lp",              "linepattern");
    360                         _AttribSet.alias("lf",              "linkframeset");
    361                         _AttribSet.alias("lt",              "linktemplate");
    362                         _AttribSet.alias("face",            "fontstyle");
    363                         _AttribSet.alias("j",               "justification");
    364                         _AttribSet.alias("w",               "width");
    365                         _AttribSet.alias("as",              "autostamp");
    366                        
    367                        
    368                         // AttribSave has some extra stuff and some stuff removed
    369                         _AttribSave.putAll(_Attrib);
    370                         _AttribSave.remove("save");
    371                         _AttribSave.remove("autostamp");
    372                         _AttribSave.put("Spacing",          Text.class.getMethod("getSpacing"),
    373                                                             Text.class.getMethod("setSpacing", pInt));
    374                         _AttribSave.put("WordSpacing",      Text.class.getMethod("getWordSpacing"),
    375                                                             Text.class.getMethod("setWordSpacing", pInt));
    376                         _AttribSave.put("LetterSpacing",    Text.class.getMethod("getLetterSpacing"),
    377                                                             Text.class.getMethod("setLetterSpacing", pInt));
    378                         _AttribSave.put("InitialSpacing",   Text.class.getMethod("getInitialSpacing"),
    379                                                             Text.class.getMethod("setInitialSpacing", pInt));
    380                         _AttribSave.put("Text",             Text.class.getMethod("getText"),
    381                                                             Text.class.getMethod("appendLine", pString));
     274                        // Aliases for attribute setting
     275                        _Attrib.alias("pos",                "position");
     276                        _Attrib.alias("p",                  "position");
     277                        _Attrib.alias("xy",                 "position");
     278                        _Attrib.alias("a",                  "action");
     279                        _Attrib.alias("d",                  "data");
     280                        _Attrib.alias("f",                  "formula");
     281                        _Attrib.alias("s",                  "size");
     282                        _Attrib.alias("l",                  "link");
     283                        _Attrib.alias("ab",                 "anchorbottom");
     284                        _Attrib.alias("ar",                 "anchorright");
     285                        _Attrib.alias("t",                  "thickness");
     286                        // _Attrib.alias("c",                  "color"); // breaks circle creation
     287                        _Attrib.alias("bgc",                "backgroundcolor");
     288                        _Attrib.alias("bc",                 "bordercolor");
     289                        _Attrib.alias("fc",                 "fillcolor");
     290                        _Attrib.alias("gc",                 "gradientcolor");
     291                        _Attrib.alias("ga",                 "gradientangle");
     292                        _Attrib.alias("fp",                 "fillpattern");
     293                        _Attrib.alias("lm",                 "linkmark");
     294                        _Attrib.alias("am",                 "actionmark");
     295                        _Attrib.alias("dt",                 "dottype");
     296                        _Attrib.alias("fill",               "filled");
     297                        _Attrib.alias("lp",                 "linepattern");
     298                        _Attrib.alias("lf",                 "linkframeset");
     299                        _Attrib.alias("lt",                 "linktemplate");
     300                        _Attrib.alias("face",               "fontstyle");
     301                        _Attrib.alias("j",                  "justification");
     302                        _Attrib.alias("w",                  "width");
     303                        _Attrib.alias("as",                 "autostamp");
    382304                       
    383305
     
    431353                        Attribute a = as.get(prop);
    432354                        // Make sure the classes of the methods match the item
    433                         if (a != null && a.getter.getDeclaringClass().isAssignableFrom(toExtract.getClass())) {
     355                        if (a != null && a.getter != null && a.getter.getDeclaringClass().isAssignableFrom(toExtract.getClass())) {
    434356                               
    435357                                try {
     
    658580                                        } else if (_IgnoreSet.contains(stripped)) {
    659581                                                return false;
    660                                         } else if (!(_AttribSet.containsKey(stripped))) {
    661                                                 return false;
    662582                                        } else {
     583                                                Attribute a = _Attrib.get(stripped);
     584                                                if(a == null || a.setter == null) {
     585                                                        return false;
     586                                                }
    663587                                                String types = "";
    664                                                 for (Class c : _AttribSet.get(stripped).setter.getParameterTypes()) {
     588                                                for (Class<?> c : a.setter.getParameterTypes()) {
    665589                                                        types += c.getSimpleName() + " ";
    666590                                                }
     
    710634                // Separate multiple values if required
    711635               
    712                 Attribute a = _AttribSet.get(attribute);
     636                Attribute a = _Attrib.get(attribute);
    713637                // if this is not the name of a method, it may be the name of an agent
    714                 if (a == null) {
     638                if (a == null || a.setter == null) {
    715639                        // System.out.println("Attrib not found for: " + attribute);
    716640                        return false;
     
    722646                        possibles.add(a.setter);
    723647                int i = 0;
    724                 while (_AttribSet.containsKey(attribute + i)) {
    725                         Method m = _AttribSet.get(attribute + i).setter;
     648                while (_Attrib.containsKey(attribute + i)) {
     649                        Method m = _Attrib.get(attribute + i).setter;
     650                        if(m == null) {
     651                                break;
     652                        }
    726653                        if (m.getDeclaringClass().isAssignableFrom(toSet.getClass())) {
    727654                                possibles.add(m);
  • trunk/src/org/expeditee/gui/FrameIO.java

    r590 r601  
    2222import org.expeditee.agents.ExistingFramesetException;
    2323import org.expeditee.io.Conversion;
    24 import org.expeditee.io.ExaReader;
    25 import org.expeditee.io.ExaWriter;
    2624import org.expeditee.io.ExpReader;
    2725import org.expeditee.io.ExpWriter;
     
    277275                        return null;
    278276
    279                 // check for the exa file name format
     277                // check for the new file name format
    280278                String fullPath = source + Conversion.getFrameNumber(frameName)
    281                                 + ExaReader.EXTENTION;
     279                                + ExpReader.EXTENTION;
    282280                tester = new File(fullPath);
    283                
     281
    284282                if (tester.exists())
    285283                        return fullPath;
    286                
    287                 // check for the exp file name format
    288                 fullPath = source + Conversion.getFrameNumber(frameName)
    289                                 + ExpReader.EXTENTION;
    290                 tester = new File(fullPath);
    291 
    292                 if (tester.exists())
    293                         return fullPath;
    294 
    295                 // check for kms file name format
     284
     285                // check for oldfile name format
    296286                fullPath = source + Conversion.getFramesetName(frameName) + "."
    297287                                + Conversion.getFrameNumber(frameName);
     
    364354                        FrameReader reader;
    365355
    366                         if(fullPath.endsWith(ExaReader.EXTENTION)) {
    367                                 reader = new ExaReader(frameName);
    368                         } else if (fullPath.endsWith(ExpReader.EXTENTION)) {
     356                        if (fullPath.endsWith(ExpReader.EXTENTION)) {
    369357                                reader = new ExpReader(frameName);
    370358                        } else {
     
    590578                        _Cache.remove(oldFrameName);
    591579
    592                 boolean deleted = false;
    593                 while(source != null) {
    594                         File del = new File(source);
    595                        
    596                         java.io.FileInputStream ff = new java.io.FileInputStream(del);
    597                 ff.close();
    598    
    599                 if (del.delete()) {
    600                         deleted = true;
    601                 }
    602                
    603                 // check if there are any save files from other formats still existing
    604                 source = getFrameFullPathName(toDelete.getPath(), toDelete.getName());
    605                 }
    606                
    607                 if(deleted) {
     580                File del = new File(source);
     581
     582                java.io.FileInputStream ff = new java.io.FileInputStream(del);
     583                ff.close();
     584
     585                if (del.delete()) {
    608586                        return toDelete.getName();
    609587                }
     
    882860                        checkBackup = false;
    883861                }
    884                
    885                 FrameWriter writer = new ExaWriter();
     862
     863                FrameWriter writer = null;
    886864                int savedVersion;
    887                 boolean converted = true;
    888 
    889865                try {
    890                        
    891866                        // if its a new frame or an existing Exp frame...
    892                 if(fullPath == null || fullPath.endsWith(ExaReader.EXTENTION)) {
    893                         savedVersion = ExaReader.getVersion(fullPath);
    894                         converted = false;
    895                 } else if (fullPath.endsWith(ExpReader.EXTENTION)) {
    896                         // writer = new ExpWriter();
    897                         savedVersion = ExpReader.getVersion(fullPath);
    898                         // delete the old file since we're replacing it with exa format
    899                 } else {
    900                         // writer = new KMSWriter();
    901                         savedVersion = KMSReader.getVersion(fullPath);
    902                         // delete the old file since we're replacing it with exa format
    903                 }
     867                        if (fullPath == null || fullPath.endsWith(ExpReader.EXTENTION)) {
     868                                writer = new ExpWriter();
     869                                savedVersion = ExpReader.getVersion(fullPath);
     870                        } else {
     871                                writer = new KMSWriter();
     872                                savedVersion = KMSReader.getVersion(fullPath);
     873                        }
    904874
    905875                        // Check if the frame doesnt exist
     
    989959                        // FrameGraphics.setMode(FrameGraphics.MODE_XRAY, true);
    990960                        writer.writeFrame(toSave);
    991                        
    992                         // Now that we've written the file, erase the old format file
    993                         // (on second thoughts probably better to leave a backup, getFrameFullPathName will preferentially return EXA anyway)
    994                         if(converted && !getFrameFullPathName(toSave.getPath(), toSave.getName()).equals(fullPath)) {
    995                                 MessageBay.displayMessage("Converted " + toSave.getName() + " to EXA format");
    996                                 // new File(fullPath).delete();
    997                         }
    998                        
    999961                        // FrameGraphics.setMode(oldMode, true);
    1000962                        toSave.setSaved();
     
    15301492                String filename = PUBLIC_PATH + Conversion.getFramesetName(frameName)
    15311493                                + File.separator + Conversion.getFrameNumber(frameName)
    1532                                 + ExaReader.EXTENTION;
     1494                                + ExpReader.EXTENTION;
    15331495
    15341496                File file = new File(filename);
     
    15361498                if (file.exists()) {
    15371499                        // Check the versions
    1538                         int savedVersion = ExaReader.getVersion(filename);
     1500                        int savedVersion = ExpReader.getVersion(filename);
    15391501
    15401502                        if (savedVersion > version) {
     
    15541516                                                + nextNum;
    15551517                                filename = PUBLIC_PATH + Conversion.getFramesetName(frameName)
    1556                                                 + File.separator + nextNum + ExaReader.EXTENTION;
     1518                                                + File.separator + nextNum + ExpReader.EXTENTION;
    15571519
    15581520                                // Show the messages alerting the user
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r589 r601  
    525525                }
    526526                frame.addItem(pic);
    527                 frame.removeItem(txt);
    528527
    529528                return true;
     
    927926                                                                        }
    928927                                                                        // check for frame images
    929                                                                 /*} else if (ItemUtils.startsWithTag(i,
     928                                                                } else if (ItemUtils.startsWithTag(i,
    930929                                                                                ItemUtils.TAG_FRAME_IMAGE)
    931930                                                                                && i.getLink() != null
     
    965964                                                                                                toParse, null);
    966965                                                                        }
    967                                                                         toParse.addItem(image);*/
     966                                                                        toParse.addItem(image);
    968967                                                                } else if (ItemUtils.startsWithTag(i, "@c")) {
    969968                                                                        // Can only have a @c
  • trunk/src/org/expeditee/io/ExaReader.java

    r593 r601  
    1515import org.expeditee.items.Item;
    1616import org.expeditee.items.Line;
    17 import org.expeditee.items.Picture;
    1817
    1918/**
    20  * Reads exa format
     19 * Experimental format which is designed to be more readable
     20 * NON FUNCTIONAL DUE TO CHANGES TO AttributeUtils
    2121 *
    2222 * @author jts21
     
    109109                                continue;
    110110                        }
    111                         Attribute attribute = AttributeUtils._FrameAttribSave.get(av[0].toLowerCase());
    112                         if(attribute == null || attribute.setter == null) {
    113                                 System.err.println("Attribute '" + attribute + "' is not supported");
    114                                 continue;
    115                         }
    116                         Object[] vals = Conversion.Convert(attribute.setter, av[1]);
    117                         try {
    118                                 attribute.setter.invoke(_frame, vals);
    119                         } catch(Exception e) {
    120                                 System.err.println("Error running method: " + attribute.setter.getName());
    121                                 e.printStackTrace();
    122                         }
     111                        // TODO: NON FUNCTIONAL DUE TO CHANGES TO AttributeUtils
     112//                      Attribute attribute = AttributeUtils._FrameAttrib.get(av[0].toLowerCase());
     113//                      if(attribute == null || attribute.saveSetter == null) {
     114//                              System.err.println("Attribute '" + attribute + "' is not supported");
     115//                              continue;
     116//                      }
     117//                      Object[] vals = Conversion.Convert(attribute.saveSetter, av[1]);
     118//                      try {
     119//                              attribute.saveSetter.invoke(_frame, vals);
     120//                      } catch(Exception e) {
     121//                              System.err.println("Error running method: " + attribute.saveSetter.getName());
     122//                              e.printStackTrace();
     123//                      }
    123124                       
    124125                }
     
    164165                                }
    165166                        } else if(item != null) {
    166                                 Attribute attribute = AttributeUtils._AttribSave.get(av[0].toLowerCase());
    167                                 if(attribute == null || attribute.setter == null) {
    168                                         System.err.println("Attribute '" + av[0] + "' is not supported");
    169                                         continue;
    170                                 }
    171                                 Object[] vals = Conversion.Convert(attribute.setter, av[1]);
    172                                 try {
    173                                         attribute.setter.invoke(item, vals);
    174                                 } catch(Exception e) {
    175                                         System.err.println("Error running method: " + attribute.setter.getName());
    176                                         e.printStackTrace();
    177                                 }
     167                                // TODO: NON FUNCTIONAL DUE TO CHANGES TO AttributeUtils
     168//                              Attribute attribute = AttributeUtils._Attrib.get(av[0].toLowerCase());
     169//                              if(attribute == null || attribute.saveSetter == null) {
     170//                                      System.err.println("Attribute '" + av[0] + "' is not supported");
     171//                                      continue;
     172//                              }
     173//                              Object[] vals = Conversion.Convert(attribute.saveSetter, av[1]);
     174//                              try {
     175//                                      attribute.saveSetter.invoke(item, vals);
     176//                              } catch(Exception e) {
     177//                                      System.err.println("Error running method: " + attribute.saveSetter.getName());
     178//                                      e.printStackTrace();
     179//                              }
    178180                        }
    179181                }
  • trunk/src/org/expeditee/io/ExaWriter.java

    r593 r601  
    1111
    1212import org.expeditee.gui.AttributeUtils;
    13 import org.expeditee.gui.FrameIO;
    1413import org.expeditee.gui.AttributeUtils.Attribute;
    1514import org.expeditee.gui.Frame;
     
    2019
    2120/**
    22  * Writes frames as exa (Expeditee Attribute) format
    23  * Less efficient on disk space than the exp format, but it makes the save files human-readable
    24  *  and also simplifies things since it mostly uses the same attribute table as attribute extraction
     21 * Experimental format which is designed to be more readable
     22 * NON FUNCTIONAL DUE TO CHANGES TO AttributeUtils
    2523 *
    2624 * @author jts21
     
    9492
    9593        private void writeHeader(Frame frame) throws IOException {
    96                 for (String prop : AttributeUtils._FrameAttribSave.keys) {
    97                         Attribute a = AttributeUtils._FrameAttribSave.get(prop);
    98                         if(a.getter.getDeclaringClass().isAssignableFrom(frame.getClass())) {
    99                                 try {
    100                                         Object o = a.getter.invoke(frame);
    101                                         o = Conversion.ConvertToExpeditee(a.getter, o);
    102                                         if (o != null) {
    103                                                 writeProperty(a.displayName, o);
    104                                         }
    105                                 } catch (Exception e) {
    106                                         e.printStackTrace();
    107                                 }
    108                         }
    109                 }
     94                // TODO: NON FUNCTIONAL DUE TO CHANGES TO AttributeUtils
     95//              for (String prop : AttributeUtils._FrameAttrib.keys) {
     96//                      Attribute a = AttributeUtils._FrameAttrib.get(prop);
     97//                      if(a == null || a.saveGetter == null) {
     98//                              continue;
     99//                      }
     100//                      if(a.saveGetter.getDeclaringClass().isAssignableFrom(frame.getClass())) {
     101//                              try {
     102//                                      Object o = a.saveGetter.invoke(frame);
     103//                                      o = Conversion.ConvertToExpeditee(a.saveGetter, o);
     104//                                      if (o != null) {
     105//                                              writeProperty(a.displayName, o);
     106//                                      }
     107//                              } catch (Exception e) {
     108//                                      e.printStackTrace();
     109//                              }
     110//                      }
     111//              }
    110112        }
    111113       
     
    120122                        }
    121123                        writeLine("Item " + item.getClass().getName() + " " + item.getID());
    122                         for (String prop : AttributeUtils._AttribSave.keys) {
    123                                 Attribute a = AttributeUtils._AttribSave.get(prop);
    124                                 Class<?> declarer = a.getter.getDeclaringClass();
    125                                 if (declarer.isAssignableFrom(item.getClass())) {
    126                                         try {
    127                                                 Object o = a.getter.invoke(item);
    128                                                 o = Conversion.ConvertToExpeditee(a.getter, o);
    129                                                 if (o != null) {
    130                                                         if (o instanceof List) {
    131                                                                 for (Object line : (List<?>) o) {
    132                                                                         writeProperty(a.displayName, line);
    133                                                                 }
    134                                                         } else {
    135                                                                 writeProperty(a.displayName, o);
    136                                                         }
    137                                                 }
    138                                         } catch (Exception e) {
    139                                                 e.printStackTrace();
    140                                         }
    141                                 }
     124                        for (String prop : AttributeUtils._Attrib.keys) {
     125                                // TODO: NON FUNCTIONAL DUE TO CHANGES TO AttributeUtils
     126//                              Attribute a = AttributeUtils._Attrib.get(prop);
     127//                              if(a == null || a.saveGetter == null) {
     128//                              continue;
     129//                      }
     130//                              Class<?> declarer = a.saveGetter.getDeclaringClass();
     131//                              if (declarer.isAssignableFrom(item.getClass())) {
     132//                                      try {
     133//                                              Object o = a.saveGetter.invoke(item);
     134//                                              o = Conversion.ConvertToExpeditee(a.saveGetter, o);
     135//                                              if (o != null) {
     136//                                                      if (o instanceof List) {
     137//                                                              for (Object line : (List<?>) o) {
     138//                                                                      writeProperty(a.displayName, line);
     139//                                                              }
     140//                                                      } else {
     141//                                                              writeProperty(a.displayName, o);
     142//                                                      }
     143//                                              }
     144//                                      } catch (Exception e) {
     145//                                              e.printStackTrace();
     146//                                      }
     147//                              }
    142148                        }
    143149                }
  • trunk/src/org/expeditee/io/WebParser.java

    r600 r601  
    1616import org.expeditee.gui.Frame;
    1717import org.expeditee.gui.FrameIO;
     18import org.expeditee.gui.FrameUtils;
    1819import org.expeditee.gui.MessageBay;
    1920import org.expeditee.items.ItemUtils;
     
    452453                ImageIO.write(img, "png", out);
    453454
    454                 if (cropEndX == null || cropStartX == null || cropEndY == null || cropStartY == null) {
    455                         cropStartX = 0;
    456                         cropStartY = 0;
    457                         cropEndX = img.getWidth();
    458                         cropEndY = img.getHeight();
    459                 }
    460 
    461455                if (width < 0) {
    462                         width = img.getWidth();
    463                 }
    464 
    465                 Picture pic = new Picture(out.getName(), frame);
    466                 pic.setWidth(width);
    467 
    468                 // Have to divide the crop coords by the image scale, since Expeditee seems to always crop then scale
    469                 pic.setCropStart(new Point((int) (cropStartX / pic.getScale()), (int) (cropStartY / pic.getScale())));
    470                 pic.setCropEnd(new Point((int) (cropEndX / pic.getScale()), (int) (cropEndY / pic.getScale())));
    471                 pic.setPosition(x, y);
    472                 frame.addItem(pic);
     456                        System.out.println("invalid width");
     457                }
     458               
     459                String imageStr = "@i: " + out.getName() + " " + width;
     460               
     461                int scale = width / img.getWidth();
     462               
     463                if (!(cropEndX == null || cropStartX == null || cropEndY == null || cropStartY == null)) {
     464                        imageStr += " " + (int) (cropStartX / scale) + " " + (int) (cropStartY / scale) + " " + (int) (cropEndX / scale) + " " + (int) (cropEndY / scale);
     465                }
     466               
     467                Text text = new Text(imageStr);
     468                text.setPosition(x, y);
     469               
     470                frame.addItem(text);
    473471        }
    474472}
  • trunk/src/org/expeditee/items/FrameBitmap.java

    r589 r601  
    11package org.expeditee.items;
    22
     3import java.awt.Color;
     4import java.awt.Image;
     5import java.awt.image.BufferedImage;
    36import java.awt.image.ImageObserver;
     7import java.util.List;
    48
    5 // TODO: Make this work with new Picture class
     9import org.expeditee.gui.Frame;
     10import org.expeditee.gui.FrameIO;
    611
    712//TODO tidy up the mess I caused with refresh during the period where I was going into XRay mode before saving
    813
    914public class FrameBitmap extends FramePicture {
     15        public FrameBitmap(Text source, ImageObserver observer, Image image){
     16                super(source, observer, image);
     17        }
    1018
    11         protected FrameBitmap(String path, ImageObserver observer) {
    12             super(path, observer);
    13     }
    14 //      public FrameBitmap(Text source, ImageObserver observer, Image image){
    15 //              super(source, observer, image);
    16 //      }
    17 //
    18 //      @Override
    19 //      public boolean refresh() {
    20 //              assert (getLink() != null);
    21 //              Frame frame = FrameIO.LoadFrame(getAbsoluteLink());
    22 //              // if the frame cant be found just use the current image
    23 //              if (frame == null) {
    24 //                      return false;
    25 //              }
    26 //
    27 //              List<Text> textList = frame.getBodyTextItems(false);
    28 //              if (textList.size() == 0)
    29 //                      return false;
    30 //              List<String> imageLines = textList.get(0).getTextList();
    31 //              int width = 0;
    32 //              int height = imageLines.size();
    33 //              // Determine the image width by finding the widest line of text
    34 //              for (String s : imageLines) {
    35 //                      if (s.length() > width)
    36 //                              width = s.length();
    37 //              }
    38 //             
    39 //              if(width == 0)
    40 //                      return false;
    41 //             
    42 //              BufferedImage bi = new BufferedImage(width, height,
    43 //                              BufferedImage.TYPE_INT_ARGB);
    44 //              // now set the bits on the image
    45 //              final int transparent = (new Color(0F, 0F, 0F, 0F)).getRGB();
    46 //              final int main = getPaintColor().getRGB();
    47 //              final Color c = getPaintColor();
    48 //              int currentColor = main;
    49 //              int row = 0;
    50 //              for (String s : imageLines) {
    51 //                      for (int i = 0; i < width; i++) {
    52 //                              currentColor = transparent;
    53 //                              if (i < s.length()) {
    54 //                                      char currentPixel = s.charAt(i);
    55 //                                      // Space is transparent as is 0
    56 //                                      if (Character.isDigit(currentPixel)) {
    57 //                                              int alpha = Math.round((currentPixel - '0') * 25.5F);
    58 //                                              currentColor = new Color(c.getRed(), c.getGreen(), c
    59 //                                                              .getBlue(), alpha).getRGB();
    60 //                                      }else if (currentPixel != ' ') {
    61 //                                              currentColor = main;
    62 //                                      }
    63 //                              }
    64 //                              bi.setRGB(i, row, currentColor);
    65 //                      }
    66 //                      row++;
    67 //              }
    68 //              _image = bi;
    69 //
    70 //              return true;
    71 //      }
    72 //
    73 //      @Override
    74 //      protected Picture createPicture() {
    75 //              return new FrameBitmap(this.getSource(), _imageObserver, _image);
    76 //      }
    77 //
    78 //      @Override
    79 //      protected String getTagText() {
    80 //              return "@b: ";
    81 //      }
     19        @Override
     20        public boolean refresh() {
     21                assert (_source.getLink() != null);
     22                Frame frame = FrameIO.LoadFrame(_source.getAbsoluteLink());
     23                // if the frame cant be found just use the current image
     24                if (frame == null) {
     25                        return false;
     26                }
     27
     28                List<Text> textList = frame.getBodyTextItems(false);
     29                if (textList.size() == 0)
     30                        return false;
     31                List<String> imageLines = textList.get(0).getTextList();
     32                int width = 0;
     33                int height = imageLines.size();
     34                // Determine the image width by finding the widest line of text
     35                for (String s : imageLines) {
     36                        if (s.length() > width)
     37                                width = s.length();
     38                }
     39               
     40                if(width == 0)
     41                        return false;
     42               
     43                BufferedImage bi = new BufferedImage(width, height,
     44                                BufferedImage.TYPE_INT_ARGB);
     45                // now set the bits on the image
     46                final int transparent = (new Color(0F, 0F, 0F, 0F)).getRGB();
     47                final int main = _source.getPaintColor().getRGB();
     48                final Color c = _source.getPaintColor();
     49                int currentColor = main;
     50                int row = 0;
     51                for (String s : imageLines) {
     52                        for (int i = 0; i < width; i++) {
     53                                currentColor = transparent;
     54                                if (i < s.length()) {
     55                                        char currentPixel = s.charAt(i);
     56                                        // Space is transparent as is 0
     57                                        if (Character.isDigit(currentPixel)) {
     58                                                int alpha = Math.round((currentPixel - '0') * 25.5F);
     59                                                currentColor = new Color(c.getRed(), c.getGreen(), c
     60                                                                .getBlue(), alpha).getRGB();
     61                                        }else if (currentPixel != ' ') {
     62                                                currentColor = main;
     63                                        }
     64                                }
     65                                bi.setRGB(i, row, currentColor);
     66                        }
     67                        row++;
     68                }
     69                _image = bi;
     70
     71                return true;
     72        }
     73
     74        @Override
     75        protected Picture createPicture() {
     76                return new FrameBitmap((Text) _source.copy(),
     77                                _imageObserver, _image);
     78        }
     79
     80        @Override
     81        protected String getTagText() {
     82                return "@b: ";
     83        }
    8284}
  • trunk/src/org/expeditee/items/FrameImage.java

    r589 r601  
    11package org.expeditee.items;
    22
     3import java.awt.Image;
    34import java.awt.image.ImageObserver;
    45
    5 //TODO: Make this work with new Picture class
     6import org.expeditee.gui.Frame;
     7import org.expeditee.gui.FrameGraphics;
     8import org.expeditee.gui.FrameIO;
    69
    710public class FrameImage extends FramePicture {
     11        /**
     12         * Creates a new Picture from the given path. The ImageObserver is optional
     13         * and can be set to NULL. <br>
     14         * Note: It is assumed that the file described in path has already been
     15         * checked to exist.
     16         *
     17         * @param source
     18         *            The Text Item that was used to create this Picture
     19         * @param path
     20         *            The Path of the Image to load from disk.
     21         * @param observer
     22         *            The ImageObserver to assign when painting the Image on the
     23         *            screen.
     24         */
     25        public FrameImage(Text source, ImageObserver observer, Image image) {
     26                super(source, observer, image);
     27        }
    828
    9         protected FrameImage(String path, ImageObserver observer) {
    10             super(path, observer);
    11     }
    12 //      /**
    13 //       * Creates a new Picture from the given path. The ImageObserver is optional
    14 //       * and can be set to NULL. <br>
    15 //       * Note: It is assumed that the file described in path has already been
    16 //       * checked to exist.
    17 //       *
    18 //       * @param source
    19 //       *            The Text Item that was used to create this Picture
    20 //       * @param path
    21 //       *            The Path of the Image to load from disk.
    22 //       * @param observer
    23 //       *            The ImageObserver to assign when painting the Image on the
    24 //       *            screen.
    25 //       */
    26 //      public FrameImage(Text source, ImageObserver observer, Image image) {
    27 //              super(source, observer, image);
    28 //      }
    29 //
    30 //      @Override
    31 //      protected Picture createPicture() {
    32 //              return new FrameImage(this.getSource(), _imageObserver, _image);
    33 //      }
    34 //
    35 //      @Override
    36 //      public boolean refresh() {
    37 //              // Need to parse the first time the frame is being displayed
    38 //              // parseSize();
    39 //              assert (getLink() != null);
    40 //              Frame frame = FrameIO.LoadFrame(getAbsoluteLink(), null, true);
    41 //              if (frame == null)
    42 //                      return false;
    43 //
    44 //              frame.setBuffer(null);
    45 //              FrameGraphics.UpdateBuffer(frame, false, false);
    46 //              _image = frame.getBuffer();
    47 //
    48 //              // TODO tidy this up, need to call parse size only when the frame has
    49 //              // been created to begin with
    50 //              // parseSize();
    51 //              updatePolygon();
    52 //              return true;
    53 //      }
    54 //
    55 //      @Override
    56 //      protected String getTagText() {
    57 //              return "@f: ";
    58 //      }
     29        @Override
     30        protected Picture createPicture() {
     31                return new FrameImage(_source.copy(), _imageObserver, _image);
     32        }
     33
     34        @Override
     35        public boolean refresh() {
     36                // Need to parse the first time the frame is being displayed
     37                // parseSize();
     38                assert (_source.getLink() != null);
     39                Frame frame = FrameIO.LoadFrame(_source.getAbsoluteLink(), null, true);
     40                if (frame == null)
     41                        return false;
     42
     43                frame.setBuffer(null);
     44                FrameGraphics.UpdateBuffer(frame, false, false);
     45                _image = frame.getBuffer();
     46
     47                // TODO tidy this up, need to call parse size only when the frame has
     48                // been created to begin with
     49                parseSize();
     50                updatePolygon();
     51                return true;
     52        }
     53
     54        @Override
     55        protected String getTagText() {
     56                return "@f: ";
     57        }
    5958}
  • trunk/src/org/expeditee/items/FramePicture.java

    r589 r601  
    11package org.expeditee.items;
    22
     3import java.awt.Color;
     4import java.awt.Image;
    35import java.awt.image.ImageObserver;
    46
    5 //TODO: Make this work with new Picture class
     7import org.expeditee.gui.AttributeValuePair;
     8import org.expeditee.gui.Frame;
    69
    710public abstract class FramePicture extends Picture {
    8         protected FramePicture(String path, ImageObserver observer) {
    9                 super(path, observer);
     11        protected FramePicture(Text source, ImageObserver observer, Image image) {
     12                super(source, observer, image);
    1013        }
    1114
    12 //      @Override
    13 //      public void setColor(Color c) {
    14 //              super.setColor(c);
    15 //              refresh();
    16 //      }
    17 //     
    18 //      @Override
    19 //      public void setLink(String frameName) {
    20 //              setLink(frameName);
    21 //              //remove the picture if the link is being removed
    22 //              if (getLink() == null) {
    23 //                      Frame parent = getParent();
    24 //                      if (parent != null) {
    25 //                              parent.removeItem(this);
    26 //                              setHidden(false);
    27 //                      }
    28 //              } else {
    29 //                      refresh();
    30 //              }
    31 //              updatePolygon();
    32 //      }
    33 //     
    34 //      @Override
    35 //      public String getName() {
    36 //              return getAbsoluteLink();
    37 //      }
    38 //     
    39 //      @Override
    40 //      protected String getImageSize() {
    41 //              return new AttributeValuePair(_source.getText()).getValue();
    42 //      }
     15        @Override
     16        public void setColor(Color c) {
     17                super.setColor(c);
     18                refresh();
     19        }
     20       
     21        @Override
     22        public void setLink(String frameName) {
     23                if (_source == null)
     24                        return;
     25                else {
     26                        _source.setLink(frameName);
     27                        //remove the picture if the link is being removed
     28                        if (_source.getLink() == null) {
     29                                Frame parent = getParent();
     30                                if (parent != null) {
     31                                        parent.removeItem(this);
     32                                        _source.setHidden(false);
     33                                        _source.removeEnclosure(this);
     34                                }
     35                        } else {
     36                                refresh();
     37                        }
     38                }
     39                updatePolygon();
     40        }
     41       
     42        @Override
     43        public String getName() {
     44                return _source.getAbsoluteLink();
     45        }
     46       
     47        @Override
     48        protected String getImageSize() {
     49                return new AttributeValuePair(_source.getText()).getValue();
     50        }
    4351}
  • trunk/src/org/expeditee/items/ItemUtils.java

    r600 r601  
    338338         * If the Image file cannot be found on disk null is returned.
    339339         *
    340          * @param path
    341          *            The path to the image file
     340         * @param source
     341         *            The Text file containing the Picture infomation
    342342         * @return The Picture object representing the file, or Null if the file is
    343343         *         not found.
     
    346346                String text = source.getText();
    347347                String path = "";
     348                String fileName = "";
    348349                String size = "";
    349                 String crop = "";
    350350
    351351                try {
     
    366366                                size = text.substring(endOfFileName).trim();
    367367                        }
     368                        fileName = path;
     369
     370                        // try images subdirectory
     371                        File file = null;
     372
     373                        for (String dir : org.expeditee.settings.UserSettings.ImageDirs) {
     374                                file = new File(dir + path);
     375                                if (file.exists() && !file.isDirectory())
     376                                        break;
     377                        }
     378
     379                        if (file == null || !file.exists() || file.isDirectory())
     380                                file = new File(path);
     381
     382                        // try relative path
     383                        if (!file.exists() || file.isDirectory()) {
     384                                URL picture = new Object().getClass().getResource(path);
     385
     386                                // decode to remove %20 in windows folder names
     387                                if (picture != null) {
     388                                        try {
     389                                                path = URLDecoder.decode(picture.getFile(), "UTF-8");
     390                                        } catch (UnsupportedEncodingException e) {
     391                                                // TODO Auto-generated catch block
     392                                                e.printStackTrace();
     393                                        }
     394                                }
     395
     396                        } else
     397                                path = file.getPath();
     398
     399                        // if the image isn't found by now, give up.
     400                        file = new File(path);
     401                        if (!file.exists() || file.isDirectory()) {
     402                                return null;
     403                        }
    368404
    369405                } catch (Exception e) {
     
    372408
    373409                try {
    374                         Picture pic = new Picture(path, source, size, observer);
     410                        Picture pic = new Picture(source, fileName, path, size, observer);
     411
    375412                        return pic;
    376413                } catch (Exception e) {
  • trunk/src/org/expeditee/items/Picture.java

    r600 r601  
    1717import java.awt.image.ImageObserver;
    1818import java.io.File;
    19 import java.io.UnsupportedEncodingException;
    20 import java.net.URL;
    21 import java.net.URLDecoder;
     19import java.io.IOException;
     20import java.text.DecimalFormat;
    2221
    2322import javax.imageio.ImageIO;
     
    2625import org.expeditee.gui.FrameGraphics;
    2726import org.expeditee.gui.FrameMouseActions;
    28 import org.expeditee.settings.UserSettings;
     27import org.expeditee.stats.Logger;
    2928
    3029/**
     
    4544 *
    4645 */
    47 public class Picture extends Item {
    48        
    49         protected static final Image imageNotFound;
    50         protected static final Polygon imageNotFoundPolygon;
    51         static {
    52                 Image iNF = null;
    53                 try {
    54                         URL image = ClassLoader.getSystemResource("org/expeditee/resources/images/imageNotFound.png");
    55                         if(image != null) {
    56                                 iNF = Toolkit.getDefaultToolkit().getImage(image);
    57                         } else {
    58                                 System.err.println("Failed to load default image");
    59                         }
    60                 } catch(Exception e) {
    61                         e.printStackTrace();
    62                 }
    63                 imageNotFound = iNF;
    64                 imageNotFoundPolygon = new Polygon();
    65                 imageNotFoundPolygon.addPoint(-1,  -1);
    66                 imageNotFoundPolygon.addPoint(65, -1);
    67                 imageNotFoundPolygon.addPoint(65,  65);
    68                 imageNotFoundPolygon.addPoint(-1, 65);
    69                 imageNotFoundPolygon.addPoint(-1,  65);
    70                 System.out.println("Loaded static members");
    71         }
     46public class Picture extends XRayable {
    7247
    7348        private static final int MINIMUM_WIDTH = 10;
     49
    7450        public static final int WIDTH = 0;
     51
    7552        public static final int RATIO = 1;
    7653
    7754        protected Image _image = null;
    78         protected Image _croppedImage = null;
    7955
    8056        private int _scaleType = RATIO;
     
    8258        private float _scale = 1.0f;
    8359
    84         // Points relative to this Picture's cropping, for creating further cropped Pictures
     60        // Start of the crop relative to START
    8561        private Point _cropStart = null;
     62
     63        // Start of the crop relative to END
    8664        private Point _cropEnd = null;
    8765
    88         // Crop data of this Picture
    8966        private Point _start = new Point(0, 0);
     67
    9068        private Point _end = new Point(0, 0);
    9169
     
    9371
    9472        private String _path = "";
     73
     74        private String _size = "";
     75
     76        private String _fileName = null;
    9577
    9678        // used to repaint animated GIF images, among other things.
    9779        protected ImageObserver _imageObserver = null;
     80
     81        protected Picture(Text source, ImageObserver observer, Image image) {
     82                super(source);
     83                _imageObserver = observer;
     84                _image = image;
     85
     86                refresh();
     87
     88                if (_image != null)
     89                        parseSize();
     90        }
    9891
    9992        /**
     
    10396         * checked to exist.
    10497         *
     98         * @param source
     99         *            The Text Item that was used to create this Picture
     100         * @param fileName
     101         *            the name of the file as it should be displayed in the source
     102         *            text
    105103         * @param path
    106104         *            The Path of the Image to load from disk.
     
    109107         *            screen.
    110108         */
    111        
    112         public Picture(int id) {
    113                 super();
    114                 setID(id);
    115         }
    116        
    117         public Picture(String path, ImageObserver observer, int id) {
    118                 super();
    119                 if(id == -1) {
    120                         id = this.getParentOrCurrentFrame().getNextItemID();
    121                 }
    122                 setID(id);
     109        public Picture(Text source, String fileName, String path, String size,
     110                        ImageObserver observer) {
     111                super(source);
    123112                _imageObserver = observer;
    124                 this.setImageSource(path);
    125         }
    126        
    127         public Picture(String path, ImageObserver observer) {
    128                 this(path, observer, -1);
    129         }
    130        
    131         public Picture(String path, Text source, String size, ImageObserver observer) {
    132                 this(path, observer, source.getID());
    133                 Item.DuplicateItem(source, this);
    134                 this.parseSize(size);
    135                 updatePolygon();
    136         }
    137        
    138         /**
    139          * Parse string input given in an @i tag
    140          */
    141         protected void parseSize(String size) {
    142                 // don't check this anymore since it's only called from constructors now
    143                 // if (_end.x != 0 || _end.y != 0)
    144                 //      return;
     113                _fileName = fileName;
     114                _path = path;
     115                _size = size;
     116
     117                refresh();
     118                parseSize();
     119        }
     120
     121        protected String getImageSize() {
     122                return _size;
     123        }
     124
     125        protected void parseSize() {
     126                String size = getImageSize();
     127
     128                if (_end.x != 0 || _end.y != 0)
     129                        return;
    145130
    146131                // set the default values for start and end
     
    170155                        if (size.length() == 0) {
    171156                                size = "" + _image.getWidth(null);
     157                                _source.setText(getTagText() + size);
    172158                                return;
    173159                        }
     
    189175        }
    190176
    191 
    192         /**
    193          * Set the start point for generating a new cropped Picture from this Picture
    194          */
    195177        public void setStartCrop(int x, int y) {
    196178                invalidateCroppedArea();
     
    199181        }
    200182
    201         /**
    202          * Set the end point for generating a new cropped Picture from this Picture
    203          */
    204183        public void setEndCrop(int x, int y) {
    205184                invalidateCroppedArea();
     
    223202        }
    224203
    225         /**
    226          * Get the top left point (_start) for generating a new cropped Picture from this Picture
    227          */
    228204        public Point getTopLeftCrop() {
    229205                return new Point(Math.min(_cropStart.x, _cropEnd.x), Math.min(
     
    231207        }
    232208
    233         /**
    234          * Get the bottom right point (_end) for generating a new cropped Picture from this Picture
    235          */
    236209        public Point getBottomRightCrop() {
    237210                return new Point(Math.max(_cropStart.x, _cropEnd.x), Math.max(
     
    246219
    247220        public boolean isCropTooSmall() {
    248                 if (_cropStart == null || _cropEnd == null || _image == imageNotFound)
     221                if (_cropStart == null || _cropEnd == null)
    249222                        return true;
    250223
     
    261234                setShowCrop(false);
    262235        }
    263        
    264         public int getStartX() {
    265                 return _image == imageNotFound ? 0 : _start.x;
    266         }
    267        
    268         public int getStartY() {
    269                 return _image == imageNotFound ? 0 : _start.y;
    270         }
    271        
    272         public int getEndX() {
    273                 return _image == imageNotFound ? 64 : _end.x == 0 ? _image.getWidth(null) : _end.x;
    274         }
    275        
    276         public int getEndY() {
    277                 return _image == imageNotFound ? 64 : _end.y == 0 ? _image.getHeight(null) : _end.y;
    278         }
    279236
    280237        public void updatePolygon() {
    281238                if (_image == null) {
    282239                        refresh();
    283                 }
    284                 if (_image == imageNotFound) {
    285                         _poly = new Polygon(imageNotFoundPolygon.xpoints, imageNotFoundPolygon.ypoints, imageNotFoundPolygon.npoints);
    286                         _poly.translate(getX(), getY());
    287                         // _start = new Point(0, 0);
    288                         // _end = new Point(_image.getWidth(null), _image.getHeight(null));
    289                         // _scale = 1f;
    290                         return;
    291                 }
    292                
     240                        parseSize();
     241                }
    293242                _poly = new Polygon();
    294243
     
    300249
    301250                        // extra pixel around the image so the highlighting is visible
    302                         _poly.addPoint(getX() + 1 + xdiff, getY() - 1);
    303                         _poly.addPoint(getX() + width, getY() - 1);
    304                         _poly.addPoint(getX() + width, getY() + height);
    305                         _poly.addPoint(getX() + 1 + xdiff, getY() + height);
     251                        _poly.addPoint(_source.getX() + 1 + xdiff, _source.getY() - 1);
     252                        _poly.addPoint(_source.getX() + width, _source.getY() - 1);
     253                        _poly.addPoint(_source.getX() + width, _source.getY() + height);
     254                        _poly.addPoint(_source.getX() + 1 + xdiff, _source.getY() + height);
    306255                } else {
    307256                        Point topLeft = getTopLeftCrop();
    308257                        Point bottomRight = getBottomRightCrop();
    309                         Rectangle clip = new Rectangle(topLeft.x + getX(),
    310                                         topLeft.y + getY(), bottomRight.x - topLeft.x,
     258                        Rectangle clip = new Rectangle(topLeft.x + _source.getX(),
     259                                        topLeft.y + _source.getY(), bottomRight.x - topLeft.x,
    311260                                        bottomRight.y - topLeft.y).getBounds();
    312261                        _poly.addPoint((int) clip.getMinX() - 1, (int) clip.getMinY() - 1);
     
    325274        @Override
    326275        public void setWidth(Integer width) {
    327                 _scaleType = WIDTH;
    328                 _scale = width * 1F / (getUnscaledWidth());
     276                _scale = width * 1F / (_end.x - _start.x);
    329277        }
    330278
     
    342290        @Override
    343291        public Integer getWidth() {
    344                 return Math.round((getUnscaledWidth()) * _scale);
     292                return Math.round((_end.x - _start.x) * _scale);
    345293        }
    346294
     
    350298        @Override
    351299        public int getHeight() {
    352                 return Math.round((getUnscaledHeight()) * _scale);
     300                return Math.round((_end.y - _start.y) * _scale);
    353301        }
    354302
     
    365313        @Override
    366314        public void paint(Graphics2D g) {
    367                 // System.out.println("drawing image");
    368 
    369                 if(_image == null) {
     315                if (_image == null)
    370316                        return;
    371                 }
    372                
    373                 int width = _image == imageNotFound ? 64 : getWidth();
    374                 int height = _image == imageNotFound ? 64 : getHeight();
    375                 int startX = getStartX();
    376                 int startY = getStartY();
    377                 int endX = getEndX();
    378                 int endY = getEndY();
    379                
    380                 // System.out.println(width + " : " + height);
     317
     318                int width = getWidth();
     319                int height = getHeight();
    381320
    382321                paintLink(g);
    383322
    384                 int dX1 = getX();
    385                 int dY1 = getY();
    386                 int dX2 = getX() + width;
    387                 int dY2 = getY() + height;
     323                int dX1 = _source.getX();
     324                int dY1 = _source.getY();
     325                int dX2 = _source.getX() + width;
     326                int dY2 = _source.getY() + height;
    388327
    389328                // if we are showing the cropping, then show the original as transparent
     
    393332                        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
    394333                                        alpha));
    395                         g.drawImage(_image, dX1, dY1, dX2, dY2, startX, startY, endX, endY, _imageObserver);
     334                        g.drawImage(_image, dX1, dY1, dX2, dY2, _start.x, _start.y, _end.x,
     335                                        _end.y, _imageObserver);
    396336
    397337                        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
     
    406346                        g.setClip(clip);
    407347
    408                         g.drawImage(_image, dX1, dY1, dX2, dY2, startX, startY, endX, endY, _imageObserver);
     348                        g.drawImage(_image, dX1, dY1, dX2, dY2, _start.x, _start.y, _end.x,
     349                                        _end.y, _imageObserver);
    409350                        g.draw(clip);
    410351                        // if the image is cropped, but we are not showing the cropping
    411352                        // otherwise, paint normally
    412353                } else {
    413                         g.drawImage(_image, dX1, dY1, dX2, dY2, startX, startY, endX, endY, _imageObserver);
     354                        g.drawImage(_image, dX1, dY1, dX2, dY2, _start.x, _start.y, _end.x,
     355                                        _end.y, _imageObserver);
    414356                }
    415357
     
    446388
    447389        protected Picture createPicture() {
    448                 return new Picture(_path, _imageObserver);
    449                 // return ItemUtils.CreatePicture((Text) _source.copy(), _imageObserver);
     390                return ItemUtils.CreatePicture((Text) _source.copy(), _imageObserver);
    450391        }
    451392
     
    455396                p._image = _image;
    456397                p._mode = _mode;
    457                 p.setPosition(getPosition());
    458398                // Doing Duplicate item duplicates link mark which we dont want to do
    459399                // when in audience mode because the linkMark will be copied incorrectly
     
    466406                        Point topLeft = getTopLeftCrop();
    467407                        Point bottomRight = getBottomRightCrop();
    468                         int startX = Math.round(topLeft.x / _scale) + getStartX();
    469                         int startY = Math.round(topLeft.y / _scale) + getStartY();
    470                         int endX = Math.round(bottomRight.x / _scale + getStartX());
    471                         int endY = Math.round(bottomRight.y / _scale + getStartY());
     408                        int startX = Math.round(topLeft.x / _scale) + _start.x;
     409                        int startY = Math.round(topLeft.y / _scale) + _start.y;
     410                        int endX = Math.round(bottomRight.x / _scale + _start.x);
     411                        int endY = Math.round(bottomRight.y / _scale + _start.y);
    472412                        int width = _image.getWidth(null);
    473413                        int height = _image.getHeight(null);
     
    488428                        p._start = new Point(startX, startY);
    489429                        p._end = new Point(endX, endY);
    490                         p.setPosition(topLeft.x + getX(), topLeft.y + getY());
     430                        p._source.setPosition(topLeft.x + _source.getX(), topLeft.y
     431                                        + _source.getY());
    491432                } else {
    492433                        p._start = _start;
     
    496437                p._scaleType = _scaleType;
    497438                p._path = _path;
    498 
     439                p._fileName = _fileName;
     440
     441                p.updateSource();
    499442                p.updatePolygon();
    500443
     
    507450
    508451        public void setScale(float scale) {
    509                 _scaleType = RATIO;
    510452                _scale = scale;
    511453        }
     
    513455        @Override
    514456        public float getSize() {
    515                 // to let scaling work
    516                 return UserSettings.ItemTemplate.getSize();
     457                return _source.getSize();
    517458        }
    518459
    519460        @Override
    520461        public void setSize(float size) {
    521                 float diff = size - getSize();
     462                float diff = size - _source.getSize();
    522463                float oldScale = _scale;
    523464
     
    529470                        _scale = oldScale;
    530471                } else {
    531                         this.translate(new Point2D.Float(FrameMouseActions.MouseX,
     472                        _source.translate(new Point2D.Float(FrameMouseActions.MouseX,
    532473                                        FrameMouseActions.MouseY), multiplier);
    533474                }
     475                updateSource();
    534476                updatePolygon();
    535477                // Make sure items that are resized display the border
     
    560502                return Toolkit.getDefaultToolkit().createImage(
    561503                                new FilteredImageSource(_image.getSource(),
    562                                                 new CropImageFilter(getStartX(), getStartY(),
     504                                                new CropImageFilter(_start.x, _start.y,
    563505                                                                getUnscaledWidth(), getUnscaledHeight())));
    564506        }
    565507
    566508        public int getUnscaledWidth() {
    567                 return getEndX() - getStartX();
     509                return _end.x - _start.x;
    568510        }
    569511
    570512        public int getUnscaledHeight() {
    571                 return getEndY() - getStartY();
     513                return _end.y - _start.y;
    572514        }
    573515
     
    576518         */
    577519        public boolean isCropped() {
    578                 return (_start.x > 0 || _start.y > 0 || (_end.x > 0 && _end.x < _image.getWidth(null)) || (_end.y > 0 && _end.y < _image.getHeight(null)));
    579                 // return _end.x != 0 || _end.y != 0 || _end.x != _image.getWidth(null) || _end.y != _image.getHeight(null) || _start.y != 0 || _start.x != 0;
    580         }
    581 
     520                return _end.x != 0 || _end.y != 0 || _start.y != 0 || _start.x != 0;
     521        }
     522
     523        @Override
    582524        public boolean refresh() {
    583                 // try images subdirectory
    584                 File file = null;
    585 
    586                 for (String dir : org.expeditee.settings.UserSettings.ImageDirs) {
    587                         file = new File(dir + _path);
    588                         if (file.exists() && !file.isDirectory())
    589                                 break;
    590                 }
    591 
    592                 if (file == null || !file.exists() || file.isDirectory())
    593                         file = new File(_path);
    594 
    595                 // try relative path
    596                 if (!file.exists() || file.isDirectory()) {
    597                         URL picture = new Object().getClass().getResource(_path);
    598 
    599                         // decode to remove %20 in windows folder names
    600                         if (picture != null) {
    601                                 try {
    602                                         _path = URLDecoder.decode(picture.getFile(), "UTF-8");
    603                                 } catch (UnsupportedEncodingException e) {
    604                                         // TODO Auto-generated catch block
    605                                         e.printStackTrace();
    606                                 }
    607                         }
    608 
    609                 } else
    610                         _path = file.getPath();
    611 
    612                 // if the image isn't found by now, give up.
    613                 file = new File(_path);
    614                 if (!file.exists() || file.isDirectory()) {
    615                         // If the image could not be read
    616                         _image = imageNotFound;
    617                         return false;
    618                 }
    619 
    620525                // ImageIcon is faster, but cannot handle some formats
    621526                // (notably.bmp) hence, we try this first, then if it fails we try
     
    630535                        try {
    631536                                _image = ImageIO.read(new File(_path));
    632                         } catch (Exception e) {
     537                        } catch (IOException e) {
    633538                                // e.printStackTrace();
    634                                 // Logger.Log(e);
    635                                
    636                                 // If the image could not be read
    637                                 _image = imageNotFound;
     539                                Logger.Log(e);
     540                                _image = null;
    638541                                return false;
    639542                        }
     
    653556                // if(!state)
    654557                // invalidateCommonTrait(ItemAppearence.LinkChanged);
    655                 super.setLinkMark(state);
     558                _source.setLinkMark(state);
    656559                // if(state)
    657560                // invalidateCommonTrait(ItemAppearence.LinkChanged);
     
    663566                // if (!state)
    664567                // invalidateCommonTrait(ItemAppearence.LinkChanged);
    665                 super.setActionMark(state);
     568                _source.setActionMark(state);
    666569                // if (state)
    667570                // invalidateCommonTrait(ItemAppearence.LinkChanged);
     
    670573
    671574        @Override
     575        public boolean getLinkMark() {
     576                return !FrameGraphics.isAudienceMode() && _source.getLinkMark();
     577        }
     578
     579        @Override
     580        public boolean getActionMark() {
     581                return _source.getActionMark();
     582        }
     583
     584        @Override
    672585        public String getName() {
    673                 return _path;
     586                return _fileName;
     587        }
     588
     589        protected String getTagText() {
     590                return "@i: " + _fileName + " ";
     591        }
     592
     593        /**
     594         * Updates the source text for this item to match the current size of the
     595         * image.
     596         *
     597         */
     598        private void updateSource() {
     599                StringBuffer newText = new StringBuffer(getTagText());
     600
     601                switch (_scaleType) {
     602                case (RATIO):
     603                        DecimalFormat format = new DecimalFormat("0.00");
     604                        newText.append(format.format(_scale));
     605                        break;
     606                case (WIDTH):
     607                        newText.append(getWidth());
     608                        break;
     609                }
     610
     611                // If the image is cropped add the position for the start and finish of
     612                // the crop to the soure text
     613                if (_start.x > 0 || _start.y > 0 || _end.x < _image.getWidth(null)
     614                                || _end.y < _image.getHeight(null)) {
     615                        newText.append(" ").append(_start.x).append(" ").append(_start.y);
     616                        newText.append(" ").append(_end.x).append(" ").append(_end.y);
     617                }
     618
     619                _source.setText(newText.toString());
    674620        }
    675621
     
    677623        public void translate(Point2D origin, double ratio) {
    678624                _scale *= ratio;
     625                updateSource();
    679626                super.translate(origin, ratio);
    680627        }
     
    699646
    700647        }
    701        
    702         public Item merge(Item merger, int mouseX, int mouseY) {
    703                 return merger;
    704         }
    705648
    706649        @Override
     
    709652                super.scale(scale, originX, originY);
    710653        }
    711        
    712         public Integer getWidthToSave() {
    713                 if(_scaleType == WIDTH) {
    714                         return this.getWidth();
    715                 }
    716                 return null;
    717         }
    718        
    719         public Float getScaleToSave() {
    720                 if(_scaleType == RATIO) {
    721                         return this.getScale();
    722                 }
    723                 return null;
    724         }
    725        
    726         public Point getCropStart() {
    727                 if (isCropped()) {
    728                         return _start;
    729                 }
    730                 return null;
    731         }
    732        
    733         public Point getCropEnd() {
    734                 if (isCropped()) {
    735                         return _end;
    736                 }
    737                 return null;
    738         }
    739        
    740         public void setCropStart(Point cropStart) {
    741                 invalidateCroppedArea();
    742                 this._start = cropStart;
    743                 updatePolygon();
    744                 invalidateAll();
    745         }
    746        
    747         public void setCropEnd(Point cropEnd) {
    748                 invalidateCroppedArea();
    749                 this._end = cropEnd;
    750                 updatePolygon();
    751                 invalidateAll();
    752         }
    753        
    754         public String getImageSource() {
    755                 return _path;
    756         }
    757        
    758         public void setImageSource(String path) {
    759                 if(_path == path) {
    760                         return;
    761                 }
    762                 // update image
    763                 invalidateAll();
    764                 _path = path;
    765                 refresh();
    766                 updatePolygon();
    767                 invalidateAll();
    768         }
    769        
    770        
    771         protected String getTagText() {
    772                 return "@i: ";
    773         }
    774        
    775         private String getCrop() {
    776                 Point start = getCropStart();
    777                 Point end = getCropEnd();
    778                 if(start == null || end == null) {
    779                         return "";
    780                 }
    781                 return " " + start.x + " " + start.y + " " + end.x + " " + end.y;
    782         }
    783        
    784         // generate a fake source item to let old code work
    785         public Text getSource() {
    786                 Text source = new Text(getID());
    787                 Item.DuplicateItem(this, source);
    788                 source.setText(this.getTagText() + this.getImageSource() + " " + this.getWidthToSave() + getCrop());
    789                 return source;
    790         }
    791        
    792         public String toString() {
    793                 return "[Image] '" + getImageSource() + "' on frame " + this.getParent().getName() + " at " + getPosition().toString();
    794         }
    795654
    796655}
Note: See TracChangeset for help on using the changeset viewer.