altos/test: Adjust CRC error rate after FEC fix
[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_14;
20
21 import java.awt.*;
22 import libaltosJNI.*;
23
24 import org.altusmetrum.altoslib_14.*;
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         final public static int font_size_huge = 4;
40
41         final public static int position_top_left = 0;
42         final public static int position_top = 1;
43         final public static int position_top_right = 2;
44         final public static int position_left = 3;
45         final public static int position_center = 4;
46         final public static int position_right = 5;
47         final public static int position_bottom_left = 6;
48         final public static int position_bottom = 7;
49         final public static int position_bottom_right = 8;
50
51         public static void set_fonts(int size) {
52                 int     brief_size;
53                 int     table_size;
54                 int     status_size;
55
56                 switch (size) {
57                 case font_size_small:
58                         brief_size = 16;
59                         status_size = 18;
60                         table_size = 11;
61                         break;
62                 default:
63                 case font_size_medium:
64                         brief_size = 22;
65                         status_size = 24;
66                         table_size = 14;
67                         break;
68                 case font_size_large:
69                         brief_size = 26;
70                         status_size = 30;
71                         table_size = 17;
72                         break;
73                 case font_size_huge:
74                         brief_size = 30;
75                         status_size = 36;
76                         table_size = 24;
77                         break;
78                 }
79                 label_font = new Font("Dialog", Font.PLAIN, brief_size);
80                 value_font = new Font("Monospaced", Font.PLAIN, brief_size);
81                 status_font = new Font("SansSerif", Font.BOLD, status_size);
82                 table_label_font = new Font("SansSerif", Font.PLAIN, table_size);
83                 table_value_font = new Font("Monospaced", Font.PLAIN, table_size);
84         }
85
86         static public final int text_width = 20;
87
88         static public boolean initialized = false;
89         static public boolean loaded_library = false;
90         static public boolean has_bluetooth = false;
91
92         static final String[] library_names = {
93                 "altos",
94                 "altos32",
95                 "altos64",
96                 "altos_i686",
97                 "altos_amd64",
98                 "altos_aarch64",
99                 "altos_armel",
100                 "altos_armhf"
101         };
102
103         public static boolean load_library() {
104                 if (!initialized) {
105                         for (String name : library_names) {
106                                 try {
107                                         System.loadLibrary(name);
108                                         libaltos.altos_init();
109                                         loaded_library = true;
110                                         break;
111                                 } catch (UnsatisfiedLinkError e) {
112                                         loaded_library = false;
113                                 }
114                         }
115                         if (!loaded_library)
116                                 System.out.printf("Cannot find 'libaltos' device access library\n");
117
118                         String OS = System.getProperty("os.name");
119
120                         if (OS.startsWith("L") || OS.startsWith("W"))
121                                 has_bluetooth = true;
122
123                         initialized = true;
124                 }
125                 return loaded_library;
126         }
127 }