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

Last change on this file since 90 was 90, checked in by imi, 18 years ago
  • fixed that toggle dialog buttons are sync with the dialogs
  • added search for timestamp (e.g. timestamp:06-3-25)
File size: 5.4 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.beans.PropertyChangeEvent;
8import java.beans.PropertyChangeListener;
9
10import javax.swing.AbstractButton;
11import javax.swing.BoxLayout;
12import javax.swing.ButtonGroup;
13import javax.swing.JPanel;
14import javax.swing.JToggleButton;
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.AddNodeAction;
21import org.openstreetmap.josm.actions.mapmode.AddWayAction;
22import org.openstreetmap.josm.actions.mapmode.DeleteAction;
23import org.openstreetmap.josm.actions.mapmode.MapMode;
24import org.openstreetmap.josm.actions.mapmode.MoveAction;
25import org.openstreetmap.josm.actions.mapmode.SelectionAction;
26import org.openstreetmap.josm.actions.mapmode.ZoomAction;
27import org.openstreetmap.josm.gui.dialogs.ConflictDialog;
28import org.openstreetmap.josm.gui.dialogs.LayerList;
29import org.openstreetmap.josm.gui.dialogs.PropertiesDialog;
30import org.openstreetmap.josm.gui.dialogs.SelectionListDialog;
31import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
32import org.openstreetmap.josm.gui.layer.Layer;
33
34/**
35 * One Map frame with one dataset behind. This is the container gui class whose
36 * display can be set to the different views.
37 *
38 * @author imi
39 */
40public class MapFrame extends JPanel {
41
42 /**
43 * The current mode, this frame operates.
44 */
45 public MapMode mapMode;
46 /**
47 * The view control displayed.
48 */
49 public MapView mapView;
50 /**
51 * The toolbar with the action icons
52 */
53 public JToolBar toolBarActions = new JToolBar(JToolBar.VERTICAL);
54 /**
55 * The status line below the map
56 */
57 public MapStatus statusLine;
58
59 public ConflictDialog conflictDialog;
60
61 /**
62 * Construct a map with a given DataSet. The set cannot be replaced after
63 * construction (but of course, the data can be altered using the map's
64 * editing features).
65 *
66 * @param layer The first layer in the mapView.
67 */
68 public MapFrame(Layer layer) {
69 setSize(400,400);
70 setLayout(new BorderLayout());
71
72 add(mapView = new MapView(layer), BorderLayout.CENTER);
73
74 // toolbar
75 toolBarActions.setFloatable(false);
76 toolBarActions.add(new IconToggleButton(new ZoomAction(this)));
77 final SelectionAction selectionAction = new SelectionAction(this);
78 toolBarActions.add(new IconToggleButton(selectionAction));
79 toolBarActions.add(new IconToggleButton(new MoveAction(this)));
80 toolBarActions.add(new IconToggleButton(new AddNodeAction(this)));
81 toolBarActions.add(new IconToggleButton(new AddSegmentAction(this)));
82 toolBarActions.add(new IconToggleButton(new AddWayAction(this, selectionAction)));
83 toolBarActions.add(new IconToggleButton(new DeleteAction(this)));
84
85 // all map modes in one button group
86 ButtonGroup toolGroup = new ButtonGroup();
87 for (Component c : toolBarActions.getComponents())
88 toolGroup.add((AbstractButton)c);
89 toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true);
90 selectMapMode((MapMode)((AbstractButton)toolBarActions.getComponent(0)).getAction());
91
92 // autoScale
93 toolBarActions.addSeparator();
94 final JToggleButton autoScaleButton = new IconToggleButton(new AutoScaleAction(this));
95 toolBarActions.add(autoScaleButton);
96 autoScaleButton.setText(null);
97 autoScaleButton.setSelected(mapView.isAutoScale());
98 mapView.addPropertyChangeListener(new PropertyChangeListener(){
99 public void propertyChange(PropertyChangeEvent evt) {
100 if (evt.getPropertyName().equals("autoScale"))
101 autoScaleButton.setSelected(mapView.isAutoScale());
102 }
103 });
104
105 JPanel toggleDialogs = new JPanel();
106 add(toggleDialogs, BorderLayout.EAST);
107
108 toggleDialogs.setLayout(new BoxLayout(toggleDialogs, BoxLayout.Y_AXIS));
109 addIconToggle(toggleDialogs, new LayerList(this));
110 addIconToggle(toggleDialogs, new PropertiesDialog(this));
111 addIconToggle(toggleDialogs, new SelectionListDialog(this));
112 addIconToggle(toggleDialogs, conflictDialog = new ConflictDialog());
113
114 // status line below the map
115 statusLine = new MapStatus(this);
116 }
117
118
119 private void addIconToggle(JPanel toggleDialogs, ToggleDialog dlg) {
120 IconToggleButton button = new IconToggleButton(dlg.action);
121 dlg.action.button = button;
122 toolBarActions.add(button);
123 toggleDialogs.add(dlg);
124 if (Main.pref.getBoolean(dlg.action.prefname+".visible"))
125 dlg.action.actionPerformed(new ActionEvent(this, 0, ""));
126 }
127
128
129 /**
130 * Fires an property changed event "visible".
131 */
132 @Override 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.