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