1 42 43 package org.jfree.chart.axis; 44 45 import java.text.FieldPosition ; 46 import java.text.NumberFormat ; 47 import java.text.ParsePosition ; 48 49 52 public class CompassFormat extends NumberFormat { 53 54 55 private static final String N = "N"; 56 57 58 private static final String E = "E"; 59 60 61 private static final String S = "S"; 62 63 64 private static final String W = "W"; 65 66 67 public static final String [] DIRECTIONS = { 68 N, N + N + E, N + E, E + N + E, E, E + S + E, S + E, S + S + E, S, 69 S + S + W, S + W, W + S + W, W, W + N + W, N + W, N + N + W, N 70 }; 71 72 75 public CompassFormat() { 76 super(); 77 } 78 79 86 public String getDirectionCode(double direction) { 87 88 direction = direction % 360; 89 if (direction < 0.0) { 90 direction = direction + 360.0; 91 } 92 int index = ((int) Math.floor(direction / 11.25) + 1) / 2; 93 return DIRECTIONS[index]; 94 95 } 96 97 101 public StringBuffer format(double number, StringBuffer toAppendTo, 102 FieldPosition pos) { 103 return toAppendTo.append(getDirectionCode(number)); 104 } 105 106 110 public StringBuffer format(long number, StringBuffer toAppendTo, 111 FieldPosition pos) { 112 return toAppendTo.append(getDirectionCode(number)); 113 } 114 115 124 public Number parse(String source, ParsePosition parsePosition) { 125 return null; 126 } 127 128 } 129 | Popular Tags |