source: osm/applications/editors/josm/plugins/livegps/src/livegps/LiveGPSPreferences.java

Last change on this file was 36330, checked in by stoecker, 6 months ago

add target display, patch by Pauline Thiele

File size: 7.4 KB
Line 
1// License: Public Domain. For details, see LICENSE file.
2package livegps;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.GridBagConstraints;
7import java.awt.GridBagLayout;
8
9//import java.beans.PropertyChangeEvent;
10//import java.beans.PropertyChangeListener;
11
12import javax.swing.Box;
13import javax.swing.JCheckBox;
14import javax.swing.JLabel;
15import javax.swing.JPanel;
16import javax.swing.JTextField;
17
18import org.openstreetmap.josm.gui.preferences.DefaultTabPreferenceSetting;
19import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
20import org.openstreetmap.josm.spi.preferences.Config;
21import org.openstreetmap.josm.tools.GBC;
22
23/**
24 * Preferences of LiveGPS
25 */
26public class LiveGPSPreferences extends DefaultTabPreferenceSetting {
27 /* option to use serial port direct access */
28 public static final String C_SERIAL = "livegps.serial.port";
29 /* default gpsd host address */
30 public static final String DEFAULT_HOST = "localhost";
31 /* option to use specify gpsd host address */
32 public static final String C_HOST = "livegps.gpsd.host";
33 /* default gpsd port number */
34 public static final int DEFAULT_PORT = 2947;
35 /* option to use specify gpsd port number */
36 public static final String C_PORT = "livegps.gpsd.port";
37 /* option to use specify gpsd disabling */
38 public static final String C_DISABLED = "livegps.gpsd.disabled";
39 /* option to use distance visualisation and set threshold */
40 public static final String C_DISTANCE_VISUALISATION = "livegps.distance_visualisation";
41 public static final String C_OFFSET_THRESHOLD = "livegps.offset_threshold";
42 public static final double DEFAULT_THRESHOLD = 0.3;
43
44 public static final String C_LIVEGPS_COLOR_POSITION = "color.livegps.position";
45 public static final String C_LIVEGPS_COLOR_POSITION_ESTIMATE = "color.livegps.position_estimate";
46
47 /* options below are hidden/expert options */
48
49 /* option to use even duplicate positions (default false) */
50 public static final String C_ALLPOSITIONS = "livegps.positions.all";
51 /* option to show offset to next way (default false) */
52 public static final String C_WAYOFFSET = "livegps.way.offset";
53
54 public static final String C_CURSOR_H = "livegps.cursor_height"; /* in pixels */
55 public static final String C_CURSOR_W = "livegps.cursor_width"; /* in pixels */
56 public static final String C_CURSOR_T = "livegps.cursor_thickness"; /* in pixels */
57
58 public static final int DEFAULT_REFRESH_INTERVAL = 250;
59 public static final String C_REFRESH_INTERVAL = "livegps.refresh_interval_msec"; /* in msec */
60 public static final int DEFAULT_CENTER_INTERVAL = 5000;
61 public static final String C_CENTER_INTERVAL = "livegps.center_interval_msec"; /* in msec */
62 public static final int DEFAULT_CENTER_FACTOR = 80;
63 public static final String C_CENTER_FACTOR = "livegps.center_factor" /* in percent */;
64
65 private final JTextField gpsdHost = new JTextField(30);
66 private final JTextField gpsdPort = new JTextField(30);
67 private final JTextField serialDevice = new JTextField(30);
68 private final JCheckBox disableGPSD = new JCheckBox(tr("Disable GPSD"));
69 private final JCheckBox showOffset = new JCheckBox(tr("Show Distance to nearest way"));
70 private final JCheckBox showDistanceVisualisation = new JCheckBox(tr("Show distance visualisation"));
71 private final JTextField threshold = new JTextField(5);
72 private JLabel thresholdLabel;
73
74 public LiveGPSPreferences() {
75 super("dialogs/livegps", tr("LiveGPS settings"), tr("Here you can change some preferences of LiveGPS plugin"));
76 }
77
78 @Override
79 public void addGui(PreferenceTabbedPane gui) {
80 JPanel panel = new JPanel(new GridBagLayout());
81
82 gpsdHost.setText(Config.getPref().get(C_HOST, DEFAULT_HOST));
83 gpsdHost.setToolTipText(tr("Host address of gpsd, default is {0}", DEFAULT_HOST));
84 panel.add(new JLabel(tr("Host address of gpsd")), GBC.std());
85 panel.add(gpsdHost, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 5));
86
87 gpsdPort.setText(String.valueOf(Config.getPref().getInt(C_PORT, DEFAULT_PORT)));
88 gpsdPort.setToolTipText(tr("Port number of gpsd, default is {0}", DEFAULT_PORT));
89 panel.add(new JLabel(tr("Port number gpsd")), GBC.std());
90 panel.add(gpsdPort, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 5));
91
92 disableGPSD.setSelected(Config.getPref().getBoolean(C_DISABLED, false));
93 panel.add(disableGPSD, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(0, 0, 0, 5));
94
95 serialDevice.setText(Config.getPref().get(C_SERIAL));
96 serialDevice.setToolTipText(tr("Serial device for direct NMEA input, does not exist by default.</html>"));
97 panel.add(new JLabel(tr("Serial device")), GBC.std());
98 panel.add(serialDevice, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 5));
99 /* I18n : {0} to {3} is like /dev/ttyACM<b>x</b>, {4} and {5} are COM1 and COM9 */
100 panel.add(new JLabel(tr("<html>For Linux {0}, {1}, {2} or {3} (<b>x</b> means any number beginning with 0).<br>"
101 +"For Windows {4} to {5} (COM ports bigger than 9 wont work).</html>", "/dev/ttyS<b>x</b>",
102 "/dev/ttyACM<b>x</b>", "/dev/ttyUSB<b>x</b>", "/dev/rfcomm<b>x</b>", "COM1", "COM9")),
103 GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(10, 0, 0, 5));
104
105 showOffset.setSelected(Config.getPref().getBoolean(C_WAYOFFSET, false));
106 panel.add(showOffset, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(0, 0, 0, 5));
107
108 showDistanceVisualisation.setSelected(Config.getPref().getBoolean(C_DISTANCE_VISUALISATION, false));
109 panel.add(showDistanceVisualisation, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(0, 0, 0, 5));
110
111 threshold.setText(String.valueOf(Config.getPref().getDouble(C_OFFSET_THRESHOLD, DEFAULT_THRESHOLD)));
112 threshold.setToolTipText(tr("Threshold, default is {0}", DEFAULT_THRESHOLD));
113 thresholdLabel = new JLabel(tr("Threshold"));
114 panel.add(thresholdLabel, GBC.std());
115 panel.add(threshold, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 5));
116 threshold.setVisible(false);
117 thresholdLabel.setVisible(false);
118
119 updateThreshold(); // beim Start
120 showDistanceVisualisation.addActionListener(e -> updateThreshold()); // wenn sich was ändert
121
122 panel.add(Box.createVerticalGlue(), GBC.eol().fill(GridBagConstraints.VERTICAL));
123 createPreferenceTabWithScrollPane(gui, panel);
124 }
125
126 private void updateThreshold() {
127 boolean isVisible = showDistanceVisualisation.isSelected();
128
129 threshold.setVisible(isVisible);
130 thresholdLabel.setVisible(isVisible);
131 }
132
133 @Override
134 public boolean ok() {
135 Config.getPref().put(C_HOST, gpsdHost.getText());
136 Config.getPref().put(C_PORT, gpsdPort.getText());
137 Config.getPref().put(C_SERIAL, serialDevice.getText());
138 Config.getPref().putBoolean(C_DISABLED, disableGPSD.isSelected());
139 Config.getPref().putBoolean(C_WAYOFFSET, showOffset.isSelected());
140 boolean oldVal = Config.getPref().getBoolean(C_DISTANCE_VISUALISATION, false);
141 boolean newVal = showDistanceVisualisation.isSelected();
142 Config.getPref().putBoolean(C_DISTANCE_VISUALISATION, newVal);
143 Config.getPref().put(C_OFFSET_THRESHOLD, threshold.getText());
144 if (oldVal != newVal) {
145 LiveGpsDialog.updateCirclePanelVisibility();
146 }
147 return false;
148 }
149}
Note: See TracBrowser for help on using the repository browser.