[919] | 1 | /**
|
---|
| 2 | * DefaultFrameWriter.java
|
---|
| 3 | * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
|
---|
| 4 | *
|
---|
| 5 | * This program is free software: you can redistribute it and/or modify
|
---|
| 6 | * it under the terms of the GNU General Public License as published by
|
---|
| 7 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 8 | * (at your option) any later version.
|
---|
| 9 | *
|
---|
| 10 | * This program is distributed in the hope that it will be useful,
|
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 13 | * GNU General Public License for more details.
|
---|
| 14 | *
|
---|
| 15 | * You should have received a copy of the GNU General Public License
|
---|
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 17 | */
|
---|
| 18 |
|
---|
[4] | 19 | package org.expeditee.io;
|
---|
| 20 |
|
---|
[348] | 21 | import java.io.BufferedOutputStream;
|
---|
[4] | 22 | import java.io.File;
|
---|
[348] | 23 | import java.io.FileOutputStream;
|
---|
[4] | 24 | import java.io.IOException;
|
---|
[348] | 25 | import java.io.OutputStream;
|
---|
| 26 | import java.io.OutputStreamWriter;
|
---|
[306] | 27 | import java.io.Writer;
|
---|
[67] | 28 | import java.lang.reflect.Method;
|
---|
[226] | 29 | import java.util.Collection;
|
---|
[286] | 30 | import java.util.HashSet;
|
---|
[67] | 31 | import java.util.LinkedHashMap;
|
---|
[1418] | 32 | import java.util.Set;
|
---|
[4] | 33 |
|
---|
[80] | 34 | import org.expeditee.agents.WriteTree;
|
---|
[1102] | 35 | import org.expeditee.gio.EcosystemManager;
|
---|
[4] | 36 | import org.expeditee.gui.Frame;
|
---|
| 37 | import org.expeditee.gui.FrameIO;
|
---|
| 38 | import org.expeditee.items.Item;
|
---|
[286] | 39 | import org.expeditee.items.Line;
|
---|
[67] | 40 | import org.expeditee.items.Text;
|
---|
[4] | 41 |
|
---|
| 42 | public abstract class DefaultFrameWriter extends ItemWriter implements
|
---|
| 43 | FrameWriter {
|
---|
[1413] | 44 | protected static final char MAGNETIZED_ITEM_BOTTOM = '/';
|
---|
| 45 | protected static final char MAGNETIZED_ITEM_TOP = '^';
|
---|
| 46 | protected static final char MAGNETIZED_ITEM_RIGHT = ']';
|
---|
| 47 | protected static final char MAGNETIZED_ITEM_LEFT = '[';
|
---|
| 48 | protected static final char PERMISSION = 'p';
|
---|
| 49 | protected static final char LINK_HISTORY = 'B';
|
---|
| 50 | protected static final char TOOLTIP = 'A';
|
---|
| 51 | protected static final char CONSTRAINT_IDS = 'c';
|
---|
| 52 | protected static final char LINE_IDS = 'l';
|
---|
| 53 | protected static final char THICKNESS = 'h';
|
---|
| 54 | protected static final char AUTO_WRAP_TO_SAVE = 'r';
|
---|
| 55 | protected static final char JUSTIFICATION = 'k';
|
---|
| 56 | protected static final char MIN_WIDTH_TO_SAVE = 'M';
|
---|
| 57 | protected static final char WIDTH_TO_SAVE = 'w';
|
---|
| 58 | protected static final char INITIAL_SPACING = 'm';
|
---|
| 59 | protected static final char LETTER_SPACING = 'b';
|
---|
| 60 | protected static final char WORD_SPACING = 'a';
|
---|
| 61 | protected static final char FORMULA = 'J';
|
---|
| 62 | protected static final char MASK = 'O';
|
---|
| 63 | protected static final char SPACING = 't';
|
---|
| 64 | protected static final char FONT = 'f';
|
---|
| 65 | protected static final char FILLED = 'z';
|
---|
| 66 | protected static final char DOT_TYPE = 'v';
|
---|
| 67 | protected static final char ARROW = 'j';
|
---|
| 68 | protected static final char LINE_PATTERN = 'g';
|
---|
| 69 | protected static final char LINK_TEMPLATE = 'y';
|
---|
| 70 | protected static final char LINK_FRAMESET = 'q';
|
---|
| 71 | protected static final char LINK_MARK = 'n';
|
---|
| 72 | protected static final char OWNER = 'o';
|
---|
| 73 | protected static final char FILL_PATTERN = 'i';
|
---|
| 74 | protected static final char ANCHOR_BOTTOM = 'I';
|
---|
| 75 | protected static final char ANCHOR_TOP = 'N';
|
---|
| 76 | protected static final char ANCHOR_RIGHT = 'H';
|
---|
| 77 | protected static final char ANCHOR_LEFT = 'R';
|
---|
| 78 | protected static final char GRADIENT_ANGLE = 'Q';
|
---|
| 79 | protected static final char GRADIENT_COLOR = 'E';
|
---|
| 80 | protected static final char FILL_COLOR = 'e';
|
---|
| 81 | protected static final char HIGHLIGHT = 'u';
|
---|
| 82 | protected static final char DATA = 'D';
|
---|
| 83 | protected static final char ACTION_LEAVE_FRAME = 'Y';
|
---|
| 84 | protected static final char ACTION_ENTER_FRAME = 'W';
|
---|
| 85 | protected static final char ACTION_CURSOR_LEAVE = 'V';
|
---|
| 86 | protected static final char ACTION_CURSOR_ENTER = 'U';
|
---|
| 87 | protected static final char ACTION_MARK = 'x';
|
---|
| 88 | protected static final char ACTION = 'X';
|
---|
| 89 | protected static final char LINK = 'F';
|
---|
| 90 | protected static final char TEXT = 'T';
|
---|
| 91 | protected static final char POSITION = 'P';
|
---|
| 92 | protected static final char BORDER_COLOR = 'K';
|
---|
| 93 | protected static final char BACKGROUND_COLOR = 'G';
|
---|
| 94 | protected static final char COLOR = 'd';
|
---|
| 95 | protected static final char DATE_CREATED = 's';
|
---|
| 96 | protected static final char TYPE_AND_ID = 'S';
|
---|
| 97 |
|
---|
| 98 | public static final String TAB_INDEX_STR = "_ti";
|
---|
| 99 | public static final String SINGLE_LINE_ONLY_STR = "_sl";
|
---|
| 100 | public static final String PLACEHOLDER_STR = "_ph";
|
---|
| 101 | public static final String ENCRYPTION_LABEL_STR = "_el";
|
---|
[1415] | 102 | public static final String ACCEPTS_ENTER = "_ae";
|
---|
[1513] | 103 | public static final String ANCHOR_CENTERX_STR = "_ax";
|
---|
| 104 | public static final String ANCHOR_CENTERY_STR = "_ay";
|
---|
[1413] | 105 | public static final String MAGNETIZED_ITEM_BOTTOM_STR = MAGNETIZED_ITEM_BOTTOM + "";
|
---|
| 106 | public static final String MAGNETIZED_ITEM_TOP_STR = MAGNETIZED_ITEM_TOP + "";
|
---|
| 107 | public static final String MAGNETIZED_ITEM_RIGHT_STR = MAGNETIZED_ITEM_RIGHT + "";
|
---|
| 108 | public static final String MAGNETIZED_ITEM_LEFT_STR = MAGNETIZED_ITEM_LEFT + "";
|
---|
| 109 | public static final String PERMISSION_STR = PERMISSION + "";
|
---|
| 110 | public static final String LINK_HISTORY_STR = LINK_HISTORY + "";
|
---|
| 111 | public static final String TOOLTIP_STR = TOOLTIP + "";
|
---|
| 112 | public static final String CONSTRAINT_IDS_STR = CONSTRAINT_IDS + "";
|
---|
| 113 | public static final String LINE_IDS_STR = LINE_IDS + "";
|
---|
| 114 | public static final String THICKNESS_STR = THICKNESS + "";
|
---|
| 115 | public static final String AUTO_WRAP_TO_SAVE_STR = AUTO_WRAP_TO_SAVE + "";
|
---|
| 116 | public static final String JUSTIFICATION_STR = JUSTIFICATION + "";
|
---|
| 117 | public static final String MIN_WIDTH_TO_SAVE_STR = MIN_WIDTH_TO_SAVE + "";
|
---|
| 118 | public static final String WIDTH_TO_SAVE_STR = WIDTH_TO_SAVE + "";
|
---|
| 119 | public static final String INITIAL_SPACING_STR = INITIAL_SPACING + "";
|
---|
| 120 | public static final String LETTER_SPACING_STR = LETTER_SPACING + "";
|
---|
| 121 | public static final String WORD_SPACING_STR = WORD_SPACING + "";
|
---|
| 122 | public static final String FORMULA_STR = FORMULA + "";
|
---|
| 123 | public static final String MASK_STR = MASK + "";
|
---|
| 124 | public static final String SPACING_STR = SPACING + "";
|
---|
| 125 | public static final String FONT_STR = FONT + "";
|
---|
| 126 | public static final String FILLED_STR = FILLED + "";
|
---|
| 127 | public static final String DOT_TYPE_STR = DOT_TYPE + "";
|
---|
| 128 | public static final String ARROW_STR = ARROW + "";
|
---|
| 129 | public static final String LINE_PATTERN_STR = LINE_PATTERN + "";
|
---|
| 130 | public static final String LINK_TEMPLATE_STR = LINK_TEMPLATE + "";
|
---|
| 131 | public static final String LINK_FRAMESET_STR = LINK_FRAMESET + "";
|
---|
| 132 | public static final String LINK_MARK_STR = LINK_MARK + "";
|
---|
| 133 | public static final String OWNER_STR = OWNER + "";
|
---|
| 134 | public static final String FILL_PATTERN_STR = FILL_PATTERN + "";
|
---|
| 135 | public static final String ANCHOR_BOTTOM_STR = ANCHOR_BOTTOM + "";
|
---|
| 136 | public static final String ANCHOR_TOP_STR = ANCHOR_TOP + "";
|
---|
| 137 | public static final String ANCHOR_RIGHT_STR = ANCHOR_RIGHT + "";
|
---|
| 138 | public static final String ANCHOR_LEFT_STR = ANCHOR_LEFT + "";
|
---|
| 139 | public static final String GRADIENT_ANGLE_STR = GRADIENT_ANGLE + "";
|
---|
| 140 | public static final String GRADIENT_COLOR_STR = GRADIENT_COLOR + "";
|
---|
| 141 | public static final String FILL_COLOR_STR = FILL_COLOR + "";
|
---|
| 142 | public static final String HIGHLIGHT_STR = HIGHLIGHT + "";
|
---|
| 143 | public static final String DATA_STR = DATA + "";
|
---|
| 144 | public static final String ACTION_LEAVE_FRAME_STR = ACTION_LEAVE_FRAME + "";
|
---|
| 145 | public static final String ACTION_ENTER_FRAME_STR = ACTION_ENTER_FRAME + "";
|
---|
| 146 | public static final String ACTION_CURSOR_LEAVE_STR = ACTION_CURSOR_LEAVE + "";
|
---|
| 147 | public static final String ACTION_CURSOR_ENTER_STR = ACTION_CURSOR_ENTER + "";
|
---|
| 148 | public static final String ACTION_MARK_STR = ACTION_MARK + "";
|
---|
| 149 | public static final String ACTION_STR = ACTION + "";
|
---|
| 150 | public static final String LINK_STR = LINK + "";
|
---|
| 151 | public static final String TEXT_STR = TEXT + "";
|
---|
| 152 | public static final String POSITION_STR = POSITION + "";
|
---|
| 153 | public static final String BORDER_COLOR_STR = BORDER_COLOR + "";
|
---|
| 154 | public static final String BACKGROUND_COLOR_STR = BACKGROUND_COLOR + "";
|
---|
| 155 | public static final String COLOR_STR = COLOR + "";
|
---|
| 156 | public static final String DATE_CREATED_STR = DATE_CREATED + "";
|
---|
| 157 | public static final String TYPE_AND_ID_STR = TYPE_AND_ID + "";
|
---|
[4] | 158 |
|
---|
| 159 | protected String _filename = null;
|
---|
| 160 |
|
---|
| 161 | protected String _output = null;
|
---|
| 162 |
|
---|
| 163 | protected ProxyWriter _writer = null;
|
---|
| 164 |
|
---|
| 165 | protected String _format = "";
|
---|
| 166 |
|
---|
| 167 | protected boolean _running = true;
|
---|
| 168 |
|
---|
| 169 | protected boolean _stop = false;
|
---|
| 170 |
|
---|
[67] | 171 | // keep track of methods that are put on the same line
|
---|
[1418] | 172 | private static LinkedHashMap<Character, Method> _ItemCharTags = new LinkedHashMap<Character, Method>();
|
---|
[1321] | 173 | // IMPORTANT: keys in _ItemTagsExt must start with underscore as their first character
|
---|
[1418] | 174 | private static LinkedHashMap<String, Method> _ItemStrTags = new LinkedHashMap<String, Method>();
|
---|
| 175 |
|
---|
| 176 | private static LinkedHashMap<String, Method> _ItemTags = new LinkedHashMap<String, Method>();
|
---|
[67] | 177 |
|
---|
[1413] | 178 | protected static LinkedHashMap<Character, Method> _FrameTags = new LinkedHashMap<Character, Method>();
|
---|
| 179 |
|
---|
| 180 | {
|
---|
[67] | 181 | try {
|
---|
[1505] | 182 | /// C H I J L N P Q R S W X Y Z
|
---|
| 183 | /// a b c f g h i j l m n o q r s t u v w x y z
|
---|
| 184 | // Standard frame tags
|
---|
[737] | 185 | _FrameTags.put('V', Frame.class.getMethod("getVersion"));
|
---|
| 186 | _FrameTags.put('p', Frame.class.getMethod("getPermission"));
|
---|
| 187 | _FrameTags.put('U', Frame.class.getMethod("getOwner"));
|
---|
| 188 | _FrameTags.put('D', Frame.class.getMethod("getDateCreated"));
|
---|
| 189 | _FrameTags.put('M', Frame.class.getMethod("getLastModifyUser"));
|
---|
| 190 | _FrameTags.put('d', Frame.class.getMethod("getLastModifyDate"));
|
---|
| 191 | _FrameTags.put('F', Frame.class.getMethod("getFrozenDate"));
|
---|
| 192 | _FrameTags.put('O', Frame.class.getMethod("getForegroundColor"));
|
---|
| 193 | _FrameTags.put('B', Frame.class.getMethod("getBackgroundColor"));
|
---|
[1242] | 194 | _FrameTags.put('T', Frame.class.getMethod("getData"));
|
---|
[1405] | 195 | _FrameTags.put('G', Frame.class.getMethod("getGroup"));
|
---|
[737] | 196 |
|
---|
[1505] | 197 | // Encryption frame tags
|
---|
| 198 | _FrameTags.put('K', Frame.class.getMethod("getFrameEncryptionLabel"));
|
---|
| 199 | _FrameTags.put('E', Frame.class.getMethod("getFrameEncryptionPermission"));
|
---|
| 200 | _FrameTags.put('k', Frame.class.getMethod("getHomogeneousEncryptionLabel"));
|
---|
| 201 | _FrameTags.put('e', Frame.class.getMethod("getEncryptionPermission"));
|
---|
[1506] | 202 | _FrameTags.put('a', Frame.class.getMethod("getHetrogeneousFrameOwnerLabels"));
|
---|
[1505] | 203 |
|
---|
[1200] | 204 | // Note: As of 26/11/18 there are no unused letter item tags. Use other characters.
|
---|
[1418] | 205 | _ItemCharTags.put(DefaultFrameWriter.TYPE_AND_ID, Item.class.getMethod("getTypeAndID"));
|
---|
| 206 | _ItemCharTags.put(DefaultFrameWriter.DATE_CREATED, Item.class.getMethod("getDateCreated"));
|
---|
| 207 | _ItemCharTags.put(DefaultFrameWriter.COLOR, Item.class.getMethod("getColor"));
|
---|
| 208 | _ItemCharTags.put(DefaultFrameWriter.BACKGROUND_COLOR, Item.class.getMethod("getBackgroundColor"));
|
---|
| 209 | _ItemCharTags.put(DefaultFrameWriter.BORDER_COLOR, Item.class.getMethod("getBorderColor"));
|
---|
[720] | 210 |
|
---|
[1418] | 211 | _ItemCharTags.put(DefaultFrameWriter.POSITION, Item.class.getMethod("getPosition"));
|
---|
| 212 | _ItemCharTags.put(DefaultFrameWriter.TEXT, Text.class.getMethod("getText"));
|
---|
| 213 | _ItemCharTags.put(DefaultFrameWriter.LINK, Item.class.getMethod("getLink"));
|
---|
| 214 | _ItemCharTags.put(DefaultFrameWriter.ACTION, Item.class.getMethod("getAction"));
|
---|
| 215 | _ItemCharTags.put(DefaultFrameWriter.ACTION_MARK, Item.class.getMethod("getActionMark"));
|
---|
| 216 | _ItemCharTags.put(DefaultFrameWriter.ACTION_CURSOR_ENTER, Item.class.getMethod("getActionCursorEnter"));
|
---|
| 217 | _ItemCharTags.put(DefaultFrameWriter.ACTION_CURSOR_LEAVE, Item.class.getMethod("getActionCursorLeave"));
|
---|
| 218 | _ItemCharTags.put(DefaultFrameWriter.ACTION_ENTER_FRAME, Item.class.getMethod("getActionEnterFrame"));
|
---|
| 219 | _ItemCharTags.put(DefaultFrameWriter.ACTION_LEAVE_FRAME, Item.class.getMethod("getActionLeaveFrame"));
|
---|
| 220 | _ItemCharTags.put(DefaultFrameWriter.DATA, Item.class.getMethod("getData"));
|
---|
| 221 | _ItemCharTags.put(DefaultFrameWriter.HIGHLIGHT, Item.class.getMethod("getHighlight"));
|
---|
| 222 | _ItemCharTags.put(DefaultFrameWriter.FILL_COLOR, Item.class.getMethod("getFillColor"));
|
---|
| 223 | _ItemCharTags.put(DefaultFrameWriter.GRADIENT_COLOR, Item.class.getMethod("getGradientColor"));
|
---|
| 224 | _ItemCharTags.put(DefaultFrameWriter.GRADIENT_ANGLE, Item.class.getMethod("getGradientAngle"));
|
---|
[874] | 225 |
|
---|
[1418] | 226 | _ItemCharTags.put(DefaultFrameWriter.ANCHOR_LEFT, Item.class.getMethod("getAnchorLeft"));
|
---|
| 227 | _ItemCharTags.put(DefaultFrameWriter.ANCHOR_RIGHT, Item.class.getMethod("getAnchorRight"));
|
---|
| 228 | _ItemCharTags.put(DefaultFrameWriter.ANCHOR_TOP, Item.class.getMethod("getAnchorTop"));
|
---|
| 229 | _ItemCharTags.put(DefaultFrameWriter.ANCHOR_BOTTOM, Item.class.getMethod("getAnchorBottom"));
|
---|
[286] | 230 |
|
---|
[1418] | 231 | _ItemCharTags.put(DefaultFrameWriter.FILL_PATTERN, Item.class.getMethod("getFillPattern"));
|
---|
| 232 | _ItemCharTags.put(DefaultFrameWriter.OWNER, Item.class.getMethod("getOwner"));
|
---|
| 233 | _ItemCharTags.put(DefaultFrameWriter.LINK_MARK, Item.class.getMethod("getLinkMark"));
|
---|
| 234 | _ItemCharTags.put(DefaultFrameWriter.LINK_FRAMESET, Item.class.getMethod("getLinkFrameset"));
|
---|
| 235 | _ItemCharTags.put(DefaultFrameWriter.LINK_TEMPLATE, Item.class.getMethod("getLinkTemplate"));
|
---|
| 236 | _ItemCharTags.put(DefaultFrameWriter.LINE_PATTERN, Item.class.getMethod("getLinePattern"));
|
---|
[67] | 237 |
|
---|
[1418] | 238 | _ItemCharTags.put(DefaultFrameWriter.ARROW, Item.class.getMethod("getArrow"));
|
---|
[427] | 239 |
|
---|
[1418] | 240 | _ItemCharTags.put(DefaultFrameWriter.DOT_TYPE, Item.class.getMethod("getDotType"));
|
---|
| 241 | _ItemCharTags.put(DefaultFrameWriter.FILLED, Item.class.getMethod("getFilled"));
|
---|
[67] | 242 |
|
---|
[1418] | 243 | _ItemCharTags.put(DefaultFrameWriter.FONT, Text.class.getMethod("getFont"));
|
---|
| 244 | _ItemCharTags.put(DefaultFrameWriter.SPACING, Text.class.getMethod("getSpacing"));
|
---|
[1200] | 245 |
|
---|
[1418] | 246 | _ItemCharTags.put(DefaultFrameWriter.MASK, Text.class.getMethod("getMask"));
|
---|
[176] | 247 |
|
---|
[286] | 248 | // TODO set a boolean flag to indicate that the text is a formula
|
---|
| 249 | // Store the formula in the text property NOT the answer
|
---|
[1418] | 250 | _ItemCharTags.put(DefaultFrameWriter.FORMULA, Item.class.getMethod("getFormula"));
|
---|
[67] | 251 |
|
---|
[1418] | 252 | _ItemCharTags.put(DefaultFrameWriter.WORD_SPACING, Text.class.getMethod("getWordSpacing"));
|
---|
| 253 | _ItemCharTags.put(DefaultFrameWriter.LETTER_SPACING, Text.class.getMethod("getLetterSpacing"));
|
---|
| 254 | _ItemCharTags.put(DefaultFrameWriter.INITIAL_SPACING, Text.class.getMethod("getInitialSpacing"));
|
---|
| 255 | _ItemCharTags.put(DefaultFrameWriter.WIDTH_TO_SAVE, Text.class.getMethod("getWidthToSave"));
|
---|
| 256 | _ItemCharTags.put(DefaultFrameWriter.MIN_WIDTH_TO_SAVE, Text.class.getMethod("getMinWidthToSave"));
|
---|
| 257 | _ItemCharTags.put(DefaultFrameWriter.JUSTIFICATION, Text.class.getMethod("getJustification"));
|
---|
| 258 | _ItemCharTags.put(DefaultFrameWriter.AUTO_WRAP_TO_SAVE, Text.class.getMethod("getAutoWrapToSave"));
|
---|
[67] | 259 |
|
---|
[1418] | 260 | _ItemCharTags.put(DefaultFrameWriter.THICKNESS, Item.class.getMethod("getThickness"));
|
---|
| 261 | _ItemCharTags.put(DefaultFrameWriter.LINE_IDS, Item.class.getMethod("getLineIDs"));
|
---|
| 262 | _ItemCharTags.put(DefaultFrameWriter.CONSTRAINT_IDS, Item.class.getMethod("getConstraintIDs"));
|
---|
[656] | 263 |
|
---|
[1418] | 264 | _ItemCharTags.put(DefaultFrameWriter.TOOLTIP, Item.class.getMethod("getTooltip"));
|
---|
| 265 | _ItemCharTags.put(DefaultFrameWriter.LINK_HISTORY, Item.class.getMethod("getLinkHistory"));
|
---|
[737] | 266 |
|
---|
[1418] | 267 | _ItemCharTags.put(DefaultFrameWriter.PERMISSION, Item.class.getMethod("getPermission"));
|
---|
[67] | 268 |
|
---|
[1418] | 269 | _ItemCharTags.put(DefaultFrameWriter.MAGNETIZED_ITEM_LEFT, Item.class.getMethod("getMagnetizedItemLeft"));
|
---|
| 270 | _ItemCharTags.put(DefaultFrameWriter.MAGNETIZED_ITEM_RIGHT, Item.class.getMethod("getMagnetizedItemRight"));
|
---|
| 271 | _ItemCharTags.put(DefaultFrameWriter.MAGNETIZED_ITEM_TOP, Item.class.getMethod("getMagnetizedItemTop"));
|
---|
| 272 | _ItemCharTags.put(DefaultFrameWriter.MAGNETIZED_ITEM_BOTTOM, Item.class.getMethod("getMagnetizedItemBottom"));
|
---|
[1296] | 273 |
|
---|
[1418] | 274 | _ItemStrTags.put(DefaultFrameWriter.ENCRYPTION_LABEL_STR, Item.class.getMethod("getEncryptionLabel"));
|
---|
[1398] | 275 |
|
---|
[1418] | 276 | _ItemStrTags.put(DefaultFrameWriter.PLACEHOLDER_STR, Text.class.getMethod("getPlaceholder"));
|
---|
| 277 | _ItemStrTags.put(DefaultFrameWriter.SINGLE_LINE_ONLY_STR, Text.class.getMethod("isSingleLineOnly"));
|
---|
| 278 | _ItemStrTags.put(DefaultFrameWriter.TAB_INDEX_STR, Text.class.getMethod("getTabIndex"));
|
---|
| 279 | _ItemStrTags.put(DefaultFrameWriter.ACCEPTS_ENTER, Item.class.getMethod("acceptsKeyboardEnter"));
|
---|
[1513] | 280 | _ItemStrTags.put(DefaultFrameWriter.ANCHOR_CENTERX_STR, Item.class.getMethod("getAnchorCenterX"));
|
---|
[67] | 281 | } catch (Exception e) {
|
---|
| 282 | e.printStackTrace();
|
---|
| 283 | }
|
---|
[1418] | 284 |
|
---|
| 285 | Set<Character> keySet = _ItemCharTags.keySet();
|
---|
| 286 | for (Character key: keySet) {
|
---|
| 287 | _ItemTags.put(key + "", _ItemCharTags.get(key));
|
---|
| 288 | }
|
---|
| 289 | _ItemTags.putAll(_ItemStrTags);
|
---|
[67] | 290 | }
|
---|
| 291 |
|
---|
[1413] | 292 | public DefaultFrameWriter() {
|
---|
| 293 |
|
---|
| 294 |
|
---|
| 295 | }
|
---|
| 296 |
|
---|
[4] | 297 | public void setOutputLocation(String filename) {
|
---|
| 298 | _filename = filename;
|
---|
| 299 | }
|
---|
| 300 |
|
---|
| 301 | public String writeFrame(Frame toWrite) throws IOException {
|
---|
[306] | 302 | return writeFrame(toWrite, null);
|
---|
| 303 | }
|
---|
[309] | 304 |
|
---|
[306] | 305 | public String writeFrame(Frame toWrite, Writer writer) throws IOException {
|
---|
[4] | 306 | try {
|
---|
[306] | 307 | initialise(toWrite, writer);
|
---|
[4] | 308 |
|
---|
| 309 | outputFrame(toWrite);
|
---|
| 310 |
|
---|
| 311 | _running = false;
|
---|
| 312 | return finaliseFrame();
|
---|
| 313 | } catch (IOException ioe) {
|
---|
| 314 | _running = false;
|
---|
| 315 | throw ioe;
|
---|
| 316 | }
|
---|
| 317 |
|
---|
| 318 | }
|
---|
| 319 |
|
---|
[80] | 320 | /**
|
---|
| 321 | * Called before writing out the body items of each frame.
|
---|
[286] | 322 | *
|
---|
| 323 | * @param starting
|
---|
| 324 | * the name of the frame currently being written out.
|
---|
[80] | 325 | * @throws IOException
|
---|
| 326 | */
|
---|
[4] | 327 | protected void writeStartFrame(Frame starting) throws IOException {
|
---|
[80] | 328 | if (starting.getTitleItem() != null) {
|
---|
| 329 | if (starting.getTitleItem().isAnnotation())
|
---|
| 330 | this.writeAnnotationTitle(starting.getTitleItem());
|
---|
[4] | 331 | else
|
---|
[1415] | 332 | this.writeTitle(starting.getTitleItem(), starting.getSortedItems());
|
---|
[4] | 333 | }
|
---|
| 334 | }
|
---|
| 335 |
|
---|
[80] | 336 | /**
|
---|
| 337 | * Called after writing out the body items of each frame.
|
---|
[286] | 338 | *
|
---|
| 339 | * @param ending
|
---|
| 340 | * the name of the frame currently being written out.
|
---|
[80] | 341 | * @throws IOException
|
---|
| 342 | */
|
---|
[4] | 343 | protected void writeEndFrame(Frame ending) throws IOException {
|
---|
| 344 | }
|
---|
[309] | 345 |
|
---|
[306] | 346 | protected final void initialise(Frame start) throws IOException {
|
---|
| 347 | initialise(start, null);
|
---|
| 348 | }
|
---|
[309] | 349 |
|
---|
[306] | 350 | protected void initialise(Frame start, Writer writer) throws IOException {
|
---|
[4] | 351 | if (_filename == null)
|
---|
[1274] | 352 | _filename = FrameIO.EXPORTS_PATH + getFileName(start) + _format;
|
---|
[4] | 353 |
|
---|
[309] | 354 | if (writer != null) {
|
---|
[306] | 355 | _writer = new ProxyWriter(writer);
|
---|
| 356 | _output = writer.toString();
|
---|
[309] | 357 | } else if (_filename.equalsIgnoreCase(WriteTree.CLIPBOARD)) {
|
---|
[4] | 358 | _writer = new ProxyWriter(true);
|
---|
[80] | 359 | _output = WriteTree.CLIPBOARD;
|
---|
[4] | 360 | } else {
|
---|
| 361 | if (_filename.contains(File.separator)) {
|
---|
| 362 | String extTest = _filename.substring(_filename
|
---|
| 363 | .lastIndexOf(File.separator) + 1);
|
---|
| 364 | if (!extTest.contains("."))
|
---|
| 365 | _filename += _format;
|
---|
| 366 | } else if (!_filename.contains("."))
|
---|
| 367 | _filename += _format;
|
---|
| 368 |
|
---|
| 369 | if (!_filename.contains(File.separator))
|
---|
[1274] | 370 | _filename = FrameIO.EXPORTS_PATH + _filename;
|
---|
[4] | 371 |
|
---|
| 372 | File test = new File(_filename);
|
---|
| 373 |
|
---|
[348] | 374 | File parent = test.getParentFile();
|
---|
| 375 | if (parent != null && !parent.exists()) {
|
---|
| 376 | parent.mkdirs();
|
---|
[4] | 377 | }
|
---|
| 378 |
|
---|
[348] | 379 | // Open an Output Stream Writer to set encoding
|
---|
| 380 | OutputStream fout = new FileOutputStream(_filename);
|
---|
| 381 | OutputStream bout = new BufferedOutputStream(fout);
|
---|
| 382 | Writer out = new OutputStreamWriter(bout, "UTF-8");
|
---|
| 383 |
|
---|
| 384 | _writer = new ProxyWriter(out);
|
---|
[4] | 385 | _output = _filename;
|
---|
| 386 | }
|
---|
| 387 | }
|
---|
| 388 |
|
---|
[286] | 389 | protected String getFileName(Frame start) {
|
---|
| 390 | return getValidFilename(start.getTitle());
|
---|
| 391 | }
|
---|
| 392 |
|
---|
[226] | 393 | public static String getValidFilename(String filename) {
|
---|
[80] | 394 | return filename.replaceAll("[ \\.]", "_");
|
---|
| 395 | }
|
---|
| 396 |
|
---|
[4] | 397 | protected String finalise() throws IOException {
|
---|
| 398 | try {
|
---|
| 399 | _writer.flush();
|
---|
| 400 | _writer.close();
|
---|
| 401 | } catch (IOException ioe) {
|
---|
| 402 | } finally {
|
---|
| 403 | _writer.close();
|
---|
| 404 | }
|
---|
[1102] | 405 | String errorMessage = EcosystemManager.getMiscManager().open(_output);
|
---|
| 406 | if (errorMessage != null) System.err.println(errorMessage);
|
---|
[4] | 407 | return " exported to " + _output;
|
---|
| 408 | }
|
---|
| 409 |
|
---|
| 410 | protected String finaliseFrame() throws IOException {
|
---|
| 411 | return "Frame" + finalise();
|
---|
| 412 | }
|
---|
| 413 |
|
---|
| 414 | protected void outputFrame(Frame toWrite) throws IOException {
|
---|
| 415 | writeStartFrame(toWrite);
|
---|
| 416 |
|
---|
[286] | 417 | Collection<Item> done = new HashSet<Item>();
|
---|
| 418 |
|
---|
[226] | 419 | for (Item i : getItemsToWrite(toWrite)) {
|
---|
[286] | 420 | if (_stop) {
|
---|
[4] | 421 | return;
|
---|
[284] | 422 | }
|
---|
[286] | 423 |
|
---|
| 424 | if (i instanceof Line) {
|
---|
| 425 | if (done.contains(i)) {
|
---|
| 426 | continue;
|
---|
| 427 | }
|
---|
| 428 | done.addAll(i.getAllConnected());
|
---|
| 429 | }
|
---|
[4] | 430 | writeItem(i);
|
---|
| 431 | }
|
---|
| 432 | writeEndFrame(toWrite);
|
---|
| 433 | }
|
---|
[286] | 434 |
|
---|
[226] | 435 | protected Collection<Item> getItemsToWrite(Frame toWrite) {
|
---|
| 436 | return toWrite.getItemsToSave();
|
---|
| 437 | }
|
---|
[4] | 438 |
|
---|
| 439 | public boolean isRunning() {
|
---|
| 440 | return _running;
|
---|
| 441 | }
|
---|
| 442 |
|
---|
| 443 | public void stop() {
|
---|
| 444 | _stop = true;
|
---|
| 445 | }
|
---|
| 446 |
|
---|
| 447 | public String getFileContents() {
|
---|
| 448 | return "Not Supported";
|
---|
| 449 | }
|
---|
[1418] | 450 |
|
---|
| 451 | public static LinkedHashMap<String, Method> getItemTags() {
|
---|
| 452 | return _ItemTags;
|
---|
| 453 | }
|
---|
[67] | 454 |
|
---|
[1408] | 455 | /**
|
---|
| 456 | * @return the _ItemTags
|
---|
| 457 | */
|
---|
[1418] | 458 | public static LinkedHashMap<Character, Method> getItemCharTags() {
|
---|
| 459 | return _ItemCharTags;
|
---|
[1408] | 460 | }
|
---|
| 461 |
|
---|
| 462 | /**
|
---|
| 463 | * @return the _ItemTagsExt
|
---|
| 464 | */
|
---|
[1418] | 465 | public static LinkedHashMap<String, Method> getItemStrTags() {
|
---|
| 466 | return _ItemStrTags;
|
---|
[1408] | 467 | }
|
---|
| 468 |
|
---|
[4] | 469 | }
|
---|