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