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