Changeset 1102 for trunk/src/org/expeditee/gui/MessageBay.java
- Timestamp:
- 05/10/18 16:04:51 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/gui/MessageBay.java
r929 r1102 19 19 package org.expeditee.gui; 20 20 21 import java.awt.Color;22 import java.awt.Font;23 import java.awt.Graphics;24 import java.awt.Graphics2D;25 import java.awt.GraphicsEnvironment;26 import java.awt.Rectangle;27 import java.awt.RenderingHints;28 import java.awt.geom.Area;29 import java.awt.image.VolatileImage;30 21 import java.util.LinkedList; 31 22 import java.util.List; 32 23 24 import org.expeditee.Util; 33 25 import org.expeditee.actions.Misc; 26 import org.expeditee.core.Clip; 27 import org.expeditee.core.Colour; 28 import org.expeditee.core.Dimension; 29 import org.expeditee.core.Font; 30 import org.expeditee.core.Image; 31 import org.expeditee.gio.EcosystemManager; 32 import org.expeditee.gio.GraphicsManager; 34 33 import org.expeditee.items.Item; 35 34 import org.expeditee.items.Text; 36 35 37 36 /** 38 * The bay at the bottom of the expeditee browser which displays messages. TODO 39 * make it thread safe! 40 * 37 * The bay at the bottom of the expeditee browser which displays messages. 38 * TODO: Make it thread safe! 41 39 */ 42 40 public final class MessageBay { 43 41 44 45 public static final int MESSAGE_BUFFER_HEIGHT = 105; 46 42 /** The distance from the top of the message bay to the Message frame link. */ 47 43 private static final int MESSAGE_LINK_Y_OFFSET = 100; 48 44 45 /** TODO: Comment. cts16 */ 49 46 private static final int MESSAGE_LINK_X = 50; 50 47 51 public static final Color ERROR_COLOR = Color.red; 52 48 /** TODO: Comment. cts16 */ 49 public static final Colour ERROR_COLOR = Colour.RED; 50 51 /** TODO: Comment. cts16 */ 53 52 public static final String MESSAGES_FRAMESET_NAME = "Messages"; 54 53 55 / / messages shown in the message window54 /** The list of messages shown in the message bay. */ 56 55 private static List<Item> _messages = new LinkedList<Item>(); 56 57 /** Messages which were delayed because they couldn't be shown at time of creation. */ 58 private static List<DelayedMessage> _delayedMessages = new LinkedList<DelayedMessage>(); 59 60 /** TODO: Comment. cts16 */ 57 61 private static Text _status = null; 58 62 59 / / buffer of the message window60 private static VolatileImage _messageBuffer = null;61 62 / / creator for creating the message frames63 /** Buffer image of the message window. */ 64 private static Image _messageBuffer = null; 65 66 /** Creator for creating the message frames. */ 63 67 private static FrameCreator _creator = null; 64 68 65 / / font used for the messages66 private static Font _messageFont = Font.decode("Serif-Plain-16");67 68 / / the number of messages currently shown (used for scrolling up)69 /** Font used for the messages. */ 70 private static Font _messageFont = new Font("Serif-Plain-16"); 71 72 /** The number of messages currently shown (used for scrolling up). */ 69 73 private static int _messageCount = 0; 70 74 71 / / if true, error messages are not shown to the user75 /** If true, error messages are not shown to the user. */ 72 76 private static boolean _suppressMessages = false; 73 77 74 // The link to the message frameset 75 private static Item _messageLink = new Text(-2, "@" 76 + MESSAGES_FRAMESET_NAME, Color.black, Color.white); 77 78 private static List<Rectangle> _dirtyAreas = new LinkedList<Rectangle>(); 79 78 /** The link to the message frameset. */ 79 private static Item _messageLink = new Text(-2, "@" + MESSAGES_FRAMESET_NAME, Colour.BLACK, Colour.WHITE); 80 81 /** TODO: Comment. cts16 */ 80 82 private static String _lastMessage = null; 81 83 82 private MessageBay() { 83 } 84 85 /** 86 * Syncs messsage bay size according to FrameGraphics max size. 87 * 88 */ 89 static void updateSize() { 90 91 _messageBuffer = null; 92 84 /** TODO: Comment. cts16 */ 85 private static boolean isLinkInitialized = false; 86 87 /** Static-only class. */ 88 private MessageBay() 89 { 90 } 91 92 /** Whether the message bay is ready to display messages. */ 93 public static boolean isReady() 94 { 95 return Browser.isInitComplete(); 96 } 97 98 /** Syncs message bay size according to FrameGraphics max size. */ 99 static void updateSize() 100 { 93 101 for(Item i : _messages) { 94 102 if(i != null) { 95 i.setOffset(0, -FrameGraphics.getMaxFrameSize().height); 96 // i.setMaxWidth(FrameGraphics.getMaxFrameSize().width); 103 i.setOffset(0, -DisplayController.getMessageBayPaintArea().getMinY()); 97 104 } 98 105 } 99 106 100 _messageLink.setOffset(0, -FrameGraphics.getMaxFrameSize().height); 101 // _messageLink.setMaxWidth(FrameGraphics.getMaxFrameSize().width); 102 // _messageLink.setPosition(FrameGraphics.getMaxFrameSize().width 103 // - MESSAGE_LINK_Y_OFFSET, MESSAGE_LINK_X); 107 _messageLink.setOffset(0, -DisplayController.getMessageBayPaintArea().getMinY()); 108 104 109 updateLink(); 105 initBuffer(); 106 } 107 108 /** 109 * @param i 110 * @return True if i is an item in the message bay 111 */ 112 public static boolean isMessageItem(Item i) { 113 114 return _messages.contains(i) || i == _messageLink; 115 } 116 117 public synchronized static void addDirtyArea(Rectangle r) { 118 _dirtyAreas.add(r); 119 } 120 121 static synchronized int getMessageBufferHeight() { 122 if (_messageBuffer != null) 123 return _messageBuffer.getHeight(); 124 return 0; 125 } 126 127 public synchronized static Item getMessageLink() { 110 } 111 112 /** Whether the given item is an item in the message bay. */ 113 public static boolean isMessageItem(Item i) 114 { 115 return _messages.contains(i) || i == _messageLink || i == _status; 116 } 117 118 /** TODO: Comment. cts16 */ 119 public synchronized static Item getMessageLink() 120 { 128 121 return _messageLink; 129 122 } 130 123 131 public synchronized static List<Item> getMessages() { 124 /** TODO: Comment. cts16 */ 125 public synchronized static List<Item> getMessages() 126 { 132 127 return _messages; 133 128 } 134 129 135 public synchronized static boolean isDirty() { 136 return !_dirtyAreas.isEmpty(); 137 } 138 139 public synchronized static void invalidateFullBay() { 140 if (_messageBuffer != null) { 141 _dirtyAreas.clear(); 142 addDirtyArea(new Rectangle(0, 143 FrameGraphics.getMaxFrameSize().height, _messageBuffer 144 .getWidth(), _messageBuffer.getHeight())); 145 } 146 } 147 148 private synchronized static boolean initBuffer() { 149 if (_messageBuffer == null) { 150 if (FrameGraphics.isAudienceMode() 151 || FrameGraphics.getMaxSize().width <= 0) 152 return false; 153 154 GraphicsEnvironment ge = GraphicsEnvironment 155 .getLocalGraphicsEnvironment(); 156 _messageBuffer = ge.getDefaultScreenDevice() 157 .getDefaultConfiguration().createCompatibleVolatileImage( 158 FrameGraphics.getMaxSize().width, 159 MESSAGE_BUFFER_HEIGHT); 160 } 161 return true; 162 } 163 164 private static boolean isLinkInitialized = false; 165 166 private static void updateLink() { 167 168 if (!isLinkInitialized && FrameGraphics.getMaxSize().width > 0) { 130 /** Causes the entire message bay area to be invalidated. */ 131 public synchronized static void invalidateFullBay() 132 { 133 DisplayController.invalidateArea(DisplayController.getMessageBayPaintArea()); 134 } 135 136 /** TODO: Comment. cts16 */ 137 private static void updateLink() 138 { 139 if (!isLinkInitialized && DisplayController.getFramePaintArea().getWidth() > 0) { 169 140 // set up 'Messages' link on the right hand side 170 _messageLink.setPosition(FrameGraphics.getMaxSize().width 171 - MESSAGE_LINK_Y_OFFSET, MESSAGE_LINK_X); 172 _messageLink.setOffset(0, -FrameGraphics.getMaxFrameSize().height); 141 _messageLink.setPosition(DisplayController.getMessageBayPaintArea().getWidth() - MESSAGE_LINK_Y_OFFSET, MESSAGE_LINK_X); 142 _messageLink.setOffset(0, -DisplayController.getMessageBayPaintArea().getMinY()); 173 143 isLinkInitialized = true; 174 175 144 } else { 176 _messageLink.setPosition(FrameGraphics.getMaxSize().width 177 - MESSAGE_LINK_Y_OFFSET, MESSAGE_LINK_X); 178 } 179 } 180 181 /** 182 * Repaints the message bay. Updates the message bay buffer and draws to 183 * given graphics. 184 * 185 * @param useInvalidation 186 * Set to true of repinting dirty areas only. Otherwise false for 187 * full-repaint. 188 * 189 * @param g 190 * 191 * @param background 192 * The color of the message background 193 */ 194 public static synchronized void refresh(boolean useInvalidation, 195 Graphics g, Color background) { 196 197 if(g == null) 198 return; 199 200 if (FrameGraphics.getMaxSize().width <= 0) 201 return; 202 203 Area clip = null; 204 205 if (useInvalidation) { // build clip 206 207 if (!_dirtyAreas.isEmpty()) { 208 209 for (Rectangle r : _dirtyAreas) { 210 r.y = (r.y < 0) ? 0 : r.y; 211 r.x = (r.x < 0) ? 0 : r.x; 212 if (clip == null) 213 clip = new Area(r); 214 else 215 clip.add(new Area(r)); 145 _messageLink.setPosition(DisplayController.getMessageBayPaintArea().getWidth() - MESSAGE_LINK_Y_OFFSET, MESSAGE_LINK_X); 146 } 147 } 148 149 /** TODO: Comment. cts16 */ 150 public static Image getImage(Clip clip, Dimension size) 151 { 152 // Can't get an image with an invalid size 153 if (size == null || size.width <= 0 || size.height <= 0) return null; 154 155 // Update the buffer 156 updateBuffer(Item.DEFAULT_BACKGROUND, clip, size); 157 158 // Return the image buffer 159 return _messageBuffer; 160 } 161 162 /** Updates the image buffer to reflect the current state of the message bay. */ 163 private static void updateBuffer(Colour background, Clip clip, Dimension size) 164 { 165 // If the buffer doesn't exist or is the wrong size, recreate it 166 if (_messageBuffer == null || !_messageBuffer.getSize().equals(size)) { 167 _messageBuffer = Image.createImage(size, true); 168 clip = null; // Need to recreate the entire image; 169 updateSize(); 170 } 171 172 GraphicsManager g = EcosystemManager.getGraphicsManager(); 173 g.pushDrawingSurface(_messageBuffer); 174 175 if (clip != null) g.pushClip(clip); 176 g.setAntialiasing(true); 177 178 g.clear(background); 179 180 g.setFont(_messageFont); 181 182 for (Item message : _messages) { 183 if (message != null) { 184 if (clip == null || clip.isNotClipped() || message.isInDrawingArea(clip.getBounds())) { 185 FrameGraphics.PaintItem(message); 216 186 } 217 } else 218 return; // nothing to render 219 } 220 221 _dirtyAreas.clear(); 222 223 // Update the buffer 224 updateBuffer(background, clip); 225 226 // Now repaint to screen 227 if (!FrameGraphics.isAudienceMode()) { 228 229 // Translate clip to messagebox coords 230 // clip.transform(t) // TODO 231 // g.setClip(clip); 232 233 g.drawImage(_messageBuffer, 0, FrameGraphics.getMaxFrameSize().height, null); 234 } 235 236 } 237 238 private static void updateBuffer(Color background, Area clip) { 239 if (!initBuffer()) 240 return; 241 242 Graphics2D g = _messageBuffer.createGraphics(); 243 244 g.setClip(clip); 245 246 g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, 247 RenderingHints.VALUE_TEXT_ANTIALIAS_ON); 248 g.setColor(background); 249 g.fillRect(0, 0, FrameGraphics.getMaxSize().width, 250 MESSAGE_BUFFER_HEIGHT); 251 g.setFont(_messageFont); 252 g.setColor(Color.BLACK); 253 g.drawLine(0, 0, FrameGraphics.getMaxSize().width, 0); 254 255 for (Item t : _messages) { 256 if (t == null) 257 continue; 258 if (clip == null || t.isInDrawingArea(clip)) 259 FrameGraphics.PaintItem(g, t); 260 } 261 if(_status != null) 262 FrameGraphics.PaintItem(g, _status); 263 264 if (// _messageLink.getLink() != null 265 // && 266 (clip == null || _messageLink.isInDrawingArea(clip))) { 267 FrameGraphics.PaintItem(g, _messageLink); 268 } 269 g.dispose(); 270 271 } 272 273 private static Text displayMessage(String message, String link, 274 List<String> actions, Color color) { 187 } 188 } 189 190 if (_status != null) FrameGraphics.PaintItem(_status); 191 192 if (clip == null || clip.isNotClipped() || _messageLink.isInDrawingArea(clip.getBounds())) { 193 FrameGraphics.PaintItem(_messageLink); 194 } 195 196 g.popDrawingSurface(); 197 } 198 199 /** TODO: Comment. cts16 */ 200 private static Text displayMessage(String message, String link, List<String> actions, Colour color) 201 { 275 202 return displayMessage(message, link, actions, color, true); 276 203 } 277 204 278 public synchronized static Text displayMessage(String message, String link, Color color, 279 boolean displayAlways, String action) { 205 /** TODO: Comment. cts16 */ 206 public synchronized static Text displayMessage(String message, String link, Colour color, boolean displayAlways, String action) 207 { 280 208 List<String> actions = new LinkedList<String>(); 281 if (action != null) 282 actions.add(action); 209 if (action != null) actions.add(action); 283 210 return displayMessage(message, link, actions, color, displayAlways); 284 211 } 285 286 private static Text newMessage(String message, String link, List<String> actions, Color color) { 212 213 /** TODO: Comment. cts16 */ 214 private static Text newMessage(String message, String link, List<String> actions, Colour color) 215 { 287 216 Text t = new Text(getMessagePrefix(true) + message); 288 217 t.setPosition(20, 15 + _messages.size() * 25); 289 t.setOffset(0, - FrameGraphics.getMaxFrameSize().height);218 t.setOffset(0, -DisplayController.getFramePaintArea().getHeight()); 290 219 t.setColor(color); 291 220 t.setLink(link); … … 296 225 return t; 297 226 } 298 299 private synchronized static Text displayMessage(String message, String link, 300 List<String> actions, Color color, boolean displayAlways, boolean redraw) { 227 228 /** TODO: Comment. cts16 */ 229 private synchronized static Text displayMessage(String message, String link, List<String> actions, Colour color, boolean displayAlways, boolean redraw) 230 { 231 assert (message != null); 232 233 if (!isReady()) { 234 delayMessage(message, link, actions, color, displayAlways, redraw); 235 return null; 236 } 237 301 238 System.out.println(message); 302 assert (message != null);303 239 304 240 // Invalidate whole area 305 241 invalidateFullBay(); 306 242 307 if (_suppressMessages) 308 return null; 243 if (_suppressMessages) return null; 309 244 310 245 if (!displayAlways && message.equals(_lastMessage)) { … … 312 247 return null; 313 248 } 249 314 250 _lastMessage = message; 315 251 316 252 if (_creator == null) { 317 _creator = new FrameCreator(MESSAGES_FRAMESET_NAME, 318 FrameIO.MESSAGES_PATH, MESSAGES_FRAMESET_NAME, true, false); 253 _creator = new FrameCreator(MESSAGES_FRAMESET_NAME, FrameIO.MESSAGES_PATH, MESSAGES_FRAMESET_NAME, true, false); 319 254 } 320 255 … … 336 271 _messageLink.setLink(_creator.getCurrent()); 337 272 273 // TODO: Can we just make this DisplayController.requestRefresh()? cts16 338 274 if(redraw) { 339 Graphics g = FrameGraphics.createGraphics(); 340 if (g != null) { 341 refresh(false, g, Item.DEFAULT_BACKGROUND); 342 } 275 DisplayController.requestRefresh(true); 343 276 } 344 277 … … 346 279 } 347 280 348 public synchronized static Text displayMessage(String message, String link, 349 List<String> actions, Color color, boolean displayAlways) { 281 /** TODO: Comment. cts16 */ 282 public synchronized static Text displayMessage(String message, String link, List<String> actions, Colour color, boolean displayAlways) 283 { 350 284 return displayMessage(message, link, actions, color, displayAlways, true); 351 285 } 352 286 353 public synchronized static void overwriteMessage(String message) { 287 /** TODO: Comment. cts16 */ 288 public synchronized static void overwriteMessage(String message) 289 { 354 290 overwriteMessage(message, null); 355 291 } 356 292 357 public synchronized static void overwriteMessage(String message, Color color) { 293 /** TODO: Comment. cts16 */ 294 public synchronized static void overwriteMessage(String message, Colour color) 295 { 358 296 _messages.remove(_messages.size() - 1); 359 297 Text t = newMessage(message, null, null, color); 360 298 _messages.add(t); 361 Graphics g = FrameGraphics.createGraphics(); 362 if (g != null) { 363 refresh(false, g, Item.DEFAULT_BACKGROUND); 364 } 365 } 366 367 private static String getMessagePrefix(int counter) { 299 DisplayController.requestRefresh(true); 300 } 301 302 /** TODO: Comment. cts16 */ 303 private static String getMessagePrefix(int counter) 304 { 368 305 return "@" + counter + ": "; 369 306 } 370 307 371 private static String getMessagePrefix(boolean incrementCounter) { 372 if (incrementCounter) 373 _messageCount++; 308 /** TODO: Comment. cts16 */ 309 private static String getMessagePrefix(boolean incrementCounter) 310 { 311 if (incrementCounter) _messageCount++; 312 374 313 return getMessagePrefix(_messageCount); 375 314 } … … 382 321 * the message to be displayed 383 322 */ 384 public synchronized static Text linkedErrorMessage(String message) {385 if (_suppressMessages)386 323 public synchronized static Text linkedErrorMessage(String message) 324 { 325 if (_suppressMessages) return null; 387 326 Misc.beep(); 388 327 String[] tokens = message.split(Text.FRAME_NAME_SEPARATOR); 389 328 String link = null; 390 if (tokens.length > 1) 391 link = tokens[tokens.length - 1]; 329 if (tokens.length > 1) link = tokens[tokens.length - 1]; 392 330 return displayMessage(message, link, null, ERROR_COLOR); 393 331 } 394 332 395 public synchronized static Text errorMessage(String message) { 396 if (_suppressMessages) 397 return null; 333 /** TODO: Comment. cts16 */ 334 public synchronized static Text errorMessage(String message) 335 { 336 if (_suppressMessages) return null; 398 337 Misc.beep(); 399 338 return displayMessage(message, null, null, ERROR_COLOR, false); … … 407 346 * The message to display to the user in the message area 408 347 */ 409 public synchronized static Text displayMessage(String message) { 348 public synchronized static Text displayMessage(String message) 349 { 410 350 return displayMessageAlways(message); 411 351 } 412 352 413 public synchronized static Text displayMessageOnce(String message) { 414 return displayMessage(message, null, null, Color.BLACK, false); 415 } 416 417 public synchronized static Text displayMessage(String message, Color textColor) { 353 /** TODO: Comment. cts16 */ 354 public synchronized static Text displayMessageOnce(String message) 355 { 356 return displayMessage(message, null, null, Colour.BLACK, false); 357 } 358 359 /** TODO: Comment. cts16 */ 360 public synchronized static Text displayMessage(String message, Colour textColor) 361 { 418 362 return displayMessage(message, null, null, textColor); 419 // Misc.Beep(); 420 } 421 422 public synchronized static Text displayMessage(Text message) { 363 } 364 365 /** TODO: Comment. cts16 */ 366 public synchronized static Text displayMessage(Text message) 367 { 423 368 Text t = null; 424 369 String link = message.getLink(); 425 370 List<String> action = message.getAction(); 426 Colo r color = message.getColor();371 Colour color = message.getColor(); 427 372 for (String s : message.getTextList()) { 428 373 t = displayMessage(s, link, action, color); 429 374 } 430 375 return t; 376 } 377 378 /** TODO: Comment. cts16 */ 379 public synchronized static Text displayMessageAlways(String message) 380 { 381 return displayMessage(message, null, null, Colour.BLACK); 431 382 // Misc.Beep(); 432 383 } 433 384 434 public synchronized static Text displayMessageAlways(String message) { 435 return displayMessage(message, null, null, Color.BLACK); 436 // Misc.Beep(); 437 } 438 439 public synchronized static Text warningMessage(String message) { 440 return displayMessage(message, null, null, Color.MAGENTA); 441 // Misc.Beep(); 442 } 443 444 public synchronized static void suppressMessages(boolean val) { 385 /** TODO: Comment. cts16 */ 386 public synchronized static Text warningMessage(String message) 387 { 388 return displayMessage(message, null, null, Colour.MAGENTA); 389 } 390 391 /** TODO: Comment. cts16 */ 392 public synchronized static List<Text> warningMessages(List<String> messages) 393 { 394 if (messages == null) return null; 395 List<Text> ret = new LinkedList<Text>(); 396 for (String message : messages) ret.add(warningMessage(message)); 397 return ret; 398 } 399 400 /** TODO: Comment. cts16 */ 401 public synchronized static void suppressMessages(boolean val) 402 { 445 403 _suppressMessages = val; 446 404 } 447 448 public synchronized static void setStatus(String status) { 405 406 /** TODO: Comment. cts16 */ 407 public synchronized static void setStatus(String status) 408 { 449 409 if (_status == null) { 450 410 _status = new Text(status); 451 411 _status.setPosition(0, 85); 452 _status.setOffset(0, FrameGraphics.getMaxFrameSize().height);412 _status.setOffset(0, -DisplayController.getMessageBayPaintArea().getMinY()); 453 413 _status.setLink(null); // maybe link to a help frame? 454 _status.setFont( Font.decode(Text.MONOSPACED_FONT));414 _status.setFont(new Font(Text.MONOSPACED_FONT)); 455 415 } else { 456 416 _status.setText(status); 457 417 } 458 Graphics g = FrameGraphics.createGraphics(); 459 if (g != null) { 460 refresh(false, g, Item.DEFAULT_BACKGROUND); 461 } 462 } 463 464 public static final class Progress { 465 466 private static final String filled = "\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592"; 467 private static final String unfilled = "\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591"; 468 469 String message; 470 Text text; 471 472 protected Progress(String text) { 473 this.text = displayMessage(text, null, null, Color.GREEN.darker(), true, false); 474 //this.text.setFont(Font.decode(Text.MONOSPACED_FONT + "-16")); 475 this.message = this.text.getText(); 476 this.text.setText(this.message + " [" + unfilled + "] 0%"); 477 refresh(false, FrameGraphics.createGraphics(), Item.DEFAULT_BACKGROUND); 478 } 479 480 public void UpdateMessage(final String text, final int newProgress) throws Exception { 481 this.message = text; 418 419 //invalidateFullBay(); 420 DisplayController.requestRefresh(true); 421 } 422 423 /** TODO: Comment. cts16 */ 424 public static final class Progress 425 { 426 /** The colour progress bars should be displayed in. */ 427 private static final Colour BAR_COLOUR = Colour.GREEN.darker(); 428 429 /** The character used to assemble the uncompleted portions of the progress bar. */ 430 private static final char UNCOMPLETED_CHARACTER = '\u2591'; // ░ 431 /** The character used to assemble the completed portions of the progress bar. */ 432 private static final char COMPLETED_CHARACTER = '\u2592'; // ▒ 433 434 /** What the progress bar should look like when at 100% completion. */ 435 private static final String COMPLETED_BAR = Util.nCopiesOf(20, COMPLETED_CHARACTER); 436 /** What the progress bar should look like when at 0% completion. */ 437 private static final String UNCOMPLETED_BAR = Util.nCopiesOf(20, UNCOMPLETED_CHARACTER); 438 439 private String _message; 440 private Text _text; 441 442 protected Progress(String text) 443 { 444 this._text = displayMessage(text, null, null, BAR_COLOUR, true, false); 445 this._message = this._text.getText(); 446 this._text.setText(this._message + " [" + UNCOMPLETED_BAR + "] 0%"); 447 DisplayController.requestRefresh(true); 448 } 449 450 public void UpdateMessage(final String text, final int newProgress) throws Exception 451 { 452 this._message = text; 482 453 set(newProgress); 483 454 } 484 455 485 public String GetMessage() { 486 return message; 456 public String GetMessage() 457 { 458 return _message; 487 459 } 488 460 … … 493 465 * @throws Exception if progress out of bounds 494 466 */ 495 public boolean set(int progress) throws Exception { 467 public boolean set(int progress) throws Exception 468 { 496 469 if(progress < 0 || progress > 100) throw new Exception("Progress value out of bounds"); 497 470 int p = progress / 5; 498 if(isMessageItem(this. text)) {499 this. text.setText(this.message + " [" + filled.substring(0, p) + unfilled.substring(p) + "] " + progress + "%");500 refresh(false, FrameGraphics.createGraphics(), Item.DEFAULT_BACKGROUND);471 if(isMessageItem(this._text)) { 472 this._text.setText(this._message + " [" + COMPLETED_BAR.substring(0, p) + UNCOMPLETED_BAR.substring(p) + "] " + progress + "%"); 473 DisplayController.requestRefresh(true); 501 474 return true; 502 475 } … … 504 477 } 505 478 } 479 480 /** TODO: Comment. cts16 */ 481 public synchronized static Progress displayProgress(String message) 482 { 483 return new Progress(message); 484 } 506 485 507 public synchronized static Progress displayProgress(String message) { 508 return new Progress(message); 486 /** Remembers the arguments to a displayMessage call for later use. */ 487 private static class DelayedMessage { 488 489 private String _message; 490 private String _link; 491 private List<String> _actions; 492 private Colour _colour; 493 private boolean _displayAlways; 494 private boolean _redraw; 495 496 public DelayedMessage(String message, String link, List<String> actions, Colour color, boolean displayAlways, boolean redraw) 497 { 498 _message = message; 499 _link = link; 500 if (actions == null) { 501 _actions = null; 502 } else { 503 _actions = new LinkedList<String>(); 504 _actions.addAll(actions); 505 } 506 _colour = color == null ? null : color.clone(); 507 _displayAlways = displayAlways; 508 _redraw = redraw; 509 } 510 511 public void display() 512 { 513 displayMessage(_message, _link, _actions, _colour, _displayAlways, _redraw); 514 } 515 516 } 517 518 private static void delayMessage(String message, String link, List<String> actions, Colour color, boolean displayAlways, boolean redraw) 519 { 520 _delayedMessages.add(new DelayedMessage(message, link, actions, color, displayAlways, redraw)); 521 } 522 523 public static void showDelayedMessages() 524 { 525 if (isReady()) { 526 for (DelayedMessage message : _delayedMessages) message.display(); 527 _delayedMessages.clear(); 528 invalidateFullBay(); 529 DisplayController.requestRefresh(true); 530 } 509 531 } 510 532
Note:
See TracChangeset
for help on using the changeset viewer.