1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.gui.preferences;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.Color;
|
---|
7 | import java.awt.GridBagLayout;
|
---|
8 |
|
---|
9 | import javax.swing.BorderFactory;
|
---|
10 | import javax.swing.JComboBox;
|
---|
11 | import javax.swing.JLabel;
|
---|
12 | import javax.swing.JPanel;
|
---|
13 |
|
---|
14 | import org.openstreetmap.josm.Main;
|
---|
15 | import org.openstreetmap.josm.data.projection.Projection;
|
---|
16 | import org.openstreetmap.josm.data.coor.LatLon.CoordinateFormat;
|
---|
17 | import org.openstreetmap.josm.tools.GBC;
|
---|
18 |
|
---|
19 | public class ProjectionPreference implements PreferenceSetting {
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Combobox with all projections available
|
---|
23 | */
|
---|
24 | private JComboBox projectionCombo = new JComboBox(Projection.allProjections);
|
---|
25 | private JComboBox coordinatesCombo = new JComboBox(CoordinateFormat.values());
|
---|
26 |
|
---|
27 | public void addGui(PreferenceDialog gui) {
|
---|
28 |
|
---|
29 | for (int i = 0; i < projectionCombo.getItemCount(); ++i) {
|
---|
30 | if (projectionCombo.getItemAt(i).getClass().getName().equals(Main.pref.get("projection"))) {
|
---|
31 | projectionCombo.setSelectedIndex(i);
|
---|
32 | break;
|
---|
33 | }
|
---|
34 | }
|
---|
35 |
|
---|
36 | for (int i = 0; i < coordinatesCombo.getItemCount(); ++i) {
|
---|
37 | if (((CoordinateFormat)coordinatesCombo.getItemAt(i)).name().equals(Main.pref.get("coordinates"))) {
|
---|
38 | coordinatesCombo.setSelectedIndex(i);
|
---|
39 | break;
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | JPanel projPanel = new JPanel();
|
---|
44 | projPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.gray), tr("Map Projection")));
|
---|
45 | projPanel.setLayout(new GridBagLayout());
|
---|
46 | projPanel.add(new JLabel(tr("Projection method")), GBC.std().insets(5,5,0,5));
|
---|
47 | projPanel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
|
---|
48 | projPanel.add(projectionCombo, GBC.eop().fill(GBC.HORIZONTAL).insets(0,5,5,5));
|
---|
49 | projPanel.add(new JLabel(tr("Display coordinates as")), GBC.std().insets(5,5,0,5));
|
---|
50 | projPanel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
|
---|
51 | projPanel.add(coordinatesCombo, GBC.eop().fill(GBC.HORIZONTAL).insets(0,5,5,5));
|
---|
52 | gui.map.add(projPanel, GBC.eol().insets(0,0,0,10).fill(GBC.HORIZONTAL));
|
---|
53 | }
|
---|
54 |
|
---|
55 | public boolean ok() {
|
---|
56 | boolean restart = Main.pref.put("projection",
|
---|
57 | projectionCombo.getSelectedItem().getClass().getName());
|
---|
58 | if(Main.pref.put("coordinates",
|
---|
59 | ((CoordinateFormat)coordinatesCombo.getSelectedItem()).name()))
|
---|
60 | restart = true;
|
---|
61 | return restart;
|
---|
62 | }
|
---|
63 | }
|
---|