| 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 |
|
|---|
| 63 | public LiveGPSPreferences() {
|
|---|
| 64 | super("dialogs/livegps", tr("LiveGPS settings"), tr("Here you can change some preferences of LiveGPS plugin"));
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | @Override
|
|---|
| 68 | public void addGui(PreferenceTabbedPane gui) {
|
|---|
| 69 | JPanel panel = new JPanel(new GridBagLayout());
|
|---|
| 70 |
|
|---|
| 71 | gpsdHost.setText(Config.getPref().get(C_HOST, DEFAULT_HOST));
|
|---|
| 72 | gpsdHost.setToolTipText(tr("Host address of gpsd, default is {0}", DEFAULT_HOST));
|
|---|
| 73 | panel.add(new JLabel(tr("Host address of gpsd")), GBC.std());
|
|---|
| 74 | panel.add(gpsdHost, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 5));
|
|---|
| 75 |
|
|---|
| 76 | gpsdPort.setText(String.valueOf(Config.getPref().getInt(C_PORT, DEFAULT_PORT)));
|
|---|
| 77 | gpsdPort.setToolTipText(tr("Port number of gpsd, default is {0}", DEFAULT_PORT));
|
|---|
| 78 | panel.add(new JLabel(tr("Port number gpsd")), GBC.std());
|
|---|
| 79 | panel.add(gpsdPort, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 5));
|
|---|
| 80 |
|
|---|
| 81 | serialDevice.setText(Config.getPref().get(C_SERIAL));
|
|---|
| 82 | serialDevice.setToolTipText(tr("Serial device for direct NMEA input, does not exist by default"));
|
|---|
| 83 | panel.add(new JLabel(tr("Serial device")), GBC.std());
|
|---|
| 84 | panel.add(serialDevice, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 5));
|
|---|
| 85 |
|
|---|
| 86 | disableGPSD.setSelected(Config.getPref().getBoolean(C_DISABLED));
|
|---|
| 87 | panel.add(disableGPSD, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 5));
|
|---|
| 88 |
|
|---|
| 89 | panel.add(Box.createVerticalGlue(), GBC.eol().fill(GridBagConstraints.VERTICAL));
|
|---|
| 90 | createPreferenceTabWithScrollPane(gui, panel);
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | @Override
|
|---|
| 94 | public boolean ok() {
|
|---|
| 95 | Config.getPref().put(C_HOST, gpsdHost.getText());
|
|---|
| 96 | Config.getPref().put(C_PORT, gpsdPort.getText());
|
|---|
| 97 | Config.getPref().put(C_SERIAL, serialDevice.getText());
|
|---|
| 98 | Config.getPref().putBoolean(C_DISABLED, disableGPSD.isSelected());
|
|---|
| 99 | return false;
|
|---|
| 100 | }
|
|---|
| 101 | }
|
|---|