AltosVoice voice;
public JTextField callsign_value;
+ public JComboBox position_value;
/* DocumentListener interface methods */
public void insertUpdate(DocumentEvent e) {
row++;
}
+ final static String[] position_names = {
+ "Top left",
+ "Top",
+ "Top right",
+ "Left",
+ "Center",
+ "Right",
+ "Bottom left",
+ "Bottom",
+ "Bottom right",
+ };
+
+ public void add_position() {
+ pane.add(new JLabel ("Menu position"), constraints(0, 1));
+
+ position_value = new JComboBox (position_names);
+ position_value.setMaximumRowCount(position_names.length);
+ int position = AltosUIPreferences.position();
+ position_value.setSelectedIndex(position);
+ position_value.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ int position = position_value.getSelectedIndex();
+ AltosUIPreferences.set_position(position);
+ }
+ });
+ pane.add(position_value, constraints(1, 2, GridBagConstraints.BOTH));
+ position_value.setToolTipText("Position of main AltosUI window");
+ row++;
+ }
+
public AltosConfigureUI(JFrame owner, AltosVoice voice) {
super(owner);
doLayout();
validate();
- setVisible(true);
-
- Insets i = getInsets();
- Dimension ps = rootPane.getPreferredSize();
- ps.width += i.left + i.right;
- ps.height += i.top + i.bottom;
- setPreferredSize(ps);
- setSize(ps);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
@Override
System.exit(0);
}
});
+
+ setLocationByPlatform(false);
+
+ /* Insets aren't set before the window is visible */
+ setVisible(true);
}
private void ConnectToDevice() {
--- /dev/null
+/*
+ * Copyright © 2013 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package org.altusmetrum.altosuilib;
+
+public interface AltosPositionListener {
+ public void position_changed(int position);
+}
row++;
}
- public void add_serial_debug() {
- GridBagConstraints c = new GridBagConstraints();
+ public void add_position () {
+ }
+ public void add_serial_debug() {
/* Serial debug setting */
pane.add(new JLabel("Serial Debug"), constraints(0, 1));
}
});
serial_debug.setToolTipText("Enable/Disable USB I/O getting sent to the console");
- c.gridx = 1;
- c.gridy = row++;
- c.gridwidth = 3;
- c.fill = GridBagConstraints.NONE;
- c.anchor = GridBagConstraints.WEST;
- pane.add(serial_debug, c);
+ pane.add(serial_debug, constraints(1,2));
+ row++;
}
public void add_bluetooth() {
add_log_dir();
add_callsign();
add_units();
+ add_serial_debug();
add_font_size();
add_look_and_feel();
+ add_position();
add_bluetooth();
add_frequencies();
}
}
-public class AltosUIFrame extends JFrame implements AltosUIListener {
+public class AltosUIFrame extends JFrame implements AltosUIListener, AltosPositionListener {
public void ui_changed(String look_and_feel) {
SwingUtilities.updateComponentTreeUI(this);
super.setLocationByPlatform(lbp);
}
+ public void setSize() {
+ /* Smash sizes around so that the window comes up in the right shape */
+ Insets i = getInsets();
+ Dimension ps = rootPane.getPreferredSize();
+ ps.width += i.left + i.right;
+ ps.height += i.top + i.bottom;
+ setPreferredSize(ps);
+ setSize(ps);
+ }
+
+ public void setPosition (int position) {
+ Insets i = getInsets();
+ Dimension ps = getSize();
+
+ /* Stick the window in the desired location on the screen */
+ setLocationByPlatform(false);
+ GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
+ GraphicsConfiguration gc = gd.getDefaultConfiguration();
+ Rectangle r = gc.getBounds();
+
+ /* compute X position */
+ int x = 0;
+ int y = 0;
+ switch (position) {
+ case AltosUILib.position_top_left:
+ case AltosUILib.position_left:
+ case AltosUILib.position_bottom_left:
+ x = 0;
+ break;
+ case AltosUILib.position_top:
+ case AltosUILib.position_center:
+ case AltosUILib.position_bottom:
+ x = (r.width - ps.width) / 2;
+ break;
+ case AltosUILib.position_top_right:
+ case AltosUILib.position_right:
+ case AltosUILib.position_bottom_right:
+ x = r.width - ps.width + i.right;
+ break;
+ }
+
+ /* compute Y position */
+ switch (position) {
+ case AltosUILib.position_top_left:
+ case AltosUILib.position_top:
+ case AltosUILib.position_top_right:
+ y = 0;
+ break;
+ case AltosUILib.position_left:
+ case AltosUILib.position_center:
+ case AltosUILib.position_right:
+ y = (r.height - ps.height) / 2;
+ break;
+ case AltosUILib.position_bottom_left:
+ case AltosUILib.position_bottom:
+ case AltosUILib.position_bottom_right:
+ y = r.height - ps.height + i.bottom;
+ break;
+ }
+ setLocation(x, y);
+ }
+
+ int position;
+
+ public void position_changed(int position) {
+ this.position = position;
+ if (!location_by_platform)
+ setPosition(position);
+ }
+
public void setVisible (boolean visible) {
if (visible)
setLocationByPlatform(location_by_platform);
super.setVisible(visible);
+ if (visible) {
+ setSize();
+ if (!location_by_platform)
+ setPosition(position);
+ }
}
- public AltosUIFrame() {
+ void init() {
AltosUIPreferences.register_ui_listener(this);
+ AltosUIPreferences.register_position_listener(this);
+ position = AltosUIPreferences.position();
addWindowListener(new AltosUIFrameListener());
set_icon();
}
+ public AltosUIFrame() {
+ init();
+ }
+
public AltosUIFrame(String name) {
super(name);
- AltosUIPreferences.register_ui_listener(this);
- addWindowListener(new AltosUIFrameListener());
- set_icon();
+ init();
}
}
final public static int font_size_medium = 2;
final public static int font_size_large = 3;
- static void set_fonts(int size) {
+ final public static int position_top_left = 0;
+ final public static int position_top = 1;
+ final public static int position_top_right = 2;
+ final public static int position_left = 3;
+ final public static int position_center = 4;
+ final public static int position_right = 5;
+ final public static int position_bottom_left = 6;
+ final public static int position_bottom = 7;
+ final public static int position_bottom_right = 8;
+
+ public static void set_fonts(int size) {
int brief_size;
int table_size;
int status_size;
table_value_font = new Font("Monospaced", Font.PLAIN, table_size);
}
- static final int text_width = 20;
+ static public final int text_width = 20;
static public boolean initialized = false;
static public boolean loaded_library = false;
/* Look&Feel preference name */
final static String lookAndFeelPreference = "LOOK-AND-FEEL";
+ /* Window position preference name */
+ final static String positionPreference = "POSITION";
+
/* UI Component to pop dialogs up */
static Component component;
/* Serial debug */
public static boolean serial_debug;
+ static LinkedList<AltosPositionListener> position_listeners;
+
+ public static int position = AltosUILib.position_top_left;
+
public static void init() {
AltosPreferences.init(new AltosUIPreferencesBackend());
ui_listeners = new LinkedList<AltosUIListener>();
serial_debug = backend.getBoolean(serialDebugPreference, false);
+
AltosLink.set_debug(serial_debug);
+
+ position = backend.getInt(positionPreference, AltosUILib.position_top_left);
+ position_listeners = new LinkedList<AltosPositionListener>();
}
static { init(); }
}
}
+ public static void register_position_listener(AltosPositionListener l) {
+ synchronized(backend) {
+ position_listeners.add(l);
+ }
+ }
+
+ public static void unregister_position_listener(AltosPositionListener l) {
+ synchronized (backend) {
+ position_listeners.remove(l);
+ }
+ }
+
+ public static void set_position(int new_position) {
+ synchronized (backend) {
+ position = new_position;
+ backend.putInt(positionPreference, position);
+ flush_preferences();
+ for (AltosPositionListener l : position_listeners)
+ l.position_changed(position);
+ }
+ }
+
+ public static int position() {
+ synchronized (backend) {
+ return position;
+ }
+ }
}
AltosDeviceDialog.java \
AltosUSBDevice.java \
AltosFontListener.java \
+ AltosPositionListener.java \
AltosUIDialog.java \
AltosUIFrame.java \
AltosUILib.java \