From 570f129421b6dff4e295ad3c003539f00dce77f1 Mon Sep 17 00:00:00 2001 From: Nico Date: Fri, 29 Apr 2016 00:20:39 +0200 Subject: [PATCH] fixes #37 plugin supports projections by code noew --- .../org/matsim/contrib/josm/ImportAction.java | 2 +- .../org/matsim/contrib/josm/ImportDialog.java | 32 +++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/matsim/contrib/josm/ImportAction.java b/src/main/java/org/matsim/contrib/josm/ImportAction.java index 7fa275a..dc5b5ed 100644 --- a/src/main/java/org/matsim/contrib/josm/ImportAction.java +++ b/src/main/java/org/matsim/contrib/josm/ImportAction.java @@ -42,7 +42,7 @@ public void actionPerformed(ActionEvent e) { dialog.schedulePathButton.setText(null); } ImportTask task = new ImportTask(dialog.networkPathButton.getText(), dialog.schedulePathButton.getText(), - ((ProjectionChoice) dialog.importSystem.getSelectedItem()).getProjection()); + dialog.getSelectedProjection()); Main.worker.execute(task); } } diff --git a/src/main/java/org/matsim/contrib/josm/ImportDialog.java b/src/main/java/org/matsim/contrib/josm/ImportDialog.java index be67450..deadfb2 100644 --- a/src/main/java/org/matsim/contrib/josm/ImportDialog.java +++ b/src/main/java/org/matsim/contrib/josm/ImportDialog.java @@ -1,6 +1,6 @@ package org.matsim.contrib.josm; -import java.awt.*; +import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -13,6 +13,9 @@ import javax.swing.filechooser.FileNameExtensionFilter; import org.openstreetmap.josm.Main; +import org.openstreetmap.josm.data.projection.Projection; +import org.openstreetmap.josm.data.projection.Projections; +import org.openstreetmap.josm.gui.preferences.projection.CodeProjectionChoice; import org.openstreetmap.josm.gui.preferences.projection.ProjectionChoice; import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference; import org.openstreetmap.josm.tools.GBC; @@ -36,8 +39,10 @@ class ImportDialog extends JPanel { final JLabel schedulePath = new JLabel("transit schedule"); final JButton schedulePathButton = new JButton("choose"); - final JComboBox importSystem = new JComboBox<>(ProjectionPreference.getProjectionChoices().toArray(new ProjectionChoice[] {})); + final JComboBox importSystemCB = new JComboBox<>(ProjectionPreference.getProjectionChoices().toArray(new ProjectionChoice[] {})); + private Projection selectedProjection; private JPanel projSubPrefPanelWrapper = new JPanel(new GridBagLayout()); + private JPanel projSubPrefPanel; public ImportDialog() { setLayout(new GridBagLayout()); @@ -52,18 +57,18 @@ public ImportDialog() { JLabel importSystemLabel = new JLabel("origin system:"); add(importSystemLabel, GBC.std()); - importSystem.addActionListener(new ActionListener() { + importSystemCB.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - ProjectionChoice pc = (ProjectionChoice) importSystem.getSelectedItem(); + ProjectionChoice pc = (ProjectionChoice) importSystemCB.getSelectedItem(); selectedProjectionChanged(pc); } }); - add(importSystem, GBC.eop()); + add(importSystemCB, GBC.eop()); add(projSubPrefPanelWrapper, GBC.eop()); - selectedProjectionChanged((ProjectionChoice) importSystem.getSelectedItem()); + selectedProjectionChanged((ProjectionChoice) importSystemCB.getSelectedItem()); networkPathButton.addActionListener(new ActionListener() { @Override @@ -114,17 +119,26 @@ private void selectedProjectionChanged(final ProjectionChoice pc) { final ActionListener listener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - // updateMeta(pc); + if((pc instanceof CodeProjectionChoice)) { + selectedProjection = Projections.getProjectionByCode(pc.getPreferences(projSubPrefPanel).iterator().next()); + } } }; // Replace old panel with new one projSubPrefPanelWrapper.removeAll(); - JPanel projSubPrefPanel = pc.getPreferencePanel(listener); + projSubPrefPanel = pc.getPreferencePanel(listener); projSubPrefPanelWrapper.add(projSubPrefPanel, GBC.std().fill(GBC.BOTH).weight(1.0, 1.0)); revalidate(); repaint(); - // updateMeta(pc); + if(!(pc instanceof CodeProjectionChoice)) { + selectedProjection = pc.getProjection(); + } + } + + public Projection getSelectedProjection() { + return selectedProjection; } + }