1 | // License: Public Domain. For details, see LICENSE file.
|
---|
2 | package livegps;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.GridBagConstraints;
|
---|
7 | import java.awt.GridBagLayout;
|
---|
8 |
|
---|
9 | import javax.swing.Box;
|
---|
10 | import javax.swing.JCheckBox;
|
---|
11 | import javax.swing.JLabel;
|
---|
12 | import javax.swing.JPanel;
|
---|
13 | import javax.swing.JTextField;
|
---|
14 |
|
---|
15 | import org.openstreetmap.josm.gui.preferences.DefaultTabPreferenceSetting;
|
---|
16 | import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
|
---|
17 | import org.openstreetmap.josm.spi.preferences.Config;
|
---|
18 | import org.openstreetmap.josm.tools.GBC;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Preferences of LiveGPS
|
---|
22 | */
|
---|
23 | public class LiveGPSPreferences extends DefaultTabPreferenceSetting {
|
---|
24 | /* option to use serial port direct access */
|
---|
25 | public static final String C_SERIAL = "livegps.serial.port";
|
---|
26 | /* default gpsd host address */
|
---|
27 | public static final String DEFAULT_HOST = "localhost";
|
---|
28 | /* option to use specify gpsd host address */
|
---|
29 | public static final String C_HOST = "livegps.gpsd.host";
|
---|
30 | /* default gpsd port number */
|
---|
31 | public static final int DEFAULT_PORT = 2947;
|
---|
32 | /* option to use specify gpsd port number */
|
---|
33 | public static final String C_PORT = "livegps.gpsd.port";
|
---|
34 | /* option to use specify gpsd disabling */
|
---|
35 | public static final String C_DISABLED = "livegps.gpsd.disabled";
|
---|
36 |
|
---|
37 | public static final String C_LIVEGPS_COLOR_POSITION = "color.livegps.position";
|
---|
38 | public static final String C_LIVEGPS_COLOR_POSITION_ESTIMATE = "color.livegps.position_estimate";
|
---|
39 |
|
---|
40 | /* options below are hidden/expert options */
|
---|
41 |
|
---|
42 | /* option to use even duplicate positions (default false) */
|
---|
43 | public static final String C_ALLPOSITIONS = "livegps.positions.all";
|
---|
44 | /* option to show offset to next way (default false) */
|
---|
45 | public static final String C_WAYOFFSET = "livegps.way.offset";
|
---|
46 |
|
---|
47 | public static final String C_CURSOR_H = "livegps.cursor_height"; /* in pixels */
|
---|
48 | public static final String C_CURSOR_W = "livegps.cursor_width"; /* in pixels */
|
---|
49 | public static final String C_CURSOR_T = "livegps.cursor_thickness"; /* in pixels */
|
---|
50 |
|
---|
51 | public static final int DEFAULT_REFRESH_INTERVAL = 250;
|
---|
52 | public static final String C_REFRESH_INTERVAL = "livegps.refresh_interval_msec"; /* in msec */
|
---|
53 | public static final int DEFAULT_CENTER_INTERVAL = 5000;
|
---|
54 | public static final String C_CENTER_INTERVAL = "livegps.center_interval_msec"; /* in msec */
|
---|
55 | public static final int DEFAULT_CENTER_FACTOR = 80;
|
---|
56 | public static final String C_CENTER_FACTOR = "livegps.center_factor" /* in percent */;
|
---|
57 |
|
---|
58 | private final JTextField gpsdHost = new JTextField(30);
|
---|
59 | private final JTextField gpsdPort = new JTextField(30);
|
---|
60 | private final JTextField serialDevice = new JTextField(30);
|
---|
61 | private final JCheckBox disableGPSD = new JCheckBox(tr("Disable GPSD"));
|
---|
62 | private final JCheckBox showOffset = new JCheckBox(tr("Show Distance to nearest way"));
|
---|
63 |
|
---|
64 | public LiveGPSPreferences() {
|
---|
65 | super("dialogs/livegps", tr("LiveGPS settings"), tr("Here you can change some preferences of LiveGPS plugin"));
|
---|
66 | }
|
---|
67 |
|
---|
68 | @Override
|
---|
69 | public void addGui(PreferenceTabbedPane gui) {
|
---|
70 | JPanel panel = new JPanel(new GridBagLayout());
|
---|
71 |
|
---|
72 | gpsdHost.setText(Config.getPref().get(C_HOST, DEFAULT_HOST));
|
---|
73 | gpsdHost.setToolTipText(tr("Host address of gpsd, default is {0}", DEFAULT_HOST));
|
---|
74 | panel.add(new JLabel(tr("Host address of gpsd")), GBC.std());
|
---|
75 | panel.add(gpsdHost, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 5));
|
---|
76 |
|
---|
77 | gpsdPort.setText(String.valueOf(Config.getPref().getInt(C_PORT, DEFAULT_PORT)));
|
---|
78 | gpsdPort.setToolTipText(tr("Port number of gpsd, default is {0}", DEFAULT_PORT));
|
---|
79 | panel.add(new JLabel(tr("Port number gpsd")), GBC.std());
|
---|
80 | panel.add(gpsdPort, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 5));
|
---|
81 |
|
---|
82 | disableGPSD.setSelected(Config.getPref().getBoolean(C_DISABLED, false));
|
---|
83 | panel.add(disableGPSD, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(0, 0, 0, 5));
|
---|
84 |
|
---|
85 | serialDevice.setText(Config.getPref().get(C_SERIAL));
|
---|
86 | serialDevice.setToolTipText(tr(".Serial device for direct NMEA input, does not exist by default.</html>"));
|
---|
87 | panel.add(new JLabel(tr("Serial device")), GBC.std());
|
---|
88 | panel.add(serialDevice, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 5));
|
---|
89 | /* I18n : {0} to {3} is like /dev/ttyACM<b>x</b>, {4} and {5} are COM1 and COM9 */
|
---|
90 | panel.add(new JLabel(tr("<html>For Linux {0}, {1}, {2} or {3} (<b>x</b> means any number beginning with 0).<br>For Windows {4} to {5} (COM ports bigger than 9 wont work).</html>", "/dev/ttyS<b>x</b>", "/dev/ttyACM<b>x</b>", "/dev/ttyUSB<b>x</b>", "/dev/rfcomm<b>x</b>", "COM1", "COM9")), GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(10, 0, 0, 5));
|
---|
91 |
|
---|
92 | showOffset.setSelected(Config.getPref().getBoolean(C_WAYOFFSET, false));
|
---|
93 | panel.add(showOffset, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(0, 0, 0, 5));
|
---|
94 |
|
---|
95 | panel.add(Box.createVerticalGlue(), GBC.eol().fill(GridBagConstraints.VERTICAL));
|
---|
96 | createPreferenceTabWithScrollPane(gui, panel);
|
---|
97 | }
|
---|
98 |
|
---|
99 | @Override
|
---|
100 | public boolean ok() {
|
---|
101 | Config.getPref().put(C_HOST, gpsdHost.getText());
|
---|
102 | Config.getPref().put(C_PORT, gpsdPort.getText());
|
---|
103 | Config.getPref().put(C_SERIAL, serialDevice.getText());
|
---|
104 | Config.getPref().putBoolean(C_DISABLED, disableGPSD.isSelected());
|
---|
105 | Config.getPref().putBoolean(C_WAYOFFSET, showOffset.isSelected());
|
---|
106 | return false;
|
---|
107 | }
|
---|
108 | }
|
---|