Changeset 29376 in osm for applications/editors/josm/plugins/imagery_offset_db/src
- Timestamp:
- 2013-03-19T20:46:10+01:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/imagery_offset_db/src/iodb
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery_offset_db/src/iodb/CalibrationObject.java
r29371 r29376 2 2 3 3 import java.util.Map; 4 import org.openstreetmap.josm.data.osm.*; 4 import org.openstreetmap.josm.data.coor.LatLon; 5 import org.openstreetmap.josm.data.osm.Node; 6 import org.openstreetmap.josm.data.osm.OsmPrimitive; 7 import org.openstreetmap.josm.data.osm.Way; 5 8 6 9 /** … … 9 12 */ 10 13 public class CalibrationObject extends ImageryOffsetBase { 11 private OsmPrimitive object; 12 private long lastUserId; 14 private LatLon[] geometry; 13 15 14 public CalibrationObject(OsmPrimitive object, long lastUserId) { 15 this.object = object; 16 this.lastUserId = lastUserId; 16 public CalibrationObject(LatLon[] geometry) { 17 this.geometry = geometry; 17 18 } 18 19 19 public CalibrationObject(OsmPrimitive object) { 20 this(object, 0); 20 public CalibrationObject( OsmPrimitive p ) { 21 if( p instanceof Node ) 22 geometry = new LatLon[] { ((Node)p).getCoor() }; 23 else if( p instanceof Way ) { 24 geometry = new LatLon[((Way)p).getNodesCount()]; 25 for( int i = 0; i < geometry.length; i++ ) 26 geometry[i] = ((Way)p).getNode(i).getCoor(); 27 } else 28 throw new IllegalArgumentException("Calibration Object can be created either from node or a way"); 21 29 } 22 30 23 public long getLastUserId() {24 return lastUserId;31 public LatLon[] getGeometry() { 32 return geometry; 25 33 } 26 34 27 public OsmPrimitive getObject() {28 return object;29 }30 31 35 @Override 32 36 public void putServerParams( Map<String, String> map ) { 33 37 super.putServerParams(map); 34 map.put("object", object instanceof Node ? "node" : "way"); 35 map.put("id", String.valueOf(object.getId())); 38 StringBuilder sb = new StringBuilder(); 39 for( int i = 0; i < geometry.length; i++ ) { 40 if( i > 0 ) 41 sb.append(','); 42 sb.append(geometry[i].lon()).append(' ').append(geometry[i].lat()); 43 } 44 map.put("geometry", sb.toString()); 36 45 } 37 46 38 47 @Override 39 48 public String toString() { 40 return "CalibrationObject{" + "object=" + object + ", lastUserId=" + lastUserId + "position=" + position + ", date=" + date + ", author=" + author + ", description=" + description + ", abandonDate=" + abandonDate + '}';49 return "CalibrationObject{" + geometry.length + "nodes; position=" + position + ", date=" + date + ", author=" + author + ", description=" + description + ", abandonDate=" + abandonDate + '}'; 41 50 } 42 51 } -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/GetImageryOffsetAction.java
r29371 r29376 9 9 import javax.swing.JOptionPane; 10 10 import org.openstreetmap.josm.Main; 11 import org.openstreetmap.josm.actions.AutoScaleAction;12 import org.openstreetmap.josm.actions.DownloadPrimitiveAction;13 11 import org.openstreetmap.josm.actions.JosmAction; 14 12 import org.openstreetmap.josm.data.coor.LatLon; 15 import org.openstreetmap.josm.data.osm.*;16 13 import org.openstreetmap.josm.data.projection.Projection; 17 14 import org.openstreetmap.josm.gui.layer.ImageryLayer; … … 70 67 Main.map.repaint(); 71 68 } else if( offset instanceof CalibrationObject ) { 72 OsmPrimitive obj = ((CalibrationObject)offset).getObject(); 73 final List<PrimitiveId> ids = new ArrayList<PrimitiveId>(1); 74 ids.add(obj); 75 DownloadPrimitiveAction.processItems(false, ids, false, true); 76 Main.worker.submit(new AfterCalibrationDownloadTask((CalibrationObject)offset)); 69 CalibrationLayer clayer = new CalibrationLayer((CalibrationObject)offset); 70 Main.map.mapView.addLayer(clayer); 71 clayer.panToCenter(); 72 if( !Main.pref.getBoolean("iodb.calibration.message", false) ) { 73 JOptionPane.showMessageDialog(Main.parent, // todo: update text 74 tr("A layer has been added with a calibration geometry. Hide data layers,\n" 75 + "find the corresponding feature on the imagery layer and move it accordingly."), 76 ImageryOffsetTools.DIALOG_TITLE, JOptionPane.INFORMATION_MESSAGE); 77 Main.pref.put("iodb.calibration.message", true); 78 } 77 79 } 78 80 } 79 81 } 80 82 81 class AfterCalibrationDownloadTask implements Runnable {82 private CalibrationObject offset;83 84 public AfterCalibrationDownloadTask( CalibrationObject offset ) {85 this.offset = offset;86 }87 88 @Override89 public void run() {90 OsmPrimitive p = getCurrentDataSet().getPrimitiveById(offset.getObject());91 if( p == null ) {92 return;93 }94 // check for last user95 if( offset.getLastUserId() > 0 ) {96 long uid = p.getUser().getId();97 Date ts = p.getTimestamp();98 if( p instanceof Way ) {99 for( Node n : ((Way)p).getNodes() ) {100 if( n.getTimestamp().after(ts) ) {101 ts = n.getTimestamp();102 uid = n.getUser().getId();103 }104 }105 }106 if( uid != offset.getLastUserId() ) {107 int result = JOptionPane.showConfirmDialog(Main.parent,108 tr("The calibration object has been changed in unknown way.\n"109 + "It may be moved or extended, thus ceasing to be a reliable mark\n"110 + "for imagery calibration. Do you want to notify the server of this?"),111 ImageryOffsetTools.DIALOG_TITLE, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);112 if( result == JOptionPane.YES_OPTION ) {113 DeprecateOffsetAction.deprecateOffset(offset);114 return;115 }116 }117 }118 Main.main.getCurrentDataSet().setSelected(p);119 AutoScaleAction.zoomTo(Collections.singleton(p));120 if( !Main.pref.getBoolean("iodb.calibration.message", false) ) {121 JOptionPane.showMessageDialog(Main.parent,122 tr("An object has been selected on the map. Find the corresponding feature\n"123 + "on the imagery layer and move that layer accordingly.\n"124 + "DO NOT touch the selected object, so it can be used by others later."),125 ImageryOffsetTools.DIALOG_TITLE, JOptionPane.INFORMATION_MESSAGE);126 Main.pref.put("iodb.calibration.message", true);127 }128 }129 }130 131 83 class DownloadOffsetsTask extends SimpleOffsetQueryTask { 132 84 private ImageryLayer layer; … … 138 90 String query = "get?lat=" + center.lat() + "&lon=" + center.lon() 139 91 + "&imagery=" + URLEncoder.encode(imagery, "UTF8"); 92 int radius = Main.pref.getInteger("iodb.radius", -1); 93 if( radius > 0 ) 94 query = query + "?radius=" + radius; 140 95 setQuery(query); 141 96 } catch( UnsupportedEncodingException e ) { -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/IODBReader.java
r29371 r29376 11 11 import javax.xml.parsers.SAXParserFactory; 12 12 import org.openstreetmap.josm.data.coor.LatLon; 13 import org.openstreetmap.josm.data.osm.Node;14 import org.openstreetmap.josm.data.osm.OsmPrimitive;15 import org.openstreetmap.josm.data.osm.Way;16 13 import org.openstreetmap.josm.io.UTFInputStreamReader; 17 14 import org.xml.sax.Attributes; … … 33 30 private IOFields fields; 34 31 private boolean parsingOffset; 32 private boolean parsingDeprecate; 35 33 private SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-MM-dd"); 36 34 … … 51 49 public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { 52 50 if( !parsingOffset ) { 53 if( qName.equals("offset") || qName.equals("calibration -object") ) {51 if( qName.equals("offset") || qName.equals("calibration") ) { 54 52 parsingOffset = true; 53 parsingDeprecate = false; 55 54 fields.clear(); 56 55 fields.position = parseLatLon(attributes); 56 fields.id = Integer.parseInt(attributes.getValue("id")); 57 57 } 58 58 } else { 59 if( qName.equals("object") ) { 60 fields.isNode = attributes.getValue("type").equals("node"); 61 } else if( qName.equals("last-user") ) { 62 fields.lastUserId = Integer.parseInt(attributes.getValue("id")); 59 if( qName.equals("node") ) { 60 fields.geometry.add(parseLatLon(attributes)); 63 61 } else if( qName.equals("imagery-position") ) { 64 62 fields.imageryPos = parseLatLon(attributes); … … 70 68 if( maxZoom != null ) 71 69 fields.maxZoom = Integer.parseInt(maxZoom); 70 } else if( qName.equals("deprecated") ) { 71 parsingDeprecate = true; 72 72 } 73 73 } … … 85 85 if( parsingOffset ) { 86 86 if( qName.equals("author") ) { 87 fields.author = accumulator.toString(); 87 if( !parsingDeprecate ) 88 fields.author = accumulator.toString(); 89 else 90 fields.abandonAuthor = accumulator.toString(); 88 91 } else if( qName.equals("description") ) { 89 92 fields.description = accumulator.toString(); 93 } else if( qName.equals("reason") && parsingDeprecate ) { 94 fields.abandonReason = accumulator.toString(); 90 95 } else if( qName.equals("date") ) { 91 96 try { 92 fields.date = dateParser.parse(accumulator.toString()); 97 if( !parsingDeprecate ) 98 fields.date = dateParser.parse(accumulator.toString()); 99 else 100 fields.abandonDate = dateParser.parse(accumulator.toString()); 93 101 } catch (ParseException ex) { 94 102 throw new SAXException(ex); 95 103 } 96 104 } else if( qName.equals("deprecated") ) { 97 try { 98 fields.abandonDate = dateParser.parse(accumulator.toString()); 99 } catch (ParseException ex) { 100 throw new SAXException(ex); 101 } 105 parsingDeprecate = false; 102 106 } else if( qName.equals("imagery") ) { 103 107 fields.imagery = accumulator.toString(); 104 } else if( qName.equals("object") ) { 105 fields.objectId = Integer.parseInt(accumulator.toString()); 106 } else if( qName.equals("offset") || qName.equals("calibration-object") ) { 108 } else if( qName.equals("offset") || qName.equals("calibration") ) { 107 109 // store offset 108 110 try { … … 136 138 137 139 private class IOFields { 140 public int id; 138 141 public LatLon position; 139 142 public Date date; … … 141 144 public String description; 142 145 public Date abandonDate; 146 public String abandonAuthor; 147 public String abandonReason; 143 148 public LatLon imageryPos; 144 149 public String imagery; 145 150 public int minZoom, maxZoom; 146 public boolean isNode; 147 public long objectId; 148 public long lastUserId; 151 public List<LatLon> geometry; 149 152 150 153 public IOFields() { … … 153 156 154 157 public void clear() { 158 id = -1; 155 159 position = null; 156 160 date = null; … … 158 162 description = null; 159 163 abandonDate = null; 164 abandonAuthor = null; 165 abandonReason = null; 160 166 imageryPos = null; 161 167 imagery = null; 162 168 minZoom = -1; 163 169 maxZoom = -1; 164 isNode = false; 165 objectId = -1; 166 lastUserId = -1; 170 geometry = new ArrayList<LatLon>(); 167 171 } 168 172 … … 170 174 if( author == null || description == null || position == null || date == null ) 171 175 throw new IllegalArgumentException("Not enought arguments to build an object"); 172 if( objectId < 0 ) { 176 ImageryOffsetBase result; 177 if( geometry.isEmpty() ) { 173 178 if( imagery == null || imageryPos == null ) 174 179 throw new IllegalArgumentException("Both imagery and imageryPos should be sepcified for the offset"); 175 ImageryOffsetresult = new ImageryOffset(imagery, imageryPos);180 result = new ImageryOffset(imagery, imageryPos); 176 181 if( minZoom >= 0 ) 177 result.setMinZoom(minZoom);182 ((ImageryOffset)result).setMinZoom(minZoom); 178 183 if( maxZoom >= 0 ) 179 result.setMaxZoom(maxZoom); 180 result.setBasicInfo(position, author, description, date); 181 result.setAbandonDate(abandonDate); 182 return result; 184 ((ImageryOffset)result).setMaxZoom(maxZoom); 183 185 } else { 184 OsmPrimitive p = isNode ? new Node(objectId) : new Way(objectId); 185 CalibrationObject result = new CalibrationObject(p, lastUserId); 186 result.setBasicInfo(position, author, description, date); 187 result.setAbandonDate(abandonDate); 188 return result; 186 result = new CalibrationObject(geometry.toArray(new LatLon[0])); 189 187 } 188 if( id >= 0 ) 189 result.setId(id); 190 result.setBasicInfo(position, author, description, date); 191 result.setDeprecated(abandonDate, abandonAuthor, abandonReason); 192 return result; 190 193 } 191 194 } -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/ImageryOffsetBase.java
r29371 r29376 37 37 } 38 38 39 public void set AbandonDate(Date abandonDate) {39 public void setDeprecated(Date abandonDate, String author, String reason) { 40 40 this.abandonDate = abandonDate; 41 this.abandonAuthor = author; 42 this.abandonReason = reason; 41 43 } 42 44 -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/ImageryOffsetTools.java
r29371 r29376 1 1 package iodb; 2 2 3 import java.text.SimpleDateFormat; 3 4 import java.util.*; 4 5 import org.openstreetmap.josm.Main; … … 18 19 public class ImageryOffsetTools { 19 20 public static final String DIALOG_TITLE = tr("Imagery Offset"); 21 public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); 20 22 21 23 public static ImageryLayer getTopImageryLayer() { -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialog.java
r29371 r29376 1 1 package iodb; 2 2 3 import java.awt.FlowLayout; 3 4 import java.awt.GridLayout; 5 import java.awt.Insets; 4 6 import java.awt.event.ActionEvent; 5 7 import java.awt.event.ActionListener; 6 import java.util.List; 8 import java.awt.event.KeyEvent; 9 import java.util.*; 7 10 import javax.swing.*; 11 import javax.swing.border.CompoundBorder; 12 import javax.swing.border.EmptyBorder; 8 13 import org.openstreetmap.josm.Main; 9 14 import static org.openstreetmap.josm.tools.I18n.tr; … … 15 20 */ 16 21 public class OffsetDialog extends JDialog implements ActionListener { 22 protected static final String PREF_CALIBRATION = "iodb.show.calibration"; 23 protected static final String PREF_DEPRECATED = "iodb.show.deprecated"; 24 17 25 private List<ImageryOffsetBase> offsets; 18 26 private ImageryOffsetBase selectedOffset; 27 private JPanel buttonPanel; 19 28 20 29 public OffsetDialog( List<ImageryOffsetBase> offsets ) { 21 super(JOptionPane.getFrameForComponent(Main.parent), tr("Imagery Offset"), ModalityType.DOCUMENT_MODAL);30 super(JOptionPane.getFrameForComponent(Main.parent), ImageryOffsetTools.DIALOG_TITLE, ModalityType.DOCUMENT_MODAL); 22 31 setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 32 setResizable(false); 23 33 this.offsets = offsets; 34 35 // make this dialog close on "escape" 36 getRootPane().registerKeyboardAction(this, 37 KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), 38 JComponent.WHEN_IN_FOCUSED_WINDOW); 24 39 } 25 40 26 41 private void prepareDialog() { 27 JPanel buttonPanel = new JPanel(new GridLayout(offsets.size() + 1, 1)); 28 for( ImageryOffsetBase offset : offsets ) { 42 Box dialog = new Box(BoxLayout.Y_AXIS); 43 updateButtonPanel(); 44 // todo: calibration objects and deprecated offsets button 45 final JCheckBox calibrationBox = new JCheckBox(tr("Hide calibration geometries")); 46 calibrationBox.setSelected(Main.pref.getBoolean(PREF_CALIBRATION, true)); 47 calibrationBox.addActionListener(new ActionListener() { 48 public void actionPerformed( ActionEvent e ) { 49 Main.pref.put(PREF_CALIBRATION, calibrationBox.isSelected()); 50 updateButtonPanel(); 51 } 52 }); 53 final JCheckBox deprecatedBox = new JCheckBox(tr("Show deprecated offsets")); 54 deprecatedBox.setSelected(Main.pref.getBoolean(PREF_DEPRECATED, false)); 55 deprecatedBox.addActionListener(new ActionListener() { 56 public void actionPerformed( ActionEvent e ) { 57 Main.pref.put(PREF_DEPRECATED, deprecatedBox.isSelected()); 58 updateButtonPanel(); 59 } 60 }); 61 Box checkBoxPanel = new Box(BoxLayout.X_AXIS); 62 checkBoxPanel.add(calibrationBox); 63 checkBoxPanel.add(deprecatedBox); 64 JButton cancelButton = new JButton("Cancel"); 65 cancelButton.addActionListener(this); 66 cancelButton.setAlignmentX(CENTER_ALIGNMENT); 67 68 dialog.add(buttonPanel); 69 dialog.add(checkBoxPanel); 70 dialog.add(cancelButton); 71 72 dialog.setBorder(new CompoundBorder(dialog.getBorder(), new EmptyBorder(5, 5, 5, 5))); 73 setContentPane(dialog); 74 pack(); 75 setLocationRelativeTo(Main.parent); 76 } 77 78 private void updateButtonPanel() { 79 List<ImageryOffsetBase> filteredOffsets = filterOffsets(); 80 if( buttonPanel == null ) 81 buttonPanel = new JPanel(); 82 buttonPanel.removeAll(); 83 buttonPanel.setLayout(new GridLayout(filteredOffsets.size(), 1, 0, 5)); 84 for( ImageryOffsetBase offset : filteredOffsets ) { 29 85 OffsetDialogButton button = new OffsetDialogButton(offset); 30 86 button.addActionListener(this); 31 /*JPopupMenu popupMenu = new JPopupMenu();87 JPopupMenu popupMenu = new JPopupMenu(); 32 88 popupMenu.add(new OffsetInfoAction(offset)); 33 89 if( !offset.isDeprecated() ) 34 90 popupMenu.add(new DeprecateOffsetAction(offset)); 35 button. add(popupMenu);*/91 button.setComponentPopupMenu(popupMenu); 36 92 buttonPanel.add(button); 37 93 } 38 // todo: calibration objects and deprecated offsets button39 JButton cancelButton = new JButton("Cancel");40 cancelButton.addActionListener(this);41 buttonPanel.add(cancelButton); // todo: proper button42 setContentPane(buttonPanel);43 94 pack(); 44 setLocationRelativeTo(Main.parent); 95 } 96 97 private List<ImageryOffsetBase> filterOffsets() { 98 boolean showCalibration = Main.pref.getBoolean(PREF_CALIBRATION, true); 99 boolean showDeprecated = Main.pref.getBoolean(PREF_DEPRECATED, false); 100 List<ImageryOffsetBase> filteredOffsets = new ArrayList<ImageryOffsetBase>(); 101 for( ImageryOffsetBase offset : offsets ) { 102 if( offset.isDeprecated() && !showDeprecated ) 103 continue; 104 if( offset instanceof CalibrationObject && !showCalibration ) 105 continue; 106 filteredOffsets.add(offset); 107 } 108 return filteredOffsets; 45 109 } 46 110 -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/StoreImageryOffsetAction.java
r29371 r29376 46 46 if( selectedObjects.size() == 1 ) { 47 47 OsmPrimitive selection = selectedObjects.iterator().next(); 48 if( selection instanceof Node || selection instanceof Way ) { 49 boolean suitable = !selection.isNewOrUndeleted() && !selection.isDeleted() && !selection.isModified(); 50 if( selection instanceof Way ) { 51 for( Node n : ((Way)selection).getNodes() ) 52 if( n.isNewOrUndeleted() || n.isDeleted() || n.isModified() ) 53 suitable = false; 54 } else if( selection.isReferredByWays(1) ) { 55 suitable = false; 56 } 57 if( suitable ) { 58 String[] options = new String[] {tr("Store calibration object"), tr("Store imagery offset"), tr("Cancel")}; 59 int result = JOptionPane.showOptionDialog(Main.parent, 60 tr("The selected object can be used as a calibration object. What do you intend to do?"), ImageryOffsetTools.DIALOG_TITLE, JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, 61 null, options, options[0]); 62 if( result == 2 || result == JOptionPane.CLOSED_OPTION ) 63 return; 64 if( result == 0 ) 65 calibration = selection; 66 } else { 67 String[] options = new String[] {tr("Store imagery offset"), tr("Cancel")}; 68 int result = JOptionPane.showOptionDialog(Main.parent, 69 tr("You have an object selected and might want to use it as a calibration object.\n" 70 + "But in this case it should be uploaded to OSM server first."), ImageryOffsetTools.DIALOG_TITLE, JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, 71 null, options, options[1]); 72 if( result == 1 || result == JOptionPane.CLOSED_OPTION ) 73 return; 74 } 48 if( (selection instanceof Node || selection instanceof Way) && !selection.isIncomplete() && !selection.isReferredByWays(1) ) { 49 String[] options = new String[] {tr("Store calibration geometry"), tr("Store imagery offset"), tr("Cancel")}; 50 int result = JOptionPane.showOptionDialog(Main.parent, 51 tr("The selected object can be used as a calibration geometry. What do you intend to do?"), 52 ImageryOffsetTools.DIALOG_TITLE, JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, 53 null, options, options[0]); 54 if( result == 2 || result == JOptionPane.CLOSED_OPTION ) 55 return; 56 if( result == 0 ) 57 calibration = selection; 75 58 } 76 59 } … … 88 71 LatLon offset = ImageryOffsetTools.getLayerOffset(layer, center); 89 72 offsetObj = new ImageryOffset(ImageryOffsetTools.getImageryID(layer), offset); 90 message = "You are registering an imagery offset.\n" 91 + "Other users in this area will be able to use it for mapping.\n" 92 + "Please make sure it is as precise as possible, and\n" 93 + "describe a region this offset is applicable to."; 73 message = "You are registering an imagery offset. Other users in this area will be able to use it for mapping.\n" 74 + "Please make sure it is as precise as possible, and describe a region this offset is applicable to."; 94 75 } else { 95 76 // register calibration object 96 77 offsetObj = new CalibrationObject(calibration); 97 message = "You are registering calibration object.\n" 98 + "It should be the most precisely positioned object,\n" 78 message = "You are registering a calibration geometry. It should be the most precisely positioned object,\n" 99 79 + "with clearly visible boundaries on various satellite imagery.\n" 100 80 + "Please describe a region where this object is located.";
Note:
See TracChangeset
for help on using the changeset viewer.