1 | package org.openstreetmap.josm.gui;
|
---|
2 |
|
---|
3 | import java.awt.BorderLayout;
|
---|
4 | import java.awt.Component;
|
---|
5 | import java.awt.Container;
|
---|
6 | import java.beans.PropertyChangeEvent;
|
---|
7 | import java.beans.PropertyChangeListener;
|
---|
8 |
|
---|
9 | import javax.swing.AbstractButton;
|
---|
10 | import javax.swing.BoxLayout;
|
---|
11 | import javax.swing.ButtonGroup;
|
---|
12 | import javax.swing.JPanel;
|
---|
13 | import javax.swing.JToggleButton;
|
---|
14 | import javax.swing.JToolBar;
|
---|
15 |
|
---|
16 | import org.openstreetmap.josm.actions.AutoScaleAction;
|
---|
17 | import org.openstreetmap.josm.actions.mapmode.AddLineSegmentAction;
|
---|
18 | import org.openstreetmap.josm.actions.mapmode.AddNodeAction;
|
---|
19 | import org.openstreetmap.josm.actions.mapmode.AddTrackAction;
|
---|
20 | import org.openstreetmap.josm.actions.mapmode.DeleteAction;
|
---|
21 | import org.openstreetmap.josm.actions.mapmode.MapMode;
|
---|
22 | import org.openstreetmap.josm.actions.mapmode.MoveAction;
|
---|
23 | import org.openstreetmap.josm.actions.mapmode.SelectionAction;
|
---|
24 | import org.openstreetmap.josm.actions.mapmode.ZoomAction;
|
---|
25 | import org.openstreetmap.josm.gui.dialogs.LayerList;
|
---|
26 | import org.openstreetmap.josm.gui.dialogs.PropertiesDialog;
|
---|
27 | import org.openstreetmap.josm.gui.dialogs.SelectionListDialog;
|
---|
28 | import 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 | */
|
---|
36 | public 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 | toolBarActions.add(new IconToggleButton(this, new SelectionAction(this)));
|
---|
84 | toolBarActions.add(new IconToggleButton(this, new MoveAction(this)));
|
---|
85 | toolBarActions.add(new IconToggleButton(this, new AddNodeAction(this)));
|
---|
86 | toolBarActions.add(new IconToggleButton(this, new AddLineSegmentAction(this)));
|
---|
87 | toolBarActions.add(new IconToggleButton(this, new AddTrackAction(this)));
|
---|
88 | toolBarActions.add(new IconToggleButton(this, new DeleteAction(this)));
|
---|
89 |
|
---|
90 | // all map modes in one button group
|
---|
91 | ButtonGroup toolGroup = new ButtonGroup();
|
---|
92 | for (Component c : toolBarActions.getComponents())
|
---|
93 | toolGroup.add((AbstractButton)c);
|
---|
94 | toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true);
|
---|
95 | selectMapMode((MapMode)((AbstractButton)toolBarActions.getComponent(0)).getAction());
|
---|
96 |
|
---|
97 | // autoScale
|
---|
98 | toolBarActions.addSeparator();
|
---|
99 | final JToggleButton autoScaleButton = new IconToggleButton(this, new AutoScaleAction(this));
|
---|
100 | toolBarActions.add(autoScaleButton);
|
---|
101 | autoScaleButton.setText(null);
|
---|
102 | autoScaleButton.setSelected(mapView.isAutoScale());
|
---|
103 | mapView.addPropertyChangeListener(new PropertyChangeListener(){
|
---|
104 | public void propertyChange(PropertyChangeEvent evt) {
|
---|
105 | if (evt.getPropertyName().equals("autoScale"))
|
---|
106 | autoScaleButton.setSelected(mapView.isAutoScale());
|
---|
107 | }
|
---|
108 | });
|
---|
109 |
|
---|
110 | JPanel toggleDialogs = new JPanel();
|
---|
111 | add(toggleDialogs, BorderLayout.EAST);
|
---|
112 |
|
---|
113 | toggleDialogs.setLayout(new BoxLayout(toggleDialogs, BoxLayout.Y_AXIS));
|
---|
114 | toolBarActions.add(new IconToggleButton(this, layerList = new LayerList(this)));
|
---|
115 | toggleDialogs.add(layerList);
|
---|
116 | toolBarActions.add(new IconToggleButton(this, propertiesDialog = new PropertiesDialog(this)));
|
---|
117 | toggleDialogs.add(propertiesDialog);
|
---|
118 | toolBarActions.add(new IconToggleButton(this, selectionListDialog = new SelectionListDialog(this)));
|
---|
119 | toggleDialogs.add(selectionListDialog);
|
---|
120 |
|
---|
121 |
|
---|
122 | // status line below the map
|
---|
123 | statusLine = new MapStatus(this);
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * Fires an property changed event "visible".
|
---|
129 | */
|
---|
130 | @Override
|
---|
131 | public void setVisible(boolean aFlag) {
|
---|
132 | boolean old = isVisible();
|
---|
133 | super.setVisible(aFlag);
|
---|
134 | if (old != aFlag)
|
---|
135 | firePropertyChange("visible", old, aFlag);
|
---|
136 | }
|
---|
137 |
|
---|
138 |
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * Change the operating map mode for the view. Will call unregister on the
|
---|
142 | * old MapMode and register on the new one.
|
---|
143 | * @param mapMode The new mode to set.
|
---|
144 | */
|
---|
145 | public void selectMapMode(MapMode mapMode) {
|
---|
146 | if (this.mapMode != null)
|
---|
147 | this.mapMode.unregisterListener();
|
---|
148 | this.mapMode = mapMode;
|
---|
149 | mapMode.registerListener();
|
---|
150 | }
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * Fill the given panel by adding all necessary components to the different
|
---|
154 | * locations.
|
---|
155 | *
|
---|
156 | * @param panel The container to fill. Must have an BorderLayout.
|
---|
157 | */
|
---|
158 | public void fillPanel(Container panel) {
|
---|
159 | panel.add(this, BorderLayout.CENTER);
|
---|
160 | panel.add(toolBarActions, BorderLayout.WEST);
|
---|
161 | panel.add(statusLine, BorderLayout.SOUTH);
|
---|
162 | }
|
---|
163 | }
|
---|