Changeset 689
- Timestamp:
- 01/13/14 17:01:03 (10 years ago)
- Location:
- trunk/src/org/expeditee
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/actions/Misc.java
r668 r689 37 37 import org.expeditee.gui.FreeItems; 38 38 import org.expeditee.gui.MessageBay; 39 import org.expeditee.gui.MessageBay.Progress; 39 40 import org.expeditee.gui.Reminders; 40 41 import org.expeditee.gui.TimeKeeper; … … 1576 1577 FrameIO.SaveFrame(frame); 1577 1578 } 1579 1580 public static void testProgress() { 1581 new Thread(new Runnable() { 1582 1583 @Override 1584 public void run() { 1585 Progress p = MessageBay.displayProgress("Loading something"); 1586 for(int i = 1; i <= 100; i++) { 1587 try { 1588 Thread.sleep(100); 1589 p.set(i); 1590 } catch (Exception e) { 1591 e.printStackTrace(); 1592 } 1593 } 1594 } 1595 1596 }).start(); 1597 } 1578 1598 } -
trunk/src/org/expeditee/gui/FrameIO.java
r655 r689 139 139 // do not display errors encountered to the user 140 140 // (they will be shown at load time) 141 MessageBay.sup ressMessages(true);141 MessageBay.suppressMessages(true); 142 142 // loading automatically caches the frame is caching is turned on 143 143 LoadFromDisk(framename, null, false); 144 MessageBay.sup ressMessages(false);144 MessageBay.suppressMessages(false); 145 145 } 146 146 -
trunk/src/org/expeditee/gui/MessageBay.java
r678 r689 36 36 37 37 // messages shown in the message window 38 private static Text[] _messages = new Text[3];38 private static List<Item> _messages = new LinkedList<Item>(); 39 39 private static Text _status = null; 40 40 … … 52 52 53 53 // if true, error messages are not shown to the user 54 private static boolean _sup ressMessages = false;54 private static boolean _suppressMessages = false; 55 55 56 56 // The link to the message frameset … … 73 73 _messageBuffer = null; 74 74 75 for (int i = 0; i < _messages.length; i++) { 76 if (_messages[i] != null) { 77 _messages[i].setOffset(0, 78 -FrameGraphics.getMaxFrameSize().height); 79 // _messages[i].setMaxWidth(FrameGraphics.getMaxFrameSize().width); 75 for(Item i : _messages) { 76 if(i != null) { 77 i.setOffset(0, -FrameGraphics.getMaxFrameSize().height); 78 // i.setMaxWidth(FrameGraphics.getMaxFrameSize().width); 80 79 } 81 80 } … … 94 93 */ 95 94 public static boolean isMessageItem(Item i) { 96 if (_messages != null) { 97 for (Text txt : _messages) { 98 if (txt == i) 99 return true; 100 } 101 } 102 103 return i == _messageLink; 95 96 return _messages.contains(i) || i == _messageLink; 104 97 } 105 98 … … 118 111 } 119 112 120 public synchronized static Text[]getMessages() {113 public synchronized static List<Item> getMessages() { 121 114 return _messages; 122 115 } … … 184 177 Graphics g, Color background) { 185 178 179 if(g == null) 180 return; 181 186 182 if (FrameGraphics.getMaxSize().width <= 0) 187 183 return; … … 217 213 // g.setClip(clip); 218 214 219 g.drawImage(_messageBuffer, 0, 220 FrameGraphics.getMaxFrameSize().height, null); 215 g.drawImage(_messageBuffer, 0, FrameGraphics.getMaxFrameSize().height, null); 221 216 } 222 217 … … 270 265 return displayMessage(message, link, actions, color, displayAlways); 271 266 } 272 273 public synchronized static Text displayMessage(String message, String link, 274 List<String> actions, Color color, boolean displayAlways) { 275 267 268 private static Text newMessage(String message, String link, List<String> actions, Color color) { 269 Text t = new Text(getMessagePrefix(true) + message); 270 t.setPosition(20, 15 + _messages.size() * 25); 271 t.setOffset(0, -FrameGraphics.getMaxFrameSize().height); 272 t.setColor(color); 273 t.setLink(link); 274 t.setActions(actions); 275 t.setFont(_messageFont); 276 _creator.addItem(t.copy(), true); 277 if(link == null) t.setLink(_creator.getCurrent()); 278 return t; 279 } 280 281 private synchronized static Text displayMessage(String message, String link, 282 List<String> actions, Color color, boolean displayAlways, boolean redraw) { 276 283 System.out.println(message); 277 284 assert (message != null); … … 280 287 invalidateFullBay(); 281 288 282 if (_sup ressMessages)289 if (_suppressMessages) 283 290 return null; 284 291 … … 297 304 updateLink(); 298 305 299 // if the message slots have not all been used yet 300 if (_messageCount <= _messages.length) { 301 int pos = 15; 302 // find the next empty slot, and create the new message 303 for (int i = 0; i < _messages.length; i++) { 304 if (_messages[i] == null) { 305 _messages[i] = new Text(getMessagePrefix(true) + message); 306 _messages[i].setPosition(20, pos); 307 _messages[i].setOffset(0, 308 -FrameGraphics.getMaxFrameSize().height); 309 // _messages[i].setMaxWidth(FrameGraphics.getMaxFrameSize().width); 310 _messages[i].setColor(color); 311 _messages[i].setLink(link); 312 _messages[i].setActions(actions); 313 _messages[i].setFont(_messageFont); 314 _creator.addItem(_messages[i].copy(), true); 315 _messageLink.setLink(_creator.getCurrent()); 316 317 Graphics g = FrameGraphics.createGraphics(); 318 if (g != null) { 319 refresh(false, g, Item.DEFAULT_BACKGROUND); 320 } 321 return _messages[i]; 322 } 323 324 pos += 25; 306 if(_messages.size() >= 3) { 307 _messages.remove(0); 308 for(Item i : _messages) { 309 i.setY(i.getY() - 25); 325 310 } 326 311 } 327 328 // if we have not returned then all message slots are used 329 for (int i = 0; i < _messages.length - 1; i++) { 330 _messages[i].setText(_messages[i + 1].getFirstLine()); 331 _messages[i].setColor(_messages[i + 1].getColor()); 332 _messages[i].setLink(_messages[i + 1].getLink()); 333 _messages[i].setActions(_messages[i + 1].getAction()); 334 } 335 336 // show the new message 337 Text last = _messages[_messages.length - 1]; 338 last.setColor(color); 339 // Set the text for the new message 340 last.setText(getMessagePrefix(true) + message); 341 last.setLink(link); 342 last.setActions(actions); 343 344 _creator.addItem(last.copy(), true); 312 313 Text t = newMessage(message, link, actions, color); 314 315 _messages.add(t); 316 345 317 // update the link to the latest message frame 346 318 _messageLink.setLink(_creator.getCurrent()); 347 319 320 if(redraw) { 321 Graphics g = FrameGraphics.createGraphics(); 322 if (g != null) { 323 refresh(false, g, Item.DEFAULT_BACKGROUND); 324 } 325 } 326 327 return t; 328 } 329 330 public synchronized static Text displayMessage(String message, String link, 331 List<String> actions, Color color, boolean displayAlways) { 332 return displayMessage(message, link, actions, color, displayAlways, true); 333 } 334 335 public synchronized static void overwriteMessage(String message) { 336 overwriteMessage(message, null); 337 } 338 339 public synchronized static void overwriteMessage(String message, Color color) { 340 _messages.remove(_messages.size()); 341 Text t = newMessage(message, null, null, color); 342 _messages.add(t); 348 343 Graphics g = FrameGraphics.createGraphics(); 349 344 if (g != null) { 350 345 refresh(false, g, Item.DEFAULT_BACKGROUND); 351 346 } 352 353 return last; 354 } 355 356 public synchronized static void overwriteMessage(String message) { 357 overwriteMessage(message, null); 358 } 359 360 public synchronized static void overwriteMessage(String message, Color color) { 361 for (int ind = _messages.length - 1; ind >= 0; ind--) { 362 if (_messages[ind] != null) { 363 _messages[ind].setColor(color); 364 _messages[ind].setText(getMessagePrefix(false) + message); 365 refresh(false, FrameGraphics.createGraphics(), 366 Item.DEFAULT_BACKGROUND); 367 return; 368 } 369 } 370 371 // if we have not returned, then there are no messages yet 372 displayMessage(message, Color.darkGray); 347 } 348 349 private static String getMessagePrefix(int counter) { 350 return "@" + counter + ": "; 373 351 } 374 352 … … 376 354 if (incrementCounter) 377 355 _messageCount++; 378 return "@" + _messageCount + ": ";356 return getMessagePrefix(_messageCount); 379 357 } 380 358 … … 387 365 */ 388 366 public synchronized static Text linkedErrorMessage(String message) { 389 if (_sup ressMessages)367 if (_suppressMessages) 390 368 return null; 391 369 Misc.beep(); … … 398 376 399 377 public synchronized static Text errorMessage(String message) { 400 if (_sup ressMessages)378 if (_suppressMessages) 401 379 return null; 402 380 Misc.beep(); … … 446 424 } 447 425 448 public synchronized static void sup ressMessages(boolean val) {449 _sup ressMessages = val;426 public synchronized static void suppressMessages(boolean val) { 427 _suppressMessages = val; 450 428 } 451 429 … … 465 443 } 466 444 } 445 446 public static final class Progress { 447 448 private static final String t = "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓"; 449 private static final String f = "░░░░░░░░░░░░░░░░░░░░"; 450 451 String message; 452 Text text; 453 454 protected Progress(String text) { 455 this.text = displayMessage(text, null, null, Color.BLACK, true, false); 456 //this.text.setFont(Font.decode(Text.MONOSPACED_FONT + "-16")); 457 this.message = this.text.getText(); 458 this.text.setText(this.message + " [" + f + "] 0%"); 459 refresh(false, FrameGraphics.createGraphics(), Item.DEFAULT_BACKGROUND); 460 } 461 462 /** 463 * 464 * @param progress progress value from 0 to 100 465 * @return true if the progress was updated, false if the progress was off the screen 466 * @throws Exception if progress out of bounds 467 */ 468 public boolean set(int progress) throws Exception { 469 if(progress < 0 || progress > 100) throw new Exception("Progress value out of bounds"); 470 int p = progress / 5; 471 if(isMessageItem(this.text)) { 472 this.text.setText(this.message + " [" + t.substring(0, p) + f.substring(p) + "] " + progress + "%"); 473 refresh(false, FrameGraphics.createGraphics(), Item.DEFAULT_BACKGROUND); 474 return true; 475 } 476 return false; 477 } 478 } 479 480 public synchronized static Progress displayProgress(String message) { 481 return new Progress(message); 482 } 467 483 468 484 }
Note:
See TracChangeset
for help on using the changeset viewer.