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

import java.awt.Component;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;

import javax.swing.JLabel;

import org.helioviewer.base.math.GL3DVec3d;
import org.helioviewer.base.math.MathUtils;
import org.helioviewer.jhv.display.Displayer;
import org.helioviewer.jhv.gui.interfaces.InputControllerPlugin;

/**
 * Status panel for displaying the current mouse position.
 */
@SuppressWarnings({ "serial" })
public class PositionStatusPanel extends JLabel implements MouseMotionListener, InputControllerPlugin {

    private Point lastPosition;

    public PositionStatusPanel() {
        setText("(\u03B8, \u03C6) =( --\u00B0, --\u00B0)");
    }

    /**
     * Updates the displayed position.
     *
     * If the physical dimensions are available, translates the screen
     * coordinates to physical coordinates.
     *
     * @param position
     *            Position on the screen.
     */
    private void updatePosition(Point position) {
        if (position == lastPosition)
            return;

        GL3DVec3d computedposition = Displayer.getViewport().getCamera().getVectorFromSphereAlt(position);
        double radius = Displayer.getViewport().getCamera().getRadiusFromSphereAlt(position);

        if (computedposition == null) {
            //setText("(x, y) = " + "(" + String.format("%.2fR\u2609", computedposition.x) + "," + String.format("%.2fR\u2609", computedposition.y) + ")");
            setText(String.format("%.2f", radius) + " R\u2299; ( \u03B8, \u03C6) =(--\u00B0, --\u00B0)");
        } else {
            double theta = 90. - Math.acos(computedposition.y) * 180. / Math.PI;
            double phi = 90. - Math.atan2(computedposition.z, computedposition.x) * 180. / Math.PI;
            phi = MathUtils.mapToMinus180To180(phi);
            setText(String.format("%.2f", radius) + " R\u2299; ( \u03B8, \u03C6) = " + "(" + String.format("%.2f\u00B0", theta) + "," + String.format("%.2f\u00B0", phi) + ")");
        }
        lastPosition = position;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setComponent(Component _component) {
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void mouseDragged(MouseEvent e) {
        updatePosition(e.getPoint());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void mouseMoved(MouseEvent e) {
        updatePosition(e.getPoint());
    }

}

@@ -1363,10 +1363,8 @@
     
-//
 setT
@@ -1373,243 +1373,99 @@
 t(%22(
-x, y) = %22 + %22(%22 + String.format(%22%25.2fR%5Cu2609%22, computedposition.x) + %22,%22 + String.format(%22%25.2fR%5Cu2609%22, computedposition.y) + %22)%22);%0A            setText(String.format(%22%25.2f%22, radius) + %22 R%5Cu2299; ( %5Cu03B8, %5Cu03C6) =(--%5Cu00B0, --%5Cu00B0)%22
+%5Cu03B8, %5Cu03C6) : (--%5Cu00B0, --%5Cu00B0)%22 + String.format(%22 %7C %5Cu03c1 : %25.2f R%5Cu2299%22, radius)
 );%0A 
@@ -1753,81 +1753,39 @@
 at(%22
-%25.2f%22, radius) + %22 R%5Cu2299; ( %5Cu03B8, %5Cu03C6) = %22 + %22(%22 + String.format(%22
+(%5Cu03B8, %5Cu03C6) : (%25.2f%5Cu00B0,
 %25.2f
@@ -1794,16 +1794,17 @@
 00B0
+)
 %22, theta
 ) + 
@@ -1803,17 +1803,17 @@
 heta
-) + %22,%22 +
+, phi) + 
  Str
@@ -1828,31 +1828,42 @@
 at(%22
-%25.2f%5Cu00B0%22, phi) + %22)%22
+ %7C %5Cu03c1 : %25.2f R%5Cu2299%22, radius)
 );%0A 

Improve position formatting