Changeset 4001 in josm
- Timestamp:
- 2011-03-22T21:31:53+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/ImageryAdjustAction.java
r3948 r4001 89 89 if (event.getID() != KeyEvent.KEY_PRESSED) return; 90 90 if (layer == null) return; 91 if (offsetDialog != null && offsetDialog.areFieldsInFocus()) return; 91 92 KeyEvent kev = (KeyEvent)event; 92 93 double dx = 0, dy = 0; … … 148 149 149 150 class ImageryOffsetDialog extends ExtendedDialog implements FocusListener { 150 public final JTextField easting = new JTextField(); 151 public final JTextField northing = new JTextField(); 151 public final JTextField tOffset = new JTextField(); 152 152 JTextField tBookmarkName = new JTextField(); 153 153 private boolean ignoreListener; … … 163 163 "You can also enter east and north offset in the {0} coordinates.\n" + 164 164 "If you want to save the offset as bookmark, enter the bookmark name below",Main.proj.toString())), GBC.eop()); 165 pnl.add(new JLabel(tr("Easting") + ": "),GBC.std()); 166 pnl.add(easting,GBC.std().fill(GBC.HORIZONTAL).insets(0, 0, 5, 0)); 167 pnl.add(new JLabel(tr("Northing") + ": "),GBC.std()); 168 pnl.add(northing,GBC.eol().fill(GBC.HORIZONTAL)); 169 pnl.add(new JLabel(tr("Bookmark name: ")),GBC.eol().insets(0,5,0,0)); 165 pnl.add(new JLabel(tr("Offset: ")),GBC.std()); 166 pnl.add(tOffset,GBC.eol().fill(GBC.HORIZONTAL).insets(0,0,0,5)); 167 pnl.add(new JLabel(tr("Bookmark name: ")),GBC.std()); 170 168 pnl.add(tBookmarkName,GBC.eol().fill(GBC.HORIZONTAL)); 171 easting.setColumns(8); 172 northing.setColumns(8); 173 easting.setText(String.valueOf(layer.getDx())); 174 northing.setText(String.valueOf(layer.getDy())); 175 easting.addFocusListener(this); 176 northing.addFocusListener(this); 169 tOffset.setColumns(16); 170 updateOffsetIntl(); 171 tOffset.addFocusListener(this); 177 172 setContent(pnl); 178 173 setupDialog(); 179 174 } 180 175 176 public boolean areFieldsInFocus() { 177 return tOffset.hasFocus(); 178 } 179 181 180 @Override 182 181 public void focusGained(FocusEvent e) { … … 186 185 public void focusLost(FocusEvent e) { 187 186 if (ignoreListener) return; 188 double dx = oldDx; 189 try { 190 dx = Double.parseDouble(easting.getText()); 191 } catch (NumberFormatException nfe) { 192 easting.setText(String.valueOf(oldDx)); 193 } 194 double dy = oldDy; 195 try { 196 dy = Double.parseDouble(northing.getText()); 197 } catch (NumberFormatException nfe) { 198 northing.setText(String.valueOf(oldDy)); 199 } 200 layer.setOffset(dx, dy); 187 String ostr = tOffset.getText(); 188 int semicolon = ostr.indexOf(';'); 189 if( semicolon >= 0 && semicolon + 1 < ostr.length() ) { 190 try { 191 // here we assume that Double.parseDouble() needs '.' as a decimal separator 192 String easting = ostr.substring(0, semicolon).trim().replace(',', '.'); 193 String northing = ostr.substring(semicolon + 1).trim().replace(',', '.'); 194 double dx = Double.parseDouble(easting); 195 double dy = Double.parseDouble(northing); 196 layer.setOffset(dx, dy); 197 } catch (NumberFormatException nfe) { 198 // we repaint offset numbers in any case 199 } 200 } 201 updateOffsetIntl(); 201 202 Main.map.repaint(); 202 203 } … … 204 205 public void updateOffset() { 205 206 ignoreListener = true; 206 easting.setText(String.valueOf(layer.getDx())); 207 northing.setText(String.valueOf(layer.getDy())); 207 updateOffsetIntl(); 208 208 ignoreListener = false; 209 } 210 211 public void updateOffsetIntl() { 212 // Support projections with very small numbers (e.g. 4326) 213 int precision = Main.proj.getDefaultZoomInPPD() >= 1.0 ? 2 : 7; 214 // US locale to force decimal separator to be '.' 215 tOffset.setText(new java.util.Formatter(java.util.Locale.US).format( 216 "%1." + precision + "f; %1." + precision + "f", 217 layer.getDx(), layer.getDy()).toString()); 209 218 } 210 219
Note:
See TracChangeset
for help on using the changeset viewer.