Changeset 29384 in osm for applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialog.java
- Timestamp:
- 2013-03-22T22:18:26+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialog.java
r29382 r29384 5 5 import java.awt.event.ActionListener; 6 6 import java.awt.event.KeyEvent; 7 import java.io.IOException; 8 import java.net.HttpURLConnection; 9 import java.net.URL; 7 10 import java.util.*; 8 11 import java.util.List; … … 17 20 import org.openstreetmap.josm.gui.layer.ImageryLayer; 18 21 import org.openstreetmap.josm.gui.layer.MapViewPaintable; 22 import org.openstreetmap.josm.tools.*; 19 23 import static org.openstreetmap.josm.tools.I18n.tr; 20 import org.openstreetmap.josm.tools.ImageProvider;21 import org.openstreetmap.josm.tools.OpenBrowser;22 24 23 25 /** 24 26 * The dialog which presents a choice between imagery align options. 25 27 * 26 * @author zverik 28 * @author Zverik 29 * @license WTFPL 27 30 */ 28 31 public class OffsetDialog extends JDialog implements ActionListener, NavigatableComponent.ZoomChangeListener, MapViewPaintable { … … 30 33 protected static final String PREF_DEPRECATED = "iodb.show.deprecated"; 31 34 private static final int MAX_OFFSETS = Main.main.pref.getInteger("iodb.max.offsets", 5); 32 private static final boolean MODAL = false; // modal does not work for executing actions 35 36 /** 37 * Whether to create a modal frame. It turns out, modal dialogs 38 * block swing worker thread, so offset deprecation, for example, takes 39 * place only after the dialog is closed. Very inconvenient. 40 */ 41 private static final boolean MODAL = false; 33 42 34 43 private List<ImageryOffsetBase> offsets; … … 36 45 private JPanel buttonPanel; 37 46 47 /** 48 * Initialize the dialog and install listeners. 49 * @param offsets The list of offset to choose from. 50 */ 38 51 public OffsetDialog( List<ImageryOffsetBase> offsets ) { 39 52 super(JOptionPane.getFrameForComponent(Main.parent), ImageryOffsetTools.DIALOG_TITLE, … … 50 63 } 51 64 65 /** 66 * Creates the GUI. 67 */ 52 68 private void prepareDialog() { 53 69 updateButtonPanel(); … … 89 105 } 90 106 107 /** 108 * As the name states, this method updates the button panel. It is called 109 * when a user clicks filtering checkboxes or deprecates an offset. 110 */ 91 111 private void updateButtonPanel() { 92 112 List<ImageryOffsetBase> filteredOffsets = filterOffsets(); … … 112 132 } 113 133 134 /** 135 * Make a filtered offset list out of the full one. Takes into 136 * account both checkboxes. 137 */ 114 138 private List<ImageryOffsetBase> filterOffsets() { 115 139 boolean showCalibration = Main.pref.getBoolean(PREF_CALIBRATION, true); … … 128 152 } 129 153 154 /** 155 * This listener method is called when a user pans or zooms the map. 156 * It does nothing, only passes the event to all displayed offset buttons. 157 */ 130 158 public void zoomChanged() { 131 159 for( Component c : buttonPanel.getComponents() ) { … … 136 164 } 137 165 166 /** 167 * Draw dots on the map where offsets are located. I doubt it has practical 168 * value, but looks nice. 169 */ 138 170 public void paint( Graphics2D g, MapView mv, Bounds bbox ) { 139 171 if( offsets == null ) … … 152 184 } 153 185 186 /** 187 * Display the dialog and get the return value is case of a modal frame. 188 * Creates GUI, install a temporary map layer (see {@link #paint} and 189 * shows the window. 190 * @return Null for a non-modal dialog, the selected offset 191 * (or, again, a null value) otherwise. 192 */ 154 193 public ImageryOffsetBase showDialog() { 155 194 // todo: add a temporary layer showing all offsets … … 164 203 } 165 204 205 /** 206 * This is a listener method for all buttons (except "Help"). 207 * It assigns a selected offset value and closes the dialog. 208 * If the dialog wasn't modal, it applies the offset immediately. 209 * Should it apply the offset either way? Probably. 210 * @see #applyOffset() 211 */ 212 public void actionPerformed( ActionEvent e ) { 213 if( e.getSource() instanceof OffsetDialogButton ) { 214 selectedOffset = ((OffsetDialogButton)e.getSource()).getOffset(); 215 } else 216 selectedOffset = null; 217 NavigatableComponent.removeZoomChangeListener(this); 218 setVisible(false); 219 if( !MODAL ) { 220 Main.map.mapView.removeTemporaryLayer(this); 221 Main.map.mapView.repaint(); 222 if( selectedOffset != null ) 223 applyOffset(); 224 } 225 } 226 227 228 /** 229 * Either applies imagery offset or adds a calibration geometry layer. 230 * If the offset for each type was chosen for the first time ever, 231 * it displays an informational message. 232 */ 166 233 public void applyOffset() { 167 234 if( selectedOffset instanceof ImageryOffset ) { … … 191 258 } 192 259 193 public void actionPerformed( ActionEvent e ) { 194 if( e.getSource() instanceof OffsetDialogButton ) { 195 selectedOffset = ((OffsetDialogButton)e.getSource()).getOffset(); 196 } else 197 selectedOffset = null; 198 NavigatableComponent.removeZoomChangeListener(this); 199 setVisible(false); 200 if( !MODAL ) { 201 Main.map.mapView.removeTemporaryLayer(this); 202 Main.map.mapView.repaint(); 203 if( selectedOffset != null ) 204 applyOffset(); 205 } 206 } 207 260 /** 261 * A lisntener for successful deprecations. 262 */ 208 263 private class DeprecateOffsetListener implements QuerySuccessListener { 209 264 ImageryOffsetBase offset; 210 265 266 /** 267 * Initialize the listener with an offset. 268 */ 211 269 public DeprecateOffsetListener( ImageryOffsetBase offset ) { 212 270 this.offset = offset; 213 271 } 214 272 273 /** 274 * Remove the deprecated offset from the offsets list. Then rebuild the button panel. 275 */ 215 276 public void queryPassed() { 216 277 offset.setDeprecated(new Date(), JosmUserIdentityManager.getInstance().getUserName(), ""); … … 219 280 } 220 281 282 /** 283 * Opens a web browser with the wiki page in user's language. 284 */ 221 285 class HelpAction extends AbstractAction { 222 286 … … 227 291 228 292 public void actionPerformed( ActionEvent e ) { 229 String base = "http://wiki.openstreetmap.org/wiki/"; 293 String base = Main.pref.get("url.openstreetmap-wiki", "http://wiki.openstreetmap.org/wiki/"); 294 String lang = LanguageInfo.getWikiLanguagePrefix(); 230 295 String page = "Imagery_Offset_Database"; 231 String lang = "RU:"; // todo: determine it 296 try { 297 // this logic was snatched from {@link org.openstreetmap.josm.gui.dialogs.properties.PropertiesDialog.HelpAction} 298 HttpURLConnection conn = Utils.openHttpConnection(new URL(base + lang + page)); 299 conn.setConnectTimeout(Main.pref.getInteger("socket.timeout.connect", 10) * 1000); 300 if( conn.getResponseCode() != 200 ) { 301 conn.disconnect(); 302 lang = ""; 303 } 304 } catch( IOException ex ) { 305 lang = ""; 306 } 232 307 OpenBrowser.displayUrl(base + lang + page); 233 308 }
Note:
See TracChangeset
for help on using the changeset viewer.
