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

Last change on this file since 61 was 61, checked in by imi, 18 years ago
  • added search dialog in selection menu
  • changed way mapmode to switch to selection mode after way creation
  • changed way mapmode to ask what to do, if an other way was selected
  • fixed html encoding for tag attributes in OSM data export
File size: 5.3 KB
Line 
1package org.openstreetmap.josm.gui;
2
3import java.awt.BorderLayout;
4import java.awt.Component;
5import java.awt.Container;
6import java.beans.PropertyChangeEvent;
7import java.beans.PropertyChangeListener;
8
9import javax.swing.AbstractButton;
10import javax.swing.BoxLayout;
11import javax.swing.ButtonGroup;
12import javax.swing.JPanel;
13import javax.swing.JToggleButton;
14import javax.swing.JToolBar;
15
16import org.openstreetmap.josm.actions.AutoScaleAction;
17import org.openstreetmap.josm.actions.mapmode.AddLineSegmentAction;
18import org.openstreetmap.josm.actions.mapmode.AddNodeAction;
19import org.openstreetmap.josm.actions.mapmode.AddWayAction;
20import org.openstreetmap.josm.actions.mapmode.DeleteAction;
21import org.openstreetmap.josm.actions.mapmode.MapMode;
22import org.openstreetmap.josm.actions.mapmode.MoveAction;
23import org.openstreetmap.josm.actions.mapmode.SelectionAction;
24import org.openstreetmap.josm.actions.mapmode.ZoomAction;
25import org.openstreetmap.josm.gui.dialogs.LayerList;
26import org.openstreetmap.josm.gui.dialogs.PropertiesDialog;
27import org.openstreetmap.josm.gui.dialogs.SelectionListDialog;
28import org.openstreetmap.josm.gui.layer.Layer;
29
30/**
31 * One Map frame with one dataset behind. This is the container gui class whose
32 * display can be set to the different views.
33 *
34 * @author imi
35 */
36public class MapFrame extends JPanel {
37
38 /**
39 * The current mode, this frame operates.
40 */
41 public MapMode mapMode;
42 /**
43 * The view control displayed.
44 */
45 public MapView mapView;
46 /**
47 * The toolbar with the action icons
48 */
49 public JToolBar toolBarActions = new JToolBar(JToolBar.VERTICAL);
50 /**
51 * The status line below the map
52 */
53 public MapStatus statusLine;
54 /**
55 * The action to open the layer list
56 */
57 private LayerList layerList;
58 /**
59 * Action to open the properties panel for the selected objects
60 */
61 private PropertiesDialog propertiesDialog;
62 /**
63 * Action to open a list of all selected objects
64 */
65 private SelectionListDialog selectionListDialog;
66
67 /**
68 * Construct a map with a given DataSet. The set cannot be replaced after
69 * construction (but of course, the data can be altered using the map's
70 * editing features).
71 *
72 * @param layer The first layer in the mapView.
73 */
74 public MapFrame(Layer layer) {
75 setSize(400,400);
76 setLayout(new BorderLayout());
77
78 add(mapView = new MapView(layer), BorderLayout.CENTER);
79
80 // toolbar
81 toolBarActions.setFloatable(false);
82 toolBarActions.add(new IconToggleButton(this, new ZoomAction(this)));
83 final SelectionAction selectionAction = new SelectionAction(this);
84 toolBarActions.add(new IconToggleButton(this, selectionAction));
85 toolBarActions.add(new IconToggleButton(this, new MoveAction(this)));
86 toolBarActions.add(new IconToggleButton(this, new AddNodeAction(this)));
87 toolBarActions.add(new IconToggleButton(this, new AddLineSegmentAction(this)));
88 toolBarActions.add(new IconToggleButton(this, new AddWayAction(this, selectionAction)));
89 toolBarActions.add(new IconToggleButton(this, new DeleteAction(this)));
90
91 // all map modes in one button group
92 ButtonGroup toolGroup = new ButtonGroup();
93 for (Component c : toolBarActions.getComponents())
94 toolGroup.add((AbstractButton)c);
95 toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true);
96 selectMapMode((MapMode)((AbstractButton)toolBarActions.getComponent(0)).getAction());
97
98 // autoScale
99 toolBarActions.addSeparator();
100 final JToggleButton autoScaleButton = new IconToggleButton(this, new AutoScaleAction(this));
101 toolBarActions.add(autoScaleButton);
102 autoScaleButton.setText(null);
103 autoScaleButton.setSelected(mapView.isAutoScale());
104 mapView.addPropertyChangeListener(new PropertyChangeListener(){
105 public void propertyChange(PropertyChangeEvent evt) {
106 if (evt.getPropertyName().equals("autoScale"))
107 autoScaleButton.setSelected(mapView.isAutoScale());
108 }
109 });
110
111 JPanel toggleDialogs = new JPanel();
112 add(toggleDialogs, BorderLayout.EAST);
113
114 toggleDialogs.setLayout(new BoxLayout(toggleDialogs, BoxLayout.Y_AXIS));
115 toolBarActions.add(new IconToggleButton(this, layerList = new LayerList(this)));
116 toggleDialogs.add(layerList);
117 toolBarActions.add(new IconToggleButton(this, propertiesDialog = new PropertiesDialog(this)));
118 toggleDialogs.add(propertiesDialog);
119 toolBarActions.add(new IconToggleButton(this, selectionListDialog = new SelectionListDialog(this)));
120 toggleDialogs.add(selectionListDialog);
121
122
123 // status line below the map
124 statusLine = new MapStatus(this);
125 }
126
127
128 /**
129 * Fires an property changed event "visible".
130 */
131 @Override
132 public void setVisible(boolean aFlag) {
133 boolean old = isVisible();
134 super.setVisible(aFlag);
135 if (old != aFlag)
136 firePropertyChange("visible", old, aFlag);
137 }
138
139
140
141 /**
142 * Change the operating map mode for the view. Will call unregister on the
143 * old MapMode and register on the new one.
144 * @param mapMode The new mode to set.
145 */
146 public void selectMapMode(MapMode mapMode) {
147 if (this.mapMode != null)
148 this.mapMode.unregisterListener();
149 this.mapMode = mapMode;
150 mapMode.registerListener();
151 }
152
153 /**
154 * Fill the given panel by adding all necessary components to the different
155 * locations.
156 *
157 * @param panel The container to fill. Must have an BorderLayout.
158 */
159 public void fillPanel(Container panel) {
160 panel.add(this, BorderLayout.CENTER);
161 panel.add(toolBarActions, BorderLayout.WEST);
162 panel.add(statusLine, BorderLayout.SOUTH);
163 }
164}
Note: See TracBrowser for help on using the repository browser.