/[schmitzm]/trunk/src/skrueger/geotools/MapView.java
ViewVC logotype

Contents of /trunk/src/skrueger/geotools/MapView.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations)
Tue Feb 24 22:43:52 2009 UTC (16 years ago) by mojays
File size: 12497 byte(s)
First Commit, corresponds to Revision 1008 of Wikisquare-SVN
includes:
- schmitzm.* (except schmitzm.test)
- org.geotools.* (all overridden classes)
- skrueger.geotools
- skrueger.i8n
- skrueger.swing
- appl.data.LateLoadable (dependency in SCHMITZM)
- appl.data.LoadingException (dependency in SCHMITZM)
- appl.util.RasterMetaData (dependency in SCHMITZM)

1 package skrueger.geotools;
2
3 import java.awt.BorderLayout;
4 import java.awt.Dimension;
5 import java.awt.Window;
6 import java.awt.event.ActionEvent;
7 import java.util.ArrayList;
8 import java.util.LinkedList;
9
10 import javax.swing.AbstractAction;
11 import javax.swing.BorderFactory;
12 import javax.swing.ButtonGroup;
13 import javax.swing.ImageIcon;
14 import javax.swing.JButton;
15 import javax.swing.JComponent;
16 import javax.swing.JLabel;
17 import javax.swing.JPanel;
18 import javax.swing.JSplitPane;
19 import javax.swing.JToggleButton;
20 import javax.swing.JToolBar;
21
22 import org.apache.log4j.Logger;
23
24 import schmitzm.geotools.gui.GeoMapPane;
25 import schmitzm.geotools.gui.JMapPane;
26 import schmitzm.geotools.gui.MapContextControlPane;
27 import schmitzm.geotools.gui.MapPaneStatusBar;
28 import schmitzm.geotools.map.event.JMapPaneEvent;
29 import schmitzm.geotools.map.event.JMapPaneListener;
30 import schmitzm.geotools.map.event.MapAreaChangedEvent;
31 import schmitzm.geotools.styling.ColorMapManager;
32 import schmitzm.swing.SwingUtil;
33
34 import com.vividsolutions.jts.geom.Envelope;
35
36 /**
37 * Achtung! Dieser code ist verwuestet
38 */
39
40 /**
41 * TODO DOKU und initialize schöner machen. SK
42 */
43 public class MapView extends JPanel {
44 private static final Logger LOGGER = Logger.getLogger(MapView.class);
45
46 private final JSplitPane splitPane = new JSplitPane(
47 JSplitPane.HORIZONTAL_SPLIT);
48
49 protected MapPaneStatusBar statusBar = null;
50
51 /**
52 * Komponente, in der die Karten, der Massstab und das Koordinaten-Raster
53 * dargestellt werden
54 */
55 protected final GeoMapPane geoMapPane = new GeoMapPane();
56
57 //
58 // /** This is the layered Pane that holds the buttons and maybe the flying logo * */
59 // protected JLayeredPane layeredPane;
60
61 protected boolean zoomBackForwardButtonInAction;
62
63 private MapPaneToolBar jToolBar;
64
65 /**
66 * Creates a new {@link MapView}. A {@link MapView} is a combination of a
67 * {@link GeoMapPane}, a {@link MapContextManagerInterface} on the left,
68 * and some buttons floating over the {@link JMapPane}
69 */
70 public MapView(Window owner2, MapPaneToolBar toolBar) {
71 super(new BorderLayout());
72 // Call initialize() by yourself afterwards.
73 // Needed because variables for the overwritten methods
74 // are not yet set.
75 getGeoMapPane().getMapPane().setWaitCursorComponent(owner2);
76 if ( toolBar == null )
77 toolBar = new MapPaneToolBar(getMapPane());
78 jToolBar = toolBar;
79 }
80
81 /**
82 * Creates a new {@link MapView}. A {@link MapView} is a combination of a
83 * {@link GeoMapPane}, a {@link MapContextManagerInterface} on the left,
84 * and some buttons floating over the {@link JMapPane}
85 */
86 public MapView(Window owner2) {
87 this(owner2, null);
88 }
89
90 // /**
91 // * Nuetzlich wenn die Componente gedruckt wird. Dann wird der Hintergrund
92 // auf {@link Color#WHITE} gesetzt.zoomoutToggleButton
93 // *
94 // * @author <a href="mailto:[email protected]">Stefan Alfons
95 // Kr&uuml;ger</a>
96 // */
97 // @Override
98 // public void print(Graphics g) {
99 //
100 // // SK: Ich habe keine Ahnung mehr, was das soll... Ich habs mal
101 // auskommentiert.
102 //
103 // // wrap in try/finally so that we always restore the state
104 // try {
105 // panToggleButton.setVisible(false);
106 // zoominToggleButton.setVisible(false);
107 // zoomoutToggleButton.setVisible(false);
108 // infoToggleButton.setVisible(false);
109 //
110 // super.print(g);
111 // } finally {
112 // panToggleButton.setVisible(true);
113 // zoominToggleButton.setVisible(true);
114 // zoomoutToggleButton.setVisible(true);
115 // infoToggleButton.setVisible(true);
116 // }
117 // }
118
119 /**
120 * Calls #getSidePanel() which can be overwritten.
121 *
122 * @see #adjustSizeOfGeoMapPane()
123 */
124 public void initialize() {
125 // horizontales SplitPane initialisieren
126
127 // Status-Zeile
128 statusBar = new MapPaneStatusBar(getGeoMapPane()
129 .getMapPane());
130 statusBar.setBorder(BorderFactory.createCompoundBorder(BorderFactory
131 .createLoweredBevelBorder(), BorderFactory.createEmptyBorder(2,
132 5, 2, 5)));
133 this.add(statusBar, BorderLayout.SOUTH);
134
135 splitPane.setDividerLocation(0.4);
136 splitPane.setDividerSize(5);
137
138 splitPane.add(getSidePane());
139
140 /***********************************************************************
141 * To the right side we now add a JPanel that consists of a toolbar and
142 * a gmp
143 */
144 JPanel newRight = new JPanel(new BorderLayout());
145 newRight.add(getToolBar(), BorderLayout.NORTH);
146 newRight.add(getGeoMapPane(), BorderLayout.CENTER);
147 splitPane.add(newRight);
148
149 // gpSize = new Dimension(40,50);
150 // getGeoMapPane().setSize(gpSize);
151
152 // layeredPane = new JLayeredPane();
153 // layeredPane.add(getGeoMapPane(), JLayeredPane.DEFAULT_LAYER);
154 // createMapButtons(layeredPane);
155
156 // //****************************************************************************
157 // // The JLayeredPane doesn't manage the size of its layers.. we do it
158 // // This listener will actually correct the size of the JLayeredPane
159 // //****************************************************************************
160 // splitPane.addPropertyChangeListener(new PropertyChangeListener() {
161 //
162 // public void propertyChange(final PropertyChangeEvent evt) {
163 // final JSplitPane sp = (JSplitPane) evt.getSource();
164 //
165 // adjustSizeOfGeoMapPane();
166 //
167 // }
168 //
169 // });
170
171 this.add(splitPane, BorderLayout.CENTER);
172 }
173
174 /**
175 * Returns the tool bar which controls the active mouse actions on the map.
176 * @return
177 */
178 public MapPaneToolBar getToolBar() {
179 return jToolBar;
180 }
181
182 /**
183 * Returns the split pane which divides the layer list from the map panel.
184 */
185 public JSplitPane getSplitPane() {
186 return this.splitPane;
187 }
188
189 //
190 // /**
191 // * Called by the listerner. Calculates the exact size of the {@link
192 // GeoMapPane} and sets it.
193 // */
194 // private void adjustSizeOfGeoMapPane() {
195 // final int newWidth = (int) (splitPane.getSize().getWidth()
196 // - splitPane.getComponent(1).getSize().getWidth()
197 // - splitPane.getComponent(0).getSize().getWidth())
198 // - 4;
199 // final int newHeight = (int) splitPane.getComponent(1).getSize()
200 // .getHeight();
201 //
202 // if (newWidth <= 20 )
203 // return;
204 //
205 // gpSize.setSize(newWidth, newHeight);
206 //
207 // getGeoMapPane().getMapPane().setWaitCursorDuringNextRepaint(true);
208 //
209 // getGeoMapPane().setSize( gpSize );
210 // // getGeoMapPane().refreshMap(); nicht nötig .. schön
211 //
212 // positionLayeredObjects();
213 // }
214 //
215 // /**
216 // * Adds the floating Map Contol Buttons to the {@link JLayeredPane}, with Z =
217 // * 10
218 // *
219 // * @param lp
220 // * {@link JLayeredPane} that contains the {@link GeoMapPane}
221 // */
222 // private void createMapButtons(final JLayeredPane lp) {
223 //
224 // final Integer zlayer = new Integer(10);
225 //
226 // toggleButtonsList = new LinkedList<JToggleButton>();
227 // toggleButtonsList.add(infoToggleButton);
228 // toggleButtonsList.add(panToggleButton);
229 // toggleButtonsList.add(zoominToggleButton);
230 // toggleButtonsList.add(zoomoutToggleButton);
231 //
232 //
233 // positionLayeredObjects();
234 //
235 // final ButtonGroup bg = new ButtonGroup();
236 // for (final JToggleButton b : toggleButtonsList) {
237 // // final FontMetrics fm = b.getFontMetrics( b.getFont() );
238 // // final int w = fm.stringWidth( b.getText() );
239 //
240 // // b.setBorder( BorderFactory.createRaisedBevelBorder() );
241 // b.setBorder(BorderFactory.createEmptyBorder());
242 // b.setSize(new Dimension(32, 32));
243 // bg.add(b);
244 // lp.add(b, zlayer);
245 // }
246 //
247 // zoomBackButton.setSize(32, 32);
248 // zoomBackButton.setBorder(BorderFactory.createEmptyBorder());
249 // lp.add(zoomBackButton, zlayer);
250 //
251 // zoomForwardButton.setSize(32, 32);
252 // zoomForwardButton.setBorder(BorderFactory.createEmptyBorder());
253 // lp.add(zoomForwardButton, zlayer);
254 // }
255
256 // /**
257 // * This method will update the
258 // */
259 // public void updateIconsForButtons() {
260 // if (zoomoutToggleButton.isSelected())
261 // zoomoutToggleButton.setIcon(new ImageIcon(MapView.class
262 // .getResource("zoom_out.png")));
263 // else
264 // zoomoutToggleButton.setIcon(new ImageIcon(MapView.class
265 // .getResource("zoom_out.png")));
266 //
267 // if (zoominToggleButton.isSelected())
268 // zoominToggleButton.setIcon(new ImageIcon(MapView.class
269 // .getResource("zoom_in.png")));
270 // else
271 // zoominToggleButton.setIcon(new ImageIcon(MapView.class
272 // .getResource("zoom_in.png")));
273 //
274 // if (infoToggleButton.isSelected())
275 // infoToggleButton.setIcon(new ImageIcon(MapView.class
276 // .getResource("info.png")));
277 // else
278 // infoToggleButton.setIcon(new ImageIcon(MapView.class
279 // .getResource("info_aus.png")));
280 //
281 // if (panToggleButton.isSelected())
282 // panToggleButton.setIcon(new ImageIcon(MapView.class
283 // .getResource("pan.png")));
284 // else
285 // panToggleButton.setIcon(new ImageIcon(MapView.class
286 // .getResource("pan_aus.png")));
287 //
288 // }
289
290 /**
291 * Sets the active tool.
292 * Simply calls {@link MapPaneToolBar#setSelectedTool(Integer)}.
293 * @param tool
294 * One of {@link #TOOL_INFO}, {@link #TOOL_PAN} .. constants
295 */
296 public void setSelectedTool(Integer tool) {
297 jToolBar.setSelectedTool(tool);
298 }
299
300 /**
301 * Sets whether a tool is activated or not.
302 * Simply calls {@link MapPaneToolBar#setButtonEnabled(int, boolean, boolean)}.
303 * @param tool tool ID
304 * @param enabled if {@code true} the tool becomes available
305 * @param hideOnDisable if {@code true} the button is also hidden if
306 * {@code enabled} is {@code false}
307 */
308 public void setToolEnabled(Integer tool, boolean enabled, boolean hideOnDisable) {
309 jToolBar.setButtonEnabled(tool,enabled,hideOnDisable);
310 }
311
312 /**
313 * Sets the activation for all tools.
314 * Simply calls {@link MapPaneToolBar#setAllToolsEnabled(boolean, boolean)}.
315 * @param enabled if {@code true} all tool becomes available
316 * @param hideOnDisable if {@code true} the buttons are also hidden if
317 * {@code enabled} is {@code false}
318 */
319 public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {
320 jToolBar.setAllToolsEnabled(enabled, hideOnDisable);
321 }
322
323 /**
324 * Checks whether a tool is activated.
325 * Simply calls {@link MapPaneToolBar#isButtonEnabled(Integer)}.
326 * @param tool tool ID
327 * @return {@code false} if an unknown ID is specified
328 */
329 public boolean isToolEnabled(Integer tool) {
330 return jToolBar.isButtonEnabled(tool);
331 }
332 //
333 // /**
334 // * Positions the Map Control Buttons on top of the {@link GeoMapPane}
335 // *
336 // * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>
337 // *
338 // */
339 // protected void positionLayeredObjects() {
340 //
341 // // Abstand zwischen den Buttons und Button zu Rand
342 // final int gap = 10;
343 //
344 // // 45 entspicht der breite des Grids/ der Gradanzeige
345 // // TODO den wert aus der geomappane auslesen...
346 // int x = GridPanel.VERT_WIDTH;
347 //
348 // for (final JToggleButton b : toggleButtonsList) {
349 // x += gap;
350 // // final FontMetrics fm = b.getFontMetrics( b.getFont() );
351 // b.setLocation(x, 10);
352 //
353 // final int w = 32;
354 // x += w;
355 // // y += b.getWidth();
356 // }
357 //
358 // // Und noch die zwei ZoomBackup und ZoomForward Buttons
359 // zoomBackButton.setLocation(x + 32 + gap, 10);
360 // zoomForwardButton.setLocation(x + 64 + gap * 2, 10);
361 // }
362
363 /**
364 * called by initialize() to fill the left of the XULUMapView Supposed to be
365 * overwritten by AtlasMapView or DesignMapView
366 */
367 public JComponent getSidePane() {
368 return new MapContextControlPane(getGeoMapPane().getMapPane(),
369 new ColorMapManager());
370 }
371
372 /**
373 * Liefert die Status-Zeile, in der die Koordinaten und Raster-Werte
374 * angezeigt werden.
375 */
376 public MapPaneStatusBar getStatusBar() {
377 return this.statusBar;
378 }
379
380 /**
381 * Liefert den Karten-Bereich der Komponente.
382 */
383 public final JMapPane getMapPane() {
384 return getGeoMapPane().getMapPane();
385 }
386
387 // /**
388 // * Liefert das in einem Layer dargestellte Objekt.
389 // *
390 // * @param layer
391 // * ein Layer
392 // */
393 // public Object getMapObject(final MapLayer layer) {
394 // // return layerObjects.get(layer);
395 // return null;
396 // }
397
398 public GeoMapPane getGeoMapPane() {
399 return geoMapPane;
400 }
401
402 public int getSelectedTool() {
403 return jToolBar.getSelectedTool();
404 }
405
406 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26