Changeset 1434 for trunk/src/org/expeditee/items/ItemUtils.java
- Timestamp:
- 10/02/19 14:19:48 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/ItemUtils.java
r1426 r1434 39 39 import org.expeditee.gui.FreeItems; 40 40 import org.expeditee.gui.Vector; 41 import org.expeditee.gui.management.ResourceManager; 41 42 import org.expeditee.items.Item.HighlightMode; 42 43 import org.expeditee.items.widgets.InteractiveWidgetInitialisationFailedException; … … 376 377 */ 377 378 public static Picture CreatePicture(Text source, boolean tryRemote) { 378 String text = source.getText(); 379 String path = ""; 380 String fileName = ""; 381 String size = ""; 382 383 try { 384 // remove @i tag 385 text = text.replaceFirst("@i:", ""); 386 text = text.replaceAll("\n", ""); 387 text = text.trim(); 388 389 int fileSuffixChar = text.indexOf('.'); 390 if (fileSuffixChar < 0) { 391 return null; 392 } 393 int endOfFileName = text.indexOf(' ', fileSuffixChar); 394 if (endOfFileName < 0) { 395 path = text; 396 size = ""; 397 } else { 398 path = text.substring(0, endOfFileName); 399 size = text.substring(endOfFileName).trim(); 400 } 401 fileName = path; 402 403 if (!fileName.equals(Picture.REDACTED_IMAGE_NAME)) { 404 // try images subdirectory 405 File file = null; 406 407 for (String dir : FolderSettings.ImageDirs.getAbsoluteDirs()) { 408 file = new File(dir + path); 409 if (file.exists() && !file.isDirectory()) { 410 break; 411 } 412 } 413 414 if (file == null || !file.exists() || file.isDirectory()) { 415 file = new File(path); 416 } 417 418 // try relative path 419 if (!file.exists() || file.isDirectory()) { 420 URL picture = new Object().getClass().getResource(path); 421 422 // decode to remove %20 in windows folder names 423 if (picture != null) { 424 try { 425 path = URLDecoder.decode(picture.getFile(), "UTF-8"); 426 } catch (UnsupportedEncodingException e) { 427 // TODO Auto-generated catch block 428 e.printStackTrace(); 429 } 430 } 431 432 } else { 433 path = file.getPath(); 434 } 435 436 // if the image isn't found by now, try remote servers 437 file = new File(path); 438 if (!file.exists() || file.isDirectory()) { 439 if(tryRemote && FrameShare.getInstance().loadImage(fileName, null)) { 440 // call CreatePicture again, but with tryRemote set to false so we won't get into an infinite loop 441 // if something goes wrong with finding the downloaded image 442 return CreatePicture(source, false); 443 } 444 return null; 445 } 446 } 447 } catch (Exception e) { 448 return null; 449 } 450 451 try { 452 Picture pic = new Picture(source, fileName, path, size); 453 454 return pic; 455 } catch (Exception e) { 456 e.printStackTrace(); 457 return null; 458 } 459 460 } 379 return ResourceManager.getExpediteePicture(source, tryRemote); 380 } 381 // public static Picture CreatePicture(Text source, boolean tryRemote) { 382 // String text = source.getText(); 383 // String path = ""; 384 // String fileName = ""; 385 // String size = ""; 386 // 387 // try { 388 // // remove @i tag 389 // text = text.replaceFirst("@i:", ""); 390 // text = text.replaceAll("\n", ""); 391 // text = text.trim(); 392 // 393 // int fileSuffixChar = text.indexOf('.'); 394 // if (fileSuffixChar < 0) { 395 // return null; 396 // } 397 // int endOfFileName = text.indexOf(' ', fileSuffixChar); 398 // if (endOfFileName < 0) { 399 // path = text; 400 // size = ""; 401 // } else { 402 // path = text.substring(0, endOfFileName); 403 // size = text.substring(endOfFileName).trim(); 404 // } 405 // fileName = path; 406 // 407 // if (!fileName.equals(Picture.REDACTED_IMAGE_NAME)) { 408 // // try images subdirectory 409 // File file = null; 410 // 411 // List<String> absoluteDirs = FolderSettings.ImageDirs.getAbsoluteDirs(); 412 // for (String dir : absoluteDirs) { 413 // file = new File(dir + path); 414 // if (file.exists() && !file.isDirectory()) { 415 // break; 416 // } 417 // } 418 // 419 // if (file == null || !file.exists() || file.isDirectory()) { 420 // file = new File(path); 421 // } 422 // 423 // // try relative path 424 // if (!file.exists() || file.isDirectory()) { 425 // URL picture = new Object().getClass().getResource(path); 426 // 427 // // decode to remove %20 in windows folder names 428 // if (picture != null) { 429 // try { 430 // path = URLDecoder.decode(picture.getFile(), "UTF-8"); 431 // } catch (UnsupportedEncodingException e) { 432 // // TODO Auto-generated catch block 433 // e.printStackTrace(); 434 // } 435 // } 436 // 437 // } else { 438 // path = file.getPath(); 439 // } 440 // 441 // // if the image isn't found by now, try remote servers 442 // file = new File(path); 443 // if (!file.exists() || file.isDirectory()) { 444 // if(tryRemote && FrameShare.getInstance().loadImage(fileName, null)) { 445 // // call CreatePicture again, but with tryRemote set to false so we won't get into an infinite loop 446 // // if something goes wrong with finding the downloaded image 447 // return CreatePicture(source, false); 448 // } 449 // return null; 450 // } 451 // } 452 // } catch (Exception e) { 453 // return null; 454 // } 455 // 456 // try { 457 // Picture pic = new Picture(source, fileName, path, size); 458 // 459 // return pic; 460 // } catch (Exception e) { 461 // e.printStackTrace(); 462 // return null; 463 // } 464 // 465 // } 461 466 462 467 public static Picture CreatePicture(Text source) {
Note:
See TracChangeset
for help on using the changeset viewer.