package org.helioviewer.jhv.gui.components.statusplugins;

import java.awt.Dimension;

import javax.swing.BorderFactory;

import org.helioviewer.jhv.gui.controller.ZoomController;
import org.helioviewer.jhv.layers.LayersModel;
import org.helioviewer.viewmodel.view.View;

/**
 * Status panel for displaying the current zoom.
 * 
 * <p>
 * A displayed zoom of 100% means that one pixel one the screen corresponds to
 * exactly one pixel in the native resolution of the image.
 * 
 * <p>
 * The information of this panel is always shown for the active layer.
 * 
 * <p>
 * If there is no layer present, this panel will be invisible.
 */
public class ZoomStatusPanel extends ViewStatusPanelPlugin {

    private static final long serialVersionUID = 1L;

    /**
     * Default constructor.
     */
    public ZoomStatusPanel() {
        setBorder(BorderFactory.createEtchedBorder());

        setPreferredSize(new Dimension(100, 20));
        setText("Zoom:");

        LayersModel.getSingletonInstance().addLayersListener(this);
    }

    /**
     * Updates the displayed zoom.
     */
    private void updateZoomLevel() {
        View view = LayersModel.getSingletonInstance().getActiveView();

        if (view != null) {
            long zoom = Math.round(ZoomController.getZoom(view) * 100);
            if (zoom != 0.0) {
                setText("Zoom: " + zoom + "%");
            } else {
                setText("Zoom: n/a");
            }
            setVisible(true);
        } else {
            setVisible(false);
        }
    }

    public void activeLayerChanged(int idx) {
        updateZoomLevel();
    }

    public void viewportGeometryChanged() {
        updateZoomLevel();
    }

}

@@ -78,16 +78,44 @@
 mension;
+%0Aimport java.awt.EventQueue;
 %0A%0Aimport
@@ -1555,32 +1555,369 @@
        %7D%0A    %7D%0A%0A
+    private void updateZoomLevel_eq() %7B%0A        if (EventQueue.isDispatchThread()) %7B%0A            updateZoomLevel();%0A        %7D else %7B%0A            EventQueue.invokeLater(new Runnable() %7B%0A                @Override%0A                public void run() %7B%0A                    updateZoomLevel();%0A                %7D%0A            %7D);%0A        %7D%0A    %7D%0A%0A
     public void 
@@ -1961,32 +1961,35 @@
  updateZoomLevel
+_eq
 ();%0A    %7D%0A%0A    p
@@ -2023,24 +2023,24 @@
 Changed() %7B%0A
-
         upda
@@ -2042,29 +2042,32 @@
  updateZoomLevel
+_eq
 ();%0A    %7D%0A%0A%7D%0A

Update zoom status from EventQueue