including changes from cdmlib-print
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / forms / PointElement.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.forms;
12
13 import java.text.ParseException;
14
15 import org.eclipse.jface.util.PropertyChangeEvent;
16
17 import eu.etaxonomy.cdm.model.location.Point;
18 import eu.etaxonomy.taxeditor.editor.EditorUtil;
19 import eu.etaxonomy.taxeditor.forms.CdmFormFactory.TermComboType;
20 import eu.etaxonomy.taxeditor.forms.term.ReferenceSystemComboElement;
21 import eu.etaxonomy.taxeditor.preference.Resources;
22
23 /**
24 * <p>PointElement class.</p>
25 *
26 * @author n.hoffmann
27 * @created Oct 15, 2010
28 * @version 1.0
29 */
30 public class PointElement extends AbstractCdmFormElement implements IEntityElement<Point>{
31
32 private Point point;
33
34 private ReferenceSystemComboElement combo_referenceSystem;
35 private TextWithLabelElement text_latitude;
36 private TextWithLabelElement text_longitude;
37 private NumberWithLabelElement number_errorRadius;
38
39 /**
40 * <p>Constructor for PointElement.</p>
41 *
42 * @param formFactory a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory} object.
43 * @param formElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
44 * @param point a {@link eu.etaxonomy.cdm.model.location.Point} object.
45 * @param style a int.
46 */
47 public PointElement(CdmFormFactory formFactory, ICdmFormElement formElement, Point point, final int style) {
48 super(formFactory, formElement);
49
50 formFactory.addPropertyChangeListener(this);
51
52 text_latitude = formFactory.createTextWithLabelElement(formElement, "Latitude (hexagesimal)", null, style);
53 text_longitude = formFactory.createTextWithLabelElement(formElement, "Longitude (hexagesimal)", null, style);
54 number_errorRadius = formFactory.createIntegerTextWithLabelElement(formElement, "Error Radius (m)", null, style);
55 combo_referenceSystem = (ReferenceSystemComboElement) formFactory.createTermComboElement(TermComboType.REFERENCE_SYSTEM, formElement, "Reference System", null, style);
56
57 setPoint(point);
58 }
59
60 /* (non-Javadoc)
61 * @see eu.etaxonomy.taxeditor.forms.ISelectable#setSelected(boolean)
62 */
63 /** {@inheritDoc} */
64 @Override
65 public void setSelected(boolean selected) {
66
67 }
68
69 /* (non-Javadoc)
70 * @see eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
71 */
72 /** {@inheritDoc} */
73 @Override
74 public void propertyChange(PropertyChangeEvent event) {
75 if(event == null){
76 return;
77 }
78
79 boolean propagate = false;
80
81 Object eventSource = event.getSource();
82 if(eventSource == text_latitude){
83 try {
84 getPoint().setLatitudeByParsing(text_latitude.getText());
85 text_latitude.setText(point.getLatitudeSexagesimal().toString(false));
86 text_latitude.setBackground(EditorUtil.getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
87 propagate = true;
88 } catch (ParseException e) {
89 text_latitude.setBackground(EditorUtil.getColor(Resources.COLOR_PARSE_ERROR));
90 }
91 }
92 else if(eventSource == text_longitude){
93 try {
94 getPoint().setLongitudeByParsing(text_longitude.getText());
95 text_longitude.setText(point.getLongitudeSexagesimal().toString(false));
96 text_longitude.setBackground(EditorUtil.getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
97 propagate = true;
98 } catch (ParseException e) {
99 text_latitude.setBackground(EditorUtil.getColor(Resources.COLOR_PARSE_ERROR));
100 }
101 }
102 else if(eventSource == number_errorRadius){
103 getPoint().setErrorRadius(number_errorRadius.getInteger());
104 propagate = true;
105 }
106 else if(eventSource == combo_referenceSystem){
107 getPoint().setReferenceSystem(combo_referenceSystem.getSelection());
108 propagate = true;
109 }
110
111 if(propagate){
112 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, event));
113 }
114 }
115
116 /* (non-Javadoc)
117 * @see eu.etaxonomy.taxeditor.forms.IEntityElement#getEntity()
118 */
119 /** {@inheritDoc} */
120 @Override
121 public Point getEntity() {
122 return getPoint();
123 }
124
125 /**
126 * <p>setEntity</p>
127 *
128 * @param point a {@link eu.etaxonomy.cdm.model.location.Point} object.
129 */
130 public void setEntity(Point point){
131 setPoint(point);
132 }
133
134 /**
135 * <p>Setter for the field <code>point</code>.</p>
136 *
137 * @param point the point to set
138 */
139 public void setPoint(Point point) {
140 this.point = point;
141 if(point != null){
142 text_latitude.setText(point.getLatitudeSexagesimal() == null ? "" : point.getLatitudeSexagesimal().toString(false));
143 text_longitude.setText(point.getLongitudeSexagesimal() == null ? "" : point.getLongitudeSexagesimal().toString(false));
144 number_errorRadius.setInteger(point.getErrorRadius());
145 combo_referenceSystem.setSelection(point.getReferenceSystem());
146 }
147 }
148
149 /**
150 * <p>Getter for the field <code>point</code>.</p>
151 *
152 * @return the point
153 */
154 public Point getPoint() {
155 if(point == null){
156 point = Point.NewInstance();
157 }
158
159 return point;
160 }
161
162 }