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