1 | package org.honours.CollectionSpace;
|
---|
2 |
|
---|
3 | import java.io.BufferedReader;
|
---|
4 | import java.io.File;
|
---|
5 | import java.io.FileReader;
|
---|
6 | import java.util.ArrayList;
|
---|
7 | import java.util.List;
|
---|
8 |
|
---|
9 | import org.expeditee.actions.Navigation;
|
---|
10 | import org.expeditee.gui.Frame;
|
---|
11 | import org.expeditee.gui.FrameIO;
|
---|
12 | import org.expeditee.gui.MessageBay;
|
---|
13 | import org.expeditee.items.ItemParentStateChangedEvent;
|
---|
14 | import org.expeditee.items.Picture;
|
---|
15 | import org.expeditee.items.Text;
|
---|
16 | import org.honours.collection.Collection;
|
---|
17 | import org.honours.gui.HonoursFrameIO;
|
---|
18 | import org.honours.items.PictureInformation;
|
---|
19 |
|
---|
20 | public class CollectionSpace {
|
---|
21 |
|
---|
22 | //the collection this collection space is associated with
|
---|
23 | private Collection _associatedCollection;
|
---|
24 |
|
---|
25 | private String _name;
|
---|
26 |
|
---|
27 | //FOr storing thumbnails for the collection space
|
---|
28 | private String _thumbnailsDirectory;
|
---|
29 |
|
---|
30 | private List<Picture> _thumbnails = new ArrayList<Picture>();
|
---|
31 |
|
---|
32 | private int _startX = 150;
|
---|
33 | private int _startY = 150;
|
---|
34 |
|
---|
35 | public static final int _gap = 20;
|
---|
36 | public static final int _columns = 4;
|
---|
37 | public static final int _imageSize = 150;
|
---|
38 | public static final int _rows = 3;
|
---|
39 |
|
---|
40 | public CollectionSpace(){
|
---|
41 |
|
---|
42 | }
|
---|
43 |
|
---|
44 | public CollectionSpace(Collection associatedCollection){
|
---|
45 | _associatedCollection = associatedCollection;
|
---|
46 | _name = "collectionspace-" + _associatedCollection.getName();
|
---|
47 | _thumbnailsDirectory = FrameIO.IMAGES_FOLDER + "thumbnails-" +
|
---|
48 | _associatedCollection.getName();
|
---|
49 | }
|
---|
50 |
|
---|
51 | public void setAssociatedCollection(Collection assocCollection){
|
---|
52 | _associatedCollection = assocCollection;
|
---|
53 | }
|
---|
54 |
|
---|
55 | public Collection getAssociatedCollection(){
|
---|
56 | return _associatedCollection;
|
---|
57 | }
|
---|
58 |
|
---|
59 | public void setName(String name){
|
---|
60 | _name = name;
|
---|
61 | }
|
---|
62 |
|
---|
63 | public String getName(){
|
---|
64 | return _name;
|
---|
65 | }
|
---|
66 |
|
---|
67 | public void setThumbnailsDirectory(String dir){
|
---|
68 |
|
---|
69 | _thumbnailsDirectory = dir;
|
---|
70 |
|
---|
71 | }
|
---|
72 |
|
---|
73 | public String getThumbnailsDirectory(){
|
---|
74 | return _thumbnailsDirectory;
|
---|
75 | }
|
---|
76 |
|
---|
77 | public void generate(){
|
---|
78 | try{
|
---|
79 |
|
---|
80 | if(_thumbnailsDirectory == null){
|
---|
81 |
|
---|
82 | MessageBay.errorMessage("ERROR: No thumbnails directory set up so" +
|
---|
83 | " cannot generate CollectionSpace");
|
---|
84 |
|
---|
85 | return;
|
---|
86 | }
|
---|
87 |
|
---|
88 | //generate actual collectionSpace frameset using _name.
|
---|
89 | createCollectionSpace();
|
---|
90 |
|
---|
91 | //Open thumbnails.info file.
|
---|
92 | BufferedReader br = new BufferedReader(new FileReader(
|
---|
93 | _thumbnailsDirectory + File.separator +
|
---|
94 | "thumbnails.info"));
|
---|
95 | String line;
|
---|
96 |
|
---|
97 | while((line = br.readLine()) != null){
|
---|
98 |
|
---|
99 | String[] split = line.split(",");
|
---|
100 |
|
---|
101 | //1st entry in split is filename, 2nd is associated frame name.
|
---|
102 | Text imageSource = new Text("@i: " + split[0] + " 1.0");
|
---|
103 | Picture newPic = PictureInformation.getPicture(imageSource);
|
---|
104 | newPic.setLink(split[1]);
|
---|
105 | _thumbnails.add(newPic);
|
---|
106 | }
|
---|
107 | br.close();
|
---|
108 |
|
---|
109 | writeThumbnails();
|
---|
110 |
|
---|
111 | MessageBay.displayMessage("Collection Space generated!");
|
---|
112 |
|
---|
113 | Navigation.Goto(_name + "1");
|
---|
114 |
|
---|
115 | }catch(Exception e){
|
---|
116 | e.printStackTrace();
|
---|
117 | }
|
---|
118 |
|
---|
119 | }
|
---|
120 |
|
---|
121 | /** Method to output thumbnails into collection space **/
|
---|
122 | private void writeThumbnails(){
|
---|
123 |
|
---|
124 | Frame currFrame = null;
|
---|
125 | int currX = _startX;
|
---|
126 | int currY = _startY;
|
---|
127 |
|
---|
128 | int frameIter = 1;
|
---|
129 |
|
---|
130 | generateNavigationLinks(frameIter);
|
---|
131 | generateDropBox(frameIter);
|
---|
132 |
|
---|
133 | for(int i = 0; i < _thumbnails.size(); i++)
|
---|
134 | {
|
---|
135 | Picture currPic = _thumbnails.get(i);
|
---|
136 |
|
---|
137 | if(i % _columns ==0 && i == 0){
|
---|
138 |
|
---|
139 | }else if(i % _columns == 0 && i > 0){
|
---|
140 | currX = _startX;
|
---|
141 | currY += _gap + _imageSize;
|
---|
142 | }else{
|
---|
143 | currX += _gap + _imageSize;
|
---|
144 | }
|
---|
145 |
|
---|
146 | //Create a new frame to display next lot of items.
|
---|
147 | if(i % (_columns * _rows) == 0 && i < _columns * _rows){
|
---|
148 | currFrame = FrameIO.LoadFrame(_name + frameIter);
|
---|
149 |
|
---|
150 | }else if(i % (_columns * _rows) == 0 && i >= _columns * _rows){
|
---|
151 | frameIter++;
|
---|
152 | Frame check = FrameIO.LoadFrame(_name + frameIter);
|
---|
153 | if(check == null){
|
---|
154 | //create new frame
|
---|
155 | HonoursFrameIO.generateFrame(frameIter, _name);
|
---|
156 | currFrame = FrameIO.LoadFrame(_name + frameIter);
|
---|
157 |
|
---|
158 | currX = _startX;
|
---|
159 | currY = _startY;
|
---|
160 | generateNavigationLinks(frameIter);
|
---|
161 | generateDropBox(frameIter);
|
---|
162 | }
|
---|
163 |
|
---|
164 | }
|
---|
165 |
|
---|
166 | currFrame.addText(currX, currY, currPic.getSource().getText(),
|
---|
167 | null, currPic.getLink());
|
---|
168 | currFrame.setSaved();
|
---|
169 | }
|
---|
170 |
|
---|
171 | _associatedCollection.setCollectionSpace(this);
|
---|
172 | }
|
---|
173 |
|
---|
174 | private void generateNavigationLinks(int frameIter){
|
---|
175 |
|
---|
176 | String backText = "<<";
|
---|
177 | String forwardText = ">>";
|
---|
178 |
|
---|
179 | int backButtonX = _startX/2;
|
---|
180 | int forwardButtonX = _startX + (_columns*_gap)+(_columns*_imageSize);
|
---|
181 | int buttonPosY = ((_rows*_imageSize) + (_rows*_gap))/2;
|
---|
182 |
|
---|
183 | Frame currFrame = FrameIO.LoadFrame(_name+frameIter);
|
---|
184 | currFrame.addText(backButtonX,buttonPosY,backText,"RotateBack");
|
---|
185 | currFrame.addText(forwardButtonX,buttonPosY,forwardText,"RotateNext");
|
---|
186 | currFrame.setSaved();
|
---|
187 | }
|
---|
188 |
|
---|
189 | private void generateDropBox(int frameIter){
|
---|
190 | int maxRowLength = _startX + (_columns * _imageSize) + ((_columns-1)* _gap);
|
---|
191 |
|
---|
192 | //the maximum height of the area displaying all the rows.
|
---|
193 | int maxRowsAreaHeight = _startY + (_rows * _imageSize) + ((_rows-1)*_gap);
|
---|
194 |
|
---|
195 | int dropBoxGap = 80;
|
---|
196 |
|
---|
197 | int dropBoxStartX = maxRowLength + (dropBoxGap*2);
|
---|
198 | int dropBoxStartY = _startY;
|
---|
199 |
|
---|
200 | int dropBoxWidth = 300;
|
---|
201 | int dropBoxHeight = maxRowsAreaHeight;
|
---|
202 |
|
---|
203 | Frame currFrame = FrameIO.LoadFrame(_name + frameIter);
|
---|
204 |
|
---|
205 | String dropBoxSourceText = "@iw: org.honours.widgets.CollectionSpaceDropBox " + dropBoxWidth + " " + dropBoxHeight;
|
---|
206 | Text newText = currFrame.addText(dropBoxStartX, dropBoxStartY, dropBoxSourceText, null);
|
---|
207 | newText.onParentStateChanged(new ItemParentStateChangedEvent(currFrame, ItemParentStateChangedEvent.EVENT_TYPE_ADDED));
|
---|
208 |
|
---|
209 | currFrame.setSaved();
|
---|
210 | }
|
---|
211 |
|
---|
212 | private void createCollectionSpace(){
|
---|
213 | Frame check = FrameIO.LoadFrame(_name + "1");
|
---|
214 |
|
---|
215 | if(check != null){
|
---|
216 | FrameIO.deleteFrameset(_name);
|
---|
217 | }
|
---|
218 |
|
---|
219 | try{
|
---|
220 | FrameIO.CreateNewFrameset(_name);
|
---|
221 | }catch(Exception e){
|
---|
222 | e.printStackTrace();
|
---|
223 | }
|
---|
224 | }
|
---|
225 | }
|
---|