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

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

close bug #1575

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