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

import javax.swing.JFormattedTextField;
import javax.swing.JFormattedTextField.AbstractFormatter;
import javax.swing.JFormattedTextField.AbstractFormatterFactory;
import javax.swing.text.DefaultFormatter;

@SuppressWarnings({"serial"})
public class DegreeFormatterFactory extends AbstractFormatterFactory {

    private final String format;

    public DegreeFormatterFactory(String format) {
        super();
        this.format = format;
    }

    @Override
    public AbstractFormatter getFormatter(JFormattedTextField tf) {
        return new DefaultFormatter() {
            @Override
            public Object stringToValue(String string) {
                if (string == null || string.length() == 0) {
                    return new Double(0.);
                }
                return Double.parseDouble(string.substring(0, string.length() - 1));
            }

            @Override
            public String valueToString(Object value) {
                return String.format(format, value);
            }

            @Override
            public Class<?> getValueClass() {
                return Double.class;
            }
        };
    }

}

@@ -249,16 +249,58 @@
 atter;%0A%0A
+import org.helioviewer.base.logging.Log;%0A%0A
 @Suppres
@@ -314,16 +314,17 @@
 gs(%7B
+ 
 %22serial%22
 %7D)%0Ap
@@ -319,16 +319,17 @@
 %22serial%22
+ 
 %7D)%0Apubli
@@ -731,24 +731,71 @@
 g string) %7B%0A
+                Double value = new Double(0.);%0A
             
@@ -813,18 +813,18 @@
 ing 
-=
+!
 = null 
-%7C%7C
+&&
  str
@@ -836,17 +836,17 @@
 ength() 
-=
+!
 = 0) %7B%0A 
@@ -868,30 +868,62 @@
     
-return new Double(0.);
+if (string.charAt(string.length() - 1) == '%5Cu00B0') %7B%0A
 %0A   
@@ -927,33 +927,45 @@
                 
-%7D
+        try %7B
 %0A               
@@ -957,38 +957,51 @@
                 
-return
+            value =
  Double.parseDou
@@ -1047,16 +1047,512 @@
  - 1));%0A
+                        %7D catch (NumberFormatException ex2) %7B%0A                            Log.warn(%22Could not parse number%22);%0A                        %7D%0A                    %7D else %7B%0A                        try %7B%0A                            value = Double.parseDouble(string);%0A                        %7D catch (NumberFormatException ex) %7B%0A                            Log.warn(%22Could not parse number%22);%0A                        %7D%0A                    %7D%0A                %7D%0A                return value;%0A
         
@@ -1840,11 +1840,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

improve number formatting