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.project.ui.internal.properties;
018:
019: import org.eclipse.ui.views.properties.IPropertyDescriptor;
020: import org.eclipse.ui.views.properties.IPropertySource2;
021: import org.eclipse.ui.views.properties.TextPropertyDescriptor;
022:
023: import com.vividsolutions.jts.geom.Coordinate;
024:
025: /**
026: * A Property source for coordinate objects
027: *
028: * @author jeichar
029: * @since 0.3
030: */
031: public class CoordinatePropertySource implements IPropertySource2 {
032: private Coordinate coord;
033: private Coordinate old;
034: private TextPropertyDescriptor[] descriptors;
035:
036: /**
037: * Creates a new instance of CoordinatePropertyDescriptor
038: *
039: * @param coordinate
040: */
041: public CoordinatePropertySource(Coordinate coordinate) {
042: this .coord = coordinate;
043: old = new Coordinate(coordinate);
044: }
045:
046: /**
047: * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
048: */
049: public Object getEditableValue() {
050: return null;
051: }
052:
053: /**
054: * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
055: */
056: public IPropertyDescriptor[] getPropertyDescriptors() {
057: if (descriptors == null) {
058: descriptors = new TextPropertyDescriptor[] {
059: new TextPropertyDescriptor("x", "x"), //$NON-NLS-1$ //$NON-NLS-2$
060: new TextPropertyDescriptor("y", "y"), //$NON-NLS-1$ //$NON-NLS-2$
061: new TextPropertyDescriptor("z", "z"), //$NON-NLS-1$ //$NON-NLS-2$
062: };
063: }
064:
065: IPropertyDescriptor[] c = new IPropertyDescriptor[descriptors.length];
066: System.arraycopy(descriptors, 0, c, 0, c.length);
067: return c;
068: }
069:
070: /**
071: * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
072: */
073: public Object getPropertyValue(Object id) {
074: if (id.equals("x")) //$NON-NLS-1$
075: return String.valueOf(coord.x);
076: if (id.equals("y")) //$NON-NLS-1$
077: return String.valueOf(coord.y);
078: if (id.equals("z")) //$NON-NLS-1$
079: return String.valueOf(coord.z);
080: return null;
081: }
082:
083: /**
084: * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)
085: */
086: public boolean isPropertySet(Object id) {
087: if (id.equals("x")) //$NON-NLS-1$
088: return old.x == coord.x;
089: if (id.equals("y")) //$NON-NLS-1$
090: return old.x == coord.y;
091: if (id.equals("z")) //$NON-NLS-1$
092: return old.x == coord.z;
093: return false;
094: }
095:
096: /**
097: * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
098: */
099: public void resetPropertyValue(Object id) {
100: if (id.equals("x")) //$NON-NLS-1$
101: coord.x = old.x;
102: else if (id.equals("y")) //$NON-NLS-1$
103: coord.y = old.y;
104: else if (id.equals("z")) //$NON-NLS-1$
105: coord.z = old.z;
106: }
107:
108: /**
109: * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object,
110: * java.lang.Object)
111: */
112: public void setPropertyValue(Object id, Object value) {
113: if (id.equals("x")) //$NON-NLS-1$
114: coord.x = new Double((String) value).doubleValue();
115: else if (id.equals("y")) //$NON-NLS-1$
116: coord.y = new Double((String) value).doubleValue();
117: else if (id.equals("z")) //$NON-NLS-1$
118: coord.z = new Double((String) value).doubleValue();
119:
120: }
121:
122: /**
123: * @see org.eclipse.ui.views.properties.IPropertySource2#isPropertyResettable(java.lang.Object)
124: */
125: public boolean isPropertyResettable(Object id) {
126: // TODO
127: return true;
128: }
129: }
|