30813ae7636d603974f8bc97573633c0aa4e93f8
[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; 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 org.altusmetrum.altosuilib_9;
19
20 import java.awt.*;
21 import libaltosJNI.*;
22
23 import org.altusmetrum.altoslib_9.*;
24
25 public class AltosUILib extends AltosLib {
26
27         public static final int tab_elt_pad = 5;
28
29         public static Font label_font;
30         public static Font value_font;
31         public static Font status_font;
32         public static Font table_label_font;
33         public static Font table_value_font;
34
35         final public static int font_size_small = 1;
36         final public static int font_size_medium = 2;
37         final public static int font_size_large = 3;
38
39         final public static int position_top_left = 0;
40         final public static int position_top = 1;
41         final public static int position_top_right = 2;
42         final public static int position_left = 3;
43         final public static int position_center = 4;
44         final public static int position_right = 5;
45         final public static int position_bottom_left = 6;
46         final public static int position_bottom = 7;
47         final public static int position_bottom_right = 8;
48
49         public static void set_fonts(int size) {
50                 int     brief_size;
51                 int     table_size;
52                 int     status_size;
53
54                 switch (size) {
55                 case font_size_small:
56                         brief_size = 16;
57                         status_size = 18;
58                         table_size = 11;
59                         break;
60                 default:
61                 case font_size_medium:
62                         brief_size = 22;
63                         status_size = 24;
64                         table_size = 14;
65                         break;
66                 case font_size_large:
67                         brief_size = 26;
68                         status_size = 30;
69                         table_size = 17;
70                         break;
71                 }
72                 label_font = new Font("Dialog", Font.PLAIN, brief_size);
73                 value_font = new Font("Monospaced", Font.PLAIN, brief_size);
74                 status_font = new Font("SansSerif", Font.BOLD, status_size);
75                 table_label_font = new Font("SansSerif", Font.PLAIN, table_size);
76                 table_value_font = new Font("Monospaced", Font.PLAIN, table_size);
77         }
78
79         static public final int text_width = 20;
80
81         static public boolean initialized = false;
82         static public boolean loaded_library = false;
83         static public boolean has_bluetooth = false;
84
85         static final String[] library_names_32 = { "altos", "altos32", "altos64" };
86         static final String[] library_names_64 = { "altos", "altos64", "altos32" };
87
88         public static boolean load_library() {
89                 if (!initialized) {
90                         String model = System.getProperty("sun.arch.data.model", "missing");
91                         boolean is_64 = false;
92                         if (model.equals("64")) {
93                                 is_64 = true;
94                         } else if (model.equals("32")) {
95                                 ;
96                         } else {
97                                 String arch = System.getProperty("os.arch", "missing");
98                                 if (arch.endsWith("64"))
99                                         is_64 = true;
100                         }
101                         for (String name : is_64 ? library_names_64 : library_names_32) {
102                                 try {
103                                         System.loadLibrary(name);
104                                         libaltos.altos_init();
105                                         loaded_library = true;
106                                         break;
107                                 } catch (UnsatisfiedLinkError e) {
108                                         System.out.printf("Link error %s\n", e.getMessage());
109                                         loaded_library = false;
110                                 }
111                         }
112
113                         String OS = System.getProperty("os.name");
114
115                         if (OS.startsWith("L") || OS.startsWith("W"))
116                                 has_bluetooth = true;
117
118                         initialized = true;
119                 }
120                 return loaded_library;
121         }
122 }