001: // ----------------------------------------------------------- ZoomToWMSPLugIn
002: /*
003: * With this PlugIn you can zoom on a OpenJUMP WMS-Layer to available BoundingBoxes receiving from
004: * the WMS-Server ( right-click on the WMS-Layer and then ZoomToWMS...). Also you can get all
005: * BoundingBox informations receiving from the WMS-Server.
006: *
007: * This PlugIn works together with extended code in com.vividsolutions.wms.MapLayer.class and
008: * com.vividsolutions.wms.Parser.class
009: *
010: * So you have to exchange these two files with my extended files!
011: *
012: * The extension for this PlugIn is WMSSupportExtension.class
013: *
014: * For more information please contact:
015: *
016: * University of Applied Sciences Department of Geomatics Dipl.-Ing. Uwe Dalluege Hebebrandstr. 1
017: * 22297 Hamburg Germany Tel.: +49 40 42875 - 5335 oder 5353 oder 5313 Fax: +49 40 42875 - 5409
018: * E-Mail: uwe.dalluege@rzcn.haw-hamburg.de Url: http://www.haw-hamburg.de/geomatik
019: *
020: * Last change: 29.11.2005
021: */
022: package org.openjump.core.ui.plugin.wms;
023:
024: import java.lang.reflect.*;
025: import java.util.List;
026: import javax.swing.*;
027: import javax.swing.table.*;
028: import java.util.*;
029: import java.awt.*;
030: import java.awt.event.*;
031:
032: import com.vividsolutions.jump.I18N;
033: import com.vividsolutions.jump.workbench.plugin.*;
034: import com.vividsolutions.jump.workbench.model.*;
035: import com.vividsolutions.wms.*;
036: import com.vividsolutions.jts.geom.*;
037: import com.vividsolutions.jump.workbench.ui.MenuNames;
038: import com.vividsolutions.jump.workbench.ui.plugin.*;
039: import com.vividsolutions.jump.util.*;
040:
041: public class ZoomToWMSPlugIn extends AbstractPlugIn {
042: PlugInContext context;
043:
044: Object[][] values = null;
045:
046: String[] columnNames = null;
047:
048: JTable infoTable = null;
049:
050: TableColumnModel tcm = null;
051:
052: JPanel jp = null;
053:
054: JScrollPane infoTableSc = null;
055:
056: public void initialize(PlugInContext context) throws Exception {
057: this .context = context;
058:
059: EnableCheckFactory enableCheckFactory = new EnableCheckFactory(
060: context.getWorkbenchContext());
061:
062: EnableCheck enableCheck = new MultiEnableCheck()
063: .add(
064: enableCheckFactory
065: .createWindowWithLayerManagerMustBeActiveCheck())
066: .add(
067: enableCheckFactory
068: .createExactlyNLayerablesMustBeSelectedCheck(
069: 1, WMSLayer.class));
070:
071: context
072: .getFeatureInstaller()
073: // .addMainMenuItemWithJava14Fix ( this, new String [ ] { "View" },
074: .addMainMenuItemWithJava14Fix(
075: this ,
076: new String[] { MenuNames.VIEW },
077: I18N
078: .get("org.openjump.core.ui.plugin.wms.ZoomToWMSPlugIn.zoom-to-wms-layer")
079: + "{pos:8}", false, null, enableCheck); //enableCheck );
080: // Add PlugIn to WMSPopupMenu
081: context
082: .getFeatureInstaller()
083: .addPopupMenuItem(
084: context.getWorkbenchFrame()
085: .getWMSLayerNamePopupMenu(),
086: this ,
087: I18N
088: .get("org.openjump.core.ui.plugin.wms.ZoomToWMSPlugIn.zoom-to-wms-layer"),
089: false, null, enableCheck);
090:
091: } // End initialize ( )
092:
093: public boolean execute(PlugInContext context) throws Exception {
094: this .context = context;
095: ArrayList mapLayerOfChoosenLayers = getMapLayerOfChoosenLayers(context);
096: String selectedSRS = getSelectedSRS(context);
097:
098: Hashtable boundingBoxesForSRS = getBoundingBoxesForSRS(
099: mapLayerOfChoosenLayers, selectedSRS);
100: zoomToBoundingBox(context, boundingBoxesForSRS, selectedSRS);
101:
102: return true;
103: } // End execute ( )
104:
105: public String getName() {
106: return "ZoomToWMS";
107: }
108:
109: WMSLayer[] getSelectedWMSLayer(PlugInContext context) {
110: Collection listWMS = context.getLayerNamePanel().selectedNodes(
111: WMSLayer.class);
112: Object[] obWMSLayer = listWMS.toArray();
113:
114: int anzSelectedWMSLayer = Array.getLength(obWMSLayer);
115:
116: if (anzSelectedWMSLayer <= 0)
117: return null;
118:
119: WMSLayer[] wmsLayer = new WMSLayer[anzSelectedWMSLayer];
120:
121: for (int i = 0; i < anzSelectedWMSLayer; i++) {
122: wmsLayer[i] = (WMSLayer) obWMSLayer[i];
123: }
124:
125: return wmsLayer;
126: } // End getSelectedWMSLayer ( )
127:
128: String[] getSelectedWMSLayerNames(PlugInContext context) {
129: WMSLayer[] wmsLayer = getSelectedWMSLayer(context);
130:
131: if (wmsLayer == null)
132: return null;
133:
134: int anzSelectedWMSLayer = Array.getLength(wmsLayer);
135:
136: String[] selectedWMSLayerNames = new String[anzSelectedWMSLayer];
137:
138: for (int i = 0; i < anzSelectedWMSLayer; i++) {
139: selectedWMSLayerNames[i] = wmsLayer[i].getName();
140: }
141: // ------------------------------ ZoomToWMSPLugIn getSelectedWMSLayerNames ( )
142: return selectedWMSLayerNames;
143: } // End getSelectedWMSLayerNames ( )
144:
145: ArrayList getMapLayerOfChoosenLayers(PlugInContext context)
146: throws Exception {
147: ArrayList mapLayerOfChoosenLayers = new ArrayList();
148: ArrayList wmsLayerNames = new ArrayList();
149:
150: // Choosen Layers
151: WMSLayer[] wmsLayer = getSelectedWMSLayer(context);
152:
153: if (wmsLayer == null) {
154: JOptionPane
155: .showMessageDialog(
156: context.getWorkbenchFrame(),
157: I18N
158: .get("org.openjump.core.ui.plugin.wms.ZoomToWMSPlugIn.no-wms-layer-selected"));
159: return null;
160: }
161:
162: for (int i = 0; i < Array.getLength(wmsLayer); i++) {
163: java.util.List wmsList = wmsLayer[i].getLayerNames();
164:
165: for (int k = 0; k < wmsList.size(); k++) {
166: String name = (String) wmsList.get(k);
167: wmsLayerNames.add(name);
168: }
169: }
170:
171: // Get all available MapLayer
172: WMService wmService = wmsLayer[0].getService();
173: Capabilities cap = wmService.getCapabilities();
174: MapLayer topLayer = cap.getTopLayer();
175: // ArrayList allLayer = topLayer.getLayerList ( );
176:
177: ArrayList allLayer = this .getAllMapLayer(context);
178:
179: for (int i = 0; i < allLayer.size(); i++) {
180: MapLayer mL = (MapLayer) allLayer.get(i);
181: }
182:
183: // Filter choosen Layer
184: for (int i = 0; i < wmsLayerNames.size(); i++) {
185: String name = (String) wmsLayerNames.get(i);
186:
187: for (int k = 0; k < allLayer.size(); k++) {
188: MapLayer mapLayer = (MapLayer) allLayer.get(k);
189: String mapLayerTitle = mapLayer.getTitle();
190: String mapLayerName = mapLayer.getName();
191:
192: if (mapLayerTitle != null && mapLayerName != null) {
193: if (mapLayerTitle.indexOf(name) >= 0
194: || mapLayerName.indexOf(name) >= 0)
195: mapLayerOfChoosenLayers.add(mapLayer);
196: } else if (mapLayerTitle != null) {
197: if (mapLayerTitle.indexOf(name) >= 0)
198: mapLayerOfChoosenLayers.add(mapLayer);
199: } else if (mapLayerName != null) {
200: if (mapLayerName.indexOf(name) >= 0)
201: mapLayerOfChoosenLayers.add(mapLayer);
202: }
203:
204: } // End for k ...
205: } // End for i ...
206: return mapLayerOfChoosenLayers;
207: } // End getMapLayerOfChoosenLayers ( )
208:
209: String getSelectedSRS(PlugInContext context) {
210: String selectedSRS = "0";
211: // Choosen Layers
212: WMSLayer[] wmsLayer = getSelectedWMSLayer(context);
213:
214: for (int i = 0; i < Array.getLength(wmsLayer); i++) {
215: // Choosen SRS
216: selectedSRS = (String) wmsLayer[i].getSRS();
217: selectedSRS = selectedSRS.toLowerCase();
218: /*
219: * if ( selectedSRS != null ) { // if ( selectedSRS.indexOf ( "4326" ) >= 0 )
220: * selectedSRS = "LatLon"; } else { // Problems, when loading a task // selectedSRS =
221: * "LatLon"; }
222: */
223: }
224:
225: return selectedSRS;
226: } // End getSelectedSRS ( )
227:
228: Hashtable getBoundingBoxesForSRS(ArrayList mapLayerList, String srs) {
229: Hashtable boundingBoxesForSRS = new Hashtable();
230:
231: for (int i = 0; i < mapLayerList.size(); i++) {
232: MapLayer mapLayer = (MapLayer) mapLayerList.get(i);
233:
234: // All BoundingBoxes
235: ArrayList boundingBoxList = mapLayer
236: .getAllBoundingBoxList();
237: // LatLon BoundingBox (epsg:4326)
238: BoundingBox latLonBoundingBox = mapLayer
239: .getLatLonBoundingBox();
240:
241: if (latLonBoundingBox != null)
242: boundingBoxList.add(latLonBoundingBox);
243:
244: int anzBB = boundingBoxList.size();
245:
246: if (anzBB == 0) {
247: System.out
248: .println(I18N
249: .get("org.openjump.core.ui.plugin.wms.ZoomToWMSPlugIn.no-bounding-box")
250: + mapLayer.getTitle());
251: continue;
252: } else {
253: // If double key - count up.
254: HashSet doppelt = new HashSet();
255: int zaehler = 0;
256:
257: for (int k = 0; k < anzBB; k++) {
258: BoundingBox tmpBB = (BoundingBox) boundingBoxList
259: .get(k);
260: String tmpSRS = tmpBB.getSRS().toLowerCase();
261: if (tmpSRS.indexOf("latlon") >= 0)
262: tmpSRS = "epsg:4326";
263:
264: if (tmpSRS.equals(srs.toLowerCase())) { // SRS found
265: String key = mapLayer.getTitle();
266: if (!doppelt.add(key)) {
267: zaehler++;
268: key = key + " (" + zaehler + ")";
269: }
270:
271: boundingBoxesForSRS.put(key, tmpBB);
272: }
273: }
274: }
275: }
276:
277: return boundingBoxesForSRS;
278: } // End getBoundingBoxesForSRS ( )
279:
280: JComboBox makeComboBox(Hashtable boundingBoxesForSRS) {
281: JComboBox comboBox = new JComboBox();
282: if (boundingBoxesForSRS.size() > 0) {
283: Object[] keys = boundingBoxesForSRS.keySet().toArray();
284: Arrays.sort(keys);
285: comboBox = new JComboBox(keys);
286: } else {
287: comboBox
288: .addItem(I18N
289: .get("org.openjump.core.ui.plugin.wms.ZoomToWMSPlugIn.no-bounding-boxes-available"));
290: }
291: // ------------------------------------------ ZoomToWMSPLugIn makeComboBox ( )
292: return comboBox;
293: } // End makeComboBox ( )
294:
295: void zoomToBoundingBox(PlugInContext context,
296: Hashtable boundingBoxesForSRS, String selectedSRS)
297: throws Exception {
298: JComboBox comboBox = makeComboBox(boundingBoxesForSRS);
299: JPanel jp = new JPanel();
300: JButton jb = new JButton("?");
301: jb.setActionCommand("showInfoTable");
302: jb.addActionListener(new AL());
303:
304: String tmpLatLon = "";
305: if (selectedSRS.indexOf("4326") >= 0)
306: tmpLatLon = " (LatLon)";
307:
308: jp.add(comboBox);
309: jp.add(jb);
310:
311: int back = JOptionPane
312: .showConfirmDialog(
313: context.getWorkbenchFrame(),
314: jp,
315: I18N
316: .get("org.openjump.core.ui.plugin.wms.ZoomToWMSPlugIn.bounding-box-for")
317: + " " + selectedSRS + tmpLatLon,
318: JOptionPane.OK_CANCEL_OPTION,
319: JOptionPane.INFORMATION_MESSAGE);
320:
321: if (back == JOptionPane.CANCEL_OPTION || back < 0)
322: return;
323:
324: // Get the BoundingBox from name
325: BoundingBox selectedBB = (BoundingBox) boundingBoxesForSRS
326: .get(comboBox.getSelectedItem());
327: if (selectedBB == null)
328: return;
329:
330: String tmpSRS = selectedBB.getSRS();
331: if (tmpSRS.toLowerCase().indexOf("latlon") >= 0)
332: tmpSRS = "EPSG:4326";
333: String message = tmpSRS + " ("
334: + Math.round(selectedBB.getMinX()) + ", "
335: + Math.round(selectedBB.getMinY()) + ") ("
336: + Math.round(selectedBB.getMaxX()) + ", "
337: + Math.round(selectedBB.getMaxY()) + ")";
338:
339: context.getWorkbenchFrame().setStatusMessage(message);
340:
341: // ------------------------------------- ZoomToWMSPLugIn zoomToBoundingBox ( )
342: Coordinate min = new Coordinate(selectedBB.getMinX(),
343: selectedBB.getMinY());
344: Coordinate max = new Coordinate(selectedBB.getMaxX(),
345: selectedBB.getMaxY());
346: Envelope env = new Envelope(min, max);
347:
348: context.getLayerViewPanel().getViewport().zoom(env);
349: context.getLayerViewPanel().fireSelectionChanged();
350:
351: JInternalFrame intFrame = context.getActiveInternalFrame();
352: intFrame.updateUI();
353:
354: } // End zoomToBoundingBox ( )
355:
356: ArrayList getAllMapLayer(PlugInContext context) throws Exception {
357: WMSLayer[] wmsLayer = getSelectedWMSLayer(context);
358:
359: if (wmsLayer == null || Array.getLength(wmsLayer) == 0)
360: return null;
361:
362: // Get all available MapLayer
363: WMService wmService = wmsLayer[0].getService();
364: Capabilities cap = wmService.getCapabilities();
365: MapLayer topLayer = cap.getTopLayer();
366: ArrayList allMapLayer = topLayer.getLayerList();
367: // ---------------------------------------- ZoomToWMSPLugIn getAllMapLayer ( )
368: return allMapLayer;
369: } // End getAllMapLayer ( )
370:
371: void showInformationTable(PlugInContext context) throws Exception {
372:
373: this .values = getMapLayerInformationForTable(context);
374: this .columnNames = MapLayerAttributes.getColumnNames();
375:
376: InfoTableModel itm = new InfoTableModel();
377:
378: this .infoTable = new JTable(itm);
379:
380: JTableHeader th = infoTable.getTableHeader();
381: th.setReorderingAllowed(false);
382: th.addMouseListener(new MASort());
383:
384: tcm = infoTable.getColumnModel();
385:
386: TableColumn tc0 = tcm.getColumn(0);
387: TableColumn tc1 = tcm.getColumn(1);
388: TableColumn tc2 = tcm.getColumn(2);
389:
390: TableColumn tc3 = tcm.getColumn(3);
391: TableColumn tc4 = tcm.getColumn(4);
392: TableColumn tc5 = tcm.getColumn(5);
393: TableColumn tc6 = tcm.getColumn(6);
394:
395: tc0.setMinWidth(160);
396: tc1.setMinWidth(120);
397: tc2.setMinWidth(70);
398:
399: tc3.setMinWidth(90);
400: tc4.setMinWidth(90);
401: tc5.setMinWidth(90);
402: tc6.setMinWidth(90);
403:
404: th.setResizingAllowed(true);
405: infoTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
406:
407: //infoTable.setPreferredSize ( new java.awt.Dimension ( 700, 300 ) );
408:
409: this .infoTableSc = new JScrollPane(infoTable);
410: infoTableSc.setPreferredSize(new java.awt.Dimension(735, 300));
411:
412: JOptionPane.showMessageDialog(context.getWorkbenchFrame(),
413: infoTableSc, "InfoTable",
414: JOptionPane.INFORMATION_MESSAGE);
415: // ---------------------------------- ZoomToWMSPLugIn showInformationTable ( )
416: } // End showInformationTable
417:
418: public void sortTable(int sortAfter) {
419: MapLayerAttributes[] mapLayerAttributes = toMapLayerAttributesArray(values);
420:
421: MapLayerAttributes.setSortAfter(sortAfter);
422:
423: Arrays.sort(mapLayerAttributes);
424:
425: getMapLayerInformationForTable(mapLayerAttributes);
426: infoTable.updateUI();
427: } // End sortTable ( )
428:
429: Object[][] getMapLayerInformationForTable(PlugInContext context)
430: throws Exception {
431: Object[][] mapLayerInformationForTable = null;
432:
433: MapLayerAttributes mapLayerAttr = new MapLayerAttributes();
434:
435: ArrayList mapLayerRows = new ArrayList();
436: ArrayList mapLayerList = getAllMapLayer(context);
437:
438: if (mapLayerList == null)
439: return null;
440:
441: int anzLayer = mapLayerList.size();
442:
443: if (anzLayer == 0)
444: return null;
445:
446: for (int i = 0; i < anzLayer; i++) {
447: MapLayer mapLayer = (MapLayer) mapLayerList.get(i);
448: mapLayerRows.addAll(mapLayerAttr.getMapLayerRows(mapLayer));
449: }
450:
451: int anzRows = mapLayerRows.size();
452: int anzColumns = Array.getLength(MapLayerAttributes
453: .getColumnNames());
454:
455: mapLayerInformationForTable = new Object[anzRows][anzColumns];
456:
457: for (int k = 0; k < anzRows; k++) {
458: MapLayerAttributes mLA = (MapLayerAttributes) mapLayerRows
459: .get(k);
460: Object[] attrib = mLA.toObjectArray();
461:
462: for (int m = 0; m < Array.getLength(attrib); m++) {
463: mapLayerInformationForTable[k][m] = attrib[m];
464: }
465: }
466: // ------------------------ ZoomToWMSPLugIn getMapLayerInformationForTable ( )
467: return mapLayerInformationForTable;
468: } // End getMapLayerInformationForTable ( a )
469:
470: String[][] getMapLayerInformationForTable(
471: MapLayerAttributes[] mapLayerAttributesArray) {
472:
473: int numRows = Array.getLength(mapLayerAttributesArray);
474: int numCols = Array.getLength(MapLayerAttributes
475: .getColumnNames());
476:
477: String[][] mapLayerInformationForTable = new String[numRows][numCols];
478:
479: for (int k = 0; k < numRows; k++) {
480: MapLayerAttributes mLA = mapLayerAttributesArray[k];
481: Object[] attrib = mLA.toObjectArray();
482:
483: for (int m = 0; m < Array.getLength(attrib); m++) {
484: // mapLayerInformationForTable [ k ] [ m ] = attrib [ m ];
485: values[k][m] = attrib[m];
486: }
487: }
488:
489: return mapLayerInformationForTable;
490: } // End getMapLayerInformationForTable ( b )
491:
492: MapLayerAttributes[] toMapLayerAttributesArray(Object[][] m) {
493: if (m == null)
494: return null;
495:
496: int numRows = m.length;
497: int numCol = m[0].length;
498:
499: MapLayerAttributes[] mapLayerAttributesArray = new MapLayerAttributes[numRows];
500:
501: for (int i = 0; i < numRows; i++) {
502: String title = (String) m[i][0];
503: String name = (String) m[i][1];
504: String srs = (String) m[i][2];
505: double minx = ((Double) m[i][3]).doubleValue();
506: double miny = ((Double) m[i][4]).doubleValue();
507: double maxx = ((Double) m[i][5]).doubleValue();
508: double maxy = ((Double) m[i][6]).doubleValue();
509:
510: mapLayerAttributesArray[i] = new MapLayerAttributes(title,
511: name, srs, minx, miny, maxx, maxy);
512: }
513: // ----------------------------- ZoomToWMSPLugIn toMapLayerAttributesArray ( )
514: return mapLayerAttributesArray;
515: } // End toMapLayerAttributesArray ( )
516:
517: // s, what does this action listener do? Can't it hava proper name?
518: public class AL implements ActionListener {
519: public void actionPerformed(ActionEvent ae) {
520: if (ae.getActionCommand().equals("showInfoTable")) {
521: try {
522: showInformationTable(context);
523: } catch (Exception e) {
524: System.out.println("Error in AL");
525: }
526: }
527: }
528:
529: } // End AL
530:
531: public static class MapLayerAttributes implements Comparable {
532:
533: public static final int SORT_UP = 1;
534:
535: public static final int SORT_DOWN = -1;
536:
537: public static final int SORT_AFTER_TITLE = 1;
538:
539: public static final int SORT_AFTER_NAME = 2;
540:
541: public static final int SORT_AFTER_SRS = 3;
542:
543: public static final int SORT_AFTER_MINX = 4;
544:
545: public static final int SORT_AFTER_MINY = 5;
546:
547: public static final int SORT_AFTER_MAXX = 6;
548:
549: public static final int SORT_AFTER_MAXY = 7;
550:
551: public static int[] sortUpDown = { SORT_DOWN, SORT_DOWN,
552: SORT_DOWN, SORT_DOWN, SORT_DOWN, SORT_DOWN, SORT_DOWN };
553:
554: public static int sortAfter;
555:
556: String srs, name, title;
557:
558: // String minx, miny, maxx, maxy;
559:
560: double minx, miny, maxx, maxy;
561:
562: MapLayerAttributes() {
563: this .srs = " ";
564: this .name = "Unknown";
565: this .title = "Unknown";
566:
567: this .minx = 0.;
568: this .miny = 0.;
569: this .maxx = 0.;
570: this .maxy = 0.;
571:
572: }
573:
574: MapLayerAttributes(String title, String name, String srs,
575: double minx, double miny, double maxx, double maxy) {
576: this .title = title;
577: this .name = name;
578: this .srs = srs;
579:
580: this .minx = minx;
581: this .miny = miny;
582: this .maxx = maxx;
583: this .maxy = maxy;
584:
585: }
586:
587: public int compareTo(Object object) { // Muss zum Sortieren überschrieben werden.
588: int ret = 1;
589: MapLayerAttributes mla = (MapLayerAttributes) object;
590:
591: if (sortAfter == SORT_AFTER_TITLE) {
592: ret = title.compareTo(mla.title) * sortUpDown[0];
593: }
594:
595: else if (sortAfter == SORT_AFTER_NAME) {
596: ret = name.compareTo(mla.name) * sortUpDown[1];
597: }
598:
599: else if (sortAfter == SORT_AFTER_SRS) {
600: ret = srs.compareTo(mla.srs) * sortUpDown[2];
601: }
602:
603: else if (sortAfter == SORT_AFTER_MINX) {
604: if (minx > mla.minx) {
605: ret = 1 * sortUpDown[3];
606: } else {
607: ret = -1 * sortUpDown[3];
608: }
609: }
610:
611: else if (sortAfter == SORT_AFTER_MINY) {
612: if (miny > mla.miny) {
613: ret = 1 * sortUpDown[4];
614: } else {
615: ret = -1 * sortUpDown[4];
616: }
617: }
618:
619: else if (sortAfter == SORT_AFTER_MAXX) {
620: if (maxx > mla.maxx) {
621: ret = 1 * sortUpDown[5];
622: } else {
623: ret = -1 * sortUpDown[5];
624: }
625: }
626:
627: else if (sortAfter == SORT_AFTER_MAXY) {
628: if (maxy > mla.maxy) {
629: ret = 1 * sortUpDown[6];
630: } else {
631: ret = -1 * sortUpDown[6];
632: }
633: }
634:
635: return ret;
636:
637: } // End compareTo ( )
638:
639: double cutDouble(double value, int afterComma) {
640: double mulQuot = Math.pow(10.d, afterComma);
641: long tmp = (long) (value * mulQuot);
642: return tmp / mulQuot;
643: }
644:
645: public static String[] getColumnNames() {
646: String[] columNames = { "Title", "Name", "SRS", "MinX",
647: "MinY", "MaxX", "MaxY" };
648: return columNames;
649: }
650:
651: ArrayList getMapLayerRows(MapLayer mapLayer) {
652: double minX, minY, maxX, maxY;
653:
654: String srs, name, title;
655: String unknown = "Unknown";
656:
657: ArrayList mapLayerRows = new ArrayList();
658:
659: name = mapLayer.getName();
660: if (name == null)
661: name = unknown;
662: title = mapLayer.getTitle();
663: if (title == null)
664: title = unknown;
665: /* I think this is not usefull [u.d., 05.11.29]
666: BoundingBox latLonBB = mapLayer.getLatLonBoundingBox();
667:
668: if ( latLonBB == null ) {
669: srs = unknown;
670: minX = 0.;
671: minY = 0.;
672: maxX = 400.;
673: maxY = 400.;
674: } else {
675: srs = "epsg:4326";
676: System.out.println ( "ZoomToWMS srs: " + srs + " latLonBBMinX: " + latLonBB.getMinX() );
677: minX = cutDouble( latLonBB.getMinX(), 1 );
678: minY = cutDouble( latLonBB.getMinY(), 1 );
679: maxX = cutDouble( latLonBB.getMaxX(), 1 );
680: maxY = cutDouble( latLonBB.getMaxY(), 1 );
681: }
682:
683: mapLayerRows.add( new MapLayerAttributes( title, name, srs, minX, minY, maxX, maxY ) );
684: */
685:
686: ArrayList boundingBoxList = mapLayer
687: .getAllBoundingBoxList();
688:
689: for (int i = 0; i < boundingBoxList.size(); i++) {
690: BoundingBox bb = (BoundingBox) boundingBoxList.get(i);
691:
692: if (bb == null) {
693: srs = unknown;
694: minX = 0.;
695: minY = 0.;
696: maxX = 400.;
697: maxY = 400.;
698: } else {
699: srs = bb.getSRS().toLowerCase();
700: /* not so good? [u.d., 05.11.29]
701: minX = cutDouble( bb.getMinX(), 2 );
702: minY = cutDouble( bb.getMinY(), 2 );
703: maxX = cutDouble( bb.getMaxX(), 2 );
704: maxY = cutDouble( bb.getMaxY(), 2 );
705: */
706: // better?
707: minX = bb.getMinX();
708: minY = bb.getMinY();
709: maxX = bb.getMaxX();
710: maxY = bb.getMaxY();
711: }
712:
713: mapLayerRows.add(new MapLayerAttributes(title, name,
714: srs, minX, minY, maxX, maxY));
715: } // End for bb
716:
717: return mapLayerRows;
718: } // End getMapLayerRows ( )
719:
720: String getName() {
721: return this .name;
722: }
723:
724: String getTitle() {
725: return this .title;
726: }
727:
728: String getSRS() {
729: return this .srs;
730: }
731:
732: double getMinx() {
733: return this .minx;
734: }
735:
736: double getMiny() {
737: return this .miny;
738: }
739:
740: double getMaxx() {
741: return this .maxx;
742: }
743:
744: double getMaxy() {
745: return this .maxy;
746: }
747:
748: Object[] toObjectArray() {
749: int anzColumns = Array.getLength(this .getColumnNames());
750: Object[] objectArray = new Object[anzColumns];
751:
752: objectArray[0] = this .getTitle();
753: objectArray[1] = this .getName();
754: objectArray[2] = this .getSRS();
755: objectArray[3] = Double.valueOf(String.valueOf(this
756: .getMinx()));
757: objectArray[4] = Double.valueOf(String.valueOf(this
758: .getMiny()));
759: objectArray[5] = Double.valueOf(String.valueOf(this
760: .getMaxx()));
761: objectArray[6] = Double.valueOf(String.valueOf(this
762: .getMaxy()));
763:
764: return objectArray;
765: } // End toObjectArray ( )
766:
767: public static void setSortAfter(int sortAfter) {
768: if (sortAfter == MapLayerAttributes.SORT_AFTER_TITLE) {
769: MapLayerAttributes.sortUpDown[0] = -1
770: * MapLayerAttributes.sortUpDown[0];
771: }
772: if (sortAfter == MapLayerAttributes.SORT_AFTER_NAME) {
773: MapLayerAttributes.sortUpDown[1] = -1
774: * MapLayerAttributes.sortUpDown[1];
775: }
776: if (sortAfter == MapLayerAttributes.SORT_AFTER_SRS) {
777: MapLayerAttributes.sortUpDown[2] = -1
778: * MapLayerAttributes.sortUpDown[2];
779: }
780: if (sortAfter == MapLayerAttributes.SORT_AFTER_MINX) {
781: MapLayerAttributes.sortUpDown[3] = -1
782: * MapLayerAttributes.sortUpDown[3];
783: }
784: if (sortAfter == MapLayerAttributes.SORT_AFTER_MINY) {
785: MapLayerAttributes.sortUpDown[4] = -1
786: * MapLayerAttributes.sortUpDown[4];
787: }
788: if (sortAfter == MapLayerAttributes.SORT_AFTER_MAXX) {
789: MapLayerAttributes.sortUpDown[5] = -1
790: * MapLayerAttributes.sortUpDown[5];
791: }
792: if (sortAfter == MapLayerAttributes.SORT_AFTER_MAXY) {
793: MapLayerAttributes.sortUpDown[6] = -1
794: * MapLayerAttributes.sortUpDown[6];
795: }
796:
797: MapLayerAttributes.sortAfter = sortAfter;
798: } // End setSortAfter ( )
799:
800: } // End MapLayerAttributes
801:
802: class InfoTableModel extends AbstractTableModel {
803:
804: public int getColumnCount() {
805: return columnNames.length;
806: }
807:
808: public int getRowCount() {
809: return values.length;
810: }
811:
812: public String getColumnName(int col) {
813: return columnNames[col];
814: }
815:
816: public Object getValueAt(int row, int col) {
817: return values[row][col];
818: }
819:
820: public Class getColumnClass(int c) {
821: return getValueAt(0, c).getClass();
822: }
823:
824: public boolean isCellEditable(int row, int col) {
825: return false;
826: }
827:
828: } // End InfoTableModel
829:
830: class MASort extends MouseAdapter { // Mausadapter für Spaltensortierung
831:
832: public void mousePressed(MouseEvent me) {
833: if (me.getButton() == MouseEvent.BUTTON3) {
834: int viewColumn = tcm.getColumnIndexAtX(me.getX());
835: int column = infoTable
836: .convertColumnIndexToModel(viewColumn);
837:
838: if (column == 0) {
839: sortTable(MapLayerAttributes.SORT_AFTER_TITLE);
840: } else if (column == 1) {
841: sortTable(MapLayerAttributes.SORT_AFTER_NAME);
842: }
843:
844: else if (column == 2) {
845: sortTable(MapLayerAttributes.SORT_AFTER_SRS);
846: }
847:
848: else if (column == 3) {
849: sortTable(MapLayerAttributes.SORT_AFTER_MINX);
850: }
851:
852: else if (column == 4) {
853: sortTable(MapLayerAttributes.SORT_AFTER_MINY);
854: }
855:
856: else if (column == 5) {
857: sortTable(MapLayerAttributes.SORT_AFTER_MAXX);
858: }
859:
860: else if (column == 6) {
861: sortTable(MapLayerAttributes.SORT_AFTER_MAXY);
862: }
863:
864: }
865:
866: }
867:
868: } // Ende MASpasKu
869:
870: } // End ZoomToWMSPLugIn
|