Changeset 36330 in osm for applications/editors
- Timestamp:
- 2024-09-05T10:36:28+02:00 (4 months ago)
- Location:
- applications/editors/josm/plugins/livegps/src/livegps
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/livegps/src/livegps/LiveGPSPreferences.java
r36257 r36330 6 6 import java.awt.GridBagConstraints; 7 7 import java.awt.GridBagLayout; 8 9 //import java.beans.PropertyChangeEvent; 10 //import java.beans.PropertyChangeListener; 8 11 9 12 import javax.swing.Box; … … 34 37 /* option to use specify gpsd disabling */ 35 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; 36 43 37 44 public static final String C_LIVEGPS_COLOR_POSITION = "color.livegps.position"; … … 61 68 private final JCheckBox disableGPSD = new JCheckBox(tr("Disable GPSD")); 62 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; 63 73 64 74 public LiveGPSPreferences() { … … 96 106 panel.add(showOffset, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(0, 0, 0, 5)); 97 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 98 122 panel.add(Box.createVerticalGlue(), GBC.eol().fill(GridBagConstraints.VERTICAL)); 99 123 createPreferenceTabWithScrollPane(gui, panel); 124 } 125 126 private void updateThreshold() { 127 boolean isVisible = showDistanceVisualisation.isSelected(); 128 129 threshold.setVisible(isVisible); 130 thresholdLabel.setVisible(isVisible); 100 131 } 101 132 … … 107 138 Config.getPref().putBoolean(C_DISABLED, disableGPSD.isSelected()); 108 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 } 109 147 return false; 110 148 } -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsData.java
r36322 r36330 32 32 private WayPoint waypoint; 33 33 private static final DecimalFormat offsetFormat = new DecimalFormat("0.00"); 34 private double offs = 0; 34 35 35 36 public LiveGpsData(double latitude, double longitude, float course, float speed) { … … 165 166 return getClass().getSimpleName() + "[fix=" + fix + ", lat=" + latLon.lat() 166 167 + ", long=" + latLon.lon() + ", speed=" + speed + ", course=" + course + ']'; 168 } 169 170 public void setOffset(double offs) { 171 this.offs = offs; 172 } 173 174 public double getOffset() { 175 return this.offs; 167 176 } 168 177 … … 194 203 } 195 204 if (Config.getPref().getBoolean(LiveGPSPreferences.C_WAYOFFSET, false)) { 196 doubleoffs = Geometry.getDistanceWayNode(way, n);205 offs = Geometry.getDistanceWayNode(way, n); 197 206 WaySegment ws = Geometry.getClosestWaySegment(way, n); 198 207 if (!Geometry.angleIsClockwise(ws.getFirstNode(), ws.getSecondNode(), n)) 199 offs = -offs;208 setOffset(-offs); 200 209 /* I18N: side offset and way name for livegps way display with offset */ 201 210 wayString = tr("{0} ({1})", offsetFormat.format(offs), wayString); -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsDialog.java
r36121 r36330 5 5 6 6 import java.awt.Color; 7 import java.awt.GridLayout; 7 import java.awt.BorderLayout; 8 import java.awt.GridBagLayout; 9 import java.awt.GridBagConstraints; 10 8 11 import java.awt.event.KeyEvent; 12 9 13 import java.beans.PropertyChangeEvent; 10 14 import java.beans.PropertyChangeListener; … … 13 17 import javax.swing.JPanel; 14 18 import javax.swing.SwingUtilities; 19 import javax.swing.UIManager; 15 20 16 21 import org.openstreetmap.josm.data.coor.conversion.CoordinateFormatManager; … … 43 48 private JLabel wayText; 44 49 private JPanel panel; 50 private JPanel opanel; 51 private Color backgroundColor; 45 52 private LiveGpsStatus status = new LiveGpsStatus(LiveGpsStatus.GpsStatus.CONNECTING, tr("Connecting")); 46 53 private LiveGpsStatus nmeaStatus = new LiveGpsStatus(LiveGpsStatus.GpsStatus.CONNECTING, tr("Connecting")); 47 54 private LiveGpsData data; 55 private CirclePanel circlePanel; 56 57 private static volatile LiveGpsDialog dialog; 48 58 49 59 public LiveGpsDialog(final MapFrame mapFrame) { … … 51 61 Shortcut.registerShortcut("subwindow:livegps", tr("Toggle: {0}", tr("Live GPS")), 52 62 KeyEvent.VK_G, Shortcut.ALT_CTRL_SHIFT), 100); 63 64 dialog = this; 65 66 backgroundColor = UIManager.getColor("Panel.background"); 67 68 opanel = new JPanel(); 69 opanel.setLayout(new BorderLayout()); 70 53 71 panel = new JPanel(); 54 panel.setLayout(new GridLayout(7, 2)); 55 panel.add(statusText = new JLabel(tr("Status gpsd"))); 56 panel.add(statusLabel = new JLabel()); 57 panel.add(nmeaStatusText = new JLabel(tr("Status NMEA"))); 58 panel.add(nmeaStatusLabel = new JLabel()); 59 panel.add(wayText = new JLabel(tr("Way Info"))); 60 panel.add(wayLabel = new JLabel()); 61 panel.add(latText = new JLabel(tr("Latitude"))); 62 panel.add(latLabel = new JLabel()); 63 panel.add(longText = new JLabel(tr("Longitude"))); 64 panel.add(longLabel = new JLabel()); 65 panel.add(new JLabel(tr("Speed"))); 66 panel.add(speedLabel = new JLabel()); 67 panel.add(new JLabel(tr("Course"))); 68 panel.add(courseLabel = new JLabel()); 72 73 GridBagLayout layout = new GridBagLayout(); 74 panel.setLayout(layout); 75 GridBagConstraints gbc = new GridBagConstraints(); 76 77 // first column 78 gbc.weightx = 0.3; 79 gbc.gridx = 0; 80 gbc.anchor = GridBagConstraints.WEST; 81 gbc.fill = GridBagConstraints.HORIZONTAL; 82 83 panel.add(statusText = new JLabel("Status gpsd "), gbc); 84 panel.add(nmeaStatusText = new JLabel("Status NMEA "), gbc); 85 panel.add(wayText = new JLabel("Way Info"), gbc); 86 panel.add(latText = new JLabel("Latitude"), gbc); 87 panel.add(longText = new JLabel("Longitude"), gbc); 88 panel.add(new JLabel(tr("Speed")), gbc); 89 panel.add(new JLabel(tr("Course")), gbc); 90 91 // second column 92 gbc.weightx = 0.7; 93 gbc.gridx = 1; 94 gbc.fill = GridBagConstraints.HORIZONTAL; 95 96 panel.add(statusLabel = new JLabel(), gbc); 97 panel.add(nmeaStatusLabel = new JLabel(), gbc); 98 panel.add(wayLabel = new JLabel(), gbc); 99 panel.add(latLabel = new JLabel(), gbc); 100 panel.add(longLabel = new JLabel(), gbc); 101 panel.add(speedLabel = new JLabel(), gbc); 102 panel.add(courseLabel = new JLabel(), gbc); 103 104 opanel.add(panel, BorderLayout.NORTH); 105 106 addPropertyChangeListener(new PropertyChangeListener() { 107 @Override 108 public void propertyChange(PropertyChangeEvent evt) { 109 updateCirclePanelVisibility(); 110 } 111 }); 112 113 circlePanel = new CirclePanel(0); 114 opanel.add(circlePanel, BorderLayout.CENTER); 115 69 116 setStatusVisibility(true); 70 117 if (Config.getPref().getBoolean(LiveGPSPreferences.C_WAYOFFSET, false)) { … … 74 121 wayText.setText(tr("Way Info")); 75 122 } 76 createLayout(panel, true, null); 123 createLayout(opanel, true, null); 124 } 125 126 public static void updateCirclePanelVisibility() { 127 if (dialog != null) { 128 boolean vis = Config.getPref().getBoolean(LiveGPSPreferences.C_DISTANCE_VISUALISATION, false); 129 130 dialog.circlePanel.setVisible(vis); 131 132 dialog.circlePanel.revalidate(); 133 dialog.circlePanel.repaint(); 134 } 77 135 } 78 136 … … 108 166 public void run() { 109 167 if (data.isFix()) { 110 panel.setBackground( Color.WHITE);168 panel.setBackground(backgroundColor); 111 169 ICoordinateFormat mCord = CoordinateFormatManager.getDefaultFormat(); 112 170 if (ProjectedCoordinateFormat.INSTANCE.equals(mCord)) { … … 126 184 String wayString = data.getWayInfo(); 127 185 if (!wayString.isEmpty()) { 128 wayLabel.setText(wayString); 186 wayLabel.setText(tr("<html><body width={0}>{1}</html>", (int) getWidth()*0.8, wayString)); 187 188 circlePanel.setOffset(data.getOffset()); 189 circlePanel.setBackground(backgroundColor); 190 circlePanel.validate(); 191 circlePanel.repaint(); 192 129 193 } else { 130 194 wayLabel.setText(tr("unknown")); … … 136 200 wayText.setText(tr("Way Info")); 137 201 } 202 138 203 } else { 139 204 latLabel.setText(""); … … 143 208 panel.setBackground(Color.RED); 144 209 } 145 } }); 210 } 211 212 }); 146 213 } else if ("gpsstatus".equals(evt.getPropertyName())) { 147 214 LiveGpsStatus oldStatus = status; … … 162 229 panel.setBackground(Color.RED); 163 230 } else { 164 panel.setBackground( Color.WHITE);231 panel.setBackground(backgroundColor); 165 232 } 166 233 } }); -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsPlugin.java
r36120 r36330 48 48 private LiveGpsLayer lgpslayer = null; 49 49 50 /** 51 * Main action to start data capture 52 */ 50 53 public class CaptureAction extends JosmAction { 51 54 public CaptureAction() { … … 65 68 } 66 69 70 /** 71 * Center view to newest data 72 */ 67 73 public class CenterAction extends JosmAction { 68 74 public CenterAction() { … … 82 88 } 83 89 90 /** 91 * Automatically center view to newest data 92 */ 84 93 public class AutoCenterAction extends JosmAction { 85 94 public AutoCenterAction() { -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsStatus.java
r36107 r36330 7 7 */ 8 8 public class LiveGpsStatus { 9 /** 10 * Possible status of LiveGPS data input 11 */ 9 12 public enum GpsStatus { 10 13 CONNECTING, CONNECTED, DISCONNECTED, CONNECTION_FAILED
Note:
See TracChangeset
for help on using the changeset viewer.