Changeset 374
- Timestamp:
- 10/26/08 17:03:51 (16 years ago)
- Location:
- trunk/src/org/expeditee/items/widgets
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/widgets/HeavyDutyInteractiveWidget.java
r314 r374 4 4 import java.awt.Font; 5 5 import java.awt.FontMetrics; 6 import java.awt.GradientPaint; 6 7 import java.awt.Graphics; 7 8 import java.awt.Graphics2D; … … 71 72 private static final String PENDING_MESSAGE = "Pending"; 72 73 74 private static final Color LOAD_BAR_PROGRESS_COLOR = new Color(103, 171, 203); 75 private static final Color LOAD_BAR_INDETERM_COLOR = Color.ORANGE; 76 private static final Color LOAD_BAR_HIGHLIGHT_COLOR = new Color(240, 240, 240); 73 77 private static final Color LOAD_SCREEN_COLOR = Color.LIGHT_GRAY; 74 78 private static final Color LOAD_SCREEN_COLOR_FREESPACE = FREESPACE_BACKCOLOR; … … 81 85 82 86 /** Unifies state transitions to a single thread. */ 83 private LoadStateManager stateProccessor = null;84 private LinkedList<HDW Task> queuedTasks = new LinkedList<HDWTask>();87 private HDWEventDispatcher eventDispatcher = null; 88 private LinkedList<HDWEvent> queuedEvents = new LinkedList<HDWEvent>(); 85 89 86 90 // Model data … … 165 169 166 170 else if (!isInLoadProgress() || 167 stateProccessor == null ||168 ! stateProccessor.isAlive())171 eventDispatcher == null || 172 !eventDispatcher.isAlive()) 169 173 throw new IllegalStateException("Load is not in progress"); 170 174 171 // Assuming that this is called from stateProccessor.172 stateProccessor.setLoadState(percent, false);175 // Assuming that this is called from eventDispatcher. 176 eventDispatcher.setLoadState(percent, false); 173 177 } 174 178 … … 277 281 if (loadState < 0.0f) { // indeterminant 278 282 279 g.setColor(Color.ORANGE); 283 GradientPaint gp = new GradientPaint( 284 0, barY + (int)(BAR_HEIGHT * 0.8), LOAD_BAR_INDETERM_COLOR, 285 0, barY, LOAD_BAR_HIGHLIGHT_COLOR); 286 ((Graphics2D)g).setPaint(gp); 287 280 288 g.fillRect(barX, barY, barWidth, BAR_HEIGHT); 281 289 … … 284 292 int progBarWidth = (int)(barWidth * loadState); 285 293 286 g.setColor(new Color(200, 200, 255)); 294 GradientPaint gp = new GradientPaint( 295 0, barY + (int)(BAR_HEIGHT * 0.8), LOAD_BAR_PROGRESS_COLOR, 296 0, barY, LOAD_BAR_HIGHLIGHT_COLOR); 297 ((Graphics2D)g).setPaint(gp); 298 287 299 g.fillRect(barX, barY, progBarWidth, BAR_HEIGHT); 288 300 … … 313 325 314 326 try { 315 doTaskAndWait(HDWTask.Load);327 runEventAndWait(HDWEvent.Load); 316 328 } catch (InterruptedException e) { 317 329 loadState = LOAD_STATE_INCOMPLETED; // safety … … 348 360 return this.loadState == LOAD_STATE_COMPLETED; 349 361 } 350 351 352 353 /* @Override354 public final InteractiveWidget deletedCopy() throws InteractiveWidgetNotAvailableException, InteractiveWidgetInitialisationFailedException {355 356 queueTask(HDWTask.UnloadTMP);357 358 359 }*/360 362 361 363 /** … … 366 368 super.onDelete(); 367 369 // Evenetually - unload the data - with the intention of possible recovery, but not saving... 368 queue Task(HDWTask.UnloadTMP);370 queueEvent(HDWEvent.UnloadTMP); 369 371 } 370 372 … … 387 389 * <li>LOAD_STATE_INCOMPLETED 388 390 * </ul> 389 * If not, then LOAD_STATE_ COMPLETED is assumed - butan exception trace will be printed.391 * If not, then LOAD_STATE_FAILED is assumed - and an exception trace will be printed. 390 392 */ 391 393 protected abstract float loadWidgetData(); … … 471 473 public final void performSave() { 472 474 try { 473 doTaskAndWait(HDWTask.Save);475 runEventAndWait(HDWEvent.Save); 474 476 } catch (InterruptedException e) { 475 477 e.printStackTrace(); … … 491 493 */ 492 494 void expire() { 493 doTaskLater(HDWTask.Unload);495 runEventLater(HDWEvent.Unload); 494 496 } 495 497 … … 537 539 } 538 540 539 private synchronized void doTaskAndWait(HDWTask task) throws InterruptedException {540 queue Task(task);541 stateProccessor.join();542 } 543 544 private void doTaskLater(HDWTask task) {545 queue Task(task);546 } 547 548 private void queue Task(HDWTask task) {549 550 synchronized(queued Tasks) {551 552 if (!queued Tasks.contains(task))553 queued Tasks.add(task);554 555 556 if ( stateProccessor == null || !stateProccessor.isAlive()) {557 stateProccessor = new LoadStateManager();558 stateProccessor.start();541 private synchronized void runEventAndWait(HDWEvent event) throws InterruptedException { 542 queueEvent(event); 543 eventDispatcher.join(); 544 } 545 546 private void runEventLater(HDWEvent event) { 547 queueEvent(event); 548 } 549 550 private void queueEvent(HDWEvent event) { 551 552 synchronized(queuedEvents) { 553 554 if (!queuedEvents.contains(event)) 555 queuedEvents.add(event); 556 557 558 if (eventDispatcher == null || !eventDispatcher.isAlive()) { 559 eventDispatcher = new HDWEventDispatcher(); 560 eventDispatcher.start(); 559 561 } 560 562 … … 571 573 * 572 574 */ 573 private class LoadStateManager extends Thread {575 private class HDWEventDispatcher extends Thread { 574 576 575 577 /** … … 630 632 while (true) { // keep proccessing tasks 631 633 632 HDW Task task= null;633 634 synchronized(queued Tasks) {635 if (queued Tasks.isEmpty()) return;636 task = queuedTasks.remove();634 HDWEvent event = null; 635 636 synchronized(queuedEvents) { 637 if (queuedEvents.isEmpty()) return; 638 event = queuedEvents.remove(); 637 639 } 638 640 639 if ( task == HDWTask.Load) {641 if (event == HDWEvent.Load) { 640 642 doLoad(); 641 } else if ( task == HDWTask.Save) {643 } else if (event == HDWEvent.Save) { 642 644 doSave(); // does not change state 643 } else if ( task == HDWTask.Unload){645 } else if (event == HDWEvent.Unload){ 644 646 doUnload(); 645 647 } else { 646 assert( task == HDWTask.UnloadTMP);648 assert(event == HDWEvent.UnloadTMP); 647 649 doTempUnload(); 648 650 } … … 655 657 656 658 // Check that not already loaded. 657 if (loadState == LOAD_STATE_COMPLETED || 658 loadState == LOAD_STATE_FAILED) return; 659 // if (loadState == LOAD_STATE_COMPLETED || 660 // loadState == LOAD_STATE_FAILED) return; 661 if (loadState == LOAD_STATE_COMPLETED) return; 659 662 660 663 // Only load if in view … … 685 688 } catch (Exception e) { 686 689 e.printStackTrace(); 687 finalState = LOAD_STATE_ COMPLETED;690 finalState = LOAD_STATE_FAILED; 688 691 } 689 692 … … 724 727 } 725 728 726 private enum HDW Task{729 private enum HDWEvent { 727 730 Save, 728 731 Load, -
trunk/src/org/expeditee/items/widgets/InteractiveWidget.java
r352 r374 923 923 // Because widgets are comprised of four corners - they all report this 924 924 // event one after the 925 // other. So must filter out redun ant notifications like so:925 // other. So must filter out redundant notifications like so: 926 926 if (_lastParentStateChangedEvent != null 927 927 && _lastParentStateChangedEvent.getEventType() == e … … 934 934 _lastParentStateChangedMouseEvent = MouseEventRouter 935 935 .getCurrentMouseEvent(); 936 936 937 937 switch (e.getEventType()) { 938 938 … … 995 995 || e.getEventType() == ItemParentStateChangedEvent.EVENT_TYPE_SHOWN_VIA_OVERLAY 996 996 || e.getSource() == DisplayIO.getCurrentFrame()) { 997 997 998 998 onBoundsChanged(); 999 999 Browser._theBrowser.getContentPane().add(_swingComponent); -
trunk/src/org/expeditee/items/widgets/SampledHDWidget1.java
r230 r374 59 59 // fail some of them 60 60 if ((rand.nextInt() % 4) == 0) { 61 setLoadScreenMessage("Failed ");61 setLoadScreenMessage("Failed to load metadata"); 62 62 return LOAD_STATE_FAILED; 63 63 }
Note:
See TracChangeset
for help on using the changeset viewer.