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

Last change on this file since 729 was 729, checked in by stoecker, 16 years ago

added automatic tag correction system by Robin Rattay

  • Property svn:eol-style set to native
File size: 6.0 KB
Line 
1// License: GPL. See LICENSE file for details.
2
3package org.openstreetmap.josm.gui;
4
5import java.awt.BorderLayout;
6import java.awt.Component;
7import java.awt.Container;
8
9import javax.swing.AbstractButton;
10import javax.swing.Action;
11import javax.swing.BoxLayout;
12import javax.swing.ButtonGroup;
13import javax.swing.JPanel;
14import javax.swing.JToolBar;
15
16import org.openstreetmap.josm.Main;
17import org.openstreetmap.josm.actions.mapmode.DeleteAction;
18import org.openstreetmap.josm.actions.mapmode.DrawAction;
19import org.openstreetmap.josm.actions.mapmode.ExtrudeAction;
20import org.openstreetmap.josm.actions.mapmode.MapMode;
21import org.openstreetmap.josm.actions.mapmode.SelectAction;
22import org.openstreetmap.josm.actions.mapmode.ZoomAction;
23import org.openstreetmap.josm.gui.dialogs.CommandStackDialog;
24import org.openstreetmap.josm.gui.dialogs.ConflictDialog;
25import org.openstreetmap.josm.gui.dialogs.HistoryDialog;
26import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
27import org.openstreetmap.josm.gui.dialogs.PropertiesDialog;
28import org.openstreetmap.josm.gui.dialogs.RelationListDialog;
29import org.openstreetmap.josm.gui.dialogs.SelectionListDialog;
30import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
31import org.openstreetmap.josm.gui.dialogs.UserListDialog;
32import org.openstreetmap.josm.tools.Destroyable;
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 */
40public class MapFrame extends JPanel implements Destroyable {
41
42 /**
43 * The current mode, this frame operates.
44 */
45 public MapMode mapMode;
46 /**
47 * The view control displayed.
48 */
49 public MapView mapView;
50 /**
51 * The toolbar with the action icons. To add new toggle dialog actions, use addToggleDialog
52 * instead of adding directly to this list.
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 /**
62 * The panel list of all toggle dialog icons. To add new toggle dialog actions, use addToggleDialog
63 * instead of adding directly to this list.
64 */
65 public JPanel toggleDialogs = new JPanel();
66
67 public final ButtonGroup toolGroup = new ButtonGroup();
68
69 private PropertiesDialog propertiesDialog;
70
71 public MapFrame() {
72 setSize(400,400);
73 setLayout(new BorderLayout());
74
75 add(mapView = new MapView(), BorderLayout.CENTER);
76
77 // show menu entry
78 Main.main.menu.viewMenu.setVisible(true);
79
80 // toolbar
81 toolBarActions.setFloatable(false);
82 toolBarActions.add(new IconToggleButton(new ZoomAction(this)));
83 toolBarActions.add(new IconToggleButton(new SelectAction(this)));
84 toolBarActions.add(new IconToggleButton(new DrawAction(this)));
85 toolBarActions.add(new IconToggleButton(new DeleteAction(this)));
86 toolBarActions.add(new IconToggleButton(new ExtrudeAction(this)));
87
88 for (Component c : toolBarActions.getComponents())
89 toolGroup.add((AbstractButton)c);
90 toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true);
91
92 toolBarActions.addSeparator();
93
94 add(toggleDialogs, BorderLayout.EAST);
95 toggleDialogs.setLayout(new BoxLayout(toggleDialogs, BoxLayout.Y_AXIS));
96
97 addToggleDialog(new LayerListDialog(this));
98 addToggleDialog(propertiesDialog = new PropertiesDialog(this));
99 addToggleDialog(new HistoryDialog());
100 addToggleDialog(new SelectionListDialog());
101 addToggleDialog(new UserListDialog());
102 addToggleDialog(conflictDialog = new ConflictDialog());
103 addToggleDialog(new CommandStackDialog(this));
104 addToggleDialog(new RelationListDialog());
105
106 // status line below the map
107 statusLine = new MapStatus(this);
108 }
109
110 /**
111 * Called as some kind of destructor when the last layer has been removed.
112 * Delegates the call to all Destroyables within this component (e.g. MapModes)
113 */
114 public void destroy() {
115 for (int i = 0; i < toolBarActions.getComponentCount(); ++i)
116 if (toolBarActions.getComponent(i) instanceof Destroyable)
117 ((Destroyable)toolBarActions).destroy();
118
119 // remove menu entries
120 Main.main.menu.viewMenu.setVisible(false);
121 }
122
123 public Action getDefaultButtonAction() {
124 return ((AbstractButton)toolBarActions.getComponent(0)).getAction();
125 }
126
127 /**
128 * Open all ToggleDialogs that have their preferences property set. Close all others.
129 */
130 public void setVisibleDialogs() {
131 for (Component c : toggleDialogs.getComponents()) {
132 if (c instanceof ToggleDialog) {
133 boolean sel = Main.pref.getBoolean(((ToggleDialog)c).prefName+".visible");
134 ((ToggleDialog)c).action.button.setSelected(sel);
135 c.setVisible(sel);
136 }
137 }
138 }
139
140 /**
141 * Call this to add new toggle dialogs to the left button-list
142 * @param dlg The toggle dialog. It must not be in the list already.
143 */
144 public void addToggleDialog(ToggleDialog dlg) {
145 IconToggleButton button = new IconToggleButton(dlg.action);
146 dlg.action.button = button;
147 dlg.parent = toggleDialogs;
148 toolBarActions.add(button);
149 toggleDialogs.add(dlg);
150 }
151
152
153 /**
154 * Fires an property changed event "visible".
155 */
156 @Override public void setVisible(boolean aFlag) {
157 boolean old = isVisible();
158 super.setVisible(aFlag);
159 if (old != aFlag)
160 firePropertyChange("visible", old, aFlag);
161 }
162
163
164
165 /**
166 * Change the operating map mode for the view. Will call unregister on the
167 * old MapMode and register on the new one.
168 * @param mapMode The new mode to set.
169 */
170 public void selectMapMode(MapMode mapMode) {
171 if (mapMode == this.mapMode)
172 return;
173 if (this.mapMode != null)
174 this.mapMode.exitMode();
175 this.mapMode = mapMode;
176 mapMode.enterMode();
177 }
178
179 /**
180 * Fill the given panel by adding all necessary components to the different
181 * locations.
182 *
183 * @param panel The container to fill. Must have an BorderLayout.
184 */
185 public void fillPanel(Container panel) {
186 panel.add(this, BorderLayout.CENTER);
187 panel.add(toolBarActions, BorderLayout.WEST);
188 if (statusLine != null)
189 panel.add(statusLine, BorderLayout.SOUTH);
190 }
191
192 public final PropertiesDialog getPropertiesDialog() {
193 return propertiesDialog;
194 }
195}
Note: See TracBrowser for help on using the repository browser.