1 | // License: GPL. See LICENSE file for details.
|
---|
2 |
|
---|
3 | package org.openstreetmap.josm.gui;
|
---|
4 |
|
---|
5 | import java.awt.BorderLayout;
|
---|
6 | import java.awt.Component;
|
---|
7 | import java.awt.Container;
|
---|
8 |
|
---|
9 | import javax.swing.AbstractButton;
|
---|
10 | import javax.swing.Action;
|
---|
11 | import javax.swing.BoxLayout;
|
---|
12 | import javax.swing.ButtonGroup;
|
---|
13 | import javax.swing.JPanel;
|
---|
14 | import javax.swing.JToolBar;
|
---|
15 |
|
---|
16 | import org.openstreetmap.josm.Main;
|
---|
17 | import org.openstreetmap.josm.actions.mapmode.DeleteAction;
|
---|
18 | import org.openstreetmap.josm.actions.mapmode.DrawAction;
|
---|
19 | import org.openstreetmap.josm.actions.mapmode.ExtrudeAction;
|
---|
20 | import org.openstreetmap.josm.actions.mapmode.MapMode;
|
---|
21 | import org.openstreetmap.josm.actions.mapmode.SelectAction;
|
---|
22 | import org.openstreetmap.josm.actions.mapmode.ZoomAction;
|
---|
23 | import org.openstreetmap.josm.gui.dialogs.CommandStackDialog;
|
---|
24 | import org.openstreetmap.josm.gui.dialogs.ConflictDialog;
|
---|
25 | import org.openstreetmap.josm.gui.dialogs.HistoryDialog;
|
---|
26 | import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
|
---|
27 | import org.openstreetmap.josm.gui.dialogs.PropertiesDialog;
|
---|
28 | import org.openstreetmap.josm.gui.dialogs.RelationListDialog;
|
---|
29 | import org.openstreetmap.josm.gui.dialogs.SelectionListDialog;
|
---|
30 | import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
|
---|
31 | import org.openstreetmap.josm.gui.dialogs.UserListDialog;
|
---|
32 | import 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 | */
|
---|
40 | public 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. To add a new mode use addMapMode.
|
---|
53 | */
|
---|
54 | public JToolBar toolBarActions = new JToolBar(JToolBar.VERTICAL);
|
---|
55 | public JToolBar toolBarToggle = new JToolBar(JToolBar.VERTICAL);
|
---|
56 | /**
|
---|
57 | * The status line below the map
|
---|
58 | */
|
---|
59 | public MapStatus statusLine;
|
---|
60 |
|
---|
61 | public ConflictDialog conflictDialog;
|
---|
62 | /**
|
---|
63 | * The dialog that shows all relations and lets the user edit them.
|
---|
64 | */
|
---|
65 | public RelationListDialog relationListDialog;
|
---|
66 | /**
|
---|
67 | * The panel list of all toggle dialog icons. To add new toggle dialog actions, use addToggleDialog
|
---|
68 | * instead of adding directly to this list.
|
---|
69 | */
|
---|
70 | public JPanel toggleDialogs = new JPanel();
|
---|
71 |
|
---|
72 | public final ButtonGroup toolGroup = new ButtonGroup();
|
---|
73 |
|
---|
74 | public MapFrame() {
|
---|
75 | setSize(400,400);
|
---|
76 | setLayout(new BorderLayout());
|
---|
77 |
|
---|
78 | add(mapView = new MapView(), BorderLayout.CENTER);
|
---|
79 |
|
---|
80 | // show menu entry
|
---|
81 | Main.main.menu.viewMenu.setVisible(true);
|
---|
82 |
|
---|
83 | // toolbar
|
---|
84 | toolBarActions.setFloatable(false);
|
---|
85 | addMapMode(new IconToggleButton(new ZoomAction(this)));
|
---|
86 | addMapMode(new IconToggleButton(new SelectAction(this)));
|
---|
87 | addMapMode(new IconToggleButton(new DrawAction(this)));
|
---|
88 | addMapMode(new IconToggleButton(new DeleteAction(this)));
|
---|
89 | addMapMode(new IconToggleButton(new ExtrudeAction(this)));
|
---|
90 |
|
---|
91 | toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true);
|
---|
92 |
|
---|
93 | add(toggleDialogs, BorderLayout.EAST);
|
---|
94 | toggleDialogs.setLayout(new BoxLayout(toggleDialogs, BoxLayout.Y_AXIS));
|
---|
95 |
|
---|
96 | toolBarToggle.setFloatable(false);
|
---|
97 | addToggleDialog(new LayerListDialog(this));
|
---|
98 | addToggleDialog(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(relationListDialog = 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 | for (int i = 0; i < toolBarToggle.getComponentCount(); ++i)
|
---|
119 | if (toolBarToggle.getComponent(i) instanceof Destroyable)
|
---|
120 | ((Destroyable)toolBarToggle).destroy();
|
---|
121 |
|
---|
122 | // remove menu entries
|
---|
123 | Main.main.menu.viewMenu.setVisible(false);
|
---|
124 | }
|
---|
125 |
|
---|
126 | public Action getDefaultButtonAction() {
|
---|
127 | return ((AbstractButton)toolBarActions.getComponent(0)).getAction();
|
---|
128 | }
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * Open all ToggleDialogs that have their preferences property set. Close all others.
|
---|
132 | */
|
---|
133 | public void setVisibleDialogs() {
|
---|
134 | for (Component c : toggleDialogs.getComponents()) {
|
---|
135 | if (c instanceof ToggleDialog) {
|
---|
136 | boolean sel = Main.pref.getBoolean(((ToggleDialog)c).prefName+".visible");
|
---|
137 | ((ToggleDialog)c).action.button.setSelected(sel);
|
---|
138 | c.setVisible(sel);
|
---|
139 | }
|
---|
140 | }
|
---|
141 | }
|
---|
142 |
|
---|
143 | /**
|
---|
144 | * Call this to add new toggle dialogs to the left button-list
|
---|
145 | * @param dlg The toggle dialog. It must not be in the list already.
|
---|
146 | */
|
---|
147 | public void addToggleDialog(ToggleDialog dlg) {
|
---|
148 | IconToggleButton button = new IconToggleButton(dlg.action);
|
---|
149 | dlg.action.button = button;
|
---|
150 | dlg.parent = toggleDialogs;
|
---|
151 | toolBarToggle.add(button);
|
---|
152 | toggleDialogs.add(dlg);
|
---|
153 | }
|
---|
154 |
|
---|
155 | public void addMapMode(IconToggleButton b) {
|
---|
156 | toolBarActions.add(b);
|
---|
157 | toolGroup.add((AbstractButton)b);
|
---|
158 | }
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * Fires an property changed event "visible".
|
---|
162 | */
|
---|
163 | @Override public void setVisible(boolean aFlag) {
|
---|
164 | boolean old = isVisible();
|
---|
165 | super.setVisible(aFlag);
|
---|
166 | if (old != aFlag)
|
---|
167 | firePropertyChange("visible", old, aFlag);
|
---|
168 | }
|
---|
169 |
|
---|
170 |
|
---|
171 |
|
---|
172 | /**
|
---|
173 | * Change the operating map mode for the view. Will call unregister on the
|
---|
174 | * old MapMode and register on the new one.
|
---|
175 | * @param mapMode The new mode to set.
|
---|
176 | */
|
---|
177 | public void selectMapMode(MapMode mapMode) {
|
---|
178 | if (mapMode == this.mapMode)
|
---|
179 | return;
|
---|
180 | if (this.mapMode != null)
|
---|
181 | this.mapMode.exitMode();
|
---|
182 | this.mapMode = mapMode;
|
---|
183 | mapMode.enterMode();
|
---|
184 | }
|
---|
185 |
|
---|
186 | /**
|
---|
187 | * Fill the given panel by adding all necessary components to the different
|
---|
188 | * locations.
|
---|
189 | *
|
---|
190 | * @param panel The container to fill. Must have an BorderLayout.
|
---|
191 | */
|
---|
192 | public void fillPanel(Container panel) {
|
---|
193 | panel.add(this, BorderLayout.CENTER);
|
---|
194 | JToolBar jb = new JToolBar(JToolBar.VERTICAL);
|
---|
195 | jb.setFloatable(false);
|
---|
196 | jb.add(toolBarActions);
|
---|
197 | jb.addSeparator();
|
---|
198 | jb.add(toolBarToggle);
|
---|
199 | panel.add(jb, BorderLayout.WEST);
|
---|
200 | if (statusLine != null)
|
---|
201 | panel.add(statusLine, BorderLayout.SOUTH);
|
---|
202 | }
|
---|
203 | }
|
---|