altosui: Move AltosGreatCircle.java to altoslib
[fw/altos] / altosui / Altos.java
1 /*
2  * Copyright © 2010 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 package altosui;
19
20 import java.awt.*;
21 import java.util.*;
22 import java.text.*;
23 import java.nio.charset.Charset;
24
25 import libaltosJNI.*;
26
27 import org.altusmetrum.AltosLib.*;
28
29 public class Altos extends AltosLib {
30
31         static final int tab_elt_pad = 5;
32
33         static Font label_font;
34         static Font value_font;
35         static Font status_font;
36         static Font table_label_font;
37         static Font table_value_font;
38
39         final static int font_size_small = 1;
40         final static int font_size_medium = 2;
41         final static int font_size_large = 3;
42
43         static void set_fonts(int size) {
44                 int     brief_size;
45                 int     table_size;
46                 int     status_size;
47
48                 switch (size) {
49                 case font_size_small:
50                         brief_size = 16;
51                         status_size = 18;
52                         table_size = 11;
53                         break;
54                 default:
55                 case font_size_medium:
56                         brief_size = 22;
57                         status_size = 24;
58                         table_size = 14;
59                         break;
60                 case font_size_large:
61                         brief_size = 26;
62                         status_size = 30;
63                         table_size = 17;
64                         break;
65                 }
66                 label_font = new Font("Dialog", Font.PLAIN, brief_size);
67                 value_font = new Font("Monospaced", Font.PLAIN, brief_size);
68                 status_font = new Font("SansSerif", Font.BOLD, status_size);
69                 table_label_font = new Font("SansSerif", Font.PLAIN, table_size);
70                 table_value_font = new Font("Monospaced", Font.PLAIN, table_size);
71         }
72
73         static final int text_width = 20;
74
75         static public boolean initialized = false;
76         static public boolean loaded_library = false;
77
78         public static boolean load_library() {
79                 if (!initialized) {
80                         try {
81                                 System.loadLibrary("altos");
82                                 libaltos.altos_init();
83                                 loaded_library = true;
84                         } catch (UnsatisfiedLinkError e) {
85                                 try {
86                                         System.loadLibrary("altos64");
87                                         libaltos.altos_init();
88                                         loaded_library = true;
89                                 } catch (UnsatisfiedLinkError e2) {
90                                         loaded_library = false;
91                                 }
92                         }
93                         initialized = true;
94                 }
95                 return loaded_library;
96         }
97
98         static int usb_vendor_altusmetrum() {
99                 load_library();
100                 return 0xfffe;
101         }
102
103         static int usb_product_altusmetrum() {
104                 load_library();
105                 return 0x000a;
106         }
107
108         static int usb_product_altusmetrum_min() {
109                 load_library();
110                 return 0x000a;
111         }
112
113         static int usb_product_altusmetrum_max() {
114                 load_library();
115                 return 0x0013;
116         }
117
118         static int usb_product_telemetrum() {
119                 load_library();
120                 return 0x000b;
121         }
122
123         static int usb_product_teledongle() {
124                 load_library();
125                 return 0x000c;
126         }
127
128         static int usb_product_teleterra() {
129                 load_library();
130                 return 0x000d;
131         }
132
133         static int usb_product_telebt() {
134                 load_library();
135                 return 0x000e;
136         }
137
138         static int usb_product_telelaunch() {
139                 load_library();
140                 return 0x000f;
141         }
142
143         static int usb_product_telelco() {
144                 load_library();
145                 return 0x0010;
146         }
147
148         static int usb_product_telescience() {
149                 load_library();
150                 return 0x0011;
151         }
152
153         static int usb_product_telepyro() {
154                 load_library();
155                 return 0x0012;
156         }
157
158         public final static int vendor_altusmetrum = usb_vendor_altusmetrum();
159         public final static int product_altusmetrum = usb_product_altusmetrum();
160         public final static int product_telemetrum = usb_product_telemetrum();
161         public final static int product_teledongle = usb_product_teledongle();
162         public final static int product_teleterra = usb_product_teleterra();
163         public final static int product_telebt = usb_product_telebt();
164         public final static int product_telelaunch = usb_product_telelaunch();
165         public final static int product_tele10 = usb_product_telelco();
166         public final static int product_telescience = usb_product_telescience();
167         public final static int product_telepyro = usb_product_telepyro();
168         public final static int product_altusmetrum_min = usb_product_altusmetrum_min();
169         public final static int product_altusmetrum_max = usb_product_altusmetrum_max();
170
171         public final static int product_any = 0x10000;
172         public final static int product_basestation = 0x10000 + 1;
173
174         static String bt_product_telebt() {
175                 load_library();
176                 return "TeleBT";
177         }
178
179         public final static String bt_product_telebt = bt_product_telebt();
180
181         public static AltosBTKnown bt_known = new AltosBTKnown();
182 }