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

Last change on this file since 1750 was 1677, checked in by stoecker, 15 years ago

remove all these ugly tab stops introduced in the last half year

  • Property svn:eol-style set to native
File size: 8.4 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;
8import java.util.ArrayList;
9
10import javax.swing.AbstractButton;
11import javax.swing.Action;
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.mapmode.DeleteAction;
19import org.openstreetmap.josm.actions.mapmode.DrawAction;
20import org.openstreetmap.josm.actions.mapmode.ExtrudeAction;
21import org.openstreetmap.josm.actions.mapmode.MapMode;
22import org.openstreetmap.josm.actions.mapmode.SelectAction;
23import org.openstreetmap.josm.actions.mapmode.ZoomAction;
24import org.openstreetmap.josm.gui.ScrollViewport;
25import org.openstreetmap.josm.gui.dialogs.CommandStackDialog;
26import org.openstreetmap.josm.gui.dialogs.ConflictDialog;
27import org.openstreetmap.josm.gui.dialogs.HistoryDialog;
28import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
29import org.openstreetmap.josm.gui.dialogs.PropertiesDialog;
30import org.openstreetmap.josm.gui.dialogs.RelationListDialog;
31import org.openstreetmap.josm.gui.dialogs.SelectionListDialog;
32import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
33import org.openstreetmap.josm.gui.dialogs.UserListDialog;
34import org.openstreetmap.josm.tools.Destroyable;
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 implements Destroyable {
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. To add new toggle dialog actions, use addToggleDialog
54 * instead of adding directly to this list. To add a new mode use addMapMode.
55 */
56 private JToolBar toolBarActions = new JToolBar(JToolBar.VERTICAL);
57 private JToolBar toolBarToggle = new JToolBar(JToolBar.VERTICAL);
58 /**
59 * The status line below the map
60 */
61 public MapStatus statusLine;
62
63 public ConflictDialog conflictDialog;
64 /**
65 * The dialog that shows all relations and lets the user edit them.
66 */
67 public RelationListDialog relationListDialog;
68 /**
69 * The panel list of all toggle dialog icons. To add new toggle dialog actions, use addToggleDialog
70 * instead of adding directly to this list.
71 */
72 public JPanel toggleDialogs = new JPanel();
73 public ArrayList<ToggleDialog> allDialogs = new ArrayList<ToggleDialog>();
74
75 public final ButtonGroup toolGroup = new ButtonGroup();
76
77 public MapFrame() {
78 setSize(400,400);
79 setLayout(new BorderLayout());
80
81 add(mapView = new MapView(), BorderLayout.CENTER);
82
83 new FileDrop(mapView);
84
85 // show menu entry
86 Main.main.menu.viewMenu.setVisible(true);
87
88 // toolbar
89 toolBarActions.setFloatable(false);
90 addMapMode(new IconToggleButton(new SelectAction(this)));
91 addMapMode(new IconToggleButton(new DrawAction(this)));
92 addMapMode(new IconToggleButton(new ExtrudeAction(this)));
93 addMapMode(new IconToggleButton(new ZoomAction(this)));
94 addMapMode(new IconToggleButton(new DeleteAction(this)));
95
96 toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true);
97
98 add(toggleDialogs, BorderLayout.EAST);
99 toggleDialogs.setLayout(new BoxLayout(toggleDialogs, BoxLayout.Y_AXIS));
100
101 toolBarToggle.setFloatable(false);
102 addToggleDialog(new LayerListDialog(this));
103 addToggleDialog(new PropertiesDialog(this));
104 addToggleDialog(new HistoryDialog());
105 addToggleDialog(new SelectionListDialog());
106 addToggleDialog(new UserListDialog());
107 addToggleDialog(conflictDialog = new ConflictDialog());
108 addToggleDialog(new CommandStackDialog(this));
109 addToggleDialog(relationListDialog = new RelationListDialog());
110
111 // status line below the map
112 statusLine = new MapStatus(this);
113 }
114
115 public void selectSelectTool(boolean onlyIfModeless) {
116 if(onlyIfModeless && !Main.pref.getBoolean("modeless", false))
117 return;
118
119 selectMapMode((MapMode)getDefaultButtonAction());
120 }
121
122 public void selectDrawTool(boolean onlyIfModeless) {
123 if(onlyIfModeless && !Main.pref.getBoolean("modeless", false))
124 return;
125
126 Action drawAction = ((AbstractButton)toolBarActions.getComponent(1)).getAction();
127 selectMapMode((MapMode)drawAction);
128 }
129
130 /**
131 * Called as some kind of destructor when the last layer has been removed.
132 * Delegates the call to all Destroyables within this component (e.g. MapModes)
133 */
134 public void destroy() {
135 for (ToggleDialog t : allDialogs)
136 t.close();
137 for (int i = 0; i < toolBarActions.getComponentCount(); ++i)
138 if (toolBarActions.getComponent(i) instanceof Destroyable)
139 ((Destroyable)toolBarActions).destroy();
140 for (int i = 0; i < toolBarToggle.getComponentCount(); ++i)
141 if (toolBarToggle.getComponent(i) instanceof Destroyable)
142 ((Destroyable)toolBarToggle).destroy();
143
144 // remove menu entries
145 Main.main.menu.viewMenu.setVisible(false);
146
147 // MapFrame gets destroyed when the last layer is removed, but the status line background
148 // thread that collects the information doesn't get destroyed automatically.
149 if(statusLine.thread == null) return;
150 try {
151 statusLine.thread.interrupt();
152 } catch (Exception e) {}
153 }
154
155 public Action getDefaultButtonAction() {
156 return ((AbstractButton)toolBarActions.getComponent(0)).getAction();
157 }
158
159 /**
160 * Open all ToggleDialogs that have their preferences property set. Close all others.
161 */
162 public void setVisibleDialogs() {
163 for (Component c : toggleDialogs.getComponents()) {
164 if (c instanceof ToggleDialog) {
165 boolean sel = Main.pref.getBoolean(((ToggleDialog)c).prefName+".visible");
166 ((ToggleDialog)c).action.button.setSelected(sel);
167 c.setVisible(sel);
168 }
169 }
170 }
171
172 /**
173 * Call this to add new toggle dialogs to the left button-list
174 * @param dlg The toggle dialog. It must not be in the list already.
175 */
176 public IconToggleButton addToggleDialog(ToggleDialog dlg) {
177 IconToggleButton button = new IconToggleButton(dlg.action);
178 dlg.action.button = button;
179 dlg.parent = toggleDialogs;
180 toolBarToggle.add(button);
181 toggleDialogs.add(dlg);
182 allDialogs.add(dlg);
183 return button;
184 }
185
186 public void addMapMode(IconToggleButton b) {
187 toolBarActions.add(b);
188 toolGroup.add(b);
189 }
190
191 /**
192 * Fires an property changed event "visible".
193 */
194 @Override public void setVisible(boolean aFlag) {
195 boolean old = isVisible();
196 super.setVisible(aFlag);
197 if (old != aFlag)
198 firePropertyChange("visible", old, aFlag);
199 }
200
201
202
203 /**
204 * Change the operating map mode for the view. Will call unregister on the
205 * old MapMode and register on the new one.
206 * @param mapMode The new mode to set.
207 */
208 public void selectMapMode(MapMode mapMode) {
209 if (mapMode == this.mapMode)
210 return;
211 if (this.mapMode != null)
212 this.mapMode.exitMode();
213 this.mapMode = mapMode;
214 mapMode.enterMode();
215 }
216
217 /**
218 * Fill the given panel by adding all necessary components to the different
219 * locations.
220 *
221 * @param panel The container to fill. Must have an BorderLayout.
222 */
223 public void fillPanel(Container panel) {
224 panel.add(this, BorderLayout.CENTER);
225 JToolBar jb = new JToolBar(JToolBar.VERTICAL);
226 jb.setFloatable(false);
227 jb.add(toolBarActions);
228 jb.addSeparator();
229 jb.add(toolBarToggle);
230 if(Main.pref.getBoolean("sidetoolbar.visible", true))
231 {
232 if(Main.pref.getBoolean("sidetoolbar.scrollable", true))
233 panel.add(new ScrollViewport(jb, ScrollViewport.VERTICAL_DIRECTION),
234 BorderLayout.WEST);
235 else
236 panel.add(jb, BorderLayout.WEST);
237 }
238 if (statusLine != null && Main.pref.getBoolean("statusline.visible", true))
239 panel.add(statusLine, BorderLayout.SOUTH);
240 }
241}
Note: See TracBrowser for help on using the repository browser.