Ignore:
Timestamp:
09/17/18 11:36:12 (6 years ago)
Author:
bln4
Message:

org.expeditee.gui.DisplayController ->

requestRefresh now optionally takes a callback function that is call once the refresh is actually completed.

org.expeditee.gui.Browser ->

Instead of pushing delayed messages to MessageBay once execution of Browser constructor being finished, they are now delayed until the first refresh is completed. This removes a possible race condition on startup but may not be the ideal solution.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/gui/DisplayController.java

    r1137 r1140  
    2626import java.util.List;
    2727import java.util.Stack;
     28import java.util.function.BooleanSupplier;
    2829
    2930import org.expeditee.core.Clip;
     
    12251226         * requestRefresh(boolean) to ensure no infinite refresh call loops are created.
    12261227         */
    1227         private static void refresh(boolean useInvalidation)
     1228        private static boolean refresh(boolean useInvalidation)
    12281229        {
    12291230                Frame currentFrame = getCurrentFrame();
    12301231                if(currentFrame == null) {
    1231                         return;
    1232                 }
     1232                        return false;
     1233                }
     1234                //For Monday; at this point, the DisplayController is ready to do something
     1235                //RequestRefesh could have a callback method
    12331236               
    12341237                // Always get the clip as it clears at the same time
     
    12361239               
    12371240                // No damaged areas
    1238                 if (useInvalidation && clip.isFullyClipped()) return;
     1241                if (useInvalidation && clip.isFullyClipped()) return true;
    12391242               
    12401243                GraphicsManager g = EcosystemManager.getGraphicsManager();
     
    13061309                g.popDrawingSurface();
    13071310                g.drawImage(_refreshBuffer, Point.ORIGIN);
     1311                return true;
    13081312        }
    13091313       
     
    13711375        /** Runnable which ensures overlapping refresh requests are joined. */
    13721376        private static RenderRequestMarsheller _requestMarsheller = new RenderRequestMarsheller();
    1373 
     1377       
    13741378        /**
    13751379         * If wanting to refresh from another thread - other than the main thread
     
    13771381         * Use this method for thread safety.
    13781382         */
    1379         public static synchronized void requestRefresh(boolean useInvalidation)
    1380         {
     1383        public static synchronized void requestRefresh(boolean useInvalidation) {
     1384                requestRefresh(useInvalidation, () -> false);
     1385        }
     1386       
     1387        public static synchronized void requestRefresh(final boolean useInvalidation, final BooleanSupplier callback) {
    13811388                try {
    1382                         _requestMarsheller.enqueue(useInvalidation);
     1389                        _requestMarsheller.enqueue(useInvalidation, callback);
    13831390                } catch (Throwable e) {
    13841391                        e.printStackTrace();
     
    13981405                private Boolean _requeueWithInvalidation = null;
    13991406                private Object _lock = new Object();
     1407                private BooleanSupplier callback;
    14001408               
    14011409                /** Enqueues a redraw on the GIO thread, or remembers to do so once the current redraw finishes. */
    1402                 public void enqueue(boolean useInvalidation)
     1410                public void enqueue(final boolean useInvalidation, final BooleanSupplier callback)
    14031411                {
    14041412                        synchronized (_lock) {
    14051413                                if (!_enqueued) {
    14061414                                        _enqueued = true;
     1415                                        this.callback = callback;
    14071416                                        _useInvalidation = useInvalidation;
    14081417                                        EcosystemManager.getMiscManager().runOnGIOThread(this);
     
    14161425                {
    14171426                        try {
    1418                                 refresh(_useInvalidation);
     1427                                if(refresh(_useInvalidation) && callback != null) {
     1428                                        callback.getAsBoolean();
     1429                                        callback = null;
     1430                                }
    14191431                        } catch (Throwable e) {
    14201432                                e.printStackTrace();
Note: See TracChangeset for help on using the changeset viewer.