root / org.gvsig.proj / branches / refactor2018 / org.gvsig.proj / org.gvsig.proj.swing / org.gvsig.proj.swing.impl / src / main / java / org / gvsig / proj / swing / impl / CrsSelectorController.java @ 874
History | View | Annotate | Download (19 KB)
1 | 859 | cmartinez | package org.gvsig.proj.swing.impl; |
---|---|---|---|
2 | |||
3 | import java.awt.event.ActionEvent; |
||
4 | import java.awt.event.ActionListener; |
||
5 | import java.beans.PropertyChangeListener; |
||
6 | import java.text.ParseException; |
||
7 | import java.util.ArrayList; |
||
8 | 866 | cmartinez | import java.util.List; |
9 | 859 | cmartinez | |
10 | import javax.swing.Action; |
||
11 | import javax.swing.Icon; |
||
12 | import javax.swing.ImageIcon; |
||
13 | import javax.swing.JComponent; |
||
14 | import javax.swing.JTree; |
||
15 | import javax.swing.event.TreeSelectionEvent; |
||
16 | import javax.swing.event.TreeSelectionListener; |
||
17 | import javax.swing.tree.DefaultTreeCellRenderer; |
||
18 | import javax.swing.tree.DefaultTreeModel; |
||
19 | import javax.swing.tree.TreeNode; |
||
20 | import javax.swing.tree.TreePath; |
||
21 | import javax.swing.tree.TreeSelectionModel; |
||
22 | |||
23 | import org.apache.commons.io.FilenameUtils; |
||
24 | import org.gvsig.proj.CoordinateReferenceSystem; |
||
25 | import org.gvsig.proj.catalog.CRSDefinition; |
||
26 | import org.gvsig.proj.catalog.CRSType; |
||
27 | import org.gvsig.proj.catalog.exception.UnsupportedCoordinateReferenceSystemException; |
||
28 | import org.gvsig.proj.catalog.extent.GeographicBoundingBox; |
||
29 | import org.gvsig.proj.swing.CoordinateReferenceSystemSelectorComponent; |
||
30 | import org.gvsig.proj.swing.impl.tree.BranchNode; |
||
31 | import org.gvsig.proj.swing.impl.tree.CRSSearchFilter; |
||
32 | import org.gvsig.proj.swing.impl.tree.CrsLoader; |
||
33 | import org.gvsig.proj.swing.impl.tree.CrsTreeNode; |
||
34 | 866 | cmartinez | import org.gvsig.proj.swing.impl.tree.DirectGroupLoader; |
35 | 859 | cmartinez | import org.gvsig.proj.swing.impl.tree.GroupLoader; |
36 | 866 | cmartinez | import org.gvsig.proj.swing.impl.tree.AsyncGroupLoader; |
37 | 859 | cmartinez | import org.gvsig.proj.swing.impl.tree.LeafNode; |
38 | 866 | cmartinez | import org.gvsig.proj.swing.impl.tree.LoadedGroup; |
39 | 859 | cmartinez | import org.gvsig.proj.swing.impl.tree.LoadingNode; |
40 | import org.gvsig.proj.swing.impl.tree.TreeContainer; |
||
41 | import org.gvsig.tools.ToolsLocator; |
||
42 | import org.gvsig.tools.i18n.I18nManager; |
||
43 | import org.gvsig.tools.swing.api.ActionListenerSupport; |
||
44 | import org.gvsig.tools.swing.api.Component; |
||
45 | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
||
46 | import org.gvsig.tools.swing.api.ToolsSwingManager; |
||
47 | import org.gvsig.tools.swing.icontheme.IconTheme; |
||
48 | import org.slf4j.Logger; |
||
49 | import org.slf4j.LoggerFactory; |
||
50 | |||
51 | public class CrsSelectorController extends CrsSelectorView |
||
52 | implements CoordinateReferenceSystemSelectorComponent,
|
||
53 | 866 | cmartinez | Component,
|
54 | 859 | cmartinez | TreeContainer { |
55 | 866 | cmartinez | private static final long serialVersionUID = -5281166703625751190L; |
56 | 859 | cmartinez | private CoordinateReferenceSystem selectedCrs = null; |
57 | private ActionListenerSupport listenerSupport = ToolsSwingLocator.getToolsSwingManager().createActionListenerSupport();
|
||
58 | public static final String CRS_SELECTED_ACTION_COMMAND = "CrsSelected"; |
||
59 | protected ImageIcon RECENT_ICON; |
||
60 | protected ImageIcon FAVOURITE_ICON; |
||
61 | 866 | cmartinez | private ImageIcon CRS_ICON; |
62 | private ImageIcon FOLDER_OPEN_ICON; |
||
63 | private ImageIcon FOLDER_CLOSED_ICON; |
||
64 | 859 | cmartinez | private static Logger logger = LoggerFactory.getLogger(CrsSelectorController.class); |
65 | protected DefaultTreeModel model; |
||
66 | protected BranchNode root;
|
||
67 | 866 | cmartinez | protected LoadedGroup recent;
|
68 | protected LoadedGroup favorite;
|
||
69 | protected BranchNode customNode;
|
||
70 | 859 | cmartinez | protected IconTheme iconTheme = null; |
71 | protected I18nManager i18nManager = null; |
||
72 | final protected DefaultCoordinateReferenceSystemSwingManager manager; |
||
73 | 866 | cmartinez | protected String customLabel = "Layer"; |
74 | protected ArrayList<CRSDefinition> customList = new ArrayList<CRSDefinition>(); |
||
75 | 859 | cmartinez | |
76 | |||
77 | public CrsSelectorController(DefaultCoordinateReferenceSystemSwingManager manager) {
|
||
78 | super();
|
||
79 | this.manager = manager;
|
||
80 | initIcons(); |
||
81 | initComponents(); |
||
82 | initTree(); |
||
83 | 866 | cmartinez | initTreeListeners(); |
84 | 859 | cmartinez | resetSearchCombo(null);
|
85 | initSearchActions(); |
||
86 | } |
||
87 | |||
88 | @Override
|
||
89 | public ImageIcon loadImage( String imageName ) { |
||
90 | return getIconTheme().get(FilenameUtils.getBaseName(imageName));
|
||
91 | } |
||
92 | |||
93 | private IconTheme getIconTheme() {
|
||
94 | if (iconTheme == null) { |
||
95 | iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
||
96 | } |
||
97 | return iconTheme;
|
||
98 | } |
||
99 | |||
100 | private I18nManager getI18nManager() {
|
||
101 | if (i18nManager == null) { |
||
102 | i18nManager = ToolsLocator.getI18nManager(); |
||
103 | } |
||
104 | return i18nManager;
|
||
105 | } |
||
106 | |||
107 | |||
108 | protected void initComponents() { |
||
109 | 866 | cmartinez | IconTheme theme = getIconTheme(); |
110 | |||
111 | this.btnSearch.setIcon(theme.get("crs-crsselector-search")); |
||
112 | this.btnSearchRemove.setIcon(theme.get("crs-crsselector-search-remove")); |
||
113 | this.lblFilterAlpha.setIcon(theme.get("crs-crsselector-text-filter")); |
||
114 | this.lblFilterSpatial.setIcon(theme.get("crs-crsselector-spatial-filter")); |
||
115 | this.btnCrsAdd.setIcon(theme.get("crs-crsselector-crs-new")); |
||
116 | this.btnRecentCrsRemove.setIcon(theme.get("crs-crsselector-recent-remove")); |
||
117 | this.btnFavoritesAdd.setIcon(theme.get("crs-crsselector-favorite-add")); |
||
118 | this.btnFavoritesRemove.setIcon(theme.get("crs-crsselector-favorite-remove")); |
||
119 | this.btnFilterDropdown.setIcon(theme.get("crs-crsselector-dropdown")); |
||
120 | |||
121 | |||
122 | 859 | cmartinez | ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager(); |
123 | // hide spatial filter since it is currently not supported
|
||
124 | this.btnFilterDropdown.setVisible(false); |
||
125 | this.pnl_filterType.setVisible(false); |
||
126 | this.cboFilterSpatial.setVisible(false); |
||
127 | 866 | cmartinez | // hide recent remove since it is currently not supported
|
128 | this.btnRecentCrsRemove.setVisible(false); |
||
129 | 859 | cmartinez | |
130 | swingManager.translate(this.btnSearch);
|
||
131 | swingManager.translate(this.btnSearchRemove);
|
||
132 | swingManager.translate(this.btnCrsAdd);
|
||
133 | swingManager.translate(this.btnRecentCrsRemove);
|
||
134 | swingManager.translate(this.btnFavoritesAdd);
|
||
135 | swingManager.translate(this.btnFavoritesRemove);
|
||
136 | swingManager.translate(this.lblCurrentCrs);
|
||
137 | |||
138 | this.txtDescription.setEditable(false); |
||
139 | this.txtDescription.setText(""); |
||
140 | this.txtDescription.setLineWrap(true); |
||
141 | this.txtDescription.setWrapStyleWord(true); |
||
142 | this.txtCrsWkt.setEditable(false); |
||
143 | 866 | cmartinez | this.txtCrsWkt.setText(""); |
144 | |||
145 | 859 | cmartinez | /**
|
146 | * TODO Update strings in CrsPanel and change the name of some components
|
||
147 | *
|
||
148 | this.btnSearch.setToolTipText(manager.getTranslation("Search"));
|
||
149 | this.btnSearchRemove.setToolTipText(manager.getTranslation("Clear search"));
|
||
150 | this.btnFavoritesAdd.setToolTipText(manager.getTranslation("Add selected CRS to favorites"));
|
||
151 | this.btnFavoritesAdd1.setToolTipText(manager.getTranslation("Remove selected CRS from favorites"));
|
||
152 | this.btnCrsAdd.setToolTipText(manager.getTranslation("Create a new CRS"));
|
||
153 | this.btnFavoritesAdd2.setToolTipText(manager.getTranslation("Remove selected CRS from recents"));
|
||
154 | this.lbl_currentCrs.setText(manager.getTranslation("Current coordinate system:"));
|
||
155 | this.jtxt_description.setEditable(false);
|
||
156 | this.jtxt_description.setText("");
|
||
157 | this.jtxt_description.setLineWrap(true);
|
||
158 | this.jtxt_description.setWrapStyleWord(true);
|
||
159 | this.txtCrsWkt.setEditable(false);
|
||
160 | this.txtCrsWkt.setText("");
|
||
161 | */
|
||
162 | 866 | cmartinez | |
163 | |||
164 | |||
165 | 859 | cmartinez | } |
166 | 866 | cmartinez | |
167 | protected void initTreeListeners() { |
||
168 | this.btnFavoritesAdd.addActionListener(new ActionListener() { |
||
169 | @Override
|
||
170 | public void actionPerformed(ActionEvent e) { |
||
171 | CoordinateReferenceSystem selectedCrs = CrsSelectorController.this.getCoordinateReferenceSystem(); |
||
172 | if (selectedCrs != null) { |
||
173 | manager.getCoordinateReferenceSystemFavorites().add(selectedCrs.getDefinition()); |
||
174 | favorite.reloadChildren(); |
||
175 | } |
||
176 | } |
||
177 | }); |
||
178 | |||
179 | this.btnFavoritesRemove.addActionListener(new ActionListener() { |
||
180 | @Override
|
||
181 | public void actionPerformed(ActionEvent e) { |
||
182 | CoordinateReferenceSystem selectedCrs = CrsSelectorController.this.getCoordinateReferenceSystem(); |
||
183 | if (selectedCrs != null) { |
||
184 | manager.getCoordinateReferenceSystemFavorites().remove(selectedCrs.getDefinition()); |
||
185 | favorite.reloadChildren(); |
||
186 | } |
||
187 | } |
||
188 | }); |
||
189 | |||
190 | /*
|
||
191 | this.btnRecentCrsRemove.addActionListener(new ActionListener() {
|
||
192 | @Override
|
||
193 | public void actionPerformed(ActionEvent e) {
|
||
194 | CoordinateReferenceSystem selectedCrs = CrsSelectorController.this.getCoordinateReferenceSystem();
|
||
195 | if (selectedCrs != null) {
|
||
196 | manager.getCoordinateReferenceSystemHistory().remove(selectedCrs.getDefinition());
|
||
197 | }
|
||
198 | }
|
||
199 | });*/
|
||
200 | } |
||
201 | 859 | cmartinez | |
202 | protected void search() { |
||
203 | String filter = getAlphanumericFilter();
|
||
204 | if (filter != null && !filter.equals("")) { |
||
205 | manager.getCoordinateReferenceSystemTextFilterHistory().add(filter); |
||
206 | } |
||
207 | for (int i=0; i<root.getChildCount(); i++) { |
||
208 | TreeNode node = root.getChildAt(i);
|
||
209 | if (node instanceof BranchNode) { |
||
210 | ((BranchNode)node).reloadChildren(); |
||
211 | } |
||
212 | } |
||
213 | resetSearchCombo(filter); |
||
214 | model.reload(); |
||
215 | 866 | cmartinez | expandBranches(this.root);
|
216 | 859 | cmartinez | } |
217 | |||
218 | private void expandBranches(TreeNode root) { |
||
219 | for (int i=0; i<root.getChildCount(); i++) { |
||
220 | TreeNode node = root.getChildAt(i);
|
||
221 | if (node instanceof BranchNode) { |
||
222 | TreeNode[] path = this.model.getPathToRoot(node); |
||
223 | if (path != null) { |
||
224 | this.treeResults.expandPath(new TreePath(path)); |
||
225 | } |
||
226 | expandBranches(node); |
||
227 | } |
||
228 | } |
||
229 | } |
||
230 | |||
231 | protected void resetSearchCombo(String selectedItem) { |
||
232 | this.cboFilterAlpha.removeAllItems();
|
||
233 | if ("".equals(selectedItem)) { |
||
234 | this.cboFilterAlpha.insertItemAt(selectedItem, 0); |
||
235 | } |
||
236 | for (String filter: manager.getCoordinateReferenceSystemTextFilterHistory()) { |
||
237 | this.cboFilterAlpha.addItem(filter);
|
||
238 | } |
||
239 | this.cboFilterAlpha.setSelectedItem(selectedItem);
|
||
240 | } |
||
241 | |||
242 | protected void initSearchActions() { |
||
243 | this.cboFilterAlpha.getActionMap().put("enterPressed", new Action() { |
||
244 | |||
245 | @Override
|
||
246 | public void actionPerformed(ActionEvent e) { |
||
247 | search(); |
||
248 | } |
||
249 | |||
250 | @Override
|
||
251 | public void setEnabled(boolean b) { |
||
252 | // TODO Auto-generated method stub
|
||
253 | |||
254 | } |
||
255 | |||
256 | @Override
|
||
257 | public void removePropertyChangeListener(PropertyChangeListener listener) { |
||
258 | // TODO Auto-generated method stub
|
||
259 | |||
260 | } |
||
261 | |||
262 | @Override
|
||
263 | public void putValue(String key, Object value) { |
||
264 | // TODO Auto-generated method stub
|
||
265 | |||
266 | } |
||
267 | |||
268 | @Override
|
||
269 | public boolean isEnabled() { |
||
270 | return true; |
||
271 | } |
||
272 | |||
273 | @Override
|
||
274 | public Object getValue(String key) { |
||
275 | // TODO Auto-generated method stub
|
||
276 | return null; |
||
277 | } |
||
278 | |||
279 | @Override
|
||
280 | public void addPropertyChangeListener(PropertyChangeListener listener) { |
||
281 | // TODO Auto-generated method stub
|
||
282 | |||
283 | } |
||
284 | }); |
||
285 | |||
286 | this.btnSearch.addActionListener(new ActionListener() { |
||
287 | |||
288 | @Override
|
||
289 | public void actionPerformed(ActionEvent e) { |
||
290 | search(); |
||
291 | |||
292 | } |
||
293 | }); |
||
294 | |||
295 | this.btnSearchRemove.addActionListener(new ActionListener() { |
||
296 | |||
297 | @Override
|
||
298 | public void actionPerformed(ActionEvent e) { |
||
299 | resetSearchCombo("");
|
||
300 | search(); |
||
301 | } |
||
302 | }); |
||
303 | |||
304 | } |
||
305 | |||
306 | protected void reloadBranchNodes() { |
||
307 | |||
308 | } |
||
309 | |||
310 | protected void initIcons() { |
||
311 | 866 | cmartinez | RECENT_ICON = getIconTheme().get("crs-crsselector-recent");
|
312 | FAVOURITE_ICON = getIconTheme().get("crs-crsselector-favorite");
|
||
313 | CRS_ICON = getIconTheme().get("crs-crsselector-crs");
|
||
314 | FOLDER_OPEN_ICON = getIconTheme().get("crs-branchnode-tree-group-expanded");
|
||
315 | FOLDER_CLOSED_ICON = getIconTheme().get("crs-branchnode-tree-group-collapsed");
|
||
316 | 859 | cmartinez | } |
317 | |||
318 | protected void initTree() { |
||
319 | root = new BranchNode(null, this, "root"); |
||
320 | model = new DefaultTreeModel(root, false); |
||
321 | |||
322 | JTree tree = this.treeResults; |
||
323 | tree.getSelectionModel().setSelectionMode |
||
324 | (TreeSelectionModel.SINGLE_TREE_SELECTION);
|
||
325 | listenerSupport = ToolsSwingLocator.getToolsSwingManager().createActionListenerSupport(); |
||
326 | 866 | cmartinez | tree.addTreeSelectionListener(new TreeSelectionListener() { |
327 | @Override
|
||
328 | public void valueChanged(TreeSelectionEvent e) { |
||
329 | CrsSelectorController.this.treeSelectedValueChanged(e); |
||
330 | } |
||
331 | }); |
||
332 | 859 | cmartinez | tree.setCellRenderer(new CellRenderer());
|
333 | |||
334 | 866 | cmartinez | recent = new LoadedGroup(root, this, getI18nManager().getTranslation("Recent"), RECENT_ICON); |
335 | recent.setLoader(new RecentLoader(recent));
|
||
336 | 859 | cmartinez | recent.loadChildren(); |
337 | root.add(recent); |
||
338 | |||
339 | 866 | cmartinez | favorite = new LoadedGroup(root, this, getI18nManager().getTranslation("Favorites"), FAVOURITE_ICON); |
340 | favorite.setLoader(new FavoriteLoader(favorite));
|
||
341 | favorite.loadChildren(); |
||
342 | root.add(favorite); |
||
343 | |||
344 | BranchNode epsg = null;
|
||
345 | for (String authority: manager.getCatalogManager().getAuthorityNames()) { |
||
346 | BranchNode authorityNode = new BranchNode(root, this, getI18nManager().getTranslation(authority)); |
||
347 | if (authority.equals("EPSG")) { |
||
348 | epsg = authorityNode; |
||
349 | } |
||
350 | root.add(authorityNode); |
||
351 | CRSSearchFilter projectedCRSs = new CRSSearchFilter();
|
||
352 | projectedCRSs.setAuthority(authority); |
||
353 | projectedCRSs.setIncludedTypes(new CRSType[]{CRSType.ProjectedCRSType}); |
||
354 | authorityNode.add(new AuthorityLoadedGroup(authorityNode, projectedCRSs, getI18nManager().getTranslation("Projected"))); |
||
355 | |||
356 | CRSSearchFilter geographicCRSs = new CRSSearchFilter();
|
||
357 | geographicCRSs.setAuthority(authority); |
||
358 | geographicCRSs.setIncludedTypes(new CRSType[]{CRSType.GeographicCRSType}); |
||
359 | authorityNode.add(new AuthorityLoadedGroup(authorityNode, geographicCRSs, getI18nManager().getTranslation("Geographic"))); |
||
360 | 859 | cmartinez | |
361 | 866 | cmartinez | CRSSearchFilter otherCRSs = new CRSSearchFilter();
|
362 | otherCRSs.setAuthority(authority); |
||
363 | otherCRSs.setExcludedTypes(new CRSType[]{CRSType.ProjectedCRSType, CRSType.GeographicCRSType}); |
||
364 | authorityNode.add(new AuthorityLoadedGroup(authorityNode, otherCRSs, getI18nManager().getTranslation("Other"))); |
||
365 | } |
||
366 | |||
367 | initCustomBranch(); |
||
368 | |||
369 | 859 | cmartinez | tree.setModel(model); |
370 | 866 | cmartinez | if (epsg!=null) { |
371 | tree.expandPath(new TreePath(model.getPathToRoot(epsg))); |
||
372 | } |
||
373 | 859 | cmartinez | } |
374 | |||
375 | 866 | cmartinez | protected void initCustomBranch() { |
376 | if (customList.size()>0) { |
||
377 | if (customNode == null) { |
||
378 | customNode = new BranchNode(root, this, customLabel); |
||
379 | root.add(customNode); |
||
380 | } |
||
381 | customNode.clear(); |
||
382 | for (CRSDefinition def: customList) {
|
||
383 | CrsTreeNode node = new CrsTreeNode(def, customNode);
|
||
384 | customNode.add(node); |
||
385 | } |
||
386 | model.reload(); |
||
387 | } |
||
388 | } |
||
389 | |||
390 | protected void treeSelectedValueChanged(TreeSelectionEvent e) { |
||
391 | 859 | cmartinez | TreeNode selection = (TreeNode) this.treeResults.getLastSelectedPathComponent(); |
392 | if (selection==null) { |
||
393 | 874 | cmartinez | selectedCrs = null;
|
394 | String currentCrsLabel = getI18nManager().getTranslation("Selected_CRS_parametrized", new String[]{""}); |
||
395 | this.lblCurrentCrs.setText(currentCrsLabel);
|
||
396 | this.txtDescription.setText(""); |
||
397 | this.txtCrsWkt.setText(""); |
||
398 | |||
399 | 859 | cmartinez | } |
400 | 874 | cmartinez | else if (selection instanceof CrsTreeNode) { |
401 | 859 | cmartinez | CRSDefinition def = ((CrsTreeNode)selection).getCRS(); |
402 | try {
|
||
403 | selectedCrs = manager.getCRSManager().getCoordinateReferenceSystem(def); |
||
404 | 874 | cmartinez | String currentCrsLabel = getI18nManager().getTranslation("Selected_CRS_parametrized", new String[]{selectedCrs.getDefinition().toString()}); |
405 | this.lblCurrentCrs.setText(currentCrsLabel);
|
||
406 | 859 | cmartinez | this.txtDescription.setText(def.getDescription());
|
407 | 874 | cmartinez | this.txtDescription.setCaretPosition(0); |
408 | 859 | cmartinez | this.txtCrsWkt.setText(def.toWKT());
|
409 | 874 | cmartinez | this.txtCrsWkt.setCaretPosition(0); |
410 | 859 | cmartinez | listenerSupport.fireActionEvent(new ActionEvent(selection, ActionEvent.ACTION_FIRST, CRS_SELECTED_ACTION_COMMAND)); |
411 | } catch (UnsupportedCoordinateReferenceSystemException | ParseException e1) { |
||
412 | logger.debug("CRS not supported", e);
|
||
413 | } |
||
414 | } |
||
415 | } |
||
416 | |||
417 | @Override
|
||
418 | public JComponent asJComponent() { |
||
419 | return this; |
||
420 | } |
||
421 | |||
422 | @Override
|
||
423 | public CoordinateReferenceSystem getCoordinateReferenceSystem() {
|
||
424 | return selectedCrs;
|
||
425 | } |
||
426 | |||
427 | @Override
|
||
428 | public void setCoordinateReferenceSystem(CoordinateReferenceSystem crs) { |
||
429 | selectedCrs = crs; |
||
430 | 874 | cmartinez | if (crs != null) { |
431 | // add the provided node to recent nodes and select it
|
||
432 | CrsTreeNode node = new CrsTreeNode(crs.getDefinition(), recent);
|
||
433 | recent.add(node); |
||
434 | model.reload(recent); |
||
435 | this.treeResults.setSelectionPath(new TreePath(model.getPathToRoot(node))); |
||
436 | } |
||
437 | else {
|
||
438 | this.treeResults.clearSelection();
|
||
439 | } |
||
440 | 859 | cmartinez | } |
441 | |||
442 | @Override
|
||
443 | public void setCustomGroupLabel(String label) { |
||
444 | 866 | cmartinez | this.customLabel = label;
|
445 | 859 | cmartinez | } |
446 | |||
447 | @Override
|
||
448 | public void addCustomCRS(CRSDefinition customCRS) { |
||
449 | 866 | cmartinez | this.customList.add(customCRS);
|
450 | initCustomBranch(); |
||
451 | 859 | cmartinez | } |
452 | |||
453 | @Override
|
||
454 | public void addCRSSpatialFilter(String label, GeographicBoundingBox boundingBox) { |
||
455 | // TODO Auto-generated method stub
|
||
456 | } |
||
457 | |||
458 | @Override
|
||
459 | public void addCRSSelectionListener(ActionListener listener) { |
||
460 | 866 | cmartinez | listenerSupport.addActionListener(listener); |
461 | 859 | cmartinez | |
462 | } |
||
463 | |||
464 | @Override
|
||
465 | public void enableSpatialFilter(String label) { |
||
466 | // TODO Auto-generated method stub
|
||
467 | |||
468 | } |
||
469 | |||
470 | @Override
|
||
471 | public void enableAlphanumericFilter(String searchString) { |
||
472 | cboFilterAlpha.addItem(searchString); |
||
473 | cboFilterAlpha.setSelectedItem(searchString); |
||
474 | } |
||
475 | |||
476 | protected String getAlphanumericFilter() { |
||
477 | return (String) cboFilterAlpha.getSelectedItem(); |
||
478 | } |
||
479 | |||
480 | |||
481 | 866 | cmartinez | public class RecentLoader extends DirectGroupLoader { |
482 | public RecentLoader(LoadedGroup caller) {
|
||
483 | super(caller);
|
||
484 | 859 | cmartinez | } |
485 | 866 | cmartinez | |
486 | 859 | cmartinez | @Override
|
487 | 866 | cmartinez | public List<TreeNode> doExecute() { |
488 | 859 | cmartinez | String filter;
|
489 | if (CrsSelectorController.this.getAlphanumericFilter()!=null) { |
||
490 | filter = CrsSelectorController.this.getAlphanumericFilter().toLowerCase(); |
||
491 | } |
||
492 | else {
|
||
493 | filter = null;
|
||
494 | } |
||
495 | 866 | cmartinez | ArrayList<TreeNode> results = new ArrayList<TreeNode>(); |
496 | for (CRSDefinition crsDef: manager.getCoordinateReferenceSystemHistory()) {
|
||
497 | if (filter==null || crsDef.toString().toLowerCase().contains(filter)) { |
||
498 | results.add(new CrsTreeNode(crsDef, caller));
|
||
499 | 859 | cmartinez | } |
500 | } |
||
501 | 866 | cmartinez | return results;
|
502 | 859 | cmartinez | } |
503 | } |
||
504 | |||
505 | 866 | cmartinez | public class FavoriteLoader extends DirectGroupLoader { |
506 | |||
507 | public FavoriteLoader(LoadedGroup caller) {
|
||
508 | super(caller);
|
||
509 | } |
||
510 | |||
511 | @Override
|
||
512 | public List<TreeNode> doExecute() { |
||
513 | String filter;
|
||
514 | if (CrsSelectorController.this.getAlphanumericFilter()!=null) { |
||
515 | filter = CrsSelectorController.this.getAlphanumericFilter().toLowerCase(); |
||
516 | } |
||
517 | else {
|
||
518 | filter = null;
|
||
519 | } |
||
520 | ArrayList<TreeNode> results = new ArrayList<TreeNode>(); |
||
521 | for (CRSDefinition crsDef: manager.getCoordinateReferenceSystemFavorites()) {
|
||
522 | if (filter==null || crsDef.toString().toLowerCase().contains(filter)) { |
||
523 | results.add(new CrsTreeNode(crsDef, caller));
|
||
524 | } |
||
525 | } |
||
526 | return results;
|
||
527 | } |
||
528 | } |
||
529 | |||
530 | public class AuthorityLoadedGroup extends LoadedGroup { |
||
531 | 859 | cmartinez | protected final CRSSearchFilter filter; |
532 | 866 | cmartinez | public AuthorityLoadedGroup(TreeNode parent, CRSSearchFilter filter, String message, Icon icon) { |
533 | super(parent, CrsSelectorController.this, message, icon);
|
||
534 | this.filter = filter;
|
||
535 | } |
||
536 | |||
537 | 859 | cmartinez | public AuthorityLoadedGroup(TreeNode parent, CRSSearchFilter filter, String message) { |
538 | 866 | cmartinez | super(parent, CrsSelectorController.this, message, null); |
539 | 859 | cmartinez | this.filter = filter;
|
540 | } |
||
541 | |||
542 | 866 | cmartinez | protected GroupLoader getLoader() {
|
543 | 859 | cmartinez | this.filter.setTextFilter(CrsSelectorController.this.getAlphanumericFilter());
|
544 | // FIXME: set also spatial filter when supported by API and UI
|
||
545 | this.filter.setSpatialFilter(null); |
||
546 | return new CrsLoader(filter, this, CrsSelectorController.this.manager.getCatalogManager()); |
||
547 | } |
||
548 | } |
||
549 | |||
550 | public class CellRenderer extends DefaultTreeCellRenderer { |
||
551 | @Override
|
||
552 | public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, |
||
553 | boolean leaf, int row, boolean hasFocus) { |
||
554 | java.awt.Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
|
||
555 | if (value instanceof BranchNode) { |
||
556 | 866 | cmartinez | Icon icon = ((BranchNode)value).getIcon(expanded);
|
557 | if (icon!=null) { |
||
558 | this.setIcon(icon);
|
||
559 | } |
||
560 | else {
|
||
561 | if (expanded) {
|
||
562 | this.setIcon(FOLDER_OPEN_ICON);
|
||
563 | } |
||
564 | else {
|
||
565 | this.setIcon(FOLDER_CLOSED_ICON);
|
||
566 | } |
||
567 | } |
||
568 | 859 | cmartinez | } |
569 | else if (value instanceof CrsTreeNode) { |
||
570 | this.setIcon(CRS_ICON);
|
||
571 | } |
||
572 | else if (value instanceof LeafNode) { |
||
573 | 866 | cmartinez | Icon icon = ((LeafNode)value).getIcon();
|
574 | 859 | cmartinez | if (icon != null) { |
575 | this.setIcon(icon);
|
||
576 | } |
||
577 | } |
||
578 | return this; |
||
579 | } |
||
580 | } |
||
581 | |||
582 | public DefaultCoordinateReferenceSystemSwingManager getManager() {
|
||
583 | return manager;
|
||
584 | } |
||
585 | |||
586 | public DefaultTreeModel getModel() { |
||
587 | return this.model; |
||
588 | } |
||
589 | |||
590 | public LoadingNode createLoadingNode(BranchNode parent) {
|
||
591 | return new LoadingNode(parent, |
||
592 | this,
|
||
593 | getI18nManager().getTranslation("Loading..."));
|
||
594 | } |
||
595 | |||
596 | @Override
|
||
597 | public JTree getTree() { |
||
598 | return this.treeResults; |
||
599 | } |
||
600 | |||
601 | } |