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

Last change on this file since 99 was 99, checked in by imi, 18 years ago
  • added GeoImage feature (showing images on a tracklog)
  • added zoom slider
  • added Escape cancels selection rectangle
  • added "Save password" option to Auth-dialog
  • fixed that redo/undo buttons were not enabled
  • fixed hotkeys beeing inaccessible when no data is loaded
File size: 6.2 KB
Line 
1package org.openstreetmap.josm.gui;
2
3import java.awt.BorderLayout;
4import java.awt.Component;
5import java.awt.Container;
6import java.awt.event.ActionEvent;
7import java.awt.event.ActionListener;
8import java.beans.PropertyChangeEvent;
9import java.beans.PropertyChangeListener;
10
11import javax.swing.AbstractButton;
12import javax.swing.BoxLayout;
13import javax.swing.ButtonGroup;
14import javax.swing.JPanel;
15import javax.swing.JToolBar;
16
17import org.openstreetmap.josm.Main;
18import org.openstreetmap.josm.actions.AutoScaleAction;
19import org.openstreetmap.josm.actions.mapmode.AddSegmentAction;
20import org.openstreetmap.josm.actions.mapmode.AddWayAction;
21import org.openstreetmap.josm.actions.mapmode.DeleteAction;
22import org.openstreetmap.josm.actions.mapmode.MapMode;
23import org.openstreetmap.josm.actions.mapmode.MoveAction;
24import org.openstreetmap.josm.actions.mapmode.SelectionAction;
25import org.openstreetmap.josm.actions.mapmode.ZoomAction;
26import org.openstreetmap.josm.actions.mapmode.AddNodeAction.AddNodeGroup;
27import org.openstreetmap.josm.gui.dialogs.CommandStackDialog;
28import org.openstreetmap.josm.gui.dialogs.ConflictDialog;
29import org.openstreetmap.josm.gui.dialogs.LayerList;
30import org.openstreetmap.josm.gui.dialogs.PropertiesDialog;
31import org.openstreetmap.josm.gui.dialogs.SelectionListDialog;
32import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
33import org.openstreetmap.josm.gui.layer.Layer;
34
35/**
36 * One Map frame with one dataset behind. This is the container gui class whose
37 * display can be set to the different views.
38 *
39 * @author imi
40 */
41public class MapFrame extends JPanel {
42
43 /**
44 * The current mode, this frame operates.
45 */
46 public MapMode mapMode;
47 /**
48 * The view control displayed.
49 */
50 public MapView mapView;
51 /**
52 * The toolbar with the action icons
53 */
54 public JToolBar toolBarActions = new JToolBar(JToolBar.VERTICAL);
55 /**
56 * The status line below the map
57 */
58 public MapStatus statusLine;
59
60 public ConflictDialog conflictDialog;
61 private JPanel toggleDialogs = new JPanel();
62
63 /**
64 * Construct a map with a given DataSet. The set cannot be replaced after
65 * construction (but of course, the data can be altered using the map's
66 * editing features).
67 *
68 * @param layer The first layer in the mapView.
69 */
70 public MapFrame(Layer layer) {
71 setSize(400,400);
72 setLayout(new BorderLayout());
73
74 final AutoScaleAction autoScaleAction = new AutoScaleAction(this);
75 add(mapView = new MapView(autoScaleAction), BorderLayout.CENTER);
76 mapView.addLayer(layer);
77
78 // toolbar
79 toolBarActions.setFloatable(false);
80 toolBarActions.add(new IconToggleButton(new ZoomAction(this)));
81 final SelectionAction selectionAction = new SelectionAction(this);
82 toolBarActions.add(new IconToggleButton(selectionAction));
83 toolBarActions.add(new IconToggleButton(new MoveAction(this)));
84 toolBarActions.add(new IconToggleButton(new AddNodeGroup(this)));
85 toolBarActions.add(new IconToggleButton(new AddSegmentAction(this)));
86 toolBarActions.add(new IconToggleButton(new AddWayAction(this)));
87 toolBarActions.add(new IconToggleButton(new DeleteAction(this)));
88
89 // all map modes in one button group
90 ButtonGroup toolGroup = new ButtonGroup();
91 for (Component c : toolBarActions.getComponents())
92 toolGroup.add((AbstractButton)c);
93 toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true);
94 selectMapMode((MapMode)((AbstractButton)toolBarActions.getComponent(0)).getAction());
95
96 // autoScale
97 toolBarActions.addSeparator();
98 final IconToggleButton autoScaleButton = new IconToggleButton(autoScaleAction);
99 toolBarActions.add(autoScaleButton);
100 autoScaleButton.setText(null);
101 autoScaleButton.setSelected(mapView.isAutoScale());
102 autoScaleAction.putValue("active", true);
103 mapView.addPropertyChangeListener(new PropertyChangeListener(){
104 public void propertyChange(PropertyChangeEvent evt) {
105 if (evt.getPropertyName().equals("autoScale")) {
106 autoScaleAction.putValue("active", evt.getNewValue());
107 autoScaleButton.setSelected((Boolean)evt.getNewValue());
108 }
109 }
110 });
111 autoScaleButton.addActionListener(new ActionListener(){
112 public void actionPerformed(ActionEvent e) {
113 if (!autoScaleButton.groupbutton)
114 autoScaleButton.setSelected(true);
115 }
116 });
117
118 add(toggleDialogs, BorderLayout.EAST);
119 toggleDialogs.setLayout(new BoxLayout(toggleDialogs, BoxLayout.Y_AXIS));
120
121 addIconToggle(toggleDialogs, new LayerList(this));
122 addIconToggle(toggleDialogs, new PropertiesDialog(this));
123 addIconToggle(toggleDialogs, new SelectionListDialog(this));
124 addIconToggle(toggleDialogs, conflictDialog = new ConflictDialog());
125 addIconToggle(toggleDialogs, new CommandStackDialog(this));
126
127 // status line below the map
128 statusLine = new MapStatus(this);
129 }
130
131 /**
132 * Open all ToggleDialogs that have their preferences property set. Close all others.
133 */
134 public void setVisibleDialogs() {
135 for (Component c : toggleDialogs.getComponents()) {
136 if (c instanceof ToggleDialog) {
137 boolean sel = Main.pref.getBoolean(((ToggleDialog)c).prefName+".visible");
138 ((ToggleDialog)c).action.button.setSelected(sel);
139 c.setVisible(sel);
140 }
141 }
142 }
143
144 private void addIconToggle(JPanel toggleDialogs, ToggleDialog dlg) {
145 IconToggleButton button = new IconToggleButton(dlg.action);
146 dlg.action.button = button;
147 toolBarActions.add(button);
148 toggleDialogs.add(dlg);
149 }
150
151
152 /**
153 * Fires an property changed event "visible".
154 */
155 @Override public void setVisible(boolean aFlag) {
156 boolean old = isVisible();
157 super.setVisible(aFlag);
158 if (old != aFlag)
159 firePropertyChange("visible", old, aFlag);
160 }
161
162
163
164 /**
165 * Change the operating map mode for the view. Will call unregister on the
166 * old MapMode and register on the new one.
167 * @param mapMode The new mode to set.
168 */
169 public void selectMapMode(MapMode mapMode) {
170 if (mapMode == this.mapMode)
171 return;
172 if (this.mapMode != null)
173 this.mapMode.exitMode();
174 this.mapMode = mapMode;
175 mapMode.enterMode();
176 }
177
178 /**
179 * Fill the given panel by adding all necessary components to the different
180 * locations.
181 *
182 * @param panel The container to fill. Must have an BorderLayout.
183 */
184 public void fillPanel(Container panel) {
185 panel.add(this, BorderLayout.CENTER);
186 panel.add(toolBarActions, BorderLayout.WEST);
187 panel.add(statusLine, BorderLayout.SOUTH);
188 }
189}
Note: See TracBrowser for help on using the repository browser.