001: /*
002: * uDig - User Friendly Desktop Internet GIS client
003: * http://udig.refractions.net
004: * (C) 2004, Refractions Research Inc.
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package net.refractions.udig.tool.info.internal.display;
018:
019: import java.io.IOException;
020:
021: import net.refractions.udig.tool.info.InfoDisplay;
022: import net.refractions.udig.tool.info.LayerPointInfo;
023:
024: import org.eclipse.swt.SWT;
025: import org.eclipse.swt.widgets.Composite;
026: import org.eclipse.swt.widgets.Control;
027: import org.eclipse.swt.widgets.Text;
028: import org.geotools.feature.AttributeType;
029: import org.geotools.feature.Feature;
030: import org.geotools.feature.FeatureType;
031: import org.geotools.feature.GeometryAttributeType;
032:
033: import com.vividsolutions.jts.geom.Geometry;
034:
035: /**
036: * Nested browser used to display LayerPointInfo.
037: *
038: * @author Jody Garnett
039: * @since 0.3
040: */
041: public class FeatureDisplay extends InfoDisplay {
042:
043: /** <code>text</code> field */
044: protected Text text;
045:
046: //private Text location;
047: //private ViewForm viewForm;
048:
049: /**
050: * Nested viewForm containing text, and locationbar
051: * @return Control maintained by this display
052: */
053: public Control getControl() {
054: return text; //viewForm;
055: }
056:
057: public void createDisplay(Composite parent) {
058: /*
059: viewForm= new ViewForm( parent, SWT.NONE);
060: GridLayout gridLayout = new GridLayout();
061: gridLayout.numColumns = 2;
062: viewForm.setLayout(gridLayout);
063:
064: Label labelAddress = new Label(viewForm, SWT.NONE);
065: labelAddress.setText("A&ddress");
066:
067: location = new Text(viewForm, SWT.BORDER);
068: GridData data = new GridData();
069: data = new GridData();
070: data.horizontalAlignment = GridData.FILL;
071: data.grabExcessHorizontalSpace = true;
072: location.setLayoutData(data);
073: */
074: text = new Text(parent, SWT.V_SCROLL | SWT.READ_ONLY | SWT.WRAP
075: | SWT.BORDER);
076: /*
077: data = new GridData();
078: data.horizontalAlignment = GridData.FILL;
079: data.verticalAlignment = GridData.FILL;
080: data.horizontalSpan = 2;
081: data.grabExcessHorizontalSpace = true;
082: data.grabExcessVerticalSpace = true;
083: text.setLayoutData(data);
084: */
085: }
086:
087: public void setInfo(Feature feature) {
088: text.setToolTipText(null);
089: if (feature == null) {
090: text.setText(""); //$NON-NLS-1$
091: return;
092: }
093: FeatureType type = feature.getFeatureType();
094:
095: StringBuffer buf = new StringBuffer();
096: buf.append(feature.getID());
097: buf.append(": ("); //$NON-NLS-1$
098: buf.append(type.getNamespace());
099: buf.append(":"); //$NON-NLS-1$
100: buf.append(type.getTypeName());
101:
102: for (int i = 0; i < feature.getNumberOfAttributes(); i++) {
103: AttributeType attribute = type.getAttributeType(i);
104: Object value = feature.getAttribute(i);
105: buf.append("\n"); //$NON-NLS-1$
106: buf.append(attribute.getName());
107: buf.append(" = "); //$NON-NLS-1$
108: if (attribute instanceof GeometryAttributeType) {
109: buf.append(((Geometry) value).getGeometryType());
110: } else {
111: buf.append(value);
112: }
113: }
114: text.setText(buf.toString());
115: }
116:
117: public void setInfo(LayerPointInfo info) {
118: if (info == null) {
119: text.setText(""); //$NON-NLS-1$
120: } else {
121: Feature feature;
122: try {
123: feature = (Feature) info.acquireValue();
124: setInfo(feature);
125: } catch (IOException noValue) {
126: text.setText(noValue.getLocalizedMessage());
127: }
128: if (info.getRequestURL() != null) {
129: String req = info.getRequestURL().toString();
130: text.setToolTipText(req);
131: } else {
132: //location.setText( info.getMimeType() +":" );
133: text.setToolTipText(info.getMimeType());
134: }
135: }
136: }
137:
138: }
|