altosui: Split out lots of the altosui code to a shared library
[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 Font label_font;
32         static Font value_font;
33         static Font status_font;
34         static Font table_label_font;
35         static Font table_value_font;
36
37         final static int font_size_small = 1;
38         final static int font_size_medium = 2;
39         final static int font_size_large = 3;
40
41         static void set_fonts(int size) {
42                 int     brief_size;
43                 int     table_size;
44                 int     status_size;
45
46                 switch (size) {
47                 case font_size_small:
48                         brief_size = 16;
49                         status_size = 18;
50                         table_size = 11;
51                         break;
52                 default:
53                 case font_size_medium:
54                         brief_size = 22;
55                         status_size = 24;
56                         table_size = 14;
57                         break;
58                 case font_size_large:
59                         brief_size = 26;
60                         status_size = 30;
61                         table_size = 17;
62                         break;
63                 }
64                 label_font = new Font("Dialog", Font.PLAIN, brief_size);
65                 value_font = new Font("Monospaced", Font.PLAIN, brief_size);
66                 status_font = new Font("SansSerif", Font.BOLD, status_size);
67                 table_label_font = new Font("SansSerif", Font.PLAIN, table_size);
68                 table_value_font = new Font("Monospaced", Font.PLAIN, table_size);
69         }
70
71         static final int text_width = 20;
72
73         static public boolean initialized = false;
74         static public boolean loaded_library = false;
75
76         public static boolean load_library() {
77                 if (!initialized) {
78                         try {
79                                 System.loadLibrary("altos");
80                                 libaltos.altos_init();
81                                 loaded_library = true;
82                         } catch (UnsatisfiedLinkError e) {
83                                 try {
84                                         System.loadLibrary("altos64");
85                                         libaltos.altos_init();
86                                         loaded_library = true;
87                                 } catch (UnsatisfiedLinkError e2) {
88                                         loaded_library = false;
89                                 }
90                         }
91                         initialized = true;
92                 }
93                 return loaded_library;
94         }
95
96         static int usb_vendor_altusmetrum() {
97                 load_library();
98                 return 0xfffe;
99         }
100
101         static int usb_product_altusmetrum() {
102                 load_library();
103                 return 0x000a;
104         }
105
106         static int usb_product_altusmetrum_min() {
107                 load_library();
108                 return 0x000a;
109         }
110
111         static int usb_product_altusmetrum_max() {
112                 load_library();
113                 return 0x0013;
114         }
115
116         static int usb_product_telemetrum() {
117                 load_library();
118                 return 0x000b;
119         }
120
121         static int usb_product_teledongle() {
122                 load_library();
123                 return 0x000c;
124         }
125
126         static int usb_product_teleterra() {
127                 load_library();
128                 return 0x000d;
129         }
130
131         static int usb_product_telebt() {
132                 load_library();
133                 return 0x000e;
134         }
135
136         static int usb_product_telelaunch() {
137                 load_library();
138                 return 0x000f;
139         }
140
141         static int usb_product_telelco() {
142                 load_library();
143                 return 0x0010;
144         }
145
146         static int usb_product_telescience() {
147                 load_library();
148                 return 0x0011;
149         }
150
151         static int usb_product_telepyro() {
152                 load_library();
153                 return 0x0012;
154         }
155
156         public final static int vendor_altusmetrum = usb_vendor_altusmetrum();
157         public final static int product_altusmetrum = usb_product_altusmetrum();
158         public final static int product_telemetrum = usb_product_telemetrum();
159         public final static int product_teledongle = usb_product_teledongle();
160         public final static int product_teleterra = usb_product_teleterra();
161         public final static int product_telebt = usb_product_telebt();
162         public final static int product_telelaunch = usb_product_telelaunch();
163         public final static int product_tele10 = usb_product_telelco();
164         public final static int product_telescience = usb_product_telescience();
165         public final static int product_telepyro = usb_product_telepyro();
166         public final static int product_altusmetrum_min = usb_product_altusmetrum_min();
167         public final static int product_altusmetrum_max = usb_product_altusmetrum_max();
168
169         public final static int product_any = 0x10000;
170         public final static int product_basestation = 0x10000 + 1;
171
172         static String bt_product_telebt() {
173                 load_library();
174                 return "TeleBT";
175         }
176
177         public final static String bt_product_telebt = bt_product_telebt();
178
179         public static AltosBTKnown bt_known = new AltosBTKnown();
180 }