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

Last change on this file since 98 was 98, checked in by imi, 18 years ago
  • added Applet version of JOSM (unfinished)
  • fixed display bug if --no-fullscreen and --geometry was specified
File size: 6.1 KB
Line 
1package org.openstreetmap.josm.gui;
2
3import java.awt.BorderLayout;
4import java.awt.Component;
5import java.awt.Container;
6import java.awt.event.ActionEvent;
7import java.awt.event.ActionListener;
8import java.beans.PropertyChangeEvent;
9import java.beans.PropertyChangeListener;
10
11import javax.swing.AbstractButton;
12import javax.swing.BoxLayout;
13import javax.swing.ButtonGroup;
14import javax.swing.JPanel;
15import javax.swing.JToolBar;
16
17import org.openstreetmap.josm.Main;
18import org.openstreetmap.josm.actions.AutoScaleAction;
19import org.openstreetmap.josm.actions.mapmode.AddSegmentAction;
20import org.openstreetmap.josm.actions.mapmode.AddWayAction;
21import org.openstreetmap.josm.actions.mapmode.DeleteAction;
22import org.openstreetmap.josm.actions.mapmode.MapMode;
23import org.openstreetmap.josm.actions.mapmode.MoveAction;
24import org.openstreetmap.josm.actions.mapmode.SelectionAction;
25import org.openstreetmap.josm.actions.mapmode.ZoomAction;
26import org.openstreetmap.josm.actions.mapmode.AddNodeAction.AddNodeGroup;
27import org.openstreetmap.josm.gui.dialogs.CommandStackDialog;
28import org.openstreetmap.josm.gui.dialogs.ConflictDialog;
29import org.openstreetmap.josm.gui.dialogs.LayerList;
30import org.openstreetmap.josm.gui.dialogs.PropertiesDialog;
31import org.openstreetmap.josm.gui.dialogs.SelectionListDialog;
32import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
33import org.openstreetmap.josm.gui.layer.Layer;
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 {
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
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 private JPanel toggleDialogs = new JPanel();
62
63 /**
64 * Construct a map with a given DataSet. The set cannot be replaced after
65 * construction (but of course, the data can be altered using the map's
66 * editing features).
67 *
68 * @param layer The first layer in the mapView.
69 */
70 public MapFrame(Layer layer) {
71 setSize(400,400);
72 setLayout(new BorderLayout());
73
74 final AutoScaleAction autoScaleAction = new AutoScaleAction(this);
75 add(mapView = new MapView(autoScaleAction), BorderLayout.CENTER);
76 mapView.addLayer(layer);
77
78 // toolbar
79 toolBarActions.setFloatable(false);
80 toolBarActions.add(new IconToggleButton(new ZoomAction(this)));
81 final SelectionAction selectionAction = new SelectionAction(this);
82 toolBarActions.add(new IconToggleButton(selectionAction));
83 toolBarActions.add(new IconToggleButton(new MoveAction(this)));
84 toolBarActions.add(new IconToggleButton(new AddNodeGroup(this)));
85 toolBarActions.add(new IconToggleButton(new AddSegmentAction(this)));
86 toolBarActions.add(new IconToggleButton(new AddWayAction(this)));
87 toolBarActions.add(new IconToggleButton(new DeleteAction(this)));
88
89 // all map modes in one button group
90 ButtonGroup toolGroup = new ButtonGroup();
91 for (Component c : toolBarActions.getComponents())
92 toolGroup.add((AbstractButton)c);
93 toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true);
94 selectMapMode((MapMode)((AbstractButton)toolBarActions.getComponent(0)).getAction());
95
96 // autoScale
97 toolBarActions.addSeparator();
98 final IconToggleButton autoScaleButton = new IconToggleButton(autoScaleAction);
99 toolBarActions.add(autoScaleButton);
100 autoScaleButton.setText(null);
101 autoScaleButton.setSelected(mapView.isAutoScale());
102 autoScaleAction.putValue("active", true);
103 mapView.addPropertyChangeListener(new PropertyChangeListener(){
104 public void propertyChange(PropertyChangeEvent evt) {
105 if (evt.getPropertyName().equals("autoScale")) {
106 autoScaleAction.putValue("active", evt.getNewValue());
107 autoScaleButton.setSelected((Boolean)evt.getNewValue());
108 }
109 }
110 });
111 autoScaleButton.addActionListener(new ActionListener(){
112 public void actionPerformed(ActionEvent e) {
113 if (!autoScaleButton.groupbutton)
114 autoScaleButton.setSelected(true);
115 }
116 });
117
118 add(toggleDialogs, BorderLayout.EAST);
119 toggleDialogs.setLayout(new BoxLayout(toggleDialogs, BoxLayout.Y_AXIS));
120
121 addIconToggle(toggleDialogs, new LayerList(this));
122 addIconToggle(toggleDialogs, new PropertiesDialog(this));
123 addIconToggle(toggleDialogs, new SelectionListDialog(this));
124 addIconToggle(toggleDialogs, conflictDialog = new ConflictDialog());
125 addIconToggle(toggleDialogs, new CommandStackDialog(this));
126
127 // status line below the map
128 statusLine = new MapStatus(this);
129 }
130
131 /**
132 * Open all ToggleDialogs that have their preferences property set. Close all others.
133 */
134 public void setVisibleDialogs() {
135 for (Component c : toggleDialogs.getComponents())
136 if (c instanceof ToggleDialog)
137 c.setVisible(Main.pref.getBoolean(((ToggleDialog)c).prefName+".visible"));
138 }
139
140 private void addIconToggle(JPanel toggleDialogs, ToggleDialog dlg) {
141 IconToggleButton button = new IconToggleButton(dlg.action);
142 dlg.action.button = button;
143 toolBarActions.add(button);
144 toggleDialogs.add(dlg);
145 }
146
147
148 /**
149 * Fires an property changed event "visible".
150 */
151 @Override public void setVisible(boolean aFlag) {
152 boolean old = isVisible();
153 super.setVisible(aFlag);
154 if (old != aFlag)
155 firePropertyChange("visible", old, aFlag);
156 }
157
158
159
160 /**
161 * Change the operating map mode for the view. Will call unregister on the
162 * old MapMode and register on the new one.
163 * @param mapMode The new mode to set.
164 */
165 public void selectMapMode(MapMode mapMode) {
166 if (mapMode == this.mapMode)
167 return;
168 if (this.mapMode != null)
169 this.mapMode.exitMode();
170 this.mapMode = mapMode;
171 mapMode.enterMode();
172 }
173
174 /**
175 * Fill the given panel by adding all necessary components to the different
176 * locations.
177 *
178 * @param panel The container to fill. Must have an BorderLayout.
179 */
180 public void fillPanel(Container panel) {
181 panel.add(this, BorderLayout.CENTER);
182 panel.add(toolBarActions, BorderLayout.WEST);
183 panel.add(statusLine, BorderLayout.SOUTH);
184 }
185}
Note: See TracBrowser for help on using the repository browser.