01: /*
02: * uDig - User Friendly Desktop Internet GIS client
03: * http://udig.refractions.net
04: * (C) 2004, Refractions Research Inc.
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: */
17: package net.refractions.udig.project.ui.operations.example;
18:
19: import java.text.MessageFormat;
20: import java.util.ArrayList;
21: import java.util.List;
22:
23: import net.refractions.udig.project.internal.Layer;
24: import net.refractions.udig.project.ui.internal.Messages;
25: import net.refractions.udig.project.ui.summary.SummaryData;
26: import net.refractions.udig.project.ui.summary.SummaryDialog;
27: import net.refractions.udig.ui.operations.IOp;
28:
29: import org.eclipse.core.runtime.IProgressMonitor;
30: import org.eclipse.swt.widgets.Display;
31: import org.opengis.referencing.crs.CoordinateReferenceSystem;
32:
33: import com.vividsolutions.jts.geom.Envelope;
34:
35: /**
36: * Displays a summary of the layer in a dialog.
37: *
38: * @author jeichar
39: * @since 0.6.0
40: */
41: public class LayerSummary implements IOp {
42: /**
43: * @see net.refractions.udig.ui.operations.IOp#op(org.eclipse.swt.widgets.Display,
44: * java.lang.Object, org.eclipse.core.runtime.IProgressMonitor)
45: */
46: public void op(final Display display, Object target,
47: IProgressMonitor monitor) throws Exception {
48:
49: final Layer layer = (Layer) target;
50: final CoordinateReferenceSystem layerCRS = layer.getCRS();
51: final Envelope bounds = layer.getBounds(monitor, layerCRS);
52:
53: final List<SummaryData> data = new ArrayList<SummaryData>();
54:
55: data.add(new SummaryData(Messages.LayerSummary_name, layer
56: .getName()));
57: data.add(new SummaryData(Messages.LayerSummary_id, layer
58: .getID()));
59: data.add(new SummaryData(Messages.LayerSummary_zorder, layer
60: .getZorder()));
61: data.add(new SummaryData(Messages.LayerSummary_crs, layerCRS
62: .getName()));
63: data.add(new SummaryData(Messages.LayerSummary_bounds,
64: parseBounds(bounds)));
65: data.add(new SummaryData(Messages.LayerSummary_selection, layer
66: .getFilter()));
67:
68: display.asyncExec(new Runnable() {
69: public void run() {
70: SummaryDialog d = new SummaryDialog(display
71: .getActiveShell(), Messages.LayerSummary_title
72: + layer.getName(), data);
73:
74: d.setBlockOnOpen(true);
75: d.open();
76: }
77: });
78: }
79:
80: public static String parseBounds(Envelope env) {
81: String minx = chopDouble(env.getMinX());
82: String maxx = chopDouble(env.getMaxX());
83: String miny = chopDouble(env.getMinY());
84: String maxy = chopDouble(env.getMaxY());
85: return MessageFormat.format(Messages.LayerSummary_boundsFormat,
86: new Object[] { minx, miny, maxx, maxy });
87: }
88:
89: private static String chopDouble(double d) {
90: String s = String.valueOf(d);
91: int end = s.indexOf('.') + 2;
92: while (end > s.length())
93: end--;
94: return s.substring(0, end);
95: }
96: }
|