| 1 | package org.openstreetmap.josm.gui;
|
|---|
| 2 |
|
|---|
| 3 | import java.awt.BorderLayout;
|
|---|
| 4 | import java.awt.Component;
|
|---|
| 5 | import java.awt.event.ActionEvent;
|
|---|
| 6 | import java.awt.event.ActionListener;
|
|---|
| 7 | import java.awt.event.KeyEvent;
|
|---|
| 8 |
|
|---|
| 9 | import javax.swing.AbstractAction;
|
|---|
| 10 | import javax.swing.AbstractButton;
|
|---|
| 11 | import javax.swing.BorderFactory;
|
|---|
| 12 | import javax.swing.Box;
|
|---|
| 13 | import javax.swing.BoxLayout;
|
|---|
| 14 | import javax.swing.ButtonGroup;
|
|---|
| 15 | import javax.swing.ImageIcon;
|
|---|
| 16 | import javax.swing.JComboBox;
|
|---|
| 17 | import javax.swing.JComponent;
|
|---|
| 18 | import javax.swing.JDialog;
|
|---|
| 19 | import javax.swing.JLabel;
|
|---|
| 20 | import javax.swing.JPanel;
|
|---|
| 21 | import javax.swing.JToggleButton;
|
|---|
| 22 | import javax.swing.JToolBar;
|
|---|
| 23 | import javax.swing.border.Border;
|
|---|
| 24 | import javax.swing.event.ChangeEvent;
|
|---|
| 25 | import javax.swing.event.ChangeListener;
|
|---|
| 26 |
|
|---|
| 27 | import org.openstreetmap.josm.actions.DebugAction;
|
|---|
| 28 | import org.openstreetmap.josm.actions.MapMode;
|
|---|
| 29 | import org.openstreetmap.josm.actions.ZoomAction;
|
|---|
| 30 | import org.openstreetmap.josm.data.Preferences;
|
|---|
| 31 | import org.openstreetmap.josm.data.osm.DataSet;
|
|---|
| 32 | import org.openstreetmap.josm.data.projection.Projection;
|
|---|
| 33 |
|
|---|
| 34 | /**
|
|---|
| 35 | * One Map frame with one dataset behind. This is the container gui class whose
|
|---|
| 36 | * display can be set to the different views.
|
|---|
| 37 | *
|
|---|
| 38 | * @author imi
|
|---|
| 39 | */
|
|---|
| 40 | public class MapFrame extends JComponent {
|
|---|
| 41 |
|
|---|
| 42 | /**
|
|---|
| 43 | * Open the properties page
|
|---|
| 44 | * @author imi
|
|---|
| 45 | */
|
|---|
| 46 | public class PropertiesAction extends AbstractAction {
|
|---|
| 47 | private JDialog dlg;
|
|---|
| 48 | public PropertiesAction() {
|
|---|
| 49 | super("Properties", new ImageIcon("images/properties.png"));
|
|---|
| 50 | putValue(MNEMONIC_KEY, KeyEvent.VK_P);
|
|---|
| 51 | }
|
|---|
| 52 | public void actionPerformed(ActionEvent e) {
|
|---|
| 53 | if (dlg != null) {
|
|---|
| 54 | dlg.setVisible(true);
|
|---|
| 55 | dlg.requestFocus();
|
|---|
| 56 | return;
|
|---|
| 57 | }
|
|---|
| 58 | dlg = new JDialog(Main.main, "Properties of "+Main.main.getNameOfLoadedMapFrame(), false);
|
|---|
| 59 | final Border panelBorder = BorderFactory.createEmptyBorder(5,0,0,0);
|
|---|
| 60 | Box panel = Box.createVerticalBox();
|
|---|
| 61 |
|
|---|
| 62 | // making an array of all projections and the current one within
|
|---|
| 63 | Projection[] allProjections = Preferences.allProjections.clone();
|
|---|
| 64 | for (int i = 0; i < allProjections.length; ++i)
|
|---|
| 65 | if (allProjections[i].getClass() == mapView.getProjection().getClass())
|
|---|
| 66 | allProjections[i] = mapView.getProjection();
|
|---|
| 67 |
|
|---|
| 68 | // projection
|
|---|
| 69 | Box projectionPanel = Box.createHorizontalBox();
|
|---|
| 70 | projectionPanel.setBorder(panelBorder);
|
|---|
| 71 | projectionPanel.add(new JLabel("Projection"));
|
|---|
| 72 | final JComboBox projectionCombo = new JComboBox(allProjections);
|
|---|
| 73 | projectionPanel.add(projectionCombo);
|
|---|
| 74 | panel.add(projectionPanel);
|
|---|
| 75 | final JPanel configurationPanel = new JPanel();
|
|---|
| 76 | configurationPanel.setLayout(new BoxLayout(configurationPanel, BoxLayout.X_AXIS));
|
|---|
| 77 |
|
|---|
| 78 | // projections details
|
|---|
| 79 | projectionCombo.addActionListener(new ActionListener(){
|
|---|
| 80 | public void actionPerformed(ActionEvent e) {
|
|---|
| 81 | configurationPanel.removeAll();
|
|---|
| 82 | mapView.setProjection((Projection)projectionCombo.getSelectedItem());
|
|---|
| 83 | JComponent panel = mapView.getProjection().getConfigurationPanel();
|
|---|
| 84 | if (panel != null) {
|
|---|
| 85 | panel.setBorder(panelBorder);
|
|---|
| 86 | configurationPanel.add(panel);
|
|---|
| 87 | }
|
|---|
| 88 | dlg.pack();
|
|---|
| 89 | }
|
|---|
| 90 | });
|
|---|
| 91 | panel.add(configurationPanel);
|
|---|
| 92 | projectionCombo.setSelectedItem(mapView.getProjection());
|
|---|
| 93 |
|
|---|
| 94 | panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
|
|---|
| 95 | dlg.setContentPane(panel);
|
|---|
| 96 | dlg.pack();
|
|---|
| 97 | dlg.setResizable(false);
|
|---|
| 98 | dlg.setVisible(true);
|
|---|
| 99 | }
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | /**
|
|---|
| 103 | * The current mode, this frame operates.
|
|---|
| 104 | */
|
|---|
| 105 | public MapMode mapMode;
|
|---|
| 106 | /**
|
|---|
| 107 | * The view control displayed.
|
|---|
| 108 | */
|
|---|
| 109 | public MapView mapView;
|
|---|
| 110 | /**
|
|---|
| 111 | * The toolbar with the action icons
|
|---|
| 112 | */
|
|---|
| 113 | private JToolBar toolBarActions = new JToolBar(JToolBar.VERTICAL);
|
|---|
| 114 |
|
|---|
| 115 | /**
|
|---|
| 116 | * Construct a map with a given DataSet. The set cannot be replaced after construction
|
|---|
| 117 | * (but of course, the data can be altered using the map's editing features).
|
|---|
| 118 | */
|
|---|
| 119 | public MapFrame(DataSet dataSet) {
|
|---|
| 120 | setSize(400,400);
|
|---|
| 121 | setLayout(new BorderLayout());
|
|---|
| 122 |
|
|---|
| 123 | add(mapView = new MapView(dataSet), BorderLayout.CENTER);
|
|---|
| 124 |
|
|---|
| 125 | toolBarActions.setFloatable(false);
|
|---|
| 126 | toolBarActions.add(new IconToggleButton(new ZoomAction(this)));
|
|---|
| 127 | toolBarActions.add(new IconToggleButton(new DebugAction(this)));
|
|---|
| 128 |
|
|---|
| 129 | // all map modes in one button group
|
|---|
| 130 | ButtonGroup toolGroup = new ButtonGroup();
|
|---|
| 131 | for (Component c : toolBarActions.getComponents())
|
|---|
| 132 | toolGroup.add((AbstractButton)c);
|
|---|
| 133 | toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true);
|
|---|
| 134 | selectMapMode((MapMode)((AbstractButton)toolBarActions.getComponent(0)).getAction());
|
|---|
| 135 |
|
|---|
| 136 | // autoScale
|
|---|
| 137 | toolBarActions.addSeparator();
|
|---|
| 138 | final JToggleButton autoScaleButton = new IconToggleButton(mapView.new AutoScaleAction());
|
|---|
| 139 | toolBarActions.add(autoScaleButton);
|
|---|
| 140 | autoScaleButton.setText(null);
|
|---|
| 141 | autoScaleButton.setSelected(mapView.isAutoScale());
|
|---|
| 142 | mapView.addChangeListener(new ChangeListener(){
|
|---|
| 143 | public void stateChanged(ChangeEvent e) {
|
|---|
| 144 | autoScaleButton.setSelected(mapView.isAutoScale());
|
|---|
| 145 | }
|
|---|
| 146 | });
|
|---|
| 147 |
|
|---|
| 148 | // properties
|
|---|
| 149 | toolBarActions.add(new IconToggleButton(new PropertiesAction()));
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | /**
|
|---|
| 153 | * Change the operating map mode for the view. Will call unregister on the
|
|---|
| 154 | * old MapMode and register on the new one.
|
|---|
| 155 | * @param mapMode The new mode to set.
|
|---|
| 156 | */
|
|---|
| 157 | public void selectMapMode(MapMode mapMode) {
|
|---|
| 158 | if (this.mapMode != null)
|
|---|
| 159 | this.mapMode.unregisterListener(mapView);
|
|---|
| 160 | this.mapMode = mapMode;
|
|---|
| 161 | mapMode.registerListener(mapView);
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | /**
|
|---|
| 165 | * @return Returns the toolBarActions.
|
|---|
| 166 | */
|
|---|
| 167 | public JToolBar getToolBarActions() {
|
|---|
| 168 | return toolBarActions;
|
|---|
| 169 | }
|
|---|
| 170 | }
|
|---|