source: josm/trunk/src/org/openstreetmap/josm/gui/preferences/ProjectionPreference.java@ 1743

Last change on this file since 1743 was 1743, checked in by stoecker, 15 years ago

added much improved preferences for external styles and presets

  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.gui.preferences;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Color;
7import java.awt.GridBagLayout;
8
9import javax.swing.BorderFactory;
10import javax.swing.Box;
11import javax.swing.JComboBox;
12import javax.swing.JLabel;
13import javax.swing.JScrollPane;
14import javax.swing.JPanel;
15
16import org.openstreetmap.josm.Main;
17import org.openstreetmap.josm.data.coor.LatLon.CoordinateFormat;
18import org.openstreetmap.josm.data.osm.Node;
19import org.openstreetmap.josm.data.projection.Mercator;
20import org.openstreetmap.josm.data.projection.Projection;
21import org.openstreetmap.josm.tools.GBC;
22
23public class ProjectionPreference implements PreferenceSetting {
24
25 public static class Factory implements PreferenceSettingFactory {
26 public PreferenceSetting createPreferenceSetting() {
27 return new ProjectionPreference();
28 }
29 }
30
31 /**
32 * Combobox with all projections available
33 */
34 private JComboBox projectionCombo = new JComboBox(Projection.allProjections);
35 private JComboBox coordinatesCombo = new JComboBox(CoordinateFormat.values());
36
37 public void addGui(PreferenceDialog gui) {
38
39 for (int i = 0; i < projectionCombo.getItemCount(); ++i) {
40 if (projectionCombo.getItemAt(i).getClass().getName().equals(Main.pref.get("projection", Mercator.class.getName()))) {
41 projectionCombo.setSelectedIndex(i);
42 break;
43 }
44 }
45
46 for (int i = 0; i < coordinatesCombo.getItemCount(); ++i) {
47 if (((CoordinateFormat)coordinatesCombo.getItemAt(i)).name().equals(Main.pref.get("coordinates"))) {
48 coordinatesCombo.setSelectedIndex(i);
49 break;
50 }
51 }
52
53 JPanel projPanel = new JPanel();
54 projPanel.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 ));
55 projPanel.setLayout(new GridBagLayout());
56 projPanel.add(new JLabel(tr("Projection method")), GBC.std().insets(5,5,0,5));
57 projPanel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
58 projPanel.add(projectionCombo, GBC.eop().fill(GBC.HORIZONTAL).insets(0,5,5,5));
59 projPanel.add(new JLabel(tr("Display coordinates as")), GBC.std().insets(5,5,0,5));
60 projPanel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
61 projPanel.add(coordinatesCombo, GBC.eop().fill(GBC.HORIZONTAL).insets(0,5,5,5));
62 projPanel.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.BOTH));
63 JScrollPane scrollpane = new JScrollPane(projPanel);
64 gui.mapcontent.addTab(tr("Map Projection"), scrollpane);
65 }
66
67 public boolean ok() {
68 String projname = projectionCombo.getSelectedItem().getClass().getName();
69 if(Main.pref.put("projection", projname))
70 Main.setProjection(projname);
71 if(Main.pref.put("coordinates",
72 ((CoordinateFormat)coordinatesCombo.getSelectedItem()).name()))
73 Node.setCoordinateFormat();
74 return false;
75 }
76}
Note: See TracBrowser for help on using the repository browser.