Skip to content

Commit

Permalink
fixes #37 plugin supports projections by code noew
Browse files Browse the repository at this point in the history
  • Loading branch information
nkuehnel committed Apr 28, 2016
1 parent 2dc3be6 commit 570f129
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/matsim/contrib/josm/ImportAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
32 changes: 23 additions & 9 deletions src/main/java/org/matsim/contrib/josm/ImportDialog.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
Expand All @@ -36,8 +39,10 @@ class ImportDialog extends JPanel {
final JLabel schedulePath = new JLabel("transit schedule");
final JButton schedulePathButton = new JButton("choose");

final JComboBox<ProjectionChoice> importSystem = new JComboBox<>(ProjectionPreference.getProjectionChoices().toArray(new ProjectionChoice[] {}));
final JComboBox<ProjectionChoice> 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());
Expand All @@ -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
Expand Down Expand Up @@ -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;
}


}

0 comments on commit 570f129

Please sign in to comment.