1 |
mojays |
2 |
package skrueger.geotools; |
2 |
|
|
|
3 |
|
|
import java.awt.BorderLayout; |
4 |
alfonx |
87 |
import java.awt.Window; |
5 |
mojays |
2 |
|
6 |
|
|
import javax.swing.BorderFactory; |
7 |
|
|
import javax.swing.JComponent; |
8 |
|
|
import javax.swing.JPanel; |
9 |
|
|
import javax.swing.JSplitPane; |
10 |
|
|
|
11 |
|
|
import org.apache.log4j.Logger; |
12 |
alfonx |
158 |
import org.geotools.renderer.lite.StreamingRenderer; |
13 |
mojays |
2 |
|
14 |
|
|
import schmitzm.geotools.gui.GeoMapPane; |
15 |
|
|
import schmitzm.geotools.gui.JMapPane; |
16 |
|
|
import schmitzm.geotools.gui.MapContextControlPane; |
17 |
|
|
import schmitzm.geotools.gui.MapPaneStatusBar; |
18 |
|
|
import schmitzm.geotools.styling.ColorMapManager; |
19 |
|
|
|
20 |
|
|
/** |
21 |
alfonx |
165 |
* Achtung! Dieser code ist verwuestet TODO DOKU und initialize schöner machen. |
22 |
|
|
* SK |
23 |
mojays |
2 |
*/ |
24 |
|
|
public class MapView extends JPanel { |
25 |
|
|
private static final Logger LOGGER = Logger.getLogger(MapView.class); |
26 |
|
|
|
27 |
alfonx |
164 |
private final JSplitPane splitPane = new JSplitPane( |
28 |
mojays |
2 |
JSplitPane.HORIZONTAL_SPLIT); |
29 |
|
|
|
30 |
|
|
protected MapPaneStatusBar statusBar = null; |
31 |
alfonx |
165 |
|
32 |
mojays |
2 |
/** |
33 |
|
|
* Komponente, in der die Karten, der Massstab und das Koordinaten-Raster |
34 |
alfonx |
165 |
* dargestellt werden. |
35 |
mojays |
2 |
*/ |
36 |
alfonx |
165 |
|
37 |
alfonx |
154 |
/** |
38 |
|
|
* SK: 21.6.09: ShapeFileRenderer is supposed to be about 5x faster on |
39 |
alfonx |
165 |
* ShapeFiles. The ShapeFileRenderer falls back to the StreamingRenderer. |
40 |
alfonx |
154 |
*/ |
41 |
|
|
// Old code: |
42 |
alfonx |
165 |
// protected final GeoMapPane geoMapPane = new |
43 |
|
|
// GeoMapPane(null,null,null,null, new StreamingRenderer()); |
44 |
alfonx |
154 |
// New Code uses Streaming renderer. |
45 |
alfonx |
165 |
protected final GeoMapPane geoMapPane = new GeoMapPane(null, null, null, |
46 |
|
|
null, new StreamingRenderer()); |
47 |
mojays |
2 |
|
48 |
|
|
private MapPaneToolBar jToolBar; |
49 |
|
|
|
50 |
|
|
/** |
51 |
|
|
* Creates a new {@link MapView}. A {@link MapView} is a combination of a |
52 |
alfonx |
165 |
* {@link GeoMapPane}, a {@link MapContextManagerInterface} on the left, and |
53 |
|
|
* some buttons floating over the {@link JMapPane} |
54 |
mojays |
2 |
*/ |
55 |
alfonx |
87 |
public MapView(Window parentGui, MapPaneToolBar toolBar) { |
56 |
mojays |
2 |
super(new BorderLayout()); |
57 |
|
|
// Call initialize() by yourself afterwards. |
58 |
|
|
// Needed because variables for the overwritten methods |
59 |
|
|
// are not yet set. |
60 |
alfonx |
87 |
getGeoMapPane().getMapPane().setWaitCursorComponent(parentGui); |
61 |
alfonx |
165 |
if (toolBar == null) |
62 |
|
|
toolBar = new MapPaneToolBar(getMapPane()); |
63 |
|
|
jToolBar = toolBar; |
64 |
mojays |
2 |
} |
65 |
|
|
|
66 |
alfonx |
165 |
/** |
67 |
|
|
* Creates a new {@link MapView}. A {@link MapView} is a combination of a |
68 |
|
|
* {@link GeoMapPane}, a {@link MapContextManagerInterface} on the left, and |
69 |
|
|
* some buttons floating over the {@link JMapPane} |
70 |
|
|
*/ |
71 |
|
|
public MapView(Window parentGui) { |
72 |
|
|
this(parentGui, null); |
73 |
|
|
} |
74 |
mojays |
2 |
|
75 |
|
|
/** |
76 |
alfonx |
165 |
* This routine creates the main components of the GUI: The left Side and |
77 |
|
|
* the map on the right side.<br/> |
78 |
alfonx |
164 |
* Calls #getSidePanel() which can be overwritten (call super!).<br/> |
79 |
mojays |
2 |
* |
80 |
alfonx |
165 |
* This method initialized the variables {@link #statusBar} and |
81 |
|
|
* {@link #splitPane} |
82 |
alfonx |
164 |
* |
83 |
mojays |
2 |
* @see #adjustSizeOfGeoMapPane() |
84 |
|
|
*/ |
85 |
|
|
public void initialize() { |
86 |
|
|
// horizontales SplitPane initialisieren |
87 |
alfonx |
165 |
|
88 |
alfonx |
154 |
// Status-Line to show Coordinates and Rastervalues. |
89 |
alfonx |
165 |
statusBar = new MapPaneStatusBar(getGeoMapPane().getMapPane()); |
90 |
alfonx |
154 |
statusBar.setBorder(BorderFactory.createCompoundBorder(BorderFactory |
91 |
|
|
.createLoweredBevelBorder(), BorderFactory.createEmptyBorder(2, |
92 |
|
|
5, 2, 5))); |
93 |
|
|
this.add(statusBar, BorderLayout.SOUTH); |
94 |
mojays |
2 |
|
95 |
alfonx |
164 |
/** |
96 |
alfonx |
165 |
* The layout of the split pane can be configured in the atlas. |
97 |
|
|
* setDividerLocation(-1); has no effect here because the component is |
98 |
|
|
* not visible yet. |
99 |
alfonx |
164 |
*/ |
100 |
|
|
getSplitPane().setDividerSize(5); |
101 |
alfonx |
165 |
|
102 |
alfonx |
164 |
getSplitPane().setResizeWeight(0.0); |
103 |
|
|
getSplitPane().add(getSidePane()); |
104 |
mojays |
2 |
|
105 |
|
|
/*********************************************************************** |
106 |
|
|
* To the right side we now add a JPanel that consists of a toolbar and |
107 |
|
|
* a gmp |
108 |
|
|
*/ |
109 |
|
|
JPanel newRight = new JPanel(new BorderLayout()); |
110 |
|
|
newRight.add(getToolBar(), BorderLayout.NORTH); |
111 |
|
|
newRight.add(getGeoMapPane(), BorderLayout.CENTER); |
112 |
alfonx |
164 |
getSplitPane().add(newRight); |
113 |
mojays |
2 |
|
114 |
alfonx |
164 |
this.add(getSplitPane(), BorderLayout.CENTER); |
115 |
mojays |
2 |
} |
116 |
|
|
|
117 |
|
|
/** |
118 |
|
|
* Returns the tool bar which controls the active mouse actions on the map. |
119 |
alfonx |
165 |
* |
120 |
mojays |
2 |
* @return |
121 |
|
|
*/ |
122 |
|
|
public MapPaneToolBar getToolBar() { |
123 |
alfonx |
165 |
return jToolBar; |
124 |
mojays |
2 |
} |
125 |
|
|
|
126 |
|
|
/** |
127 |
|
|
* Returns the split pane which divides the layer list from the map panel. |
128 |
|
|
*/ |
129 |
|
|
public JSplitPane getSplitPane() { |
130 |
alfonx |
164 |
return splitPane; |
131 |
mojays |
2 |
} |
132 |
|
|
|
133 |
|
|
/** |
134 |
alfonx |
165 |
* Sets the active tool. Simply calls |
135 |
|
|
* {@link MapPaneToolBar#setSelectedTool(Integer)}. |
136 |
|
|
* |
137 |
mojays |
2 |
* @param tool |
138 |
|
|
* One of {@link #TOOL_INFO}, {@link #TOOL_PAN} .. constants |
139 |
|
|
*/ |
140 |
|
|
public void setSelectedTool(Integer tool) { |
141 |
alfonx |
165 |
jToolBar.setSelectedTool(tool); |
142 |
mojays |
2 |
} |
143 |
alfonx |
165 |
|
144 |
|
|
/** |
145 |
|
|
* Sets whether a tool is activated or not. Simply calls |
146 |
|
|
* {@link MapPaneToolBar#setButtonEnabled(int, boolean, boolean)}. |
147 |
|
|
* |
148 |
|
|
* @param tool |
149 |
|
|
* tool ID |
150 |
|
|
* @param enabled |
151 |
|
|
* if {@code true} the tool becomes available |
152 |
|
|
* @param hideOnDisable |
153 |
|
|
* if {@code true} the button is also hidden if {@code enabled} |
154 |
|
|
* is {@code false} |
155 |
|
|
*/ |
156 |
|
|
public void setToolEnabled(Integer tool, boolean enabled, |
157 |
|
|
boolean hideOnDisable) { |
158 |
|
|
jToolBar.setButtonEnabled(tool, enabled, hideOnDisable); |
159 |
mojays |
2 |
} |
160 |
|
|
|
161 |
alfonx |
165 |
/** |
162 |
|
|
* Sets the activation for all tools. Simply calls |
163 |
|
|
* {@link MapPaneToolBar#setAllToolsEnabled(boolean, boolean)}. |
164 |
|
|
* |
165 |
|
|
* @param enabled |
166 |
|
|
* if {@code true} all tool becomes available |
167 |
|
|
* @param hideOnDisable |
168 |
|
|
* if {@code true} the buttons are also hidden if {@code enabled} |
169 |
|
|
* is {@code false} |
170 |
|
|
*/ |
171 |
|
|
public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) { |
172 |
|
|
jToolBar.setAllToolsEnabled(enabled, hideOnDisable); |
173 |
|
|
} |
174 |
mojays |
2 |
|
175 |
alfonx |
165 |
/** |
176 |
|
|
* Checks whether a tool is activated. Simply calls |
177 |
|
|
* {@link MapPaneToolBar#isButtonEnabled(Integer)}. |
178 |
|
|
* |
179 |
|
|
* @param tool |
180 |
|
|
* tool ID |
181 |
mojays |
2 |
* @return {@code false} if an unknown ID is specified |
182 |
|
|
*/ |
183 |
|
|
public boolean isToolEnabled(Integer tool) { |
184 |
alfonx |
165 |
return jToolBar.isButtonEnabled(tool); |
185 |
mojays |
2 |
} |
186 |
|
|
|
187 |
|
|
/** |
188 |
|
|
* called by initialize() to fill the left of the XULUMapView Supposed to be |
189 |
|
|
* overwritten by AtlasMapView or DesignMapView |
190 |
|
|
*/ |
191 |
|
|
public JComponent getSidePane() { |
192 |
|
|
return new MapContextControlPane(getGeoMapPane().getMapPane(), |
193 |
|
|
new ColorMapManager()); |
194 |
|
|
} |
195 |
|
|
|
196 |
|
|
/** |
197 |
|
|
* Liefert die Status-Zeile, in der die Koordinaten und Raster-Werte |
198 |
alfonx |
165 |
* angezeigt werden. |
199 |
mojays |
2 |
*/ |
200 |
|
|
public MapPaneStatusBar getStatusBar() { |
201 |
alfonx |
165 |
return this.statusBar; |
202 |
mojays |
2 |
} |
203 |
alfonx |
165 |
|
204 |
mojays |
2 |
/** |
205 |
|
|
* Liefert den Karten-Bereich der Komponente. |
206 |
|
|
*/ |
207 |
|
|
public final JMapPane getMapPane() { |
208 |
|
|
return getGeoMapPane().getMapPane(); |
209 |
|
|
} |
210 |
|
|
|
211 |
|
|
public GeoMapPane getGeoMapPane() { |
212 |
|
|
return geoMapPane; |
213 |
|
|
} |
214 |
|
|
|
215 |
|
|
public int getSelectedTool() { |
216 |
|
|
return jToolBar.getSelectedTool(); |
217 |
|
|
} |
218 |
|
|
|
219 |
|
|
} |