Changeset 36117 in osm for applications/editors/josm/plugins
- Timestamp:
- 2023-08-15T15:55:08+02:00 (17 months ago)
- Location:
- applications/editors/josm/plugins/livegps
- Files:
-
- 48 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/livegps/src/livegps/LiveGPSPreferences.java
r36111 r36117 22 22 */ 23 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 24 58 private final JTextField gpsdHost = new JTextField(30); 25 59 private final JTextField gpsdPort = new JTextField(30); … … 35 69 JPanel panel = new JPanel(new GridBagLayout()); 36 70 37 gpsdHost.setText(Config.getPref().get( LiveGpsAcquirer.C_HOST, LiveGpsAcquirer.DEFAULT_HOST));38 gpsdHost.setToolTipText(tr("Host address of gpsd, default is {0}", LiveGpsAcquirer.DEFAULT_HOST));71 gpsdHost.setText(Config.getPref().get(C_HOST, DEFAULT_HOST)); 72 gpsdHost.setToolTipText(tr("Host address of gpsd, default is {0}", DEFAULT_HOST)); 39 73 panel.add(new JLabel(tr("Host address of gpsd")), GBC.std()); 40 74 panel.add(gpsdHost, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 5)); 41 75 42 gpsdPort.setText(String.valueOf(Config.getPref().getInt( LiveGpsAcquirer.C_PORT, LiveGpsAcquirer.DEFAULT_PORT)));43 gpsdPort.setToolTipText(tr("Port number of gpsd, default is {0}", LiveGpsAcquirer.DEFAULT_PORT));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)); 44 78 panel.add(new JLabel(tr("Port number gpsd")), GBC.std()); 45 79 panel.add(gpsdPort, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 5)); 46 80 47 serialDevice.setText(Config.getPref().get( LiveGpsAcquirerNMEA.C_SERIAL));81 serialDevice.setText(Config.getPref().get(C_SERIAL)); 48 82 serialDevice.setToolTipText(tr("Serial device for direct NMEA input, does not exist by default")); 49 83 panel.add(new JLabel(tr("Serial device")), GBC.std()); 50 84 panel.add(serialDevice, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 5)); 51 85 52 disableGPSD.setSelected(Config.getPref().getBoolean( LiveGpsAcquirer.C_DISABLED));86 disableGPSD.setSelected(Config.getPref().getBoolean(C_DISABLED)); 53 87 panel.add(disableGPSD, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 5)); 54 88 … … 59 93 @Override 60 94 public boolean ok() { 61 Config.getPref().put( LiveGpsAcquirer.C_HOST, gpsdHost.getText());62 Config.getPref().put( LiveGpsAcquirer.C_PORT, gpsdPort.getText());63 Config.getPref().put( LiveGpsAcquirerNMEA.C_SERIAL, serialDevice.getText());64 Config.getPref().putBoolean( LiveGpsAcquirer.C_DISABLED, disableGPSD.isSelected());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()); 65 99 return false; 66 100 } -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsAcquirer.java
r36111 r36117 25 25 26 26 public class LiveGpsAcquirer implements Runnable { 27 /* default gpsd host address */28 public static final String DEFAULT_HOST = "localhost";29 /* default gpsd port number */30 public static final int DEFAULT_PORT = 2947;31 /* option to use specify gpsd host address */32 public static final String C_HOST = "livegps.gpsd.host";33 /* option to use specify gpsd port number */34 public static final String C_PORT = "livegps.gpsd.port";35 /* option to use specify gpsd disabling */36 public static final String C_DISABLED = "livegps.gpsd.disabled";37 27 private String gpsdHost; 38 28 private int gpsdPort; … … 55 45 public LiveGpsAcquirer() { 56 46 57 gpsdHost = Config.getPref().get( C_HOST,DEFAULT_HOST);58 gpsdPort = Config.getPref().getInt( C_PORT,DEFAULT_PORT);47 gpsdHost = Config.getPref().get(LiveGPSPreferences.C_HOST, LiveGPSPreferences.DEFAULT_HOST); 48 gpsdPort = Config.getPref().getInt(LiveGPSPreferences.C_PORT, LiveGPSPreferences.DEFAULT_PORT); 59 49 // put the settings back in to the preferences, makes keys appear. 60 Config.getPref().put(C_HOST, gpsdHost); 61 Config.getPref().putInt(C_PORT, gpsdPort); 50 Config.getPref().put(LiveGPSPreferences.C_HOST, gpsdHost); 51 Config.getPref().putInt(LiveGPSPreferences.C_PORT, gpsdPort); 62 52 } 63 53 -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsAcquirerNMEA.java
r36111 r36117 25 25 */ 26 26 public class LiveGpsAcquirerNMEA implements Runnable { 27 /* option to use serial port direct access */28 public static final String C_SERIAL = "livegps.serial.port";29 27 private String serName; 30 28 … … 42 40 */ 43 41 public LiveGpsAcquirerNMEA() { 44 serName = Config.getPref().get(C_SERIAL); 42 serName = Config.getPref().get(LiveGPSPreferences.C_SERIAL); 45 43 } 46 44 -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsData.java
r36107 r36117 5 5 6 6 import java.awt.Point; 7 import java.text.DecimalFormat; 7 8 8 9 import org.openstreetmap.josm.data.coor.LatLon; 9 10 import org.openstreetmap.josm.data.gpx.WayPoint; 11 import org.openstreetmap.josm.data.osm.DataSet; 12 import org.openstreetmap.josm.data.osm.DefaultNameFormatter; 13 import org.openstreetmap.josm.data.osm.IPrimitive; 14 import org.openstreetmap.josm.data.osm.IWay; 15 import org.openstreetmap.josm.data.osm.Node; 10 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 11 17 import org.openstreetmap.josm.data.osm.Way; 18 import org.openstreetmap.josm.data.osm.WaySegment; 12 19 import org.openstreetmap.josm.gui.MainApplication; 13 20 import org.openstreetmap.josm.gui.MapFrame; 21 import org.openstreetmap.josm.spi.preferences.Config; 22 import org.openstreetmap.josm.tools.Geometry; 14 23 15 24 /** … … 24 33 private float epx, epy; 25 34 private String wayString; 26 private Way way;27 35 private WayPoint wp; 36 private static final DecimalFormat offsetFormat = new DecimalFormat("0.00"); 28 37 29 38 public LiveGpsData(double latitude, double longitude, float course, float speed) { … … 169 178 public String getWayInfo() { 170 179 if (wayString == null) { 171 Way way = getWay(); 180 Node n = new Node(latLon); 181 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 182 Way way = Geometry.getClosestPrimitive(n, ds.getWays()); 172 183 if (way != null) { 173 StringBuilder builder = new StringBuilder(); 174 String tmp = way.get("name"); 175 if (tmp != null) { 176 builder.append(tmp); 177 } else { 178 builder.append(tr("no name")); 184 wayString = way.getDisplayName(new DefaultNameFormatter() { 185 @Override 186 protected void decorateNameWithId(StringBuilder name, IPrimitive primitive) { 187 } 188 @Override 189 protected void decorateNameWithNodes(StringBuilder name, IWay way) { 190 } 191 }); 192 if (wayString == null) { 193 wayString = tr("no name"); 179 194 } 180 tmp = way.get("ref"); 181 if (tmp != null) { 182 builder.append(" (").append(tmp).append(")"); 195 if (Config.getPref().getBoolean(LiveGPSPreferences.C_WAYOFFSET, false)) { 196 double offs = Geometry.getDistanceWayNode(way, n); 197 WaySegment ws = Geometry.getClosestWaySegment(way, n); 198 if (!Geometry.angleIsClockwise(ws.getFirstNode(), ws.getSecondNode(), n)) 199 offs = -offs; 200 /* I18N: side offset and way name for livegps way display with offset */ 201 wayString = tr("{0} ({1})", offsetFormat.format(offs), wayString); 183 202 } 184 tmp = way.get("highway");185 if (tmp != null) {186 builder.append(" {").append(tmp).append("}");187 }188 String type = "";189 tmp = way.get("tunnel");190 if (tmp != null) {191 type = type + "T";192 }193 tmp = way.get("bridge");194 if (tmp != null) {195 type = type + "B";196 }197 if (type.length() > 0) {198 builder.append(" [").append(type).append("]");199 }200 wayString = builder.toString();201 203 } else { 202 204 wayString = ""; … … 204 206 } 205 207 return wayString; 206 }207 208 /**209 * Returns the closest way to this position.210 * @return the closest way to this position.211 */212 public Way getWay() {213 MapFrame map = MainApplication.getMap();214 if (way == null && map != null && map.mapView != null) {215 Point xy = map.mapView.getPoint(getLatLon());216 way = map.mapView.getNearestWay(xy, OsmPrimitive::isUsable);217 }218 return way;219 208 } 220 209 -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsDialog.java
r36111 r36117 16 16 import org.openstreetmap.josm.data.coor.conversion.CoordinateFormatManager; 17 17 import org.openstreetmap.josm.data.coor.conversion.ICoordinateFormat; 18 import org.openstreetmap.josm.data.coor.conversion.ProjectedCoordinateFormat; 18 19 import org.openstreetmap.josm.gui.MapFrame; 19 20 import org.openstreetmap.josm.gui.dialogs.ToggleDialog; … … 34 35 private JLabel nmeaStatusLabel; 35 36 private JLabel wayLabel; 37 private JLabel latText; 36 38 private JLabel latLabel; 39 private JLabel longText; 37 40 private JLabel longLabel; 38 41 private JLabel courseLabel; … … 55 58 panel.add(new JLabel(tr("Way Info"))); 56 59 panel.add(wayLabel = new JLabel()); 57 panel.add(new JLabel(tr("Latitude"))); 60 panel.add(latText = new JLabel(tr("Latitude"))); 58 61 panel.add(latLabel = new JLabel()); 59 panel.add(new JLabel(tr("Longitude"))); 62 panel.add(longText = new JLabel(tr("Longitude"))); 60 63 panel.add(longLabel = new JLabel()); 61 64 panel.add(new JLabel(tr("Speed"))); … … 72 75 */ 73 76 private void setStatusVisibility(boolean init) { 74 boolean statusGPSDNew = !Config.getPref().getBoolean(LiveG psAcquirer.C_DISABLED);77 boolean statusGPSDNew = !Config.getPref().getBoolean(LiveGPSPreferences.C_DISABLED); 75 78 if (init || statusGPSD != statusGPSDNew) { 76 79 statusText.setVisible(statusGPSDNew); … … 78 81 statusGPSD = statusGPSDNew; 79 82 } 80 boolean statusNMEANew = !Config.getPref().get(LiveG psAcquirerNMEA.C_SERIAL).isEmpty();83 boolean statusNMEANew = !Config.getPref().get(LiveGPSPreferences.C_SERIAL).isEmpty(); 81 84 if (init || statusNMEA != statusNMEANew) { 82 85 nmeaStatusText.setVisible(statusNMEANew); … … 100 103 panel.setBackground(Color.WHITE); 101 104 ICoordinateFormat mCord = CoordinateFormatManager.getDefaultFormat(); 105 if (ProjectedCoordinateFormat.INSTANCE.equals(mCord)) { 106 latText.setText(tr("Northing")); 107 longText.setText(tr("Easting")); 108 } else { 109 latText.setText(tr("Latitude")); 110 longText.setText(tr("Longitude")); 111 } 102 112 latLabel.setText(mCord.latToString(data.getLatLon())); 103 113 longLabel.setText(mCord.lonToString(data.getLatLon())); -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsDrawHelper.java
r34619 r36117 17 17 private final LiveGpsLayer layer; 18 18 19 public static final String C_LIVEGPS_COLOR_POSITION = "color.livegps.position";20 public static final String C_LIVEGPS_COLOR_POSITION_ESTIMATE = "color.livegps.position_estimate";21 22 19 private static final CachingProperty<Color> COLOR_POSITION = 23 new NamedColorProperty(C_LIVEGPS_COLOR_POSITION, Color.RED).cached(); 20 new NamedColorProperty(LiveGPSPreferences.C_LIVEGPS_COLOR_POSITION, Color.RED).cached(); 24 21 private static final CachingProperty<Color> COLOR_POSITION_ESTIMATE = 25 new NamedColorProperty(C_LIVEGPS_COLOR_POSITION_ESTIMATE, Color.CYAN).cached(); 26 27 private static final String C_CURSOR_H = "livegps.cursor_height"; /* in pixels */ 28 private static final String C_CURSOR_W = "livegps.cursor_width"; /* in pixels */ 29 private static final String C_CURSOR_T = "livegps.cursor_thickness"; /* in pixels */ 22 new NamedColorProperty(LiveGPSPreferences.C_LIVEGPS_COLOR_POSITION_ESTIMATE, Color.CYAN).cached(); 30 23 31 24 public LiveGpsDrawHelper(LiveGpsLayer livegpslayer) { … … 48 41 Point screen = mv.getPoint(lastPoint.getCoor()); 49 42 50 int TriaHeight = Config.getPref().getInt(C_CURSOR_H, 20); 51 int TriaWidth = Config.getPref().getInt(C_CURSOR_W, 10); 52 int TriaThick = Config.getPref().getInt(C_CURSOR_T, 4); 43 int TriaHeight = Config.getPref().getInt(LiveGPSPreferences.C_CURSOR_H, 20); 44 int TriaWidth = Config.getPref().getInt(LiveGPSPreferences.C_CURSOR_W, 10); 45 int TriaThick = Config.getPref().getInt(LiveGPSPreferences.C_CURSOR_T, 4); 53 46 54 47 /* -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsLayer.java
r36111 r36117 25 25 public static final String LAYER_NAME = tr("LiveGPS layer"); 26 26 27 private static final int DEFAULT_REFRESH_INTERVAL = 250;28 private static final int DEFAULT_CENTER_INTERVAL = 5000;29 private static final int DEFAULT_CENTER_FACTOR = 80;30 private static final String oldC_REFRESH_INTERVAL = "livegps.refreshinterval"; /* in seconds */31 private static final String C_REFRESH_INTERVAL = "livegps.refresh_interval_msec"; /* in msec */32 private static final String C_CENTER_INTERVAL = "livegps.center_interval_msec"; /* in msec */33 private static final String C_CENTER_FACTOR = "livegps.center_factor" /* in percent */;34 27 private int refreshInterval; 35 28 private int centerInterval; … … 67 60 void setCurrentPosition(double lat, double lon, WayPoint wp) { 68 61 LatLon thisPos = new LatLon(lat, lon); 69 if (lastPos != null && thisPos.equalsEpsilon(lastPos, ILatLon.MAX_SERVER_PRECISION)) 62 if (lastPos != null && thisPos.equalsEpsilon(lastPos, ILatLon.MAX_SERVER_PRECISION) && 63 Config.getPref().getBoolean(LiveGPSPreferences.C_ALLPOSITIONS, false)) 70 64 // no change in position 71 65 // maybe show a "paused" cursor or some such … … 147 141 */ 148 142 private void initIntervals() { 149 if ((refreshInterval = Config.getPref().getInt(oldC_REFRESH_INTERVAL,0)) != 0) {150 refreshInterval*= 1000;151 put(oldC_REFRESH_INTERVAL, null);152 } else153 refreshInterval = Config.getPref().getInt(C_REFRESH_INTERVAL,DEFAULT_REFRESH_INTERVAL);143 refreshInterval = Config.getPref().getInt(LiveGPSPreferences.C_REFRESH_INTERVAL, LiveGPSPreferences.DEFAULT_REFRESH_INTERVAL); 144 centerInterval = Config.getPref().getInt(LiveGPSPreferences.C_CENTER_INTERVAL, LiveGPSPreferences.DEFAULT_CENTER_INTERVAL); 145 centerFactor = Config.getPref().getInt(LiveGPSPreferences.C_CENTER_FACTOR, LiveGPSPreferences.DEFAULT_CENTER_FACTOR); 146 if (centerFactor <= 1 || centerFactor >= 99) 147 centerFactor = LiveGPSPreferences.DEFAULT_CENTER_FACTOR; 154 148 155 centerInterval = Config.getPref().getInt(C_CENTER_INTERVAL, DEFAULT_CENTER_INTERVAL); 156 centerFactor = Config.getPref().getInt(C_CENTER_FACTOR, DEFAULT_CENTER_FACTOR); 157 if (centerFactor <= 1 || centerFactor >= 99) 158 centerFactor = DEFAULT_CENTER_FACTOR; 159 160 Config.getPref().putInt(C_REFRESH_INTERVAL, refreshInterval); 161 Config.getPref().putInt(C_CENTER_INTERVAL, centerInterval); 162 Config.getPref().putInt(C_CENTER_FACTOR, (int) centerFactor); 149 Config.getPref().putInt(LiveGPSPreferences.C_REFRESH_INTERVAL, refreshInterval); 150 Config.getPref().putInt(LiveGPSPreferences.C_CENTER_INTERVAL, centerInterval); 151 Config.getPref().putInt(LiveGPSPreferences.C_CENTER_FACTOR, (int) centerFactor); 163 152 164 153 /* -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsPlugin.java
r36111 r36117 179 179 assert (acquirerThread == null); 180 180 181 if (!Config.getPref().getBoolean(LiveG psAcquirer.C_DISABLED)) {181 if (!Config.getPref().getBoolean(LiveGPSPreferences.C_DISABLED)) { 182 182 183 183 acquirer = new LiveGpsAcquirer(); … … 196 196 assert (acquirerNMEAThread == null); 197 197 198 if (!Config.getPref().get(LiveG psAcquirerNMEA.C_SERIAL).isEmpty()) {198 if (!Config.getPref().get(LiveGPSPreferences.C_SERIAL).isEmpty()) { 199 199 acquirerNMEA = new LiveGpsAcquirerNMEA(); 200 200 acquirerNMEAThread = new Thread(acquirerNMEA);
Note:
See TracChangeset
for help on using the changeset viewer.