altos: Make sure pyro remains valid during delay
[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_3;
19
20 import java.awt.*;
21 import libaltosJNI.*;
22
23 import org.altusmetrum.altoslib_5.*;
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 = { "altos", "altos32", "altos64" };
86
87         public static boolean load_library() {
88                 if (!initialized) {
89                         for (String name : library_names) {
90                                 try {
91                                         System.loadLibrary(name);
92                                         libaltos.altos_init();
93                                         loaded_library = true;
94                                         break;
95                                 } catch (UnsatisfiedLinkError e) {
96                                         System.out.printf("Link error %s\n", e.getMessage());
97                                         loaded_library = false;
98                                 }
99                         }
100
101                         String OS = System.getProperty("os.name");
102
103                         if (OS.startsWith("Linux")) {
104                                 has_bluetooth = true;
105                         }
106
107                         initialized = true;
108                 }
109                 return loaded_library;
110         }
111 }