Changeset 29377 in osm for applications
- Timestamp:
- 2013-03-20T08:05:48+01:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/imagery_offset_db/src/iodb
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery_offset_db/src/iodb/CalibrationLayer.java
r29376 r29377 87 87 @Override 88 88 public String getToolTipText() { 89 return "A calibration " + getGeometryType() + " by " + obj.getAuthor(); 89 return "A " + (obj.isDeprecated() ? "deprecated " : "") + "calibration " + OffsetInfoAction.getGeometryType(obj) 90 + " by " + obj.getAuthor(); 90 91 } 91 92 92 93 @Override 93 94 public Object getInfoComponent() { 94 String info = "A calibration " + getGeometryType() + "\n" 95 + "Created by " + obj.getAuthor() + " on " + ImageryOffsetTools.DATE_FORMAT.format(obj.getDate()) + "\n" 96 + "Description: " + obj.getDescription(); 97 if( obj.isDeprecated() ) { 98 info += "\nThis geometry was marked obsolete\n" 99 + "by " + obj.getAbandonAuthor() + " on " + ImageryOffsetTools.DATE_FORMAT.format(obj.getAbandonDate()) + "\n" 100 + "Reason: " + obj.getAbandonReason(); 101 } 102 return info; 103 } 104 105 private String getGeometryType() { 106 int n = obj.getGeometry().length; 107 if( n == 1 ) 108 return "point"; 109 else if( n > 1 && !obj.getGeometry()[0].equals(obj.getGeometry()[n-1]) ) 110 return "path"; 111 else if( n > 1 && obj.getGeometry()[0].equals(obj.getGeometry()[n-1]) ) 112 return "polygon"; 113 else 114 return "geometry"; 95 return OffsetInfoAction.getInformationObject(obj); 115 96 } 116 97 -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/DeprecateOffsetAction.java
r29371 r29377 30 30 return; 31 31 32 String desc = offset instanceof ImageryOffset ? "imagery offset is wrong" 33 : "calibration geometry is aligned badly"; 32 34 if( JOptionPane.showConfirmDialog(Main.parent, 33 tr("Warning: deprecation is irreversible"), // todo: expand35 tr("Warning: deprecation is basically irreversible!\nAre you sure this " + desc + "?"), 34 36 ImageryOffsetTools.DIALOG_TITLE, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) != JOptionPane.YES_OPTION ) { 35 37 return; … … 46 48 47 49 String message = "Please enter the reason why you mark this " 48 + (offset instanceof ImageryOffset ? "imagery offset" : "calibraion object") + " as deprecated:"; 49 String reason = null; 50 boolean iterated = false; 51 while( reason == null ) { 52 reason = JOptionPane.showInputDialog(Main.parent, message, ImageryOffsetTools.DIALOG_TITLE, JOptionPane.PLAIN_MESSAGE); 53 if( reason == null || reason.length() == 0 ) { 54 return; 55 } 56 if( reason.length() < 3 || reason.length() > 200 ) { 57 reason = null; 58 if( !iterated ) { 59 message = message + "\n" + tr("Reason text should be 3 to 200 letters long."); 60 iterated = true; 61 } 62 } 63 } 50 + (offset instanceof ImageryOffset ? "imagery offset" : "calibraion geometry") + " as deprecated:"; 51 String reason = StoreImageryOffsetAction.queryDescription(message); 52 if( reason == null ) 53 return; 64 54 65 55 try { -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/GetImageryOffsetAction.java
r29376 r29377 71 71 clayer.panToCenter(); 72 72 if( !Main.pref.getBoolean("iodb.calibration.message", false) ) { 73 JOptionPane.showMessageDialog(Main.parent, // todo: update text73 JOptionPane.showMessageDialog(Main.parent, 74 74 tr("A layer has been added with a calibration geometry. Hide data layers,\n" 75 75 + "find the corresponding feature on the imagery layer and move it accordingly."), -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/ImageryOffsetPlugin.java
r29371 r29377 1 1 package iodb; 2 2 3 import java.awt.event.KeyEvent; 4 import javax.swing.JMenu; 3 5 import org.openstreetmap.josm.Main; 4 6 import org.openstreetmap.josm.plugins.Plugin; 5 7 import org.openstreetmap.josm.plugins.PluginInformation; 8 import static org.openstreetmap.josm.tools.I18n.marktr; 6 9 7 10 /** … … 20 23 storeAction = new StoreImageryOffsetAction(); 21 24 22 // todo: correct menu 23 Main.main.menu.viewMenu.addSeparator(); 24 Main.main.menu.viewMenu.add(getAction); 25 Main.main.menu.viewMenu.add(storeAction); 25 JMenu offsetMenu = Main.main.menu.addMenu(marktr("Offset"), KeyEvent.VK_O, 6, "help"); 26 offsetMenu.add(getAction); 27 offsetMenu.add(storeAction); 26 28 27 29 // todo: add a button on toolbar -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/ImageryOffsetTools.java
r29376 r29377 19 19 public class ImageryOffsetTools { 20 20 public static final String DIALOG_TITLE = tr("Imagery Offset"); 21 public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");22 21 23 22 public static ImageryLayer getTopImageryLayer() { … … 42 41 Projection proj = Main.getProjection(); 43 42 EastNorth offsetCenter = proj.latlon2eastNorth(center); 44 EastNorth centerOffset = offsetCenter.add(-layer.getDx(), -layer.getDy()); // todo: add or substract?43 EastNorth centerOffset = offsetCenter.add(-layer.getDx(), -layer.getDy()); 45 44 LatLon offsetLL = proj.eastNorth2latlon(centerOffset); 46 45 return offsetLL; … … 48 47 49 48 public static void applyLayerOffset( ImageryLayer layer, ImageryOffset offset ) { 49 double[] dxy = calculateOffset(offset); 50 layer.setOffset(dxy[0], dxy[1]); 51 } 52 53 /** 54 * Calculate dx and dy for imagery offset. 55 * @return [dx, dy] 56 */ 57 public static double[] calculateOffset( ImageryOffset offset ) { 50 58 Projection proj = Main.getProjection(); 51 59 EastNorth center = proj.latlon2eastNorth(offset.getPosition()); 52 60 EastNorth offsetPos = proj.latlon2eastNorth(offset.getImageryPos()); 53 layer.setOffset(center.getX() - offsetPos.getX(), center.getY() - offsetPos.getY());61 return new double[] { center.getX() - offsetPos.getX(), center.getY() - offsetPos.getY() }; 54 62 } 55 63 -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialog.java
r29376 r29377 22 22 protected static final String PREF_CALIBRATION = "iodb.show.calibration"; 23 23 protected static final String PREF_DEPRECATED = "iodb.show.deprecated"; 24 private static final int MAX_OFFSETS = Main.main.pref.getInteger("iodb.max.offsets", 5); 24 25 25 26 private List<ImageryOffsetBase> offsets; … … 42 43 Box dialog = new Box(BoxLayout.Y_AXIS); 43 44 updateButtonPanel(); 44 // todo: calibration objects and deprecated offsets button 45 final JCheckBox calibrationBox = new JCheckBox(tr("Hide calibration geometries")); 45 final JCheckBox calibrationBox = new JCheckBox(tr("Calibration geometries")); 46 46 calibrationBox.setSelected(Main.pref.getBoolean(PREF_CALIBRATION, true)); 47 47 calibrationBox.addActionListener(new ActionListener() { … … 51 51 } 52 52 }); 53 final JCheckBox deprecatedBox = new JCheckBox(tr(" Show deprecated offsets"));53 final JCheckBox deprecatedBox = new JCheckBox(tr("Deprecated offsets")); 54 54 deprecatedBox.setSelected(Main.pref.getBoolean(PREF_DEPRECATED, false)); 55 55 deprecatedBox.addActionListener(new ActionListener() { … … 92 92 buttonPanel.add(button); 93 93 } 94 // buttonPanel.setMinimumSize(buttonPanel.getPreferredSize()); 94 95 pack(); 95 96 } … … 105 106 continue; 106 107 filteredOffsets.add(offset); 108 if( filteredOffsets.size() >= MAX_OFFSETS ) 109 break; 107 110 } 108 111 return filteredOffsets; -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialogButton.java
r29371 r29377 1 1 package iodb; 2 2 3 import java.awt.Component; 4 import java.awt.Dimension; 5 import java.awt.Graphics; 6 import javax.swing.Icon; 7 import javax.swing.ImageIcon; 3 8 import javax.swing.JButton; 9 import org.openstreetmap.josm.gui.layer.ImageryLayer; 10 import org.openstreetmap.josm.tools.ImageProvider; 4 11 5 12 /** … … 11 18 12 19 private ImageryOffsetBase offset; 20 private double offsetLength; 21 private double distance; 22 private double direction; 13 23 14 24 public OffsetDialogButton( ImageryOffsetBase offset ) { 15 super(offset.getDescription() + " (" + Math.round(offset.getPosition().greatCircleDistance(ImageryOffsetTools.getMapCenter())) + " m)"); 25 super(); 26 // todo: fix layout 27 setMinimumSize(new Dimension(500, 80)); 28 setMaximumSize(new Dimension(500, 140)); 29 setText("<html>" 30 + Math.round(offset.getPosition().greatCircleDistance(ImageryOffsetTools.getMapCenter())) + " m: " 31 + offset.getDescription() + "</html>"); 32 setIcon(new OffsetIcon(offset)); 16 33 this.offset = offset; 34 35 offsetLength = offset instanceof ImageryOffset ? getLengthAndDirection((ImageryOffset)offset)[0] : 0.0; 36 // todo: layout, info, map distance and direction 17 37 } 18 38 … … 20 40 return offset; 21 41 } 22 42 43 /* @Override 44 public Dimension getPreferredSize() { 45 return new Dimension(500, super.getPreferredSize().height); 46 }*/ 47 48 private double[] getLengthAndDirection( ImageryOffset offset ) { 49 ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer(); 50 double[] dxy = layer == null ? new double[] {0.0, 0.0} : new double[] {layer.getDx(), layer.getDy()}; 51 return OffsetInfoAction.getLengthAndDirection((ImageryOffset)offset, dxy[0], dxy[1]); 52 } 53 54 class OffsetIcon implements Icon { 55 private boolean isDeprecated; 56 private boolean isCalibration; 57 private double direction; 58 private double length; 59 private ImageIcon background; 60 61 public OffsetIcon( ImageryOffsetBase offset ) { 62 isDeprecated = offset.isDeprecated(); 63 isCalibration = offset instanceof CalibrationObject; 64 if( offset instanceof ImageryOffset ) { 65 background = ImageProvider.get("offset"); 66 ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer(); 67 double[] dxy = layer == null ? new double[] {0.0, 0.0} : new double[] { layer.getDx(), layer.getDy() }; 68 double[] ld = OffsetInfoAction.getLengthAndDirection((ImageryOffset)offset, dxy[0], dxy[1]); 69 length = ld[0]; 70 direction = ld[1]; 71 } else { 72 background = ImageProvider.get("calibration"); 73 } 74 } 75 76 public void paintIcon( Component c, Graphics g, int x, int y ) { 77 background.paintIcon(c, g, x, y); 78 // todo: draw an arrow 79 // todo: apply deprecation 80 } 81 82 public int getIconWidth() { 83 return background.getIconWidth(); 84 } 85 86 public int getIconHeight() { 87 return background.getIconHeight(); 88 } 89 } 23 90 } -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetInfoAction.java
r29371 r29377 2 2 3 3 import java.awt.event.ActionEvent; 4 import java.text.SimpleDateFormat; 4 5 import javax.swing.AbstractAction; 5 6 import javax.swing.JOptionPane; 6 7 import org.openstreetmap.josm.Main; 8 import org.openstreetmap.josm.data.coor.LatLon; 7 9 import static org.openstreetmap.josm.tools.I18n.tr; 8 10 import org.openstreetmap.josm.tools.ImageProvider; … … 14 16 */ 15 17 public class OffsetInfoAction extends AbstractAction { 16 private ImageryOffsetBase offset; 18 public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); 19 20 private Object info; 17 21 18 22 public OffsetInfoAction( ImageryOffsetBase offset ) { 19 23 super(tr("Offset Information")); 20 putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete")); 21 this.offset = offset; 24 putValue(SMALL_ICON, ImageProvider.get("info")); 25 if( offset != null ) 26 this.info = getInformationObject(offset); 22 27 setEnabled(offset != null); 23 28 } 24 29 25 30 public void actionPerformed(ActionEvent e) { 26 JOptionPane.showMessageDialog(Main.parent, "TODO", ImageryOffsetTools.DIALOG_TITLE, JOptionPane.PLAIN_MESSAGE); 31 JOptionPane.showMessageDialog(Main.parent, info, ImageryOffsetTools.DIALOG_TITLE, JOptionPane.PLAIN_MESSAGE); 32 } 33 34 public static Object getInformationObject( ImageryOffsetBase offset ) { 35 StringBuilder sb = new StringBuilder(); 36 if( offset instanceof ImageryOffset ) { 37 double[] ld = getLengthAndDirection((ImageryOffset)offset); 38 sb.append(tr("An imagery offset of {0} m to {1}", ld[0], explainDirection(ld[1]))).append('\n'); 39 sb.append("Imagery ID: ").append(((ImageryOffset)offset).getImagery()); 40 } else 41 sb.append(tr("A calibration {0}", getGeometryType((CalibrationObject)offset))); 42 sb.append("\n\nCreated by ").append(offset.getAuthor()); 43 sb.append(" on ").append(DATE_FORMAT.format(offset.getDate())).append("\n"); 44 sb.append("Description: ").append(offset.getDescription()); 45 if( offset.isDeprecated() ) { 46 sb.append("\n\nThis geometry was marked obsolete\n"); 47 sb.append("by ").append(offset.getAbandonAuthor()); 48 sb.append(" on ").append(DATE_FORMAT.format(offset.getAbandonDate())).append("\n"); 49 sb.append("Reason: ").append(offset.getAbandonReason()); 50 } 51 return sb.toString(); 52 } 53 54 public static String getGeometryType( CalibrationObject obj ) { 55 if( obj.getGeometry() == null ) 56 return tr("nothing"); 57 int n = obj.getGeometry().length; 58 if( n == 1 ) 59 return tr("point"); 60 else if( n > 1 && !obj.getGeometry()[0].equals(obj.getGeometry()[n - 1]) ) 61 return tr("path ({0} nodes)", n); 62 else if( n > 1 && obj.getGeometry()[0].equals(obj.getGeometry()[n - 1]) ) 63 return tr("polygon ({0} nodes)", n - 1); 64 else 65 return "geometry"; 66 } 67 68 public static double[] getLengthAndDirection( ImageryOffset offset ) { 69 return getLengthAndDirection(offset, 0.0, 0.0); 70 } 71 72 public static double[] getLengthAndDirection( ImageryOffset offset, double dx, double dy ) { 73 double length = 0.0; 74 double direction = 0.0; 75 // todo: calculate length and angular direction 76 return new double[] { length, direction }; 77 } 78 79 public static String explainDirection( double dir ) { 80 return "nowhere"; // todo 27 81 } 28 82 } -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/StoreImageryOffsetAction.java
r29376 r29377 47 47 OsmPrimitive selection = selectedObjects.iterator().next(); 48 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")};49 String[] options = new String[] {tr("Store calibration geometry"), tr("Store imagery offset")}; 50 50 int result = JOptionPane.showOptionDialog(Main.parent, 51 51 tr("The selected object can be used as a calibration geometry. What do you intend to do?"), … … 59 59 } 60 60 61 Object message = "";61 Object message; 62 62 LatLon center = ImageryOffsetTools.getMapCenter(); 63 63 ImageryOffsetBase offsetObj; … … 76 76 // register calibration object 77 77 offsetObj = new CalibrationObject(calibration); 78 message = "You are registering a calibration geometry. It should be the most precisely positioned object,\n" 79 + "with clearly visible boundaries on various satellite imagery.\n" 80 + "Please describe a region where this object is located."; 78 message = "You are registering a calibration geometry. It should be the most precisely positioned object, with\n" 79 + "clearly visible boundaries on various satellite imagery. Please describe this object and its whereabouts."; 81 80 } 81 String description = queryDescription(message); 82 if( description == null ) 83 return; 82 84 offsetObj.setBasicInfo(center, userName, null, null); 83 String description = null;84 boolean iterated = false;85 while( description == null ) {86 description = JOptionPane.showInputDialog(Main.parent, message, ImageryOffsetTools.DIALOG_TITLE, JOptionPane.PLAIN_MESSAGE);87 if( description == null || description.length() == 0 )88 return;89 if( description.length() < 3 || description.length() > 200 ) {90 description = null;91 if( !iterated ) {92 message = message + "\n" + tr("Description should be 3 to 200 letters long.");93 iterated = true;94 }95 }96 }97 85 offsetObj.setDescription(description); 98 86 … … 116 104 } 117 105 106 public static String queryDescription( Object message ) { 107 String reason = null; 108 boolean iterated = false; 109 boolean ok = false; 110 while( !ok ) { 111 Object result = JOptionPane.showInputDialog(Main.parent, message, ImageryOffsetTools.DIALOG_TITLE, JOptionPane.PLAIN_MESSAGE, null, null, reason); 112 if( result == null || result.toString().length() == 0 ) { 113 return null; 114 } 115 reason = result.toString(); 116 if( reason.length() < 3 || reason.length() > 200 ) { 117 if( !iterated ) { 118 message = message + "\n" + tr("This string should be 3 to 200 letters long."); 119 iterated = true; 120 } 121 } else 122 ok = true; 123 } 124 return reason; 125 } 126 118 127 @Override 119 128 protected void updateEnabledState() {
Note:
See TracChangeset
for help on using the changeset viewer.