Changeset 374


Ignore:
Timestamp:
10/26/08 17:03:51 (16 years ago)
Author:
bjn8
Message:

Refactor names... minor improvements made during evaluation study

Location:
trunk/src/org/expeditee/items/widgets
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/items/widgets/HeavyDutyInteractiveWidget.java

    r314 r374  
    44import java.awt.Font;
    55import java.awt.FontMetrics;
     6import java.awt.GradientPaint;
    67import java.awt.Graphics;
    78import java.awt.Graphics2D;
     
    7172        private static final String PENDING_MESSAGE = "Pending";
    7273       
     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);
    7377        private static final Color LOAD_SCREEN_COLOR = Color.LIGHT_GRAY;
    7478        private static final Color LOAD_SCREEN_COLOR_FREESPACE = FREESPACE_BACKCOLOR;
     
    8185       
    8286        /** Unifies state transitions to a single thread. */
    83         private LoadStateManager stateProccessor = null;
    84         private LinkedList<HDWTask> queuedTasks = new LinkedList<HDWTask>();
     87        private HDWEventDispatcher eventDispatcher = null;
     88        private LinkedList<HDWEvent> queuedEvents = new LinkedList<HDWEvent>();
    8589       
    8690        // Model data
     
    165169               
    166170                else if (!isInLoadProgress() ||
    167                                 stateProccessor == null ||
    168                                 !stateProccessor.isAlive())
     171                                eventDispatcher == null ||
     172                                !eventDispatcher.isAlive())
    169173                        throw new IllegalStateException("Load is not in progress");
    170174               
    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);
    173177        }
    174178       
     
    277281                if (loadState < 0.0f) { // indeterminant
    278282
    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               
    280288                        g.fillRect(barX, barY, barWidth, BAR_HEIGHT);
    281289                       
     
    284292                        int progBarWidth = (int)(barWidth * loadState);
    285293                       
    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                       
    287299                        g.fillRect(barX, barY, progBarWidth, BAR_HEIGHT);
    288300                       
     
    313325               
    314326                try {
    315                         doTaskAndWait(HDWTask.Load);
     327                        runEventAndWait(HDWEvent.Load);
    316328                } catch (InterruptedException e) {
    317329                        loadState = LOAD_STATE_INCOMPLETED; // safety
     
    348360                return this.loadState == LOAD_STATE_COMPLETED;
    349361        }
    350        
    351        
    352 
    353 /*      @Override
    354         public final InteractiveWidget deletedCopy() throws InteractiveWidgetNotAvailableException, InteractiveWidgetInitialisationFailedException {
    355 
    356                 queueTask(HDWTask.UnloadTMP);
    357                
    358                
    359         }*/
    360362
    361363        /**
     
    366368                super.onDelete();
    367369                // Evenetually - unload the data - with the intention of possible recovery, but not saving...
    368                 queueTask(HDWTask.UnloadTMP);
     370                queueEvent(HDWEvent.UnloadTMP);
    369371        }
    370372
     
    387389         *                      <li>LOAD_STATE_INCOMPLETED
    388390         *              </ul>
    389          *              If not, then LOAD_STATE_COMPLETED is assumed - but an exception trace will be printed.
     391         *              If not, then LOAD_STATE_FAILED is assumed - and an exception trace will be printed.
    390392         */
    391393        protected abstract float loadWidgetData();
     
    471473        public final void performSave() {
    472474                try {
    473                         doTaskAndWait(HDWTask.Save);
     475                        runEventAndWait(HDWEvent.Save);
    474476                } catch (InterruptedException e) {
    475477                        e.printStackTrace();
     
    491493         */
    492494        void expire() {
    493                 doTaskLater(HDWTask.Unload);
     495                runEventLater(HDWEvent.Unload);
    494496        }
    495497       
     
    537539        }
    538540
    539         private synchronized void doTaskAndWait(HDWTask task) throws InterruptedException {
    540                 queueTask(task);
    541                 stateProccessor.join();
    542         }
    543        
    544         private void doTaskLater(HDWTask task) {
    545                 queueTask(task);
    546         }
    547        
    548         private void queueTask(HDWTask task) {
    549                
    550                 synchronized(queuedTasks) {
    551                        
    552                         if (!queuedTasks.contains(task))
    553                                 queuedTasks.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();
    559561                        }
    560562               
     
    571573         *
    572574         */
    573         private class LoadStateManager extends Thread {
     575        private class HDWEventDispatcher extends Thread {
    574576               
    575577                /**
     
    630632                        while (true) { // keep proccessing tasks
    631633                               
    632                                 HDWTask task = null;
    633 
    634                                 synchronized(queuedTasks) {
    635                                         if (queuedTasks.isEmpty()) return;
    636                                         task = queuedTasks.remove();
     634                                HDWEvent event = null;
     635
     636                                synchronized(queuedEvents) {
     637                                        if (queuedEvents.isEmpty()) return;
     638                                        event = queuedEvents.remove();
    637639                                }
    638640
    639                                 if (task == HDWTask.Load) {
     641                                if (event == HDWEvent.Load) {
    640642                                        doLoad();
    641                                 } else if (task == HDWTask.Save) {
     643                                } else if (event == HDWEvent.Save) {
    642644                                        doSave(); // does not change state
    643                                 } else if (task == HDWTask.Unload){
     645                                } else if (event == HDWEvent.Unload){
    644646                                        doUnload();
    645647                                } else {
    646                                         assert(task == HDWTask.UnloadTMP);
     648                                        assert(event == HDWEvent.UnloadTMP);
    647649                                        doTempUnload();
    648650                                }
     
    655657
    656658                        // 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;
    659662                       
    660663                        // Only load if in view
     
    685688                        } catch (Exception e) {
    686689                                e.printStackTrace();
    687                                 finalState = LOAD_STATE_COMPLETED;
     690                                finalState = LOAD_STATE_FAILED;
    688691                        }
    689692                       
     
    724727        }
    725728       
    726         private enum HDWTask {
     729        private enum HDWEvent {
    727730                Save,
    728731                Load,
  • trunk/src/org/expeditee/items/widgets/InteractiveWidget.java

    r352 r374  
    923923                // Because widgets are comprised of four corners - they all report this
    924924                // event one after the
    925                 // other. So must filter out redunant notifications like so:
     925                // other. So must filter out redundant notifications like so:
    926926                if (_lastParentStateChangedEvent != null
    927927                                && _lastParentStateChangedEvent.getEventType() == e
     
    934934                _lastParentStateChangedMouseEvent = MouseEventRouter
    935935                                .getCurrentMouseEvent();
    936 
     936               
    937937                switch (e.getEventType()) {
    938938
     
    995995                                                || e.getEventType() == ItemParentStateChangedEvent.EVENT_TYPE_SHOWN_VIA_OVERLAY
    996996                                                || e.getSource() == DisplayIO.getCurrentFrame()) {
    997 
     997       
    998998                                        onBoundsChanged();
    999999                                        Browser._theBrowser.getContentPane().add(_swingComponent);
  • trunk/src/org/expeditee/items/widgets/SampledHDWidget1.java

    r230 r374  
    5959                // fail some of them
    6060                if ((rand.nextInt() % 4) == 0) {
    61                         setLoadScreenMessage("Failed");
     61                        setLoadScreenMessage("Failed to load metadata");
    6262                        return LOAD_STATE_FAILED;
    6363                }
Note: See TracChangeset for help on using the changeset viewer.