1 | package org.honours.actions;
|
---|
2 |
|
---|
3 | import java.awt.Color;
|
---|
4 |
|
---|
5 | import org.expeditee.actions.Actions;
|
---|
6 | import org.expeditee.gui.DisplayIO;
|
---|
7 | import org.expeditee.gui.Frame;
|
---|
8 | import org.expeditee.gui.FrameIO;
|
---|
9 | import org.expeditee.gui.FrameKeyboardActions;
|
---|
10 | import org.expeditee.gui.MessageBay;
|
---|
11 | import org.expeditee.items.Text;
|
---|
12 | import org.honours.Main;
|
---|
13 | import org.honours.collection.Collection;
|
---|
14 | import org.honours.collection.CollectionItem;
|
---|
15 | import org.honours.collection.NoteLayer;
|
---|
16 | import org.honours.gui.HonoursFrameIO;
|
---|
17 |
|
---|
18 | public class MiscActions {
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Copy items on a frame which
|
---|
22 | * can be pasted on another frame.
|
---|
23 | */
|
---|
24 | public static void CopyFrame(){
|
---|
25 | HonoursFrameIO.CopyFrame();
|
---|
26 | }
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Paste a copied frame on to
|
---|
30 | * the current frame being displayed.
|
---|
31 | */
|
---|
32 | public static void PasteFrame(){
|
---|
33 | HonoursFrameIO.PasteFrame();
|
---|
34 | }
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Toggle toolbar on and off.
|
---|
38 | */
|
---|
39 | public static void ToggleToolbar(){
|
---|
40 |
|
---|
41 | HonoursFrameIO.ToggleToolbar();
|
---|
42 | }
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * Toggle display of toggle toolbar on and off.
|
---|
46 | */
|
---|
47 | public static void ToggleToggler(){
|
---|
48 | HonoursFrameIO.toggleToggler();
|
---|
49 | }
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Toggle display of layers on and off.
|
---|
53 | */
|
---|
54 | /* public static void ToggleDisplayLayers(){
|
---|
55 | HonoursFrameIO.ToggleLayersDisplay();
|
---|
56 |
|
---|
57 | if(HonoursFrameIO.DISPLAY_LAYERS)
|
---|
58 | MessageBay.displayMessage("Display of layers on");
|
---|
59 | else
|
---|
60 | MessageBay.displayMessage("Display of layers off");
|
---|
61 | }*/
|
---|
62 |
|
---|
63 |
|
---|
64 | ///////////
|
---|
65 |
|
---|
66 | public static void AddNewNote(){
|
---|
67 | System.err.println("REACHED");
|
---|
68 | AddNewNote(DisplayIO.getCurrentFrame());
|
---|
69 | Actions.PerformActionCatchErrors(DisplayIO.getCurrentFrame(), null, "Format");
|
---|
70 | }
|
---|
71 |
|
---|
72 | public static void AddNewNote(Frame frame){
|
---|
73 | Collection collect = Collection.findCollection(frame);
|
---|
74 |
|
---|
75 | if(collect != null){
|
---|
76 | CollectionItem cItem = CollectionItem.findCollectionItem(frame, collect);
|
---|
77 | if(cItem != null)
|
---|
78 | AddNewNote(cItem,collect);
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * Add a new note about a collection item which will be displayed
|
---|
84 | * on the item's frame.
|
---|
85 | * @param collectItem
|
---|
86 | * @param collect
|
---|
87 | */
|
---|
88 | public static void AddNewNote(CollectionItem collectItem, Collection collect){
|
---|
89 |
|
---|
90 | NoteLayer noteLayer = null;
|
---|
91 |
|
---|
92 | //Check if collectionItem has a notelayer.
|
---|
93 | if(collectItem.getNoteLayer() != null){
|
---|
94 | noteLayer = collectItem.getNoteLayer();
|
---|
95 |
|
---|
96 | }else{
|
---|
97 | //Create a new note layer.
|
---|
98 | noteLayer = new NoteLayer();
|
---|
99 | noteLayer.setAssociatedItem(collectItem);
|
---|
100 |
|
---|
101 | //Create a new frame and set noteLayer's frame attribute.
|
---|
102 | int frameNumber = FrameIO.getLastNumber("notesmain") + 1;
|
---|
103 | HonoursFrameIO.generateFrame(frameNumber, "notesmain");
|
---|
104 | Frame layerFrame = FrameIO.LoadFrame("notesmain"+frameNumber);
|
---|
105 | noteLayer.setFrame(layerFrame);
|
---|
106 | noteLayer.setAssociatedItem(collectItem);
|
---|
107 |
|
---|
108 | collectItem.setNoteLayer(noteLayer);
|
---|
109 |
|
---|
110 | //now put collectItem back in collection list.
|
---|
111 | int itemIndex = CollectionItem.getPositionInCollection(collectItem, collect);
|
---|
112 | collect.getItems().remove(itemIndex);
|
---|
113 | collect.getItems().add(itemIndex, collectItem);
|
---|
114 |
|
---|
115 | //put collection back in collection list.
|
---|
116 | int collectIndex = Collection.getCollectionPosition(collect);
|
---|
117 | Main._collections.remove(collectIndex);
|
---|
118 | Main._collections.add(collectIndex,collect);
|
---|
119 | }
|
---|
120 |
|
---|
121 | //Add new text item to noteLayer's frame in a free space - for now
|
---|
122 | //just add at position (200,200) and hope that any other note has been moved since.
|
---|
123 | Text noteText = noteLayer.getFrame().addText(200, 200, "@[Insert note here]", null);
|
---|
124 | noteText.setBackgroundColor(Color.LIGHT_GRAY);
|
---|
125 | noteText.setColor(Color.BLACK);
|
---|
126 | noteText.setBorderColor(Color.BLACK);
|
---|
127 | noteText.setThickness(1);
|
---|
128 | noteLayer.getFrame().setSaved();
|
---|
129 | FrameKeyboardActions.Refresh();
|
---|
130 |
|
---|
131 | HonoursFrameIO.DISPLAY_NOTES = false;
|
---|
132 | HonoursFrameIO.ToggleNotesDisplay(collectItem);
|
---|
133 | }
|
---|
134 |
|
---|
135 |
|
---|
136 | public static void ToggleNotesView(){
|
---|
137 | ToggleNotesView(DisplayIO.getCurrentFrame());
|
---|
138 | }
|
---|
139 |
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * Toggle the display of notes for a collection item on and off.
|
---|
143 | * @param frame
|
---|
144 | */
|
---|
145 | public static void ToggleNotesView(Frame frame){
|
---|
146 | Collection collect = Collection.findCollection(frame);
|
---|
147 | if(collect != null){
|
---|
148 | CollectionItem cItem = CollectionItem.findCollectionItem(frame, collect);
|
---|
149 | if(cItem != null)
|
---|
150 | HonoursFrameIO.ToggleNotesDisplay(cItem);
|
---|
151 | }
|
---|
152 | }
|
---|
153 |
|
---|
154 |
|
---|
155 | }
|
---|