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

Last change on this file since 68 was 68, checked in by imi, 18 years ago
  • Remove Alt from hotkeys ('n' for new node, not Alt-n)
  • use command line options to open files/start or download (--help for a list)
File size: 5.0 KB
Line 
1package org.openstreetmap.josm.gui;
2
3import java.awt.BorderLayout;
4import java.awt.Component;
5import java.awt.Container;
6import java.beans.PropertyChangeEvent;
7import java.beans.PropertyChangeListener;
8
9import javax.swing.AbstractButton;
10import javax.swing.BoxLayout;
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.AddWayAction;
20import org.openstreetmap.josm.actions.mapmode.DeleteAction;
21import org.openstreetmap.josm.actions.mapmode.MapMode;
22import org.openstreetmap.josm.actions.mapmode.MoveAction;
23import org.openstreetmap.josm.actions.mapmode.SelectionAction;
24import org.openstreetmap.josm.actions.mapmode.ZoomAction;
25import org.openstreetmap.josm.gui.dialogs.LayerList;
26import org.openstreetmap.josm.gui.dialogs.PropertiesDialog;
27import org.openstreetmap.josm.gui.dialogs.SelectionListDialog;
28import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
29import org.openstreetmap.josm.gui.layer.Layer;
30
31/**
32 * One Map frame with one dataset behind. This is the container gui class whose
33 * display can be set to the different views.
34 *
35 * @author imi
36 */
37public class MapFrame extends JPanel {
38
39 /**
40 * The current mode, this frame operates.
41 */
42 public MapMode mapMode;
43 /**
44 * The view control displayed.
45 */
46 public MapView mapView;
47 /**
48 * The toolbar with the action icons
49 */
50 public JToolBar toolBarActions = new JToolBar(JToolBar.VERTICAL);
51 /**
52 * The status line below the map
53 */
54 public MapStatus statusLine;
55 /**
56 * Construct a map with a given DataSet. The set cannot be replaced after
57 * construction (but of course, the data can be altered using the map's
58 * editing features).
59 *
60 * @param layer The first layer in the mapView.
61 */
62 public MapFrame(Layer layer) {
63 setSize(400,400);
64 setLayout(new BorderLayout());
65
66 add(mapView = new MapView(layer), BorderLayout.CENTER);
67
68 // toolbar
69 toolBarActions.setFloatable(false);
70 toolBarActions.add(new IconToggleButton(this, new ZoomAction(this)));
71 final SelectionAction selectionAction = new SelectionAction(this);
72 toolBarActions.add(new IconToggleButton(this, selectionAction));
73 toolBarActions.add(new IconToggleButton(this, new MoveAction(this)));
74 toolBarActions.add(new IconToggleButton(this, new AddNodeAction(this)));
75 toolBarActions.add(new IconToggleButton(this, new AddLineSegmentAction(this)));
76 toolBarActions.add(new IconToggleButton(this, new AddWayAction(this, selectionAction)));
77 toolBarActions.add(new IconToggleButton(this, new DeleteAction(this)));
78
79 // all map modes in one button group
80 ButtonGroup toolGroup = new ButtonGroup();
81 for (Component c : toolBarActions.getComponents())
82 toolGroup.add((AbstractButton)c);
83 toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true);
84 selectMapMode((MapMode)((AbstractButton)toolBarActions.getComponent(0)).getAction());
85
86 // autoScale
87 toolBarActions.addSeparator();
88 final JToggleButton autoScaleButton = new IconToggleButton(this, new AutoScaleAction(this));
89 toolBarActions.add(autoScaleButton);
90 autoScaleButton.setText(null);
91 autoScaleButton.setSelected(mapView.isAutoScale());
92 mapView.addPropertyChangeListener(new PropertyChangeListener(){
93 public void propertyChange(PropertyChangeEvent evt) {
94 if (evt.getPropertyName().equals("autoScale"))
95 autoScaleButton.setSelected(mapView.isAutoScale());
96 }
97 });
98
99 JPanel toggleDialogs = new JPanel();
100 add(toggleDialogs, BorderLayout.EAST);
101
102 toggleDialogs.setLayout(new BoxLayout(toggleDialogs, BoxLayout.Y_AXIS));
103 addIconToggle(toggleDialogs, new LayerList(this));
104 addIconToggle(toggleDialogs, new PropertiesDialog(this));
105 addIconToggle(toggleDialogs, new SelectionListDialog(this));
106
107 // status line below the map
108 statusLine = new MapStatus(this);
109 }
110
111
112 private void addIconToggle(JPanel toggleDialogs, ToggleDialog dlg) {
113 toolBarActions.add(new IconToggleButton(this, dlg.action));
114 toggleDialogs.add(dlg);
115 }
116
117
118 /**
119 * Fires an property changed event "visible".
120 */
121 @Override
122 public void setVisible(boolean aFlag) {
123 boolean old = isVisible();
124 super.setVisible(aFlag);
125 if (old != aFlag)
126 firePropertyChange("visible", old, aFlag);
127 }
128
129
130
131 /**
132 * Change the operating map mode for the view. Will call unregister on the
133 * old MapMode and register on the new one.
134 * @param mapMode The new mode to set.
135 */
136 public void selectMapMode(MapMode mapMode) {
137 if (this.mapMode != null)
138 this.mapMode.unregisterListener();
139 this.mapMode = mapMode;
140 mapMode.registerListener();
141 }
142
143 /**
144 * Fill the given panel by adding all necessary components to the different
145 * locations.
146 *
147 * @param panel The container to fill. Must have an BorderLayout.
148 */
149 public void fillPanel(Container panel) {
150 panel.add(this, BorderLayout.CENTER);
151 panel.add(toolBarActions, BorderLayout.WEST);
152 panel.add(statusLine, BorderLayout.SOUTH);
153 }
154}
Note: See TracBrowser for help on using the repository browser.