source: josm/src/org/openstreetmap/josm/gui/MapFrame.java@ 15

Last change on this file since 15 was 15, checked in by imi, 19 years ago

renamed alot (Layer instead of MapView) and removed feature of having
projections on every Layer.

File size: 4.3 KB
Line 
1package org.openstreetmap.josm.gui;
2
3import java.awt.BorderLayout;
4import java.awt.Component;
5import java.awt.event.WindowAdapter;
6import java.awt.event.WindowEvent;
7import java.beans.PropertyChangeEvent;
8import java.beans.PropertyChangeListener;
9
10import javax.swing.AbstractButton;
11import javax.swing.ButtonGroup;
12import javax.swing.JPanel;
13import javax.swing.JToggleButton;
14import javax.swing.JToolBar;
15
16import org.openstreetmap.josm.actions.AutoScaleAction;
17import org.openstreetmap.josm.actions.mapmode.AddLineSegmentAction;
18import org.openstreetmap.josm.actions.mapmode.AddNodeAction;
19import org.openstreetmap.josm.actions.mapmode.AddTrackAction;
20import org.openstreetmap.josm.actions.mapmode.CombineAction;
21import org.openstreetmap.josm.actions.mapmode.DebugAction;
22import org.openstreetmap.josm.actions.mapmode.DeleteAction;
23import org.openstreetmap.josm.actions.mapmode.MapMode;
24import org.openstreetmap.josm.actions.mapmode.MoveAction;
25import org.openstreetmap.josm.actions.mapmode.SelectionAction;
26import org.openstreetmap.josm.actions.mapmode.ZoomAction;
27import org.openstreetmap.josm.data.osm.DataSet;
28import org.openstreetmap.josm.gui.dialogs.SelectionListDialog;
29
30/**
31 * One Map frame with one dataset behind. This is the container gui class whose
32 * display can be set to the different views.
33 *
34 * @author imi
35 */
36public class MapFrame extends JPanel {
37
38 /**
39 * The current mode, this frame operates.
40 */
41 public MapMode mapMode;
42 /**
43 * The view control displayed.
44 */
45 public Layer layer;
46 /**
47 * The toolbar with the action icons
48 */
49 public JToolBar toolBarActions = new JToolBar(JToolBar.VERTICAL);
50 /**
51 * The status line below the map
52 */
53 public MapStatus statusLine;
54
55 /**
56 * Construct a map with a given DataSet. The set cannot be replaced after construction
57 * (but of course, the data can be altered using the map's editing features).
58 */
59 public MapFrame(DataSet dataSet) {
60 setSize(400,400);
61 setLayout(new BorderLayout());
62
63 add(layer = new Layer(dataSet), BorderLayout.CENTER);
64
65 // toolbar
66 toolBarActions.setFloatable(false);
67 toolBarActions.add(new IconToggleButton(this, new ZoomAction(this)));
68 toolBarActions.add(new IconToggleButton(this, new SelectionAction(this)));
69 toolBarActions.add(new IconToggleButton(this, new MoveAction(this)));
70 toolBarActions.add(new IconToggleButton(this, new AddNodeAction(this)));
71 toolBarActions.add(new IconToggleButton(this, new AddLineSegmentAction(this)));
72 toolBarActions.add(new IconToggleButton(this, new AddTrackAction(this)));
73 toolBarActions.add(new IconToggleButton(this, new CombineAction(this)));
74 toolBarActions.add(new IconToggleButton(this, new DeleteAction(this)));
75 toolBarActions.add(new IconToggleButton(this, new DebugAction(this)));
76
77 // all map modes in one button group
78 ButtonGroup toolGroup = new ButtonGroup();
79 for (Component c : toolBarActions.getComponents())
80 toolGroup.add((AbstractButton)c);
81 toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true);
82 selectMapMode((MapMode)((AbstractButton)toolBarActions.getComponent(0)).getAction());
83
84 // autoScale
85 toolBarActions.addSeparator();
86 final JToggleButton autoScaleButton = new IconToggleButton(this, new AutoScaleAction(layer));
87 toolBarActions.add(autoScaleButton);
88 autoScaleButton.setText(null);
89 autoScaleButton.setSelected(layer.isAutoScale());
90 layer.addPropertyChangeListener(new PropertyChangeListener(){
91 public void propertyChange(PropertyChangeEvent evt) {
92 if (evt.getPropertyName().equals("autoScale"))
93 autoScaleButton.setSelected(layer.isAutoScale());
94 }
95 });
96
97 // selection dialog
98 SelectionListDialog selectionList = new SelectionListDialog(dataSet);
99 final IconToggleButton buttonSelection = new IconToggleButton(this, selectionList);
100 selectionList.addWindowListener(new WindowAdapter(){
101 @Override
102 public void windowClosing(WindowEvent e) {
103 buttonSelection.setSelected(false);
104 }
105 });
106 toolBarActions.add(buttonSelection);
107
108 // status line below the map
109 statusLine = new MapStatus(layer);
110 }
111
112 /**
113 * Change the operating map mode for the view. Will call unregister on the
114 * old MapMode and register on the new one.
115 * @param mapMode The new mode to set.
116 */
117 public void selectMapMode(MapMode mapMode) {
118 if (this.mapMode != null)
119 this.mapMode.unregisterListener();
120 this.mapMode = mapMode;
121 mapMode.registerListener();
122 }
123}
Note: See TracBrowser for help on using the repository browser.