package org.helioviewer.jhv.display;

import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Displayer {
    public static Object displaylock = new Object();
    private static Displayer instance = new Displayer();
    private final ArrayList<DisplayListener> listeners = new ArrayList<DisplayListener>();
    private final ArrayList<RenderListener> renderListeners = new ArrayList<RenderListener>();
    private GL3DComponentFakeInterface gl3dcomponent;
    private final ExecutorService displayPool = Executors.newSingleThreadExecutor();
    private boolean displaying=false;

    public void register(GL3DComponentFakeInterface gl3dcomponent) {
        this.gl3dcomponent = gl3dcomponent;
    }

    public static Displayer getSingletonInstance() {
        if (instance == null) {
            throw new NullPointerException("Displayer not initialized");
        }
        return instance;
    }

    public void addListener(final DisplayListener listener) {
        listeners.add(listener);
    }

    public void removeListener(final DisplayListener renderListener) {
        synchronized (renderListener) {
            listeners.remove(renderListener);
        }
    }

    public void addRenderListener(final RenderListener renderListener) {
        synchronized (renderListener) {
            renderListeners.add(renderListener);
        }
    }

    public void removeRenderListener(final RenderListener listener) {
        synchronized (renderListeners) {
            renderListeners.remove(listener);
        }
    }

    public void render() {
        if(!displaying){
        displaying=true;
        synchronized (renderListeners) {
            for (final RenderListener renderListener : renderListeners) {
                renderListener.render();
            }
        }
        displaying=false;
        }

    }

    private void tdisplay() {
        synchronized (displaylock) {
            for (final DisplayListener listener : listeners) {
                listener.display();
            }
        }
    }

    private final class DisplayTask implements Runnable {
        @Override
        public void run() {
            tdisplay();
        }
    }

    public void display() {
        displayPool.submit(new DisplayTask());
    }

}

@@ -630,25 +630,27 @@
 n displaying
-=
+ = 
 false;%0A%0A    
@@ -1631,16 +1631,17 @@
       if
+ 
 (!displa
@@ -1645,16 +1645,17 @@
 playing)
+ 
 %7B%0A      
@@ -1648,32 +1648,36 @@
 ying) %7B%0A        
+   
+ 
 displaying=true;
@@ -1670,17 +1670,19 @@
 splaying
-=
+ = 
 true;%0A  
@@ -1679,32 +1679,36 @@
 = true;%0A        
+ 
+   
 synchronized (re
@@ -1716,32 +1716,36 @@
 derListeners) %7B%0A
+    
             for 
@@ -1810,32 +1810,36 @@
                 
+ 
+   
 renderListener.r
@@ -1855,36 +1855,48 @@
             
-%7D%0A    
     %7D%0A
+            %7D%0A    
         disp
@@ -1901,17 +1901,19 @@
 splaying
-=
+ = 
 false;%0A 

Format correctly