Changeset 30583 in osm for applications
- Timestamp:
- 2014-08-15T14:26:05+02:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/opendata
- Files:
-
- 3 added
- 4 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/AbstractDataSetHandler.java
r30563 r30583 26 26 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.DefaultShpHandler; 27 27 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.GmlHandler; 28 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.MifHandler; 28 29 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.ShpHandler; 29 30 import org.openstreetmap.josm.plugins.opendata.core.io.tabular.CsvHandler; … … 440 441 } 441 442 443 // --------- MIF handling --------- 444 445 private MifHandler mifHandler; 446 447 public final void setMifHandler(MifHandler handler) { 448 mifHandler = handler; 449 } 450 451 public final MifHandler getMifHandler() { 452 return mifHandler; 453 } 454 442 455 // --------- GML handling --------- 443 456 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/gui/ProjectionChooser.java
r30582 r30583 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.plugins.opendata.core. io;2 package org.openstreetmap.josm.plugins.opendata.core.gui; 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 6 import java.awt.Component; 7 import java.awt.Dimension; 7 8 import java.awt.GridBagLayout; 9 import java.awt.event.ActionEvent; 10 import java.awt.event.ActionListener; 8 11 9 12 import javax.swing.BorderFactory; … … 12 15 import javax.swing.JPanel; 13 16 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.data.Bounds; 19 import org.openstreetmap.josm.data.coor.CoordinateFormat; 14 20 import org.openstreetmap.josm.data.projection.Projection; 15 21 import org.openstreetmap.josm.gui.ExtendedDialog; 16 22 import org.openstreetmap.josm.gui.preferences.projection.ProjectionChoice; 17 23 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference; 24 import org.openstreetmap.josm.gui.preferences.projection.SubPrefsOptions; 18 25 import org.openstreetmap.josm.tools.GBC; 19 26 27 /** 28 * Projection chooser, ugly copy-paste of ProjectionPreference. 29 * FIXME: to be refactored in core for reuse by plugins. 30 */ 20 31 public class ProjectionChooser extends ExtendedDialog { 21 32 22 /**23 * This is the panel holding all projection preferences24 */25 private final JPanel projPanel = new JPanel(new GridBagLayout());26 27 33 /** 28 34 * Combobox with all projections available … … 31 37 ProjectionPreference.getProjectionChoices().toArray(new ProjectionChoice[0])); 32 38 39 /** 40 * This variable holds the JPanel with the projection's preferences. If the 41 * selected projection does not implement this, it will be set to an empty 42 * Panel. 43 */ 44 private JPanel projSubPrefPanel; 45 private JPanel projSubPrefPanelWrapper = new JPanel(new GridBagLayout()); 46 47 private JLabel projectionCodeLabel; 48 private Component projectionCodeGlue; 49 private JLabel projectionCode = new JLabel(); 50 private JLabel projectionNameLabel; 51 private Component projectionNameGlue; 52 private JLabel projectionName = new JLabel(); 53 private JLabel bounds = new JLabel(); 54 55 /** 56 * This is the panel holding all projection preferences 57 */ 58 private final JPanel projPanel = new JPanel(new GridBagLayout()); 59 60 /** 61 * The GridBagConstraints for the Panel containing the ProjectionSubPrefs. 62 * This is required twice in the code, creating it here keeps both occurrences 63 * in sync 64 */ 65 private static final GBC projSubPrefPanelGBC = GBC.std().fill(GBC.BOTH).weight(1.0, 1.0); 66 33 67 public ProjectionChooser(Component parent) { 34 68 this(parent, tr("Projection method"), new String[] {tr("OK"), tr("Cancel")}); 35 69 } 36 70 37 protected ProjectionChooser(Component parent, String title, 38 String[] buttonTexts) { 71 protected ProjectionChooser(Component parent, String title, String[] buttonTexts) { 39 72 super(parent, title, buttonTexts); 73 setMinimumSize(new Dimension(600, 200)); 40 74 addGui(); 41 75 } … … 47 81 projPanel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL)); 48 82 projPanel.add(projectionCombo, GBC.eop().fill(GBC.HORIZONTAL).insets(0,5,5,5)); 83 projPanel.add(projectionCodeLabel = new JLabel(tr("Projection code")), GBC.std().insets(25,5,0,5)); 84 projPanel.add(projectionCodeGlue = GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL)); 85 projPanel.add(projectionCode, GBC.eop().fill(GBC.HORIZONTAL).insets(0,5,5,5)); 86 projPanel.add(projectionNameLabel = new JLabel(tr("Projection name")), GBC.std().insets(25,5,0,5)); 87 projPanel.add(projectionNameGlue = GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL)); 88 projPanel.add(projectionName, GBC.eop().fill(GBC.HORIZONTAL).insets(0,5,5,5)); 89 projPanel.add(new JLabel(tr("Bounds")), GBC.std().insets(25,5,0,5)); 90 projPanel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL)); 91 projPanel.add(bounds, GBC.eop().fill(GBC.HORIZONTAL).insets(0,5,5,5)); 92 projPanel.add(projSubPrefPanelWrapper, GBC.eol().fill(GBC.HORIZONTAL).insets(20,5,5,5)); 93 94 selectedProjectionChanged((ProjectionChoice) projectionCombo.getSelectedItem()); 95 projectionCombo.addActionListener(new ActionListener() { 96 @Override 97 public void actionPerformed(ActionEvent e) { 98 ProjectionChoice pc = (ProjectionChoice) projectionCombo.getSelectedItem(); 99 selectedProjectionChanged(pc); 100 } 101 }); 49 102 setContent(projPanel); 50 103 } 51 104 52 public Projection getProjection() { 53 ProjectionChoice choice = (ProjectionChoice) projectionCombo.getSelectedItem(); 54 return choice != null ? choice.getProjection() : null; 105 private void selectedProjectionChanged(final ProjectionChoice pc) { 106 // Don't try to update if we're still starting up 107 int size = projPanel.getComponentCount(); 108 if(size < 1) 109 return; 110 111 final ActionListener listener = new ActionListener() { 112 @Override 113 public void actionPerformed(ActionEvent e) { 114 updateMeta(pc); 115 } 116 }; 117 118 // Replace old panel with new one 119 projSubPrefPanelWrapper.removeAll(); 120 projSubPrefPanel = pc.getPreferencePanel(listener); 121 projSubPrefPanelWrapper.add(projSubPrefPanel, projSubPrefPanelGBC); 122 projPanel.revalidate(); 123 projSubPrefPanel.repaint(); 124 updateMeta(pc); 125 } 126 127 private void updateMeta(ProjectionChoice pc) { 128 pc.setPreferences(pc.getPreferences(projSubPrefPanel)); 129 Projection proj = pc.getProjection(); 130 projectionCode.setText(proj.toCode()); 131 projectionName.setText(proj.toString()); 132 Bounds b = proj.getWorldBoundsLatLon(); 133 CoordinateFormat cf = CoordinateFormat.getDefaultFormat(); 134 bounds.setText(b.getMin().lonToString(cf)+", "+b.getMin().latToString(cf)+" : "+b.getMax().lonToString(cf)+", "+b.getMax().latToString(cf)); 135 boolean showCode = true; 136 boolean showName = false; 137 if (pc instanceof SubPrefsOptions) { 138 showCode = ((SubPrefsOptions) pc).showProjectionCode(); 139 showName = ((SubPrefsOptions) pc).showProjectionName(); 140 } 141 projectionCodeLabel.setVisible(showCode); 142 projectionCodeGlue.setVisible(showCode); 143 projectionCode.setVisible(showCode); 144 projectionNameLabel.setVisible(showName); 145 projectionNameGlue.setVisible(showName); 146 projectionName.setVisible(showName); 147 } 148 149 public Projection getProjection() { 150 ProjectionChoice pc = (ProjectionChoice) projectionCombo.getSelectedItem(); 151 if (pc != null) { 152 Main.info("Chosen projection: "+pc+" ("+pc.getProjection()+")"); 153 return pc.getProjection(); 154 } else { 155 return null; 156 } 55 157 } 56 158 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/MifReader.java
r30576 r30583 29 29 import org.openstreetmap.josm.data.projection.Projection; 30 30 import org.openstreetmap.josm.data.projection.Projections; 31 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 31 32 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 32 33 import org.openstreetmap.josm.plugins.opendata.core.OdConstants; 33 34 import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler; 35 import org.openstreetmap.josm.plugins.opendata.core.gui.ChooserLauncher; 34 36 import org.openstreetmap.josm.plugins.opendata.core.io.InputStreamReaderUnbuffered; 35 37 import org.openstreetmap.josm.plugins.opendata.core.util.OdUtils; … … 53 55 END_POLYLINE 54 56 } 57 58 private final AbstractDataSetHandler handler; 55 59 56 60 private File file; … … 91 95 private int numsections = -1; 92 96 97 private MifReader(AbstractDataSetHandler handler) { 98 this.handler = handler; 99 } 100 93 101 public static DataSet parseDataSet(InputStream in, File file, 94 102 AbstractDataSetHandler handler, ProgressMonitor instance) throws IOException { 95 return new MifReader( ).parse(in, file, instance, Charset.forName(OdConstants.ISO8859_15));103 return new MifReader(handler).parse(in, file, instance, Charset.forName(OdConstants.ISO8859_15)); 96 104 } 97 105 … … 327 335 // Use syntax 2 to explicitly define a non-Earth coordinate system, such as the coordinate system used in a floor plan or other CAD drawing. 328 336 329 // FIXME: allow user to choose projection ? 330 josmProj = new CustomProjection(null); 337 if (handler != null && handler.getMifHandler() != null && handler.getMifHandler().getCoordSysNonEarthProjection() != null) { 338 josmProj = handler.getMifHandler().getCoordSysNonEarthProjection(); 339 } else { 340 josmProj = ChooserLauncher.askForProjection(NullProgressMonitor.INSTANCE); 341 } 331 342 break; 332 343 case "layout": -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/SpreadSheetReader.java
r30568 r30583 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Component;7 6 import java.awt.GraphicsEnvironment; 8 7 import java.io.IOException; … … 23 22 import org.openstreetmap.josm.data.projection.Projection; 24 23 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 25 import org.openstreetmap.josm.gui.util.GuiHelper;26 24 import org.openstreetmap.josm.io.AbstractReader; 27 25 import org.openstreetmap.josm.plugins.opendata.core.OdConstants; 28 import org.openstreetmap.josm.plugins.opendata.core. io.ProjectionChooser;26 import org.openstreetmap.josm.plugins.opendata.core.gui.ChooserLauncher; 29 27 import org.openstreetmap.josm.plugins.opendata.core.io.ProjectionPatterns; 30 28 … … 78 76 } 79 77 return col; 80 }81 82 private class ChooserLauncher implements Runnable {83 84 public Projection proj = null;85 private final ProgressMonitor progressMonitor;86 87 public ChooserLauncher(ProgressMonitor progressMonitor) {88 this.progressMonitor = progressMonitor;89 }90 91 @Override92 public void run() {93 Component parent = progressMonitor == null ? Main.parent : progressMonitor.getWindowParent();94 ProjectionChooser dialog = (ProjectionChooser) new ProjectionChooser(parent).showDialog();95 if (dialog.getValue() == 1) {96 proj = dialog.getProjection();97 }98 }99 78 } 100 79 … … 153 132 } 154 133 // TODO: filter proposed projections with min/max values ? 155 ChooserLauncher launcher = new ChooserLauncher(progressMonitor); 156 GuiHelper.runInEDTAndWait(launcher); 157 if (launcher.proj == null) { 134 Projection p = ChooserLauncher.askForProjection(progressMonitor); 135 if (p == null) { 158 136 return null; // User clicked Cancel 159 137 } 160 138 for (CoordinateColumns c : columns) { 161 c.proj = launcher.proj;139 c.proj = p; 162 140 } 163 141 } -
applications/editors/josm/plugins/opendata/test/unit/org/openstreetmap/josm/plugins/opendata/core/io/geographic/MifReaderTest.java
r30573 r30583 11 11 import org.openstreetmap.josm.JOSMFixture; 12 12 import org.openstreetmap.josm.TestUtils; 13 import org.openstreetmap.josm.data.osm.DataSet; 14 import org.openstreetmap.josm.data.projection.Projections; 15 import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler; 13 16 import org.openstreetmap.josm.plugins.opendata.core.io.NonRegFunctionalTests; 14 17 … … 26 29 } 27 30 31 private static AbstractDataSetHandler newHandler(final String epsgCode) { 32 AbstractDataSetHandler handler = new AbstractDataSetHandler() { 33 @Override 34 public boolean acceptsFilename(String filename) { 35 return true; 36 } 37 @Override 38 public void updateDataSet(DataSet ds) { 39 } 40 }; 41 DefaultMifHandler mifHandler = new DefaultMifHandler(); 42 mifHandler.setCoordSysNonEarthProjection(Projections.getProjectionByCode(epsgCode)); 43 handler.setMifHandler(mifHandler); 44 return handler; 45 } 46 28 47 /** 29 48 * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/9592">#9592</a> … … 34 53 File file = new File(TestUtils.getRegressionDataFile(9592, "bg.mif")); 35 54 try (InputStream is = new FileInputStream(file)) { 36 NonRegFunctionalTests.testGeneric("#9592", MifReader.parseDataSet(is, file, n ull, null));55 NonRegFunctionalTests.testGeneric("#9592", MifReader.parseDataSet(is, file, newHandler("EPSG:32635"), null)); 37 56 } 38 57 }
Note:
See TracChangeset
for help on using the changeset viewer.