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

Last change on this file since 312 was 312, checked in by imi, 17 years ago
  • fixed bug to allow move of one node
  • removed "new shiny beta" warning
  • fixed uploading data marks as modified when saved before
File size: 6.1 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.gui;
3
4import java.awt.BorderLayout;
5import java.awt.Component;
6import java.awt.Container;
7
8import javax.swing.AbstractButton;
9import javax.swing.Action;
10import javax.swing.BoxLayout;
11import javax.swing.ButtonGroup;
12import javax.swing.JPanel;
13import javax.swing.JToolBar;
14
15import org.openstreetmap.josm.Main;
16import org.openstreetmap.josm.actions.mapmode.AddSegmentAction;
17import org.openstreetmap.josm.actions.mapmode.AddWayAction;
18import org.openstreetmap.josm.actions.mapmode.DeleteAction;
19import org.openstreetmap.josm.actions.mapmode.MapMode;
20import org.openstreetmap.josm.actions.mapmode.SelectionAction;
21import org.openstreetmap.josm.actions.mapmode.ZoomAction;
22import org.openstreetmap.josm.actions.mapmode.AddNodeAction.AddNodeGroup;
23import org.openstreetmap.josm.actions.mapmode.MoveAction.MoveGroup;
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.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 private 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
70 public MapFrame() {
71 setSize(400,400);
72 setLayout(new BorderLayout());
73
74 add(mapView = new MapView(), BorderLayout.CENTER);
75
76 // show menu entry
77 Main.main.menu.viewMenu.setVisible(true);
78
79 // toolbar
80 toolBarActions.setFloatable(false);
81 toolBarActions.add(new IconToggleButton(new ZoomAction(this)));
82 final Action selectionAction = new SelectionAction.Group(this);
83 toolBarActions.add(new IconToggleButton(selectionAction));
84 toolBarActions.add(new IconToggleButton(new MoveGroup(this)));
85 toolBarActions.add(new IconToggleButton(new AddNodeGroup(this)));
86 toolBarActions.add(new IconToggleButton(new AddSegmentAction(this)));
87 toolBarActions.add(new IconToggleButton(new AddWayAction(this)));
88 toolBarActions.add(new IconToggleButton(new DeleteAction(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
107 // status line below the map
108 if (!Main.applet)
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.