package org.helioviewer.viewmodel.view.opengl;

import java.util.Iterator;
import java.util.concurrent.CopyOnWriteArrayList;

import javax.media.opengl.GL2;

import org.helioviewer.viewmodel.changeevent.ChangeEvent;
import org.helioviewer.viewmodel.changeevent.RegionChangedReason;
import org.helioviewer.viewmodel.changeevent.ViewChainChangedReason;
import org.helioviewer.viewmodel.renderer.physical.PhysicalRenderer;
import org.helioviewer.viewmodel.view.LayeredView;
import org.helioviewer.viewmodel.view.OverlayView;
import org.helioviewer.viewmodel.view.View;
import org.helioviewer.viewmodel.view.ViewHelper;

/**
 * Implementation of OverlayView for rendering in OpenGL mode.
 *
 * <p>
 * This class provides the capability to draw overlays in OpenGL2. Therefore it
 * manages a {@link PhysicalRenderer}, which is passed to the registered
 * renderer.
 *
 * <p>
 * For further information about the role of the OverlayView within the view
 * chain, see {@link org.helioviewer.viewmodel.view.OverlayView}.
 *
 * @author Markus Langenberg
 */
public class GLOverlayView extends AbstractGLView implements OverlayView {

    private LayeredView layeredView;
    private CopyOnWriteArrayList<OverlayPluginContainer> overlays = new CopyOnWriteArrayList<OverlayPluginContainer>();

    /**
     * {@inheritDoc}
     */
    @Override
    protected void setViewSpecificImplementation(View newView, ChangeEvent changeEvent) {
        layeredView = ViewHelper.getViewAdapter(view, LayeredView.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void renderGL(GL2 gl, boolean nextView) {
        renderChild(gl);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void viewChanged(View sender, ChangeEvent aEvent) {
        if (aEvent != null) {
            if (aEvent.reasonOccurred(RegionChangedReason.class)) {
                Iterator<OverlayPluginContainer> iterator = this.overlays.iterator();
                // Region region = sender.getAdapter(RegionView.class);
                while (iterator.hasNext()) {
                    OverlayPluginContainer overlay = iterator.next();
                    if (overlay.getRenderer3d() != null) {
                        overlay.getRenderer3d().viewChanged(sender);
                    }
                }
            }
            if (aEvent.reasonOccurred(ViewChainChangedReason.class)) {
                layeredView = ViewHelper.getViewAdapter(view, LayeredView.class);
            }
        }
        super.viewChanged(sender, aEvent);
    }

    @Override
    public void addOverlay(OverlayPluginContainer overlayPluginContainer) {
        this.overlays.add(overlayPluginContainer);
    }

    @Override
    public void removeOverlay(int index) {
    }

    @Override
    // Just implemented for exist plugin, for new one, pls don't use this
    // function
    public void setRenderer(PhysicalRenderer renderer) {
        OverlayPluginContainer overlayPluginContainer = new OverlayPluginContainer();
        overlayPluginContainer.setRenderer(renderer);
        this.overlays.add(overlayPluginContainer);
    }

    @Override
    public View getView() {
        return view;
    }

    @Override
    public void setOverlays(CopyOnWriteArrayList<OverlayPluginContainer> overlays) {
        this.overlays = overlays;
    }

    @Override
    public CopyOnWriteArrayList<OverlayPluginContainer> getOverlays() {
        return overlays;
    }

}

@@ -45,35 +45,8 @@
 l;%0A%0A
-import java.util.Iterator;%0A
 impo
@@ -186,143 +186,8 @@
 nt;%0A
-import org.helioviewer.viewmodel.changeevent.RegionChangedReason;%0Aimport org.helioviewer.viewmodel.changeevent.ViewChainChangedReason;%0A
 impo
@@ -1476,902 +1476,8 @@
  %7D%0A%0A
-    /**%0A     * %7B@inheritDoc%7D%0A     */%0A    @Override%0A    public void viewChanged(View sender, ChangeEvent aEvent) %7B%0A        if (aEvent != null) %7B%0A            if (aEvent.reasonOccurred(RegionChangedReason.class)) %7B%0A                Iterator%3COverlayPluginContainer%3E iterator = this.overlays.iterator();%0A                // Region region = sender.getAdapter(RegionView.class);%0A                while (iterator.hasNext()) %7B%0A                    OverlayPluginContainer overlay = iterator.next();%0A                    if (overlay.getRenderer3d() != null) %7B%0A                        overlay.getRenderer3d().viewChanged(sender);%0A                    %7D%0A                %7D%0A            %7D%0A            if (aEvent.reasonOccurred(ViewChainChangedReason.class)) %7B%0A                layeredView = ViewHelper.getViewAdapter(view, LayeredView.class);%0A            %7D%0A        %7D%0A        super.viewChanged(sender, aEvent);%0A    %7D%0A%0A
     

remove unused code