Changeset 3847 in josm
- Timestamp:
- 2011-02-02T19:43:23+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/ImageryAdjustAction.java
r3780 r3847 146 146 return; 147 147 oldMapMode = Main.map.mapMode; 148 layer.enableOffsetServer(false); 148 149 super.actionPerformed(e); 149 150 } -
trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java
r3808 r3847 23 23 import javax.swing.JMenuItem; 24 24 import javax.swing.JSeparator; 25 import javax.swing.SwingUtilities; 25 26 26 27 import org.openstreetmap.josm.Main; 27 28 import org.openstreetmap.josm.actions.ImageryAdjustAction; 28 29 import org.openstreetmap.josm.data.ProjectionBounds; 30 import org.openstreetmap.josm.data.coor.EastNorth; 29 31 import org.openstreetmap.josm.data.imagery.ImageryInfo; 30 32 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 31 33 import org.openstreetmap.josm.data.imagery.OffsetBookmark; 32 34 import org.openstreetmap.josm.data.preferences.IntegerProperty; 35 import org.openstreetmap.josm.io.imagery.OffsetServer; 36 import org.openstreetmap.josm.io.imagery.OsmosnimkiOffsetServer; 33 37 import org.openstreetmap.josm.tools.ImageProvider; 34 38 … … 58 62 59 63 protected int sharpenLevel; 64 65 protected boolean offsetServerSupported; 66 protected boolean offsetServerUsed; 67 protected OffsetServerThread offsetServerThread; 68 69 protected OffsetServerThread createoffsetServerThread() { 70 return new OffsetServerThread(new OsmosnimkiOffsetServer( 71 OsmosnimkiOffsetServer.PROP_SERVER_URL.get())); 72 } 60 73 61 74 public ImageryLayer(ImageryInfo info) { … … 63 76 this.info = info; 64 77 this.sharpenLevel = PROP_SHARPEN_LEVEL.get(); 78 if (OffsetServer.PROP_SERVER_ENABLED.get()) { 79 offsetServerThread = createoffsetServerThread(); 80 offsetServerThread.start(); 81 } 65 82 } 66 83 … … 129 146 public void actionPerformed(ActionEvent ev) { 130 147 setOffset(b.dx, b.dy); 148 enableOffsetServer(false); 131 149 Main.main.menu.imageryMenu.refreshOffsetMenu(); 132 150 Main.map.repaint(); … … 151 169 152 170 ImageryAdjustAction adjustAction = new ImageryAdjustAction(this); 171 AbstractAction useServerOffsetAction = new AbstractAction(tr("(use server offset)")) { 172 @Override 173 public void actionPerformed(ActionEvent e) { 174 enableOffsetServer(true); 175 } 176 }; 177 178 public void enableOffsetServer(boolean enable) { 179 offsetServerUsed = enable; 180 if (offsetServerUsed && !offsetServerThread.isAlive()) { 181 offsetServerThread = createoffsetServerThread(); 182 offsetServerThread.start(); 183 } 184 } 153 185 154 186 public JMenuItem getOffsetMenuItem() { … … 160 192 public JComponent getOffsetMenuItem(JComponent subMenu) { 161 193 JMenuItem adjustMenuItem = new JMenuItem(adjustAction); 162 if (OffsetBookmark.allBookmarks.isEmpty() ) return adjustMenuItem;194 if (OffsetBookmark.allBookmarks.isEmpty() && !offsetServerSupported) return adjustMenuItem; 163 195 164 196 subMenu.add(adjustMenuItem); 197 if (offsetServerSupported) { 198 JCheckBoxMenuItem item = new JCheckBoxMenuItem(useServerOffsetAction); 199 if (offsetServerUsed) { 200 item.setSelected(true); 201 } 202 subMenu.add(item); 203 } 165 204 subMenu.add(new JSeparator()); 166 205 boolean hasBookmarks = false; … … 170 209 } 171 210 JCheckBoxMenuItem item = new JCheckBoxMenuItem(new ApplyOffsetAction(b)); 172 if (b.dx == dx && b.dy == dy ) {211 if (b.dx == dx && b.dy == dy && !offsetServerUsed) { 173 212 item.setSelected(true); 174 213 } … … 176 215 hasBookmarks = true; 177 216 } 178 return hasBookmarks? subMenu : adjustMenuItem;217 return (hasBookmarks || offsetServerSupported) ? subMenu : adjustMenuItem; 179 218 } 180 219 … … 205 244 g.drawString(text, (img.getWidth() + g.getFontMetrics().stringWidth(text)) / 2, img.getHeight()/2); 206 245 } 246 247 protected class OffsetServerThread extends Thread { 248 OffsetServer offsetServer; 249 EastNorth oldCenter = new EastNorth(Double.NaN, Double.NaN); 250 251 public OffsetServerThread(OffsetServer offsetServer) { 252 this.offsetServer = offsetServer; 253 setDaemon(true); 254 } 255 256 private void updateOffset() { 257 if (Main.map == null || Main.map.mapView == null) return; 258 EastNorth center = Main.map.mapView.getCenter(); 259 if (center.equals(oldCenter)) return; 260 oldCenter = center; 261 262 EastNorth offset = offsetServer.getOffset(getInfo(), center); 263 if (offset != null) { 264 setOffset(offset.east(),offset.north()); 265 } 266 } 267 268 @Override 269 public void run() { 270 if (!offsetServerSupported) { 271 if (!offsetServer.isLayerSupported(getInfo())) return; 272 offsetServerSupported = true; 273 } 274 offsetServerUsed = true; 275 SwingUtilities.invokeLater(new Runnable() { 276 @Override 277 public void run() { 278 Main.main.menu.imageryMenu.refreshOffsetMenu(); 279 } 280 }); 281 try { 282 while (offsetServerUsed) { 283 updateOffset(); 284 Thread.sleep(1000); 285 } 286 } catch (InterruptedException e) { 287 } 288 offsetServerUsed = false; 289 } 290 } 207 291 } -
trunk/src/org/openstreetmap/josm/gui/preferences/ImageryPreference.java
r3826 r3847 41 41 import javax.swing.JToolBar; 42 42 import javax.swing.SpinnerNumberModel; 43 import javax.swing.event.ChangeEvent; 44 import javax.swing.event.ChangeListener; 43 45 import javax.swing.event.ListSelectionEvent; 44 46 import javax.swing.event.ListSelectionListener; … … 48 50 import org.openstreetmap.josm.Main; 49 51 import org.openstreetmap.josm.data.imagery.ImageryInfo; 52 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 50 53 import org.openstreetmap.josm.data.imagery.ImageryLayerInfo; 51 54 import org.openstreetmap.josm.data.imagery.OffsetBookmark; 52 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;53 55 import org.openstreetmap.josm.gui.layer.ImageryLayer; 54 56 import org.openstreetmap.josm.gui.layer.TMSLayer; 55 57 import org.openstreetmap.josm.gui.layer.WMSLayer; 56 58 import org.openstreetmap.josm.io.imagery.HTMLGrabber; 59 import org.openstreetmap.josm.io.imagery.OffsetServer; 60 import org.openstreetmap.josm.io.imagery.OsmosnimkiOffsetServer; 57 61 import org.openstreetmap.josm.tools.ColorHelper; 58 62 import org.openstreetmap.josm.tools.GBC; … … 75 79 private JSlider fadeAmount = new JSlider(0, 100); 76 80 private JComboBox sharpen; 81 private JCheckBox useOffsetServer; 82 private JTextField offsetServerUrl; 77 83 78 84 // WMS Settings … … 147 153 p.add(btnSettingsMigration,GBC.eol().insets(0,5,0,5)); 148 154 } 155 this.useOffsetServer = new JCheckBox(tr("Use offset server: ")); 156 this.offsetServerUrl = new JTextField(); 157 this.useOffsetServer.addChangeListener(new ChangeListener() { 158 @Override 159 public void stateChanged(ChangeEvent e) { 160 offsetServerUrl.setEnabled(useOffsetServer.isSelected()); 161 } 162 }); 163 offsetServerUrl.setEnabled(useOffsetServer.isSelected()); 164 p.add(this.useOffsetServer, GBC.eol().fill(GBC.HORIZONTAL)); 165 p.add(this.offsetServerUrl, GBC.eol().fill(GBC.HORIZONTAL)); 149 166 return p; 150 167 } … … 269 286 this.fadeAmount.setValue(ImageryLayer.PROP_FADE_AMOUNT.get()); 270 287 this.sharpen.setSelectedIndex(Math.max(0, Math.min(2, ImageryLayer.PROP_SHARPEN_LEVEL.get()))); 288 this.useOffsetServer.setSelected(OffsetServer.PROP_SERVER_ENABLED.get()); 289 this.offsetServerUrl.setText(OsmosnimkiOffsetServer.PROP_SERVER_URL.get()); 271 290 272 291 // WMS Settings … … 300 319 301 320 HTMLGrabber.PROP_BROWSER.put(browser.getEditor().getItem().toString()); 321 OffsetServer.PROP_SERVER_ENABLED.put(useOffsetServer.isSelected()); 322 OsmosnimkiOffsetServer.PROP_SERVER_URL.put(offsetServerUrl.getText()); 302 323 303 324 if (TMSLayer.PROP_ADD_TO_SLIPPYMAP_CHOOSER.get() != this.addToSlippyMapChosser.isSelected()) {
Note:
See TracChangeset
for help on using the changeset viewer.