1 | package org.openstreetmap.josm.gui;
|
---|
2 |
|
---|
3 | import java.awt.BorderLayout;
|
---|
4 | import java.awt.Component;
|
---|
5 | import java.awt.event.WindowAdapter;
|
---|
6 | import java.awt.event.WindowEvent;
|
---|
7 | import java.beans.PropertyChangeEvent;
|
---|
8 | import java.beans.PropertyChangeListener;
|
---|
9 |
|
---|
10 | import javax.swing.AbstractButton;
|
---|
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.CombineAction;
|
---|
21 | import org.openstreetmap.josm.actions.mapmode.DebugAction;
|
---|
22 | import org.openstreetmap.josm.actions.mapmode.DeleteAction;
|
---|
23 | import org.openstreetmap.josm.actions.mapmode.MapMode;
|
---|
24 | import org.openstreetmap.josm.actions.mapmode.MoveAction;
|
---|
25 | import org.openstreetmap.josm.actions.mapmode.SelectionAction;
|
---|
26 | import org.openstreetmap.josm.actions.mapmode.ZoomAction;
|
---|
27 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
28 | import org.openstreetmap.josm.gui.dialogs.SelectionListDialog;
|
---|
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 Layer layer;
|
---|
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 | /**
|
---|
56 | * Construct a map with a given DataSet. The set cannot be replaced after construction
|
---|
57 | * (but of course, the data can be altered using the map's editing features).
|
---|
58 | */
|
---|
59 | public MapFrame(DataSet dataSet) {
|
---|
60 | setSize(400,400);
|
---|
61 | setLayout(new BorderLayout());
|
---|
62 |
|
---|
63 | add(layer = new Layer(dataSet), BorderLayout.CENTER);
|
---|
64 |
|
---|
65 | // toolbar
|
---|
66 | toolBarActions.setFloatable(false);
|
---|
67 | toolBarActions.add(new IconToggleButton(this, new ZoomAction(this)));
|
---|
68 | toolBarActions.add(new IconToggleButton(this, new SelectionAction(this)));
|
---|
69 | toolBarActions.add(new IconToggleButton(this, new MoveAction(this)));
|
---|
70 | toolBarActions.add(new IconToggleButton(this, new AddNodeAction(this)));
|
---|
71 | toolBarActions.add(new IconToggleButton(this, new AddLineSegmentAction(this)));
|
---|
72 | toolBarActions.add(new IconToggleButton(this, new AddTrackAction(this)));
|
---|
73 | toolBarActions.add(new IconToggleButton(this, new CombineAction(this)));
|
---|
74 | toolBarActions.add(new IconToggleButton(this, new DeleteAction(this)));
|
---|
75 | toolBarActions.add(new IconToggleButton(this, new DebugAction(this)));
|
---|
76 |
|
---|
77 | // all map modes in one button group
|
---|
78 | ButtonGroup toolGroup = new ButtonGroup();
|
---|
79 | for (Component c : toolBarActions.getComponents())
|
---|
80 | toolGroup.add((AbstractButton)c);
|
---|
81 | toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true);
|
---|
82 | selectMapMode((MapMode)((AbstractButton)toolBarActions.getComponent(0)).getAction());
|
---|
83 |
|
---|
84 | // autoScale
|
---|
85 | toolBarActions.addSeparator();
|
---|
86 | final JToggleButton autoScaleButton = new IconToggleButton(this, new AutoScaleAction(layer));
|
---|
87 | toolBarActions.add(autoScaleButton);
|
---|
88 | autoScaleButton.setText(null);
|
---|
89 | autoScaleButton.setSelected(layer.isAutoScale());
|
---|
90 | layer.addPropertyChangeListener(new PropertyChangeListener(){
|
---|
91 | public void propertyChange(PropertyChangeEvent evt) {
|
---|
92 | if (evt.getPropertyName().equals("autoScale"))
|
---|
93 | autoScaleButton.setSelected(layer.isAutoScale());
|
---|
94 | }
|
---|
95 | });
|
---|
96 |
|
---|
97 | // selection dialog
|
---|
98 | SelectionListDialog selectionList = new SelectionListDialog(dataSet);
|
---|
99 | final IconToggleButton buttonSelection = new IconToggleButton(this, selectionList);
|
---|
100 | selectionList.addWindowListener(new WindowAdapter(){
|
---|
101 | @Override
|
---|
102 | public void windowClosing(WindowEvent e) {
|
---|
103 | buttonSelection.setSelected(false);
|
---|
104 | }
|
---|
105 | });
|
---|
106 | toolBarActions.add(buttonSelection);
|
---|
107 |
|
---|
108 | // status line below the map
|
---|
109 | statusLine = new MapStatus(layer);
|
---|
110 | }
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * Change the operating map mode for the view. Will call unregister on the
|
---|
114 | * old MapMode and register on the new one.
|
---|
115 | * @param mapMode The new mode to set.
|
---|
116 | */
|
---|
117 | public void selectMapMode(MapMode mapMode) {
|
---|
118 | if (this.mapMode != null)
|
---|
119 | this.mapMode.unregisterListener();
|
---|
120 | this.mapMode = mapMode;
|
---|
121 | mapMode.registerListener();
|
---|
122 | }
|
---|
123 | }
|
---|