1 | package org.honours.items;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 |
|
---|
5 | import org.expeditee.gui.MessageBay;
|
---|
6 | import org.expeditee.items.Picture;
|
---|
7 | import org.expeditee.items.Text;
|
---|
8 |
|
---|
9 | public class PictureInformation {
|
---|
10 |
|
---|
11 | public static Picture getPicture(Text i){
|
---|
12 |
|
---|
13 | String[] array = getPictureInfo(i);
|
---|
14 | String filename = new File(array[0]).getName();
|
---|
15 | String path = new File(array[0]).getPath();
|
---|
16 | String getSize = array[1];
|
---|
17 |
|
---|
18 | MessageBay.displayMessage("array[0]=" + array[0]);
|
---|
19 | MessageBay.displayMessage("filename = " + filename);
|
---|
20 | MessageBay.displayMessage("path = " + path);
|
---|
21 |
|
---|
22 | Picture p = new Picture((Text)i,filename,path,getSize,null);
|
---|
23 |
|
---|
24 | return p;
|
---|
25 | }
|
---|
26 |
|
---|
27 | public static String getPictureFileName(Text a){
|
---|
28 | String filename = null;
|
---|
29 |
|
---|
30 | filename = a.getText().substring(3);
|
---|
31 | String temp = filename;
|
---|
32 |
|
---|
33 | if(filename.startsWith(" ")){
|
---|
34 | filename = temp.substring(1);
|
---|
35 | }
|
---|
36 |
|
---|
37 | return filename;
|
---|
38 | }
|
---|
39 |
|
---|
40 | public static String[] getPictureInfo(Text i){
|
---|
41 |
|
---|
42 | String s = i.getText().substring(3);
|
---|
43 | String temp = s;
|
---|
44 |
|
---|
45 | if(s.startsWith(" ")){
|
---|
46 | s = temp.substring(1);
|
---|
47 | temp = s;
|
---|
48 | }
|
---|
49 | String getSize = getSizeFromImageString(s);
|
---|
50 |
|
---|
51 | //reverse the string
|
---|
52 | StringBuffer sb = new StringBuffer(getSize);
|
---|
53 | getSize = sb.reverse().toString();
|
---|
54 | s = temp.substring(0,temp.length()-getSize.length()-1);
|
---|
55 | String[] array = new String[2];
|
---|
56 | array[0] = s;
|
---|
57 | array[1] = getSize;
|
---|
58 |
|
---|
59 | return array;
|
---|
60 | }
|
---|
61 |
|
---|
62 | private static String getSizeFromImageString(String s){
|
---|
63 |
|
---|
64 | String getSize = "";
|
---|
65 | int i = s.length() - 1;
|
---|
66 | char c;
|
---|
67 |
|
---|
68 | while((c = s.charAt(i)) != ' '){
|
---|
69 | boolean valid = ((c >= '0') && (c <= '9')) || (c == '.');
|
---|
70 |
|
---|
71 | if(valid)
|
---|
72 | getSize += c;
|
---|
73 |
|
---|
74 | i--;
|
---|
75 | }
|
---|
76 | return getSize;
|
---|
77 | }
|
---|
78 |
|
---|
79 |
|
---|
80 | }
|
---|