Changeset 601
- Timestamp:
- 12/10/13 17:58:08 (10 years ago)
- Location:
- trunk/src/org/expeditee
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/actions/Misc.java
r595 r601 1362 1362 System.out.println(text.getText()); 1363 1363 } 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 }1413 1364 } -
trunk/src/org/expeditee/gui/AttributeUtils.java
r595 r601 29 29 public class AttributeUtils { 30 30 31 // private static final int GET_LENGTH = "get".length();32 33 //private static int SET_LENGTH = "set".length();34 35 31 public static final class Attribute { 36 32 public final String displayName; … … 48 44 49 45 // the internal hashmap 50 private final HashMap<String, Attribute> map = new HashMap<String, Attribute>(256);46 private final HashMap<String, Attribute> map; 51 47 // 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 55 55 public void put(String attributeName, Method getter, Method setter) { 56 56 if(map.containsKey(attributeName.toLowerCase())) { … … 63 63 } 64 64 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 80 67 public void alias(String alias, String name) { 81 68 if(map.containsKey(name.toLowerCase())) { … … 86 73 } 87 74 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 98 75 public boolean containsKey(String key) { 99 76 return map.containsKey(key); … … 105 82 } 106 83 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 127 87 128 88 // List of attributes which are ignored when extracting attributes … … 210 170 Frame.class.getMethod("setOwner", pString)); 211 171 _FrameAttrib.put("DateCreated", Frame.class.getMethod("getDateCreated"), 212 Frame.class.getMethod("setDateCreated", pString));172 null); 213 173 _FrameAttrib.put("LastModifyUser", Frame.class.getMethod("getLastModifyUser"), 214 Frame.class.getMethod("setLastModifyUser", pString));174 null); 215 175 _FrameAttrib.put("LastModifyDate", Frame.class.getMethod("getLastModifyDate"), 216 Frame.class.getMethod("setLastModifyDate", pString));176 null); 217 177 _FrameAttrib.put("ForegroundColor", Frame.class.getMethod("getForegroundColor"), 218 178 Frame.class.getMethod("setForegroundColor", pColor)); … … 220 180 Frame.class.getMethod("setBackgroundColor", pColor)); 221 181 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 237 187 238 188 // Generic Items … … 309 259 _Attrib.put("Width", Item.class.getMethod("getWidthToSave"), 310 260 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)); 311 265 312 266 // Text Items … … 318 272 Text.class.getMethod("setJustification", pJustification)); 319 273 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"); 382 304 383 305 … … 431 353 Attribute a = as.get(prop); 432 354 // 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())) { 434 356 435 357 try { … … 658 580 } else if (_IgnoreSet.contains(stripped)) { 659 581 return false; 660 } else if (!(_AttribSet.containsKey(stripped))) {661 return false;662 582 } else { 583 Attribute a = _Attrib.get(stripped); 584 if(a == null || a.setter == null) { 585 return false; 586 } 663 587 String types = ""; 664 for (Class c : _AttribSet.get(stripped).setter.getParameterTypes()) {588 for (Class<?> c : a.setter.getParameterTypes()) { 665 589 types += c.getSimpleName() + " "; 666 590 } … … 710 634 // Separate multiple values if required 711 635 712 Attribute a = _Attrib Set.get(attribute);636 Attribute a = _Attrib.get(attribute); 713 637 // 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) { 715 639 // System.out.println("Attrib not found for: " + attribute); 716 640 return false; … … 722 646 possibles.add(a.setter); 723 647 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 } 726 653 if (m.getDeclaringClass().isAssignableFrom(toSet.getClass())) { 727 654 possibles.add(m); -
trunk/src/org/expeditee/gui/FrameIO.java
r590 r601 22 22 import org.expeditee.agents.ExistingFramesetException; 23 23 import org.expeditee.io.Conversion; 24 import org.expeditee.io.ExaReader;25 import org.expeditee.io.ExaWriter;26 24 import org.expeditee.io.ExpReader; 27 25 import org.expeditee.io.ExpWriter; … … 277 275 return null; 278 276 279 // check for the exafile name format277 // check for the new file name format 280 278 String fullPath = source + Conversion.getFrameNumber(frameName) 281 + Ex aReader.EXTENTION;279 + ExpReader.EXTENTION; 282 280 tester = new File(fullPath); 283 281 284 282 if (tester.exists()) 285 283 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 296 286 fullPath = source + Conversion.getFramesetName(frameName) + "." 297 287 + Conversion.getFrameNumber(frameName); … … 364 354 FrameReader reader; 365 355 366 if(fullPath.endsWith(ExaReader.EXTENTION)) { 367 reader = new ExaReader(frameName); 368 } else if (fullPath.endsWith(ExpReader.EXTENTION)) { 356 if (fullPath.endsWith(ExpReader.EXTENTION)) { 369 357 reader = new ExpReader(frameName); 370 358 } else { … … 590 578 _Cache.remove(oldFrameName); 591 579 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()) { 608 586 return toDelete.getName(); 609 587 } … … 882 860 checkBackup = false; 883 861 } 884 885 FrameWriter writer = n ew ExaWriter();862 863 FrameWriter writer = null; 886 864 int savedVersion; 887 boolean converted = true;888 889 865 try { 890 891 866 // 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 } 904 874 905 875 // Check if the frame doesnt exist … … 989 959 // FrameGraphics.setMode(FrameGraphics.MODE_XRAY, true); 990 960 writer.writeFrame(toSave); 991 992 // Now that we've written the file, erase the old format file993 // (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 999 961 // FrameGraphics.setMode(oldMode, true); 1000 962 toSave.setSaved(); … … 1530 1492 String filename = PUBLIC_PATH + Conversion.getFramesetName(frameName) 1531 1493 + File.separator + Conversion.getFrameNumber(frameName) 1532 + Ex aReader.EXTENTION;1494 + ExpReader.EXTENTION; 1533 1495 1534 1496 File file = new File(filename); … … 1536 1498 if (file.exists()) { 1537 1499 // Check the versions 1538 int savedVersion = Ex aReader.getVersion(filename);1500 int savedVersion = ExpReader.getVersion(filename); 1539 1501 1540 1502 if (savedVersion > version) { … … 1554 1516 + nextNum; 1555 1517 filename = PUBLIC_PATH + Conversion.getFramesetName(frameName) 1556 + File.separator + nextNum + Ex aReader.EXTENTION;1518 + File.separator + nextNum + ExpReader.EXTENTION; 1557 1519 1558 1520 // Show the messages alerting the user -
trunk/src/org/expeditee/gui/FrameUtils.java
r589 r601 525 525 } 526 526 frame.addItem(pic); 527 frame.removeItem(txt);528 527 529 528 return true; … … 927 926 } 928 927 // check for frame images 929 /*} else if (ItemUtils.startsWithTag(i,928 } else if (ItemUtils.startsWithTag(i, 930 929 ItemUtils.TAG_FRAME_IMAGE) 931 930 && i.getLink() != null … … 965 964 toParse, null); 966 965 } 967 toParse.addItem(image); */966 toParse.addItem(image); 968 967 } else if (ItemUtils.startsWithTag(i, "@c")) { 969 968 // Can only have a @c -
trunk/src/org/expeditee/io/ExaReader.java
r593 r601 15 15 import org.expeditee.items.Item; 16 16 import org.expeditee.items.Line; 17 import org.expeditee.items.Picture;18 17 19 18 /** 20 * Reads exa format 19 * Experimental format which is designed to be more readable 20 * NON FUNCTIONAL DUE TO CHANGES TO AttributeUtils 21 21 * 22 22 * @author jts21 … … 109 109 continue; 110 110 } 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 // } 123 124 124 125 } … … 164 165 } 165 166 } 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 // } 178 180 } 179 181 } -
trunk/src/org/expeditee/io/ExaWriter.java
r593 r601 11 11 12 12 import org.expeditee.gui.AttributeUtils; 13 import org.expeditee.gui.FrameIO;14 13 import org.expeditee.gui.AttributeUtils.Attribute; 15 14 import org.expeditee.gui.Frame; … … 20 19 21 20 /** 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 25 23 * 26 24 * @author jts21 … … 94 92 95 93 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 // } 110 112 } 111 113 … … 120 122 } 121 123 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 // } 142 148 } 143 149 } -
trunk/src/org/expeditee/io/WebParser.java
r600 r601 16 16 import org.expeditee.gui.Frame; 17 17 import org.expeditee.gui.FrameIO; 18 import org.expeditee.gui.FrameUtils; 18 19 import org.expeditee.gui.MessageBay; 19 20 import org.expeditee.items.ItemUtils; … … 452 453 ImageIO.write(img, "png", out); 453 454 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 461 455 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); 473 471 } 474 472 } -
trunk/src/org/expeditee/items/FrameBitmap.java
r589 r601 1 1 package org.expeditee.items; 2 2 3 import java.awt.Color; 4 import java.awt.Image; 5 import java.awt.image.BufferedImage; 3 6 import java.awt.image.ImageObserver; 7 import java.util.List; 4 8 5 // TODO: Make this work with new Picture class 9 import org.expeditee.gui.Frame; 10 import org.expeditee.gui.FrameIO; 6 11 7 12 //TODO tidy up the mess I caused with refresh during the period where I was going into XRay mode before saving 8 13 9 14 public class FrameBitmap extends FramePicture { 15 public FrameBitmap(Text source, ImageObserver observer, Image image){ 16 super(source, observer, image); 17 } 10 18 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 } 82 84 } -
trunk/src/org/expeditee/items/FrameImage.java
r589 r601 1 1 package org.expeditee.items; 2 2 3 import java.awt.Image; 3 4 import java.awt.image.ImageObserver; 4 5 5 //TODO: Make this work with new Picture class 6 import org.expeditee.gui.Frame; 7 import org.expeditee.gui.FrameGraphics; 8 import org.expeditee.gui.FrameIO; 6 9 7 10 public 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 } 8 28 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 } 59 58 } -
trunk/src/org/expeditee/items/FramePicture.java
r589 r601 1 1 package org.expeditee.items; 2 2 3 import java.awt.Color; 4 import java.awt.Image; 3 5 import java.awt.image.ImageObserver; 4 6 5 //TODO: Make this work with new Picture class 7 import org.expeditee.gui.AttributeValuePair; 8 import org.expeditee.gui.Frame; 6 9 7 10 public 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); 10 13 } 11 14 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 } 43 51 } -
trunk/src/org/expeditee/items/ItemUtils.java
r600 r601 338 338 * If the Image file cannot be found on disk null is returned. 339 339 * 340 * @param path341 * The path to the image file340 * @param source 341 * The Text file containing the Picture infomation 342 342 * @return The Picture object representing the file, or Null if the file is 343 343 * not found. … … 346 346 String text = source.getText(); 347 347 String path = ""; 348 String fileName = ""; 348 349 String size = ""; 349 String crop = "";350 350 351 351 try { … … 366 366 size = text.substring(endOfFileName).trim(); 367 367 } 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 } 368 404 369 405 } catch (Exception e) { … … 372 408 373 409 try { 374 Picture pic = new Picture(path, source, size, observer); 410 Picture pic = new Picture(source, fileName, path, size, observer); 411 375 412 return pic; 376 413 } catch (Exception e) { -
trunk/src/org/expeditee/items/Picture.java
r600 r601 17 17 import java.awt.image.ImageObserver; 18 18 import java.io.File; 19 import java.io.UnsupportedEncodingException; 20 import java.net.URL; 21 import java.net.URLDecoder; 19 import java.io.IOException; 20 import java.text.DecimalFormat; 22 21 23 22 import javax.imageio.ImageIO; … … 26 25 import org.expeditee.gui.FrameGraphics; 27 26 import org.expeditee.gui.FrameMouseActions; 28 import org.expeditee.s ettings.UserSettings;27 import org.expeditee.stats.Logger; 29 28 30 29 /** … … 45 44 * 46 45 */ 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 } 46 public class Picture extends XRayable { 72 47 73 48 private static final int MINIMUM_WIDTH = 10; 49 74 50 public static final int WIDTH = 0; 51 75 52 public static final int RATIO = 1; 76 53 77 54 protected Image _image = null; 78 protected Image _croppedImage = null;79 55 80 56 private int _scaleType = RATIO; … … 82 58 private float _scale = 1.0f; 83 59 84 // Points relative to this Picture's cropping, for creating further cropped Pictures60 // Start of the crop relative to START 85 61 private Point _cropStart = null; 62 63 // Start of the crop relative to END 86 64 private Point _cropEnd = null; 87 65 88 // Crop data of this Picture89 66 private Point _start = new Point(0, 0); 67 90 68 private Point _end = new Point(0, 0); 91 69 … … 93 71 94 72 private String _path = ""; 73 74 private String _size = ""; 75 76 private String _fileName = null; 95 77 96 78 // used to repaint animated GIF images, among other things. 97 79 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 } 98 91 99 92 /** … … 103 96 * checked to exist. 104 97 * 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 105 103 * @param path 106 104 * The Path of the Image to load from disk. … … 109 107 * screen. 110 108 */ 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); 123 112 _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; 145 130 146 131 // set the default values for start and end … … 170 155 if (size.length() == 0) { 171 156 size = "" + _image.getWidth(null); 157 _source.setText(getTagText() + size); 172 158 return; 173 159 } … … 189 175 } 190 176 191 192 /**193 * Set the start point for generating a new cropped Picture from this Picture194 */195 177 public void setStartCrop(int x, int y) { 196 178 invalidateCroppedArea(); … … 199 181 } 200 182 201 /**202 * Set the end point for generating a new cropped Picture from this Picture203 */204 183 public void setEndCrop(int x, int y) { 205 184 invalidateCroppedArea(); … … 223 202 } 224 203 225 /**226 * Get the top left point (_start) for generating a new cropped Picture from this Picture227 */228 204 public Point getTopLeftCrop() { 229 205 return new Point(Math.min(_cropStart.x, _cropEnd.x), Math.min( … … 231 207 } 232 208 233 /**234 * Get the bottom right point (_end) for generating a new cropped Picture from this Picture235 */236 209 public Point getBottomRightCrop() { 237 210 return new Point(Math.max(_cropStart.x, _cropEnd.x), Math.max( … … 246 219 247 220 public boolean isCropTooSmall() { 248 if (_cropStart == null || _cropEnd == null || _image == imageNotFound)221 if (_cropStart == null || _cropEnd == null) 249 222 return true; 250 223 … … 261 234 setShowCrop(false); 262 235 } 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 }279 236 280 237 public void updatePolygon() { 281 238 if (_image == null) { 282 239 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 } 293 242 _poly = new Polygon(); 294 243 … … 300 249 301 250 // 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); 306 255 } else { 307 256 Point topLeft = getTopLeftCrop(); 308 257 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, 311 260 bottomRight.y - topLeft.y).getBounds(); 312 261 _poly.addPoint((int) clip.getMinX() - 1, (int) clip.getMinY() - 1); … … 325 274 @Override 326 275 public void setWidth(Integer width) { 327 _scaleType = WIDTH; 328 _scale = width * 1F / (getUnscaledWidth()); 276 _scale = width * 1F / (_end.x - _start.x); 329 277 } 330 278 … … 342 290 @Override 343 291 public Integer getWidth() { 344 return Math.round(( getUnscaledWidth()) * _scale);292 return Math.round((_end.x - _start.x) * _scale); 345 293 } 346 294 … … 350 298 @Override 351 299 public int getHeight() { 352 return Math.round(( getUnscaledHeight()) * _scale);300 return Math.round((_end.y - _start.y) * _scale); 353 301 } 354 302 … … 365 313 @Override 366 314 public void paint(Graphics2D g) { 367 // System.out.println("drawing image"); 368 369 if(_image == null) { 315 if (_image == null) 370 316 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(); 381 320 382 321 paintLink(g); 383 322 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; 388 327 389 328 // if we are showing the cropping, then show the original as transparent … … 393 332 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 394 333 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); 396 336 397 337 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, … … 406 346 g.setClip(clip); 407 347 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); 409 350 g.draw(clip); 410 351 // if the image is cropped, but we are not showing the cropping 411 352 // otherwise, paint normally 412 353 } 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); 414 356 } 415 357 … … 446 388 447 389 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); 450 391 } 451 392 … … 455 396 p._image = _image; 456 397 p._mode = _mode; 457 p.setPosition(getPosition());458 398 // Doing Duplicate item duplicates link mark which we dont want to do 459 399 // when in audience mode because the linkMark will be copied incorrectly … … 466 406 Point topLeft = getTopLeftCrop(); 467 407 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); 472 412 int width = _image.getWidth(null); 473 413 int height = _image.getHeight(null); … … 488 428 p._start = new Point(startX, startY); 489 429 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()); 491 432 } else { 492 433 p._start = _start; … … 496 437 p._scaleType = _scaleType; 497 438 p._path = _path; 498 439 p._fileName = _fileName; 440 441 p.updateSource(); 499 442 p.updatePolygon(); 500 443 … … 507 450 508 451 public void setScale(float scale) { 509 _scaleType = RATIO;510 452 _scale = scale; 511 453 } … … 513 455 @Override 514 456 public float getSize() { 515 // to let scaling work 516 return UserSettings.ItemTemplate.getSize(); 457 return _source.getSize(); 517 458 } 518 459 519 460 @Override 520 461 public void setSize(float size) { 521 float diff = size - getSize();462 float diff = size - _source.getSize(); 522 463 float oldScale = _scale; 523 464 … … 529 470 _scale = oldScale; 530 471 } else { 531 this.translate(new Point2D.Float(FrameMouseActions.MouseX,472 _source.translate(new Point2D.Float(FrameMouseActions.MouseX, 532 473 FrameMouseActions.MouseY), multiplier); 533 474 } 475 updateSource(); 534 476 updatePolygon(); 535 477 // Make sure items that are resized display the border … … 560 502 return Toolkit.getDefaultToolkit().createImage( 561 503 new FilteredImageSource(_image.getSource(), 562 new CropImageFilter( getStartX(), getStartY(),504 new CropImageFilter(_start.x, _start.y, 563 505 getUnscaledWidth(), getUnscaledHeight()))); 564 506 } 565 507 566 508 public int getUnscaledWidth() { 567 return getEndX() - getStartX();509 return _end.x - _start.x; 568 510 } 569 511 570 512 public int getUnscaledHeight() { 571 return getEndY() - getStartY();513 return _end.y - _start.y; 572 514 } 573 515 … … 576 518 */ 577 519 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 582 524 public boolean refresh() { 583 // try images subdirectory584 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 path596 if (!file.exists() || file.isDirectory()) {597 URL picture = new Object().getClass().getResource(_path);598 599 // decode to remove %20 in windows folder names600 if (picture != null) {601 try {602 _path = URLDecoder.decode(picture.getFile(), "UTF-8");603 } catch (UnsupportedEncodingException e) {604 // TODO Auto-generated catch block605 e.printStackTrace();606 }607 }608 609 } else610 _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 read616 _image = imageNotFound;617 return false;618 }619 620 525 // ImageIcon is faster, but cannot handle some formats 621 526 // (notably.bmp) hence, we try this first, then if it fails we try … … 630 535 try { 631 536 _image = ImageIO.read(new File(_path)); 632 } catch ( Exception e) {537 } catch (IOException e) { 633 538 // 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; 638 541 return false; 639 542 } … … 653 556 // if(!state) 654 557 // invalidateCommonTrait(ItemAppearence.LinkChanged); 655 super.setLinkMark(state);558 _source.setLinkMark(state); 656 559 // if(state) 657 560 // invalidateCommonTrait(ItemAppearence.LinkChanged); … … 663 566 // if (!state) 664 567 // invalidateCommonTrait(ItemAppearence.LinkChanged); 665 super.setActionMark(state);568 _source.setActionMark(state); 666 569 // if (state) 667 570 // invalidateCommonTrait(ItemAppearence.LinkChanged); … … 670 573 671 574 @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 672 585 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()); 674 620 } 675 621 … … 677 623 public void translate(Point2D origin, double ratio) { 678 624 _scale *= ratio; 625 updateSource(); 679 626 super.translate(origin, ratio); 680 627 } … … 699 646 700 647 } 701 702 public Item merge(Item merger, int mouseX, int mouseY) {703 return merger;704 }705 648 706 649 @Override … … 709 652 super.scale(scale, originX, originY); 710 653 } 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 image763 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 work785 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 }795 654 796 655 }
Note:
See TracChangeset
for help on using the changeset viewer.