1 |
package skrueger.geotools; |
/******************************************************************************* |
2 |
|
* Copyright (c) 2009 Martin O. J. Schmitz. |
3 |
import java.awt.BorderLayout; |
* |
4 |
import java.awt.Window; |
* This file is part of the SCHMITZM library - a collection of utility |
5 |
|
* classes based on Java 1.6, focusing (not only) on Java Swing |
6 |
import javax.swing.BorderFactory; |
* and the Geotools library. |
7 |
import javax.swing.JComponent; |
* |
8 |
import javax.swing.JPanel; |
* The SCHMITZM project is hosted at: |
9 |
import javax.swing.JSplitPane; |
* http://wald.intevation.org/projects/schmitzm/ |
10 |
|
* |
11 |
import org.apache.log4j.Logger; |
* This program is free software; you can redistribute it and/or |
12 |
import org.geotools.renderer.lite.StreamingRenderer; |
* modify it under the terms of the GNU Lesser General Public License |
13 |
import org.geotools.renderer.shape.ShapefileRenderer; |
* as published by the Free Software Foundation; either version 3 |
14 |
|
* of the License, or (at your option) any later version. |
15 |
import schmitzm.geotools.gui.GeoMapPane; |
* |
16 |
import schmitzm.geotools.gui.JMapPane; |
* This program is distributed in the hope that it will be useful, |
17 |
import schmitzm.geotools.gui.MapContextControlPane; |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 |
import schmitzm.geotools.gui.MapPaneStatusBar; |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 |
import schmitzm.geotools.styling.ColorMapManager; |
* GNU General Public License for more details. |
20 |
|
* |
21 |
/** |
* You should have received a copy of the GNU Lesser General Public License (license.txt) |
22 |
* Achtung! Dieser code ist verwuestet |
* along with this program; if not, write to the Free Software |
23 |
* TODO DOKU und initialize schöner machen. SK |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
24 |
*/ |
* or try this link: http://www.gnu.org/licenses/lgpl.html |
25 |
public class MapView extends JPanel { |
* |
26 |
private static final Logger LOGGER = Logger.getLogger(MapView.class); |
* Contributors: |
27 |
|
* Martin O. J. Schmitz - initial API and implementation |
28 |
public final JSplitPane splitPane = new JSplitPane( |
* Stefan A. Tzeggai - additional utility classes |
29 |
JSplitPane.HORIZONTAL_SPLIT); |
******************************************************************************/ |
30 |
|
package skrueger.geotools; |
31 |
protected MapPaneStatusBar statusBar = null; |
|
32 |
|
import java.awt.BorderLayout; |
33 |
/** |
import java.awt.Component; |
34 |
* Komponente, in der die Karten, der Massstab und das Koordinaten-Raster |
|
35 |
* dargestellt werden. |
import javax.swing.BorderFactory; |
36 |
*/ |
import javax.swing.JComponent; |
37 |
|
import javax.swing.JPanel; |
38 |
/** |
import javax.swing.JSplitPane; |
39 |
* SK: 21.6.09: ShapeFileRenderer is supposed to be about 5x faster on |
|
40 |
* ShapeFiles. The ShapeFileRenderer falls back to the |
import net.miginfocom.swing.MigLayout; |
41 |
* StreamingRenderer. |
|
42 |
*/ |
import org.apache.log4j.Logger; |
43 |
// Old code: |
|
44 |
// protected final GeoMapPane geoMapPane = new GeoMapPane(null,null,null,null, new StreamingRenderer()); |
import schmitzm.geotools.gui.GeoMapPane; |
45 |
|
import schmitzm.geotools.gui.MapContextControlPane; |
46 |
// New Code uses Streaming renderer. |
import schmitzm.geotools.gui.MapPaneStatusBar; |
47 |
protected final GeoMapPane geoMapPane = new GeoMapPane(null,null,null,null, new ShapefileRenderer()); |
import schmitzm.geotools.gui.SelectableXMapPane; |
48 |
|
import schmitzm.geotools.styling.ColorMapManager; |
49 |
private MapPaneToolBar jToolBar; |
|
50 |
|
/** |
51 |
/** |
* Achtung! Dieser code ist verwuestet TODO DOKU und initialize schöner machen. |
52 |
* Creates a new {@link MapView}. A {@link MapView} is a combination of a |
* SK |
53 |
* {@link GeoMapPane}, a {@link MapContextManagerInterface} on the left, |
*/ |
54 |
* and some buttons floating over the {@link JMapPane} |
public class MapView extends JPanel { |
55 |
*/ |
private static final Logger LOGGER = Logger.getLogger(MapView.class); |
56 |
public MapView(Window parentGui, MapPaneToolBar toolBar) { |
|
57 |
super(new BorderLayout()); |
private final JSplitPane splitPane = new JSplitPane( |
58 |
// Call initialize() by yourself afterwards. |
JSplitPane.HORIZONTAL_SPLIT); |
59 |
// Needed because variables for the overwritten methods |
|
60 |
// are not yet set. |
protected MapPaneStatusBar statusBar = null; |
61 |
getGeoMapPane().getMapPane().setWaitCursorComponent(parentGui); |
|
62 |
if ( toolBar == null ) |
/** |
63 |
toolBar = new MapPaneToolBar(getMapPane()); |
* Komponente, in der die Karten, der Massstab und das Koordinaten-Raster |
64 |
jToolBar = toolBar; |
* dargestellt werden. |
65 |
} |
*/ |
66 |
|
|
67 |
/** |
protected final GeoMapPane geoMapPane = new GeoMapPane(); |
68 |
* Creates a new {@link MapView}. A {@link MapView} is a combination of a |
|
69 |
* {@link GeoMapPane}, a {@link MapContextManagerInterface} on the left, |
private MapPaneToolBar jToolBar; |
70 |
* and some buttons floating over the {@link JMapPane} |
|
71 |
*/ |
/** |
72 |
public MapView(Window parentGui) { |
* Creates a new {@link MapView}. A {@link MapView} is a combination of a |
73 |
this(parentGui, null); |
* {@link GeoMapPane}, a {@link MapContextManagerInterface} on the left, and |
74 |
} |
* some buttons floating over the {@link SelectableXMapPane} |
75 |
|
*/ |
76 |
/** |
public MapView(Component parentGui, MapPaneToolBar toolBar) { |
77 |
* Calls #getSidePanel() which can be overwritten. |
super(new BorderLayout()); |
78 |
* |
// Call initialize() by yourself afterwards. |
79 |
* @see #adjustSizeOfGeoMapPane() |
// Needed because variables for the overwritten methods |
80 |
*/ |
// are not yet set. |
81 |
public void initialize() { |
jToolBar = toolBar; |
82 |
// horizontales SplitPane initialisieren |
|
83 |
// Status-Line to show Coordinates and Rastervalues. |
// By default the MapPane will render with antialiasing on |
84 |
statusBar = new MapPaneStatusBar(getGeoMapPane() |
getGeoMapPane().getMapPane() |
85 |
.getMapPane()); |
.setAntiAliasing(true); |
86 |
statusBar.setBorder(BorderFactory.createCompoundBorder(BorderFactory |
} |
87 |
.createLoweredBevelBorder(), BorderFactory.createEmptyBorder(2, |
|
88 |
5, 2, 5))); |
/** |
89 |
this.add(statusBar, BorderLayout.SOUTH); |
* Creates a new {@link MapView}. A {@link MapView} is a combination of a |
90 |
|
* {@link GeoMapPane}, a {@link MapContextManagerInterface} on the left, and |
91 |
splitPane.setDividerLocation(-1); |
* some buttons floating over the {@link SelectableXMapPane} |
92 |
splitPane.setDividerSize(5); |
*/ |
93 |
|
public MapView(Component parentGui) { |
94 |
splitPane.setResizeWeight(0.0); |
this(parentGui, null); |
95 |
splitPane.add(getSidePane()); |
} |
96 |
|
|
97 |
/*********************************************************************** |
/** |
98 |
* To the right side we now add a JPanel that consists of a toolbar and |
* This routine creates the main components of the GUI: The left Side and |
99 |
* a gmp |
* the map on the right side.<br/> |
100 |
*/ |
* Calls #getSidePanel() which can be overwritten (call super!).<br/> |
101 |
JPanel newRight = new JPanel(new BorderLayout()); |
* |
102 |
newRight.add(getToolBar(), BorderLayout.NORTH); |
* This method initialized the variables {@link #statusBar} and |
103 |
newRight.add(getGeoMapPane(), BorderLayout.CENTER); |
* {@link #splitPane} |
104 |
splitPane.add(newRight); |
* |
105 |
|
* @see #adjustSizeOfGeoMapPane() |
106 |
this.add(splitPane, BorderLayout.CENTER); |
*/ |
107 |
} |
public void initialize() { |
108 |
|
// horizontales SplitPane initialisieren |
109 |
/** |
|
110 |
* Returns the tool bar which controls the active mouse actions on the map. |
// Status-Line to show Coordinates and Rastervalues. |
111 |
* @return |
statusBar = new MapPaneStatusBar(getGeoMapPane().getMapPane()); |
112 |
*/ |
statusBar.setBorder(BorderFactory.createCompoundBorder(BorderFactory |
113 |
public MapPaneToolBar getToolBar() { |
.createLoweredBevelBorder(), BorderFactory.createEmptyBorder(2, |
114 |
return jToolBar; |
5, 2, 5))); |
115 |
} |
this.add(statusBar, BorderLayout.SOUTH); |
116 |
|
|
117 |
/** |
/** |
118 |
* Returns the split pane which divides the layer list from the map panel. |
* The layout of the split pane can be configured in the atlas. |
119 |
*/ |
* setDividerLocation(-1); has no effect here because the component is |
120 |
public JSplitPane getSplitPane() { |
* not visible yet. |
121 |
return this.splitPane; |
*/ |
122 |
} |
getSplitPane().setDividerSize(5); |
123 |
|
|
124 |
|
getSplitPane().setResizeWeight(0.0); |
125 |
/** |
getSplitPane().add(getSidePane()); |
126 |
* Sets the active tool. |
|
127 |
* Simply calls {@link MapPaneToolBar#setSelectedTool(Integer)}. |
/*********************************************************************** |
128 |
* @param tool |
* To the right side we now add a JPanel that consists of a toolbar and |
129 |
* One of {@link #TOOL_INFO}, {@link #TOOL_PAN} .. constants |
* a gmp |
130 |
*/ |
*/ |
131 |
public void setSelectedTool(Integer tool) { |
JPanel newRight = new JPanel(new MigLayout("center, wrap 1","[grow]","[][grow]")); |
132 |
jToolBar.setSelectedTool(tool); |
newRight.add(getToolBar()); |
133 |
} |
newRight.add(getGeoMapPane(),"growx, growy"); |
134 |
|
getSplitPane().add(newRight); |
135 |
/** |
|
136 |
* Sets whether a tool is activated or not. |
this.add(getSplitPane(), BorderLayout.CENTER); |
137 |
* Simply calls {@link MapPaneToolBar#setButtonEnabled(int, boolean, boolean)}. |
|
138 |
* @param tool tool ID |
} |
139 |
* @param enabled if {@code true} the tool becomes available |
|
140 |
* @param hideOnDisable if {@code true} the button is also hidden if |
/** |
141 |
* {@code enabled} is {@code false} |
* Returns the tool bar which controls the active mouse actions on the map. |
142 |
*/ |
* |
143 |
public void setToolEnabled(Integer tool, boolean enabled, boolean hideOnDisable) { |
* @return never <code>null</code>, will rather create a default |
144 |
jToolBar.setButtonEnabled(tool,enabled,hideOnDisable); |
*/ |
145 |
} |
public MapPaneToolBar getToolBar() { |
146 |
|
if (jToolBar == null) { |
147 |
/** |
jToolBar = new MapPaneToolBar(getMapPane()); |
148 |
* Sets the activation for all tools. |
} |
149 |
* Simply calls {@link MapPaneToolBar#setAllToolsEnabled(boolean, boolean)}. |
return jToolBar; |
150 |
* @param enabled if {@code true} all tool becomes available |
} |
151 |
* @param hideOnDisable if {@code true} the buttons are also hidden if |
|
152 |
* {@code enabled} is {@code false} |
/** |
153 |
*/ |
* Returns the split pane which divides the layer list from the map panel. |
154 |
public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) { |
*/ |
155 |
jToolBar.setAllToolsEnabled(enabled, hideOnDisable); |
public JSplitPane getSplitPane() { |
156 |
} |
return splitPane; |
157 |
|
} |
158 |
/** |
|
159 |
* Checks whether a tool is activated. |
/** |
160 |
* Simply calls {@link MapPaneToolBar#isButtonEnabled(Integer)}. |
* Sets the active tool. Simply calls |
161 |
* @param tool tool ID |
* {@link MapPaneToolBar#setSelectedTool(Integer)}. |
162 |
* @return {@code false} if an unknown ID is specified |
* |
163 |
*/ |
* @param tool |
164 |
public boolean isToolEnabled(Integer tool) { |
* One of {@link #TOOL_INFO}, {@link #TOOL_PAN} .. constants |
165 |
return jToolBar.isButtonEnabled(tool); |
*/ |
166 |
} |
public void setSelectedTool(Integer tool) { |
167 |
|
jToolBar.setSelectedTool(tool); |
168 |
/** |
} |
169 |
* called by initialize() to fill the left of the XULUMapView Supposed to be |
|
170 |
* overwritten by AtlasMapView or DesignMapView |
/** |
171 |
*/ |
* Sets whether a tool is activated or not. Simply calls |
172 |
public JComponent getSidePane() { |
* {@link MapPaneToolBar#setButtonEnabled(int, boolean, boolean)}. |
173 |
return new MapContextControlPane(getGeoMapPane().getMapPane(), |
* |
174 |
new ColorMapManager()); |
* @param tool |
175 |
} |
* tool ID |
176 |
|
* @param enabled |
177 |
/** |
* if {@code true} the tool becomes available |
178 |
* Liefert die Status-Zeile, in der die Koordinaten und Raster-Werte |
* @param hideOnDisable |
179 |
* angezeigt werden. |
* if {@code true} the button is also hidden if {@code enabled} |
180 |
*/ |
* is {@code false} |
181 |
public MapPaneStatusBar getStatusBar() { |
*/ |
182 |
return this.statusBar; |
public void setToolEnabled(Integer tool, boolean enabled, |
183 |
} |
boolean hideOnDisable) { |
184 |
|
jToolBar.setButtonEnabled(tool, enabled, hideOnDisable); |
185 |
/** |
} |
186 |
* Liefert den Karten-Bereich der Komponente. |
|
187 |
*/ |
/** |
188 |
public final JMapPane getMapPane() { |
* Sets the activation for all tools. Simply calls |
189 |
return getGeoMapPane().getMapPane(); |
* {@link MapPaneToolBar#setAllToolsEnabled(boolean, boolean)}. |
190 |
} |
* |
191 |
|
* @param enabled |
192 |
public GeoMapPane getGeoMapPane() { |
* if {@code true} all tool becomes available |
193 |
return geoMapPane; |
* @param hideOnDisable |
194 |
} |
* if {@code true} the buttons are also hidden if {@code enabled} |
195 |
|
* is {@code false} |
196 |
public int getSelectedTool() { |
*/ |
197 |
return jToolBar.getSelectedTool(); |
public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) { |
198 |
} |
jToolBar.setAllToolsEnabled(enabled, hideOnDisable); |
199 |
|
} |
200 |
} |
|
201 |
|
/** |
202 |
|
* Checks whether a tool is activated. Simply calls |
203 |
|
* {@link MapPaneToolBar#isButtonEnabled(Integer)}. |
204 |
|
* |
205 |
|
* @param tool |
206 |
|
* tool ID |
207 |
|
* @return {@code false} if an unknown ID is specified |
208 |
|
*/ |
209 |
|
public boolean isToolEnabled(Integer tool) { |
210 |
|
return jToolBar.isButtonEnabled(tool); |
211 |
|
} |
212 |
|
|
213 |
|
/** |
214 |
|
* called by initialize() to fill the left of the XULUMapView Supposed to be |
215 |
|
* overwritten by AtlasMapView or DesignMapView |
216 |
|
*/ |
217 |
|
public JComponent getSidePane() { |
218 |
|
return new MapContextControlPane(getGeoMapPane().getMapPane(), |
219 |
|
new ColorMapManager()); |
220 |
|
} |
221 |
|
|
222 |
|
/** |
223 |
|
* Liefert die Status-Zeile, in der die Koordinaten und Raster-Werte |
224 |
|
* angezeigt werden. |
225 |
|
*/ |
226 |
|
public MapPaneStatusBar getStatusBar() { |
227 |
|
return this.statusBar; |
228 |
|
} |
229 |
|
|
230 |
|
/** |
231 |
|
* Liefert den Karten-Bereich der Komponente. |
232 |
|
*/ |
233 |
|
public final SelectableXMapPane getMapPane() { |
234 |
|
return getGeoMapPane().getMapPane(); |
235 |
|
} |
236 |
|
|
237 |
|
public GeoMapPane getGeoMapPane() { |
238 |
|
return geoMapPane; |
239 |
|
} |
240 |
|
|
241 |
|
public int getSelectedTool() { |
242 |
|
return jToolBar.getSelectedTool(); |
243 |
|
} |
244 |
|
|
245 |
|
/** |
246 |
|
* Help the garbage collection |
247 |
|
*/ |
248 |
|
public void dispose() { |
249 |
|
if (geoMapPane != null) |
250 |
|
geoMapPane.dispose(); |
251 |
|
} |
252 |
|
|
253 |
|
} |