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

Last change on this file since 155 was 155, checked in by imi, 18 years ago
  • added online help system
File size: 6.3 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.Action;
13import javax.swing.BoxLayout;
14import javax.swing.ButtonGroup;
15import javax.swing.JPanel;
16import javax.swing.JToolBar;
17
18import org.openstreetmap.josm.Main;
19import org.openstreetmap.josm.actions.AutoScaleAction;
20import org.openstreetmap.josm.actions.mapmode.AddSegmentAction;
21import org.openstreetmap.josm.actions.mapmode.AddWayAction;
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.actions.mapmode.AddNodeAction.AddNodeGroup;
28import org.openstreetmap.josm.gui.dialogs.CommandStackDialog;
29import org.openstreetmap.josm.gui.dialogs.ConflictDialog;
30import org.openstreetmap.josm.gui.dialogs.HistoryDialog;
31import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
32import org.openstreetmap.josm.gui.dialogs.PropertiesDialog;
33import org.openstreetmap.josm.gui.dialogs.SelectionListDialog;
34import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
35
36/**
37 * One Map frame with one dataset behind. This is the container gui class whose
38 * display can be set to the different views.
39 *
40 * @author imi
41 */
42public class MapFrame extends JPanel {
43
44 /**
45 * The current mode, this frame operates.
46 */
47 public MapMode mapMode;
48 /**
49 * The view control displayed.
50 */
51 public MapView mapView;
52 /**
53 * The toolbar with the action icons
54 */
55 public JToolBar toolBarActions = new JToolBar(JToolBar.VERTICAL);
56 /**
57 * The status line below the map
58 */
59 public MapStatus statusLine;
60
61 public ConflictDialog conflictDialog;
62 private JPanel toggleDialogs = new JPanel();
63
64 /**
65 * Construct a map with a given DataSet. The set cannot be replaced after
66 * construction (but of course, the data can be altered using the map's
67 * editing features).
68 *
69 * @param layer The first layer in the mapView.
70 */
71 public MapFrame() {
72 setSize(400,400);
73 setLayout(new BorderLayout());
74
75 final AutoScaleAction autoScaleAction = new AutoScaleAction(this);
76 add(mapView = new MapView(autoScaleAction), BorderLayout.CENTER);
77
78 // toolbar
79 toolBarActions.setFloatable(false);
80 toolBarActions.add(new IconToggleButton(new ZoomAction(this)));
81 final Action selectionAction = new SelectionAction.Group(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
95 // autoScale
96 toolBarActions.addSeparator();
97 final IconToggleButton autoScaleButton = new IconToggleButton(autoScaleAction);
98 toolBarActions.add(autoScaleButton);
99 autoScaleButton.setText(null);
100 autoScaleButton.setSelected(mapView.isAutoScale());
101 autoScaleAction.putValue("active", true);
102 mapView.addPropertyChangeListener(new PropertyChangeListener(){
103 public void propertyChange(PropertyChangeEvent evt) {
104 if (evt.getPropertyName().equals("autoScale")) {
105 autoScaleAction.putValue("active", evt.getNewValue());
106 autoScaleButton.setSelected((Boolean)evt.getNewValue());
107 }
108 }
109 });
110 autoScaleButton.addActionListener(new ActionListener(){
111 public void actionPerformed(ActionEvent e) {
112 if (!autoScaleButton.groupbutton)
113 autoScaleButton.setSelected(true);
114 }
115 });
116
117 add(toggleDialogs, BorderLayout.EAST);
118 toggleDialogs.setLayout(new BoxLayout(toggleDialogs, BoxLayout.Y_AXIS));
119
120 addIconToggle(toggleDialogs, new LayerListDialog(this));
121 addIconToggle(toggleDialogs, new PropertiesDialog(this));
122 addIconToggle(toggleDialogs, new HistoryDialog());
123 addIconToggle(toggleDialogs, new SelectionListDialog());
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 public Action getDefaultButtonAction() {
132 return ((AbstractButton)toolBarActions.getComponent(0)).getAction();
133 }
134
135 /**
136 * Open all ToggleDialogs that have their preferences property set. Close all others.
137 */
138 public void setVisibleDialogs() {
139 for (Component c : toggleDialogs.getComponents()) {
140 if (c instanceof ToggleDialog) {
141 boolean sel = Main.pref.getBoolean(((ToggleDialog)c).prefName+".visible");
142 ((ToggleDialog)c).action.button.setSelected(sel);
143 c.setVisible(sel);
144 }
145 }
146 }
147
148 private void addIconToggle(JPanel toggleDialogs, ToggleDialog dlg) {
149 IconToggleButton button = new IconToggleButton(dlg.action);
150 dlg.action.button = button;
151 toolBarActions.add(button);
152 toggleDialogs.add(dlg);
153 }
154
155
156 /**
157 * Fires an property changed event "visible".
158 */
159 @Override public void setVisible(boolean aFlag) {
160 boolean old = isVisible();
161 super.setVisible(aFlag);
162 if (old != aFlag)
163 firePropertyChange("visible", old, aFlag);
164 }
165
166
167
168 /**
169 * Change the operating map mode for the view. Will call unregister on the
170 * old MapMode and register on the new one.
171 * @param mapMode The new mode to set.
172 */
173 public void selectMapMode(MapMode mapMode) {
174 if (mapMode == this.mapMode)
175 return;
176 if (this.mapMode != null)
177 this.mapMode.exitMode();
178 this.mapMode = mapMode;
179 mapMode.enterMode();
180 }
181
182 /**
183 * Fill the given panel by adding all necessary components to the different
184 * locations.
185 *
186 * @param panel The container to fill. Must have an BorderLayout.
187 */
188 public void fillPanel(Container panel) {
189 panel.add(this, BorderLayout.CENTER);
190 panel.add(toolBarActions, BorderLayout.WEST);
191 panel.add(statusLine, BorderLayout.SOUTH);
192 }
193}
Note: See TracBrowser for help on using the repository browser.