source: other-projects/GlamED/trunk/src/org/honours/collection/Collection.java@ 26605

Last change on this file since 26605 was 26605, checked in by davidb, 11 years ago

Adding more code for the Collection Space feature back into GlamED, including a setCollectionSpace method for the Collection class.

File size: 2.4 KB
Line 
1package org.honours.collection;
2
3import java.util.List;
4import java.util.concurrent.CopyOnWriteArrayList;
5
6import org.expeditee.gui.Frame;
7import org.honours.Main;
8import org.honours.CollectionSpace.*;
9
10public class Collection {
11
12 private String _name;
13 private CopyOnWriteArrayList<CollectionItem> _items;
14 private CollectionInformation _collectionInfo;
15
16 private CollectionSpace _collectionSpace;
17
18 public Collection() {}
19
20 public Collection(String name){
21 _name = name;
22 _items = new CopyOnWriteArrayList<CollectionItem>();
23 }
24
25 public void setName(String s){
26 _name = s;
27 }
28
29 public String getName(){
30 return _name;
31 }
32
33 public void setCollectionInformation(CollectionInformation ci){
34 _collectionInfo = ci;
35 }
36
37 public CollectionInformation getCollectionInformation(){
38 return _collectionInfo;
39 }
40
41 public void addItem(CollectionItem item){
42 _items.add(item);
43 }
44
45 public List<CollectionItem> getItems()
46 {
47 return _items;
48 }
49
50 public void resetItems(){
51 //_items = new ArrayList<CollectionItem>();
52 _items = new CopyOnWriteArrayList<CollectionItem>();
53 }
54
55 public void setCollectionSpace(CollectionSpace cs){
56 _collectionSpace = cs;
57 }
58
59public static Collection findCollection(Frame frame){
60
61 if(frame == null)
62 return null;
63
64 String framesetName = frame.getFramesetName();
65 for(Collection c : Main._collections){
66 if(c.getName().equals(framesetName))
67 return c;
68 }
69 return null;
70 }
71
72 /**
73 * Find a collection with the matching
74 * passed (frameset) name.
75 * @param name
76 * @return
77 */
78 public static Collection findCollection(String name){
79
80 if(name == null)
81 return null;
82 else if(name.equals(""))
83 return null;
84
85 for(Collection c : Main._collections){
86 if(c.getName().equals(name))
87 return c;
88 }
89
90 return null;
91 }
92
93 public static int getCollectionPosition(Collection c){
94
95 if(c == null)
96 return -1;
97
98 for(int i = 0; i < Main._collections.size(); i++){
99 Collection currCol = Main._collections.get(i);
100 if(currCol == c)
101 return i;
102 }
103
104 return -1;
105 }
106
107 public static int getCollectionPosition(Frame frame){
108 Collection find = findCollection(frame);
109 if(find == null)
110 return -1;
111
112 for(int i = 0; i < Main._collections.size(); i++){
113
114 Collection currCol = Main._collections.get(i);
115 if(currCol == find)
116 return i;
117
118 }
119
120 return -1;
121 }
122
123}
Note: See TracBrowser for help on using the repository browser.