]> git.gag.com Git - fw/altos/blob - altosuilib/AltosUILib.java
altos/ao_rn4678: Send '$$$' for new devices. Fix name setting code.
[fw/altos] / altosuilib / AltosUILib.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; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 package org.altusmetrum.altosuilib_11;
20
21 import java.awt.*;
22 import libaltosJNI.*;
23
24 import org.altusmetrum.altoslib_11.*;
25
26 public class AltosUILib extends AltosLib {
27
28         public static final int tab_elt_pad = 5;
29
30         public static Font label_font;
31         public static Font value_font;
32         public static Font status_font;
33         public static Font table_label_font;
34         public static Font table_value_font;
35
36         final public static int font_size_small = 1;
37         final public static int font_size_medium = 2;
38         final public static int font_size_large = 3;
39
40         final public static int position_top_left = 0;
41         final public static int position_top = 1;
42         final public static int position_top_right = 2;
43         final public static int position_left = 3;
44         final public static int position_center = 4;
45         final public static int position_right = 5;
46         final public static int position_bottom_left = 6;
47         final public static int position_bottom = 7;
48         final public static int position_bottom_right = 8;
49
50         public static void set_fonts(int size) {
51                 int     brief_size;
52                 int     table_size;
53                 int     status_size;
54
55                 switch (size) {
56                 case font_size_small:
57                         brief_size = 16;
58                         status_size = 18;
59                         table_size = 11;
60                         break;
61                 default:
62                 case font_size_medium:
63                         brief_size = 22;
64                         status_size = 24;
65                         table_size = 14;
66                         break;
67                 case font_size_large:
68                         brief_size = 26;
69                         status_size = 30;
70                         table_size = 17;
71                         break;
72                 }
73                 label_font = new Font("Dialog", Font.PLAIN, brief_size);
74                 value_font = new Font("Monospaced", Font.PLAIN, brief_size);
75                 status_font = new Font("SansSerif", Font.BOLD, status_size);
76                 table_label_font = new Font("SansSerif", Font.PLAIN, table_size);
77                 table_value_font = new Font("Monospaced", Font.PLAIN, table_size);
78         }
79
80         static public final int text_width = 20;
81
82         static public boolean initialized = false;
83         static public boolean loaded_library = false;
84         static public boolean has_bluetooth = false;
85
86         static final String[] library_names_32 = { "altos", "altos32", "altos64" };
87         static final String[] library_names_64 = { "altos", "altos64", "altos32" };
88
89         public static boolean load_library() {
90                 if (!initialized) {
91                         String model = System.getProperty("sun.arch.data.model", "missing");
92                         boolean is_64 = false;
93                         if (model.equals("64")) {
94                                 is_64 = true;
95                         } else if (model.equals("32")) {
96                                 ;
97                         } else {
98                                 String arch = System.getProperty("os.arch", "missing");
99                                 if (arch.endsWith("64"))
100                                         is_64 = true;
101                         }
102                         for (String name : is_64 ? library_names_64 : library_names_32) {
103                                 try {
104                                         System.loadLibrary(name);
105                                         libaltos.altos_init();
106                                         loaded_library = true;
107                                         break;
108                                 } catch (UnsatisfiedLinkError e) {
109                                         System.out.printf("Link error %s\n", e.getMessage());
110                                         loaded_library = false;
111                                 }
112                         }
113
114                         String OS = System.getProperty("os.name");
115
116                         if (OS.startsWith("L") || OS.startsWith("W"))
117                                 has_bluetooth = true;
118
119                         initialized = true;
120                 }
121                 return loaded_library;
122         }
123 }