Changeset 29380 in osm for applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialog.java
- Timestamp:
- 2013-03-21T07:28:34+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialog.java
r29379 r29380 11 11 import javax.swing.border.EmptyBorder; 12 12 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.tools.GBC; 13 import org.openstreetmap.josm.gui.JosmUserIdentityManager; 14 import org.openstreetmap.josm.gui.NavigatableComponent; 15 import org.openstreetmap.josm.gui.layer.ImageryLayer; 14 16 import static org.openstreetmap.josm.tools.I18n.tr; 17 import org.openstreetmap.josm.tools.ImageProvider; 18 import org.openstreetmap.josm.tools.OpenBrowser; 15 19 16 20 /** … … 19 23 * @author zverik 20 24 */ 21 public class OffsetDialog extends JDialog implements ActionListener { 25 public class OffsetDialog extends JDialog implements ActionListener, NavigatableComponent.ZoomChangeListener { 22 26 protected static final String PREF_CALIBRATION = "iodb.show.calibration"; 23 27 protected static final String PREF_DEPRECATED = "iodb.show.deprecated"; 24 28 private static final int MAX_OFFSETS = Main.main.pref.getInteger("iodb.max.offsets", 5); 29 private static final boolean MODAL = false; // modal does not work for executing actions 25 30 26 31 private List<ImageryOffsetBase> offsets; … … 29 34 30 35 public OffsetDialog( List<ImageryOffsetBase> offsets ) { 31 super(JOptionPane.getFrameForComponent(Main.parent), ImageryOffsetTools.DIALOG_TITLE, ModalityType.DOCUMENT_MODAL); 36 super(JOptionPane.getFrameForComponent(Main.parent), ImageryOffsetTools.DIALOG_TITLE, 37 MODAL ? ModalityType.DOCUMENT_MODAL : ModalityType.MODELESS); 32 38 setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 33 //setResizable(false);39 setResizable(false); 34 40 this.offsets = offsets; 41 NavigatableComponent.addZoomChangeListener(this); 35 42 36 43 // make this dialog close on "escape" … … 61 68 checkBoxPanel.add(calibrationBox); 62 69 checkBoxPanel.add(deprecatedBox); 63 JButton cancelButton = new JButton( "Cancel");70 JButton cancelButton = new JButton(tr("Cancel"), ImageProvider.get("cancel")); 64 71 cancelButton.addActionListener(this); 65 cancelButton.setAlignmentX(CENTER_ALIGNMENT); 72 JButton helpButton = new JButton(new HelpAction()); 73 JPanel cancelPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); 74 cancelPanel.add(cancelButton); 75 cancelPanel.add(helpButton); 66 76 67 77 Box dialog = new Box(BoxLayout.Y_AXIS); 68 78 dialog.add(buttonPanel); 69 79 dialog.add(checkBoxPanel); 70 dialog.add(cancel Button);80 dialog.add(cancelPanel); 71 81 72 82 dialog.setBorder(new CompoundBorder(dialog.getBorder(), new EmptyBorder(5, 5, 5, 5))); … … 87 97 JPopupMenu popupMenu = new JPopupMenu(); 88 98 popupMenu.add(new OffsetInfoAction(offset)); 89 if( !offset.isDeprecated() ) 90 popupMenu.add(new DeprecateOffsetAction(offset)); 99 if( !offset.isDeprecated() ) { 100 DeprecateOffsetAction action = new DeprecateOffsetAction(offset); 101 action.setListener(new DeprecateOffsetListener(offset)); 102 popupMenu.add(action); 103 } 91 104 button.setComponentPopupMenu(popupMenu); 92 105 buttonPanel.add(button); … … 110 123 return filteredOffsets; 111 124 } 125 126 public void zoomChanged() { 127 for( Component c : buttonPanel.getComponents() ) { 128 if( c instanceof OffsetDialogButton ) { 129 ((OffsetDialogButton)c).updateLocation(); 130 } 131 } 132 } 112 133 113 134 public ImageryOffsetBase showDialog() { … … 118 139 } 119 140 141 public void applyOffset() { 142 if( selectedOffset instanceof ImageryOffset ) { 143 ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer(); 144 ImageryOffsetTools.applyLayerOffset(layer, (ImageryOffset)selectedOffset); 145 Main.map.repaint(); 146 if( !Main.pref.getBoolean("iodb.offset.message", false) ) { 147 JOptionPane.showMessageDialog(Main.parent, 148 tr("The topmost imagery layer has been shifted to presumably match\n" 149 + "OSM data in the area. Please check that the offset is still valid\n" 150 + "by downloading GPS tracks and comparing them and OSM data to the imagery."), 151 ImageryOffsetTools.DIALOG_TITLE, JOptionPane.INFORMATION_MESSAGE); 152 Main.pref.put("iodb.offset.message", true); 153 } 154 } else if( selectedOffset instanceof CalibrationObject ) { 155 CalibrationLayer clayer = new CalibrationLayer((CalibrationObject)selectedOffset); 156 Main.map.mapView.addLayer(clayer); 157 clayer.panToCenter(); 158 if( !Main.pref.getBoolean("iodb.calibration.message", false) ) { 159 JOptionPane.showMessageDialog(Main.parent, 160 tr("A layer has been added with a calibration geometry. Hide data layers,\n" 161 + "find the corresponding feature on the imagery layer and move it accordingly."), 162 ImageryOffsetTools.DIALOG_TITLE, JOptionPane.INFORMATION_MESSAGE); 163 Main.pref.put("iodb.calibration.message", true); 164 } 165 } 166 } 167 120 168 public void actionPerformed( ActionEvent e ) { 121 169 if( e.getSource() instanceof OffsetDialogButton ) { … … 123 171 } else 124 172 selectedOffset = null; 173 NavigatableComponent.removeZoomChangeListener(this); 125 174 setVisible(false); 175 if( !MODAL && selectedOffset != null ) 176 applyOffset(); 177 } 178 179 private class DeprecateOffsetListener implements QuerySuccessListener { 180 ImageryOffsetBase offset; 181 182 public DeprecateOffsetListener( ImageryOffsetBase offset ) { 183 this.offset = offset; 184 } 185 186 public void queryPassed() { 187 offset.setDeprecated(new Date(), JosmUserIdentityManager.getInstance().getUserName(), ""); 188 updateButtonPanel(); 189 } 190 } 191 192 class HelpAction extends AbstractAction { 193 194 public HelpAction() { 195 super(tr("Help")); 196 putValue(SMALL_ICON, ImageProvider.get("help")); 197 } 198 199 public void actionPerformed( ActionEvent e ) { 200 String base = "http://wiki.openstreetmap.org/wiki/"; 201 String page = "Imagery_Offset_Database"; 202 String lang = "RU:"; // todo: determine it 203 OpenBrowser.displayUrl(base + lang + page); 204 } 126 205 } 127 206 }
Note:
See TracChangeset
for help on using the changeset viewer.
