[26588] | 1 | package org.honours.gui;
|
---|
| 2 |
|
---|
| 3 | import java.io.BufferedWriter;
|
---|
| 4 | import java.io.File;
|
---|
| 5 | import java.io.FileWriter;
|
---|
| 6 | import java.util.ArrayList;
|
---|
| 7 | import java.util.List;
|
---|
| 8 |
|
---|
[26699] | 9 | import org.expeditee.actions.Misc;
|
---|
[26588] | 10 | import org.expeditee.gui.DisplayIO;
|
---|
| 11 | import org.expeditee.gui.Frame;
|
---|
| 12 | import org.expeditee.gui.FrameIO;
|
---|
| 13 | import org.expeditee.gui.FrameKeyboardActions;
|
---|
| 14 | import org.expeditee.gui.MessageBay;
|
---|
| 15 | import org.expeditee.gui.UserSettings;
|
---|
| 16 | import org.expeditee.items.Item;
|
---|
| 17 | import org.expeditee.items.Text;
|
---|
| 18 | import org.expeditee.items.widgets.WidgetCorner;
|
---|
| 19 | import org.expeditee.stats.Formatter;
|
---|
[26699] | 20 | import org.honours.actions.MiscActions;
|
---|
[26588] | 21 | import org.honours.collection.CollectionItem;
|
---|
[26699] | 22 | import org.honours.collection.NoteLayer;
|
---|
[26588] | 23 |
|
---|
| 24 | public class HonoursFrameIO {
|
---|
| 25 |
|
---|
| 26 | private static Frame _lastCopiedFrame = null;
|
---|
| 27 |
|
---|
| 28 | public static boolean DISPLAY_TOOLBAR = true;
|
---|
| 29 | public static boolean DISPLAY_LAYERS = true;
|
---|
| 30 | public static boolean DISPLAY_NOTES = false;
|
---|
| 31 |
|
---|
| 32 | public static boolean DISPLAY_TOGGLER = true;
|
---|
| 33 |
|
---|
| 34 | public static String COLLECTIONS_PATH = FrameIO.PARENT_FOLDER +
|
---|
| 35 | "collections" + File.separator;
|
---|
| 36 |
|
---|
| 37 | /**
|
---|
| 38 | * Generate a new frame for a given (existing)
|
---|
| 39 | * frameset.
|
---|
| 40 | * @param frameNumber - frame number for this next item.
|
---|
| 41 | * @param frameset - frameset to add frame to.
|
---|
| 42 | */
|
---|
| 43 | public static void generateFrame(int frameNumber, String frameset){
|
---|
| 44 | String frameFileName = FrameIO.FRAME_PATH + frameset + File.separator +
|
---|
| 45 | frameNumber + ".exp";
|
---|
| 46 | Frame checkExistingFrame = FrameIO.LoadFrame(frameset + frameNumber);
|
---|
| 47 |
|
---|
| 48 | if(checkExistingFrame == null){
|
---|
| 49 | FileWriter fw;
|
---|
| 50 | BufferedWriter bw;
|
---|
| 51 |
|
---|
| 52 | try{
|
---|
| 53 | fw = new FileWriter(frameFileName);
|
---|
| 54 | bw = new BufferedWriter(fw);
|
---|
| 55 | writeOutFrameHeader(bw);
|
---|
| 56 | FrameIO.WriteINF(FrameIO.FRAME_PATH, frameset, frameset+frameNumber);
|
---|
| 57 | }catch(Exception e){
|
---|
| 58 | e.printStackTrace();
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | /**
|
---|
| 64 | * Writes out a frame header for a new frame.
|
---|
| 65 | * @param bw
|
---|
| 66 | */
|
---|
| 67 | public static void writeOutFrameHeader(BufferedWriter bw){
|
---|
| 68 | try {
|
---|
| 69 | StringBuffer header = new StringBuffer("");
|
---|
| 70 |
|
---|
| 71 | header.append("V 1\n");
|
---|
| 72 | header.append("p 44");
|
---|
| 73 | header.append("U " + UserSettings.UserName + "\n");
|
---|
| 74 | header.append("D " + Formatter.getDateTime() + "\n"); //
|
---|
| 75 | header.append("M " + UserSettings.UserName + "\n"); //last modified by
|
---|
| 76 | header.append("d " + Formatter.getDateTime() + "\n");
|
---|
| 77 | header.append("Z\n\n");
|
---|
| 78 | bw.write(header.toString());
|
---|
| 79 |
|
---|
| 80 | }catch(Exception e) {
|
---|
| 81 | e.printStackTrace();
|
---|
| 82 | }
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | public static Frame CopyFrame() {
|
---|
| 86 | _lastCopiedFrame = DisplayIO.getCurrentFrame();
|
---|
| 87 | MessageBay.displayMessage("Item successfully copied.");
|
---|
| 88 |
|
---|
| 89 | return _lastCopiedFrame;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | public static Frame PasteFrame() {
|
---|
| 93 |
|
---|
| 94 | Frame current = DisplayIO.getCurrentFrame();
|
---|
| 95 | if(_lastCopiedFrame != null){
|
---|
| 96 |
|
---|
| 97 | List<Item> list = _lastCopiedFrame.getVisibleItems();
|
---|
| 98 | List<Item> copy = new ArrayList<Item>();
|
---|
| 99 |
|
---|
| 100 | for(Item item : list){
|
---|
| 101 | if(!(item instanceof WidgetCorner))
|
---|
| 102 | copy.add(item);
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | current.addAllItems(copy);
|
---|
| 106 |
|
---|
| 107 | }else{
|
---|
| 108 | MessageBay.errorMessage("ERROR: NO FRAME/ITEM TO COPY");
|
---|
| 109 | return null;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | return _lastCopiedFrame;
|
---|
| 113 |
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | /**
|
---|
| 117 | * Toggles on and off the display of the "Toggle
|
---|
| 118 | * Toolbar" overlay.
|
---|
| 119 | */
|
---|
| 120 | public static void toggleToggler(){
|
---|
| 121 | if(DISPLAY_TOGGLER){
|
---|
| 122 | swapLinks(Interfaces.TOGGLE_TOOLS_OVERLAY,Interfaces.BLANK_TOGGLER_OVERLAY);
|
---|
| 123 | DISPLAY_TOGGLER = false;
|
---|
| 124 | }else{
|
---|
| 125 | swapLinks(Interfaces.BLANK_TOGGLER_OVERLAY,Interfaces.TOGGLE_TOOLS_OVERLAY);
|
---|
| 126 | DISPLAY_TOGGLER = true;
|
---|
| 127 | }
|
---|
| 128 | FrameKeyboardActions.Refresh();
|
---|
| 129 | }
|
---|
| 130 |
|
---|
[26699] | 131 | /**
|
---|
| 132 | * Toggles display of toolbar on and off.
|
---|
| 133 | */
|
---|
[26588] | 134 | public static void ToggleToolbar() {
|
---|
[26699] | 135 |
|
---|
| 136 | Text displayText = (Text)Misc.getItemContainingData("OptionViewToolbar",FrameIO.LoadFrame(Interfaces.TOGGLE_TOOLS_OVERLAY));
|
---|
| 137 |
|
---|
[26588] | 138 | if(DISPLAY_TOOLBAR){
|
---|
[26699] | 139 | displayText.setText("View Toolbar");
|
---|
| 140 | swapLinks(Interfaces.BLANK_TOOLBAR_OVERLAY,"overlayToolbar");
|
---|
[26588] | 141 | DISPLAY_TOOLBAR = false;
|
---|
| 142 |
|
---|
| 143 | }else{
|
---|
[26699] | 144 |
|
---|
| 145 | displayText.setText("Hide Toolbar");
|
---|
[26733] | 146 | swapLinks(Interfaces.NAVIGATION_OVERLAY_VIEW_NOTES_UNCLICKABLE,"overlayToolbar");
|
---|
[26588] | 147 | DISPLAY_TOOLBAR = true;
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | FrameKeyboardActions.Refresh();
|
---|
| 151 | }
|
---|
[26699] | 152 |
|
---|
[26588] | 153 |
|
---|
| 154 | public static void ToggleNotesDisplay(CollectionItem collectItem) {
|
---|
| 155 |
|
---|
| 156 | //get link to the collection item's note frame.
|
---|
[26699] | 157 | NoteLayer nl = collectItem.getNoteLayer();
|
---|
| 158 |
|
---|
| 159 | if(nl == null){
|
---|
| 160 | MessageBay.errorMessage("No notes to display");
|
---|
| 161 |
|
---|
| 162 |
|
---|
| 163 | return;
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 |
|
---|
| 167 | String noteFrameLink = nl.getFrame().getName();
|
---|
| 168 | System.err.println("*** link (in ToggleNotesDisplay method): " + noteFrameLink);
|
---|
| 169 |
|
---|
[26733] | 170 | Text displayText = (Text)Misc.getItemContainingData("OptionViewNotes",FrameIO.LoadFrame(Interfaces.NAVIGATION_OVERLAY_VIEW_NOTES_UNCLICKABLE));
|
---|
[26699] | 171 |
|
---|
| 172 | if(DISPLAY_NOTES){
|
---|
| 173 | System.err.println("Notes are NOT visible");
|
---|
| 174 | displayText.setText("View Notes");
|
---|
| 175 | //swapLinks(noteFrameLink,Interfaces.BLANK_HIDE_NOTES_OVERLAY);
|
---|
| 176 | swapLinks(Interfaces.BLANK_HIDE_NOTES_OVERLAY,"overlayNotes");
|
---|
| 177 | DISPLAY_NOTES = false;
|
---|
[26588] | 178 |
|
---|
| 179 |
|
---|
[26699] | 180 | }else{
|
---|
| 181 | System.err.println("Notes are visible");
|
---|
| 182 | displayText.setText("Hide Notes");
|
---|
| 183 | //swapLinks(Interfaces.BLANK_HIDE_NOTES_OVERLAY,noteFrameLink);
|
---|
| 184 | swapLinks(noteFrameLink,"overlayNotes");
|
---|
| 185 | DISPLAY_NOTES = true;
|
---|
| 186 | }
|
---|
[26588] | 187 |
|
---|
[26699] | 188 | FrameKeyboardActions.Refresh();
|
---|
| 189 |
|
---|
[26588] | 190 | }
|
---|
| 191 |
|
---|
| 192 |
|
---|
| 193 |
|
---|
| 194 | /**
|
---|
| 195 | * Used by toggleToolbar() and ToggleLayersDisplay() and ToggleNotesDisplay()
|
---|
| 196 | * to change the overlay annotation links. So if we want
|
---|
| 197 | * the display of these things off, the overlay will just be
|
---|
| 198 | * a blank frame. Otherwise the overlay will be the appropriate
|
---|
| 199 | * frame displaying the toolbar/layer display.
|
---|
| 200 | * @param oldLink
|
---|
| 201 | * @param newLink
|
---|
| 202 | */
|
---|
[26699] | 203 | private static void swapLinks(String newLink,String data){
|
---|
[26588] | 204 |
|
---|
[26699] | 205 | //TODO: Change this code so that it finds an item containing a data value, i.e. "overlayNotes", "overlayToolbar" or "overlayViewToolbar"
|
---|
| 206 | //The item whose link we want to change
|
---|
| 207 | Text overlayLink = (Text)Misc.getItemContainingData(data, DisplayIO.getCurrentFrame());
|
---|
| 208 |
|
---|
| 209 | overlayLink.setLink(newLink);
|
---|
[26588] | 210 | }
|
---|
| 211 | }
|
---|