Changeset 28394 in osm for applications
- Timestamp:
- 2012-05-17T11:05:51+02:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/proj4j
- Files:
-
- 1 added
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/proj4j/build.xml
r27119 r28394 36 36 <property name="commit.message" value="Commit message"/> 37 37 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 38 <property name="plugin.main.version" value=" 4549"/>38 <property name="plugin.main.version" value="5234"/> 39 39 <!-- 40 40 ************************************************ -
applications/editors/josm/plugins/proj4j/src/org/openstreetmap/josm/plugins/proj4j/Proj4J.java
r25450 r28394 3 3 package org.openstreetmap.josm.plugins.proj4j; 4 4 5 import org.openstreetmap.josm. data.projection.Projections;5 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference; 6 6 import org.openstreetmap.josm.plugins.Plugin; 7 7 import org.openstreetmap.josm.plugins.PluginInformation; … … 10 10 public Proj4J(PluginInformation info) { 11 11 super(info); 12 Projection s.addProjection(new ProjectionProj4J());12 ProjectionPreference.registerProjectionChoice(new Proj4JProjectionChoice()); 13 13 } 14 14 } -
applications/editors/josm/plugins/proj4j/src/org/openstreetmap/josm/plugins/proj4j/Proj4JProjectionChoice.java
r28393 r28394 2 2 package org.openstreetmap.josm.plugins.proj4j; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 4 6 import java.awt.Dimension; 5 7 import java.awt.GridBagConstraints; 6 import javax.swing.event.DocumentEvent;7 import static org.openstreetmap.josm.tools.I18n.tr;8 9 8 import java.awt.GridBagLayout; 10 9 import java.awt.event.ActionEvent; … … 18 17 import java.util.Collection; 19 18 import java.util.Collections; 19 20 20 import javax.swing.JLabel; 21 22 21 import javax.swing.JPanel; 23 22 import javax.swing.JScrollPane; … … 27 26 import javax.swing.RowFilter; 28 27 import javax.swing.SwingConstants; 28 import javax.swing.event.DocumentEvent; 29 29 import javax.swing.event.DocumentListener; 30 30 import javax.swing.event.ListSelectionEvent; … … 33 33 import javax.swing.table.TableRowSorter; 34 34 35 import org.openstreetmap.josm.data.Bounds; 36 import org.openstreetmap.josm.data.coor.EastNorth; 37 import org.openstreetmap.josm.data.coor.LatLon; 35 import org.openstreetmap.josm.data.projection.Projection; 36 import org.openstreetmap.josm.gui.preferences.projection.ProjectionChoice; 38 37 import org.openstreetmap.josm.tools.GBC; 39 38 … … 44 43 * * Allow user to input proj.4 settings explicitly, or load from a file 45 44 */ 46 public class Proj ectionProj4J implements org.openstreetmap.josm.data.projection.Projection, org.openstreetmap.josm.data.projection.ProjectionSubPrefs{45 public class Proj4JProjectionChoice implements ProjectionChoice { 47 46 48 47 private String crsCode = "EPSG:4326"; 49 48 private String filterText = ""; 50 private org.osgeo.proj4j.CoordinateReferenceSystem proj4jCRS;51 private org.osgeo.proj4j.CoordinateReferenceSystem wgs84CRS;52 private org.osgeo.proj4j.CoordinateTransform transformToWGS84;53 private org.osgeo.proj4j.CoordinateTransform transformFromWGS84;54 49 private JTable table; 55 50 private JTextField filterTextField; … … 59 54 private ActionListener actionListener; 60 55 61 public ProjectionProj4J() { 62 super(); 63 56 public Proj4JProjectionChoice() { 64 57 try { 65 58 model = new CRSTableModel(); … … 70 63 71 64 sorter = new TableRowSorter<CRSTableModel>(model); 72 73 setupTransformations(); 74 } 75 76 @Override 77 public void setupPreferencePanel(JPanel p, ActionListener actionListener) { 78 GridBagConstraints c = new GridBagConstraints(); 79 p.setLayout(new GridBagLayout()); 80 81 JLabel filterLabel = new JLabel(tr("Filter"), SwingConstants.TRAILING); 82 c.gridx = 0; 83 c.gridy = 0; 84 c.fill = GBC.NONE; 85 p.add(filterLabel, c); 86 87 c.gridx = 1; 88 c.gridy = 0; 89 c.fill = GBC.HORIZONTAL; 90 filterTextField = new JTextField(filterText, 20); 91 filterTextField.getDocument().addDocumentListener( 92 new DocumentListener() { 93 94 public void insertUpdate(DocumentEvent e) { 95 newFilter(); 96 } 97 98 public void removeUpdate(DocumentEvent e) { 99 newFilter(); 100 } 101 102 public void changedUpdate(DocumentEvent e) { 103 newFilter(); 104 } 105 }); 106 p.add(filterTextField, c); 107 108 selectedLabel = new JLabel(tr("Selected: {0}", crsCode), SwingConstants.TRAILING); 109 c.gridx = 3; 110 c.gridy = 0; 111 c.fill = GBC.HORIZONTAL; 112 p.add(selectedLabel); 113 114 filterLabel.setLabelFor(filterTextField); 115 116 table = new JTable(model); 117 table.setPreferredScrollableViewportSize(new Dimension(500, 70)); 118 table.setFillsViewportHeight(true); 119 table.setRowSorter(sorter); 120 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 121 122 JScrollPane scrollPane = new JScrollPane(table); 123 c.gridx = 0; 124 c.gridy = 1; 125 c.fill = GBC.BOTH; 126 c.gridwidth = 3; 127 p.add(scrollPane, c); 128 129 // Update table using filterText 130 newFilter(); 131 132 // Select and show row containing saved projection/CRS, if visible 133 int index = model.findCode(crsCode); 134 if (index >= 0) { 135 index = table.convertRowIndexToView(index); 65 } 66 67 @Override 68 public String getId() { 69 return "proj4jplugin"; 70 } 71 72 @Override 73 public JPanel getPreferencePanel(ActionListener actionListener) { 74 return new Proj4JPanel(actionListener); 75 } 76 77 protected class Proj4JPanel extends JPanel { 78 79 public Proj4JPanel(ActionListener actionListener) { 80 GridBagConstraints c = new GridBagConstraints(); 81 this.setLayout(new GridBagLayout()); 82 83 JLabel filterLabel = new JLabel(tr("Filter"), SwingConstants.TRAILING); 84 c.gridx = 0; 85 c.gridy = 0; 86 c.fill = GBC.NONE; 87 this.add(filterLabel, c); 88 89 c.gridx = 1; 90 c.gridy = 0; 91 c.fill = GBC.HORIZONTAL; 92 filterTextField = new JTextField(filterText, 20); 93 filterTextField.getDocument().addDocumentListener( 94 new DocumentListener() { 95 96 public void insertUpdate(DocumentEvent e) { 97 newFilter(); 98 } 99 100 public void removeUpdate(DocumentEvent e) { 101 newFilter(); 102 } 103 104 public void changedUpdate(DocumentEvent e) { 105 newFilter(); 106 } 107 }); 108 this.add(filterTextField, c); 109 110 selectedLabel = new JLabel(tr("Selected: {0}", crsCode), SwingConstants.TRAILING); 111 c.gridx = 3; 112 c.gridy = 0; 113 c.fill = GBC.HORIZONTAL; 114 this.add(selectedLabel); 115 116 filterLabel.setLabelFor(filterTextField); 117 118 table = new JTable(model); 119 table.setPreferredScrollableViewportSize(new Dimension(500, 70)); 120 table.setFillsViewportHeight(true); 121 table.setRowSorter(sorter); 122 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 123 124 JScrollPane scrollPane = new JScrollPane(table); 125 c.gridx = 0; 126 c.gridy = 1; 127 c.fill = GBC.BOTH; 128 c.gridwidth = 3; 129 this.add(scrollPane, c); 130 131 // Update table using filterText 132 newFilter(); 133 134 // Select and show row containing saved projection/CRS, if visible 135 int index = model.findCode(crsCode); 136 136 if (index >= 0) { 137 table.addRowSelectionInterval(index, index); 138 table.scrollRectToVisible(table.getCellRect(index, 0, true)); 139 } 140 } 141 142 // add listener to react to table selections 143 table.getSelectionModel().addListSelectionListener( 144 new SelectionListener(table)); 145 146 this.actionListener = actionListener; 137 index = table.convertRowIndexToView(index); 138 if (index >= 0) { 139 table.addRowSelectionInterval(index, index); 140 table.scrollRectToVisible(table.getCellRect(index, 0, true)); 141 } 142 } 143 144 // add listener to react to table selections 145 table.getSelectionModel().addListSelectionListener( 146 new SelectionListener(table)); 147 148 Proj4JProjectionChoice.this.actionListener = actionListener; 149 } 147 150 } 148 151 … … 168 171 filterText = array[1]; 169 172 } 170 setupTransformations(); 171 } 172 } 173 174 @Override 175 public double getDefaultZoomInPPD() { 176 //TODO: this needs to be changed per projection 177 return 1.01; 178 } 179 180 /** 181 * @param LatLon WGS84 (in degree) 182 * @return xy east/north (in whatever unit the projection uses, m/ft/deg/etc) 183 */ 184 @Override 185 public EastNorth latlon2eastNorth(LatLon p) { 186 org.osgeo.proj4j.ProjCoordinate pc1 = new org.osgeo.proj4j.ProjCoordinate(p.lon(), p.lat()); 187 org.osgeo.proj4j.ProjCoordinate pc2 = new org.osgeo.proj4j.ProjCoordinate(); 188 //System.out.println("From " + pc1.x + " " + pc1.y); 189 transformFromWGS84.transform(pc1, pc2); 190 //System.out.println("To " + pc2.x + " " + pc2.y); 191 return new EastNorth(pc2.x, pc2.y); 192 } 193 194 /** 195 * @param xy east/north (in whatever unit the projection uses, m/ft/deg/etc) 196 * @return LatLon WGS84 (in degree) 197 */ 198 @Override 199 public LatLon eastNorth2latlon(EastNorth p) { 200 org.osgeo.proj4j.ProjCoordinate pc1 = new org.osgeo.proj4j.ProjCoordinate(p.east(), p.north()); 201 org.osgeo.proj4j.ProjCoordinate pc2 = new org.osgeo.proj4j.ProjCoordinate(); 202 //System.out.println("InvFrom " + pc1.x + " " + pc1.y); 203 transformToWGS84.transform(pc1, pc2); 204 //System.out.println("InvTo " + pc2.x + " " + pc2.y); 205 return new LatLon(pc2.y, pc2.x); 173 } 174 } 175 176 @Override 177 public Projection getProjection() { 178 return new Proj4JProjection(crsCode); 206 179 } 207 180 208 181 @Override 209 182 public String toString() { 210 // TODO: include description in string 211 return tr("Proj4J: {0} selected", crsCode); 212 } 213 214 @Override 215 public String toCode() { 216 return crsCode; 217 } 218 219 @Override 220 public String getCacheDirectoryName() { 221 return "Proj4J"; 222 } 223 224 @Override 225 public Bounds getWorldBoundsLatLon() { 226 org.osgeo.proj4j.proj.Projection proj = proj4jCRS.getProjection(); 227 228 // FIXME: Do we need to convert these coords because of possibly differing datums? 229 LatLon min = new LatLon(proj.getMinLatitudeDegrees(), proj.getMinLongitudeDegrees()); 230 LatLon max = new LatLon(proj.getMaxLatitudeDegrees(), proj.getMaxLongitudeDegrees()); 231 return new Bounds(min, max); 183 return tr("Proj4J Plugin"); 232 184 } 233 185 … … 246 198 crsCode = model.getCRSEntryAt(index).getName(); 247 199 selectedLabel.setText(tr("Selected: {0}", crsCode)); 248 setupTransformations();249 200 if (actionListener != null) { 250 201 actionListener.actionPerformed(new ActionEvent(selectedLabel, 0, "CRS changed")); … … 265 216 updateSelectedCode(); 266 217 } 267 }268 269 private void setupTransformations() {270 org.osgeo.proj4j.CRSFactory crsFactory =271 new org.osgeo.proj4j.CRSFactory();272 org.osgeo.proj4j.CoordinateTransformFactory transFactory =273 new org.osgeo.proj4j.CoordinateTransformFactory();274 275 // Create coordinate reference systems for source and target276 proj4jCRS = crsFactory.createFromName(crsCode);277 wgs84CRS = crsFactory.createFromName("EPSG:4326");278 279 // Create transformations between CRS280 transformToWGS84 = transFactory.createTransform(proj4jCRS, wgs84CRS);281 transformFromWGS84 = transFactory.createTransform(wgs84CRS, proj4jCRS);282 218 } 283 219
Note:
See TracChangeset
for help on using the changeset viewer.