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.AddWayAction;
|
---|
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.dialogs.ToggleDialog;
|
---|
29 | import org.openstreetmap.josm.gui.layer.Layer;
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * One Map frame with one dataset behind. This is the container gui class whose
|
---|
33 | * display can be set to the different views.
|
---|
34 | *
|
---|
35 | * @author imi
|
---|
36 | */
|
---|
37 | public class MapFrame extends JPanel {
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * The current mode, this frame operates.
|
---|
41 | */
|
---|
42 | public MapMode mapMode;
|
---|
43 | /**
|
---|
44 | * The view control displayed.
|
---|
45 | */
|
---|
46 | public MapView mapView;
|
---|
47 | /**
|
---|
48 | * The toolbar with the action icons
|
---|
49 | */
|
---|
50 | public JToolBar toolBarActions = new JToolBar(JToolBar.VERTICAL);
|
---|
51 | /**
|
---|
52 | * The status line below the map
|
---|
53 | */
|
---|
54 | public MapStatus statusLine;
|
---|
55 | /**
|
---|
56 | * Construct a map with a given DataSet. The set cannot be replaced after
|
---|
57 | * construction (but of course, the data can be altered using the map's
|
---|
58 | * editing features).
|
---|
59 | *
|
---|
60 | * @param layer The first layer in the mapView.
|
---|
61 | */
|
---|
62 | public MapFrame(Layer layer) {
|
---|
63 | setSize(400,400);
|
---|
64 | setLayout(new BorderLayout());
|
---|
65 |
|
---|
66 | add(mapView = new MapView(layer), BorderLayout.CENTER);
|
---|
67 |
|
---|
68 | // toolbar
|
---|
69 | toolBarActions.setFloatable(false);
|
---|
70 | toolBarActions.add(new IconToggleButton(this, new ZoomAction(this)));
|
---|
71 | final SelectionAction selectionAction = new SelectionAction(this);
|
---|
72 | toolBarActions.add(new IconToggleButton(this, selectionAction));
|
---|
73 | toolBarActions.add(new IconToggleButton(this, new MoveAction(this)));
|
---|
74 | toolBarActions.add(new IconToggleButton(this, new AddNodeAction(this)));
|
---|
75 | toolBarActions.add(new IconToggleButton(this, new AddLineSegmentAction(this)));
|
---|
76 | toolBarActions.add(new IconToggleButton(this, new AddWayAction(this, selectionAction)));
|
---|
77 | toolBarActions.add(new IconToggleButton(this, new DeleteAction(this)));
|
---|
78 |
|
---|
79 | // all map modes in one button group
|
---|
80 | ButtonGroup toolGroup = new ButtonGroup();
|
---|
81 | for (Component c : toolBarActions.getComponents())
|
---|
82 | toolGroup.add((AbstractButton)c);
|
---|
83 | toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true);
|
---|
84 | selectMapMode((MapMode)((AbstractButton)toolBarActions.getComponent(0)).getAction());
|
---|
85 |
|
---|
86 | // autoScale
|
---|
87 | toolBarActions.addSeparator();
|
---|
88 | final JToggleButton autoScaleButton = new IconToggleButton(this, new AutoScaleAction(this));
|
---|
89 | toolBarActions.add(autoScaleButton);
|
---|
90 | autoScaleButton.setText(null);
|
---|
91 | autoScaleButton.setSelected(mapView.isAutoScale());
|
---|
92 | mapView.addPropertyChangeListener(new PropertyChangeListener(){
|
---|
93 | public void propertyChange(PropertyChangeEvent evt) {
|
---|
94 | if (evt.getPropertyName().equals("autoScale"))
|
---|
95 | autoScaleButton.setSelected(mapView.isAutoScale());
|
---|
96 | }
|
---|
97 | });
|
---|
98 |
|
---|
99 | JPanel toggleDialogs = new JPanel();
|
---|
100 | add(toggleDialogs, BorderLayout.EAST);
|
---|
101 |
|
---|
102 | toggleDialogs.setLayout(new BoxLayout(toggleDialogs, BoxLayout.Y_AXIS));
|
---|
103 | addIconToggle(toggleDialogs, new LayerList(this));
|
---|
104 | addIconToggle(toggleDialogs, new PropertiesDialog(this));
|
---|
105 | addIconToggle(toggleDialogs, new SelectionListDialog(this));
|
---|
106 |
|
---|
107 | // status line below the map
|
---|
108 | statusLine = new MapStatus(this);
|
---|
109 | }
|
---|
110 |
|
---|
111 |
|
---|
112 | private void addIconToggle(JPanel toggleDialogs, ToggleDialog dlg) {
|
---|
113 | toolBarActions.add(new IconToggleButton(this, dlg.action));
|
---|
114 | toggleDialogs.add(dlg);
|
---|
115 | }
|
---|
116 |
|
---|
117 |
|
---|
118 | /**
|
---|
119 | * Fires an property changed event "visible".
|
---|
120 | */
|
---|
121 | @Override
|
---|
122 | public void setVisible(boolean aFlag) {
|
---|
123 | boolean old = isVisible();
|
---|
124 | super.setVisible(aFlag);
|
---|
125 | if (old != aFlag)
|
---|
126 | firePropertyChange("visible", old, aFlag);
|
---|
127 | }
|
---|
128 |
|
---|
129 |
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * Change the operating map mode for the view. Will call unregister on the
|
---|
133 | * old MapMode and register on the new one.
|
---|
134 | * @param mapMode The new mode to set.
|
---|
135 | */
|
---|
136 | public void selectMapMode(MapMode mapMode) {
|
---|
137 | if (this.mapMode != null)
|
---|
138 | this.mapMode.unregisterListener();
|
---|
139 | this.mapMode = mapMode;
|
---|
140 | mapMode.registerListener();
|
---|
141 | }
|
---|
142 |
|
---|
143 | /**
|
---|
144 | * Fill the given panel by adding all necessary components to the different
|
---|
145 | * locations.
|
---|
146 | *
|
---|
147 | * @param panel The container to fill. Must have an BorderLayout.
|
---|
148 | */
|
---|
149 | public void fillPanel(Container panel) {
|
---|
150 | panel.add(this, BorderLayout.CENTER);
|
---|
151 | panel.add(toolBarActions, BorderLayout.WEST);
|
---|
152 | panel.add(statusLine, BorderLayout.SOUTH);
|
---|
153 | }
|
---|
154 | }
|
---|