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

Last change on this file since 1329 was 1231, checked in by ulfl, 15 years ago

drop files on the main window to open it

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