View Javadoc
1   package fr.ifremer.tutti.ui.swing.util.computable;
2   
3   /*
4    * #%L
5    * Tutti :: UI
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2012 - 2017 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU General Public License as
13   * published by the Free Software Foundation, either version 3 of the
14   * License, or (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU General Public
22   * License along with this program.  If not, see
23   * <http://www.gnu.org/licenses/gpl-3.0.html>.
24   * #L%
25   */
26  
27  import fr.ifremer.tutti.type.WeightUnit;
28  import java.awt.Color;
29  import java.awt.LayoutManager;
30  import jaxx.runtime.JAXXContext;
31  import jaxx.runtime.JAXXObjectDescriptor;
32  import jaxx.runtime.JAXXUtil;
33  import org.apache.commons.logging.Log;
34  import org.apache.commons.logging.LogFactory;
35  import org.nuiton.jaxx.widgets.number.NumberEditor;
36  
37  public class ComputableDataEditor<E extends Number> extends NumberEditor {
38  
39      /*-----------------------------------------------------------------------*/
40      /*---------------- Constants for all javaBean properties ----------------*/
41      /*-----------------------------------------------------------------------*/
42  
43      public static final String PROPERTY_COMPUTED_DATA_COLOR = "computedDataColor";
44      public static final String PROPERTY_WEIGHT_UNIT = "weightUnit";
45  
46      /*-----------------------------------------------------------------------*/
47      /*------------------------- Other static fields -------------------------*/
48      /*-----------------------------------------------------------------------*/
49  
50      private static final String $jaxxObjectDescriptor = "H4sIAAAAAAAAAI1SPW8TQRAdX7CDYwKEiCQoQSRAAc06DZUlCHKIAJmAiFAiXMDat7E3Wt8tu3P4IgTiJ/AToKdBoqNCFNQUNIi/gBAFLWJuz/E55BBcsTrNx5s3b97rb1C0BpZ2eBwzEwUoe4LdvLq1dbu1I9q4KmzbSI2hgfQreOA1oeIP4xbhXLORtFcH7dV62NNhIIKR7loDJizuKmG7QiDC6f0dbWurG8N0LdaR2UMdkspDffnju/fCf/7KA4g1sRujVRb/1ZVtcqgBnvQRTtCkx7yqeNAhGkYGHeI7mcTqilu7znviETyD8QaUNDcEhnD2/1d2GK4/1ghHz69HvZYw13xJRcsIl7cNk9tG9IRhGCFKFklm+0SCRSgVaxN0hLyl0mXS31WOPEXQ2mGXEKbSSuEnyXqoQkPTkiUY7yNzgax4oi9kp4v3AknLLB6ggLtasM1hCfUZmN8nLJ2MZSfLNC00oWgiCiPMNQ9e+S6l0vvO/XHfBNBlf81Mf3739e3a3lE9mn0yt3TEkyS2NqEWBmUy+lh60UTA6i2ua00oW6HI0M6wCznENgZpIkfzppxuTv/r3HYJojj+5f2HmYefxsBbgwkVcn+NJ/U3oIxdQyqEyo/1lRXH6Ej/ML3HE250gwfc9zdH5J590gt9oVhHYBa+cPFpTKos5KgypNYqf/w5vfFmZU+ZAjE99dfyTJ3ifSjJQMlAOMMPvJxr8Iq2IvLDzLN5LgatycmTireE2pTYTfi73Kx75/NUKHXdqgjepeU4SsrOuA2Sv6UUsNIi74XBHR4I9RtBg92XmAQAAA==";
51      private static final Log log = LogFactory.getLog(ComputableDataEditor.class);
52      private static final long serialVersionUID = 1L;
53  
54      /*-----------------------------------------------------------------------*/
55      /*--------------------------- Internal states ---------------------------*/
56      /*-----------------------------------------------------------------------*/
57  
58      private boolean allComponentsCreated;
59  
60      /*-----------------------------------------------------------------------*/
61      /*------------------------ Protected components  ------------------------*/
62      /*-----------------------------------------------------------------------*/
63  
64      protected Color computedDataColor;
65      protected WeightUnit weightUnit;
66  
67      /*-----------------------------------------------------------------------*/
68      /*------------------------- Private components  -------------------------*/
69      /*-----------------------------------------------------------------------*/
70  
71      private ComputableDataEditor<E> $NumberEditor0 = this;
72  
73      /*-----------------------------------------------------------------------*/
74      /*---------------------- Raw body code from script ----------------------*/
75      /*-----------------------------------------------------------------------*/
76  
77      public void setBean(ComputableData<E> bean) {
78              super.setBean(bean);
79          }
80      
81          public void init() { super.setProperty(ComputableData.PROPERTY_DATA); super.init(); }
82      
83          public void setProperty(String property) {
84              // cannot change the property
85          }
86  
87      /*-----------------------------------------------------------------------*/
88      /*---------------------------- Constructors  ----------------------------*/
89      /*-----------------------------------------------------------------------*/
90  
91      public ComputableDataEditor(LayoutManager param0) {
92          super(param0);
93          $initialize();
94      }
95  
96      public ComputableDataEditor(JAXXContext param0, LayoutManager param1, boolean param2) {
97          super(param0 ,param1 ,param2);
98          $initialize();
99      }
100 
101     public ComputableDataEditor(LayoutManager param0, boolean param1) {
102         super(param0 ,param1);
103         $initialize();
104     }
105 
106     public ComputableDataEditor(JAXXContext param0) {
107         super(param0);
108         $initialize();
109     }
110 
111     public ComputableDataEditor(boolean param0) {
112         super(param0);
113         $initialize();
114     }
115 
116     public ComputableDataEditor(JAXXContext param0, boolean param1) {
117         super(param0 ,param1);
118         $initialize();
119     }
120 
121     public ComputableDataEditor() {
122         $initialize();
123     }
124 
125     public ComputableDataEditor(JAXXContext param0, LayoutManager param1) {
126         super(param0 ,param1);
127         $initialize();
128     }
129 
130     /*-----------------------------------------------------------------------*/
131     /*--------------------------- Statics methods ---------------------------*/
132     /*-----------------------------------------------------------------------*/
133 
134     public static JAXXObjectDescriptor $getJAXXObjectDescriptor() {
135         return JAXXUtil.decodeCompressedJAXXObjectDescriptor($jaxxObjectDescriptor);
136     }
137 
138     /*-----------------------------------------------------------------------*/
139     /*----------------------- Public acessor methods  -----------------------*/
140     /*-----------------------------------------------------------------------*/
141 
142     public Color getComputedDataColor() {
143         return computedDataColor;
144     }
145 
146     @Override
147     public ComputableDataEditorHandler getHandler() {
148         return (fr.ifremer.tutti.ui.swing.util.computable.ComputableDataEditorHandler)super.getHandler();
149     }
150 
151     public WeightUnit getWeightUnit() {
152         return weightUnit;
153     }
154 
155     /*-----------------------------------------------------------------------*/
156     /*----------------------- Public mutator methods  -----------------------*/
157     /*-----------------------------------------------------------------------*/
158 
159     public void setComputedDataColor(Color computedDataColor) {
160         Color oldValue = this.computedDataColor;
161         this.computedDataColor = computedDataColor;
162         firePropertyChange(PROPERTY_COMPUTED_DATA_COLOR, oldValue, computedDataColor);
163     }
164 
165     public void setWeightUnit(WeightUnit weightUnit) {
166         WeightUnit oldValue = this.weightUnit;
167         this.weightUnit = weightUnit;
168         firePropertyChange(PROPERTY_WEIGHT_UNIT, oldValue, weightUnit);
169     }
170 
171     /*-----------------------------------------------------------------------*/
172     /*--------------------- Components creation methods ---------------------*/
173     /*-----------------------------------------------------------------------*/
174 
175     protected void createComputedDataColor() {
176         $objectMap.put("computedDataColor", computedDataColor = null);
177     }
178 
179     @Override
180     protected ComputableDataEditorHandler createHandler() {
181         return new ComputableDataEditorHandler();
182     }
183 
184     protected void createWeightUnit() {
185         $objectMap.put("weightUnit", weightUnit = null);
186     }
187 
188     /*-----------------------------------------------------------------------*/
189     /*------------------------ Internal jaxx methods ------------------------*/
190     /*-----------------------------------------------------------------------*/
191 
192     private void $completeSetup() {
193         allComponentsCreated = true;
194         if (log.isDebugEnabled()) {
195             log.debug(this);
196         }
197     }
198 
199     private void $initialize() {
200         if (allComponentsCreated) {
201             return;
202         }
203         if (log.isDebugEnabled()) {
204             log.debug(this);
205         }
206         handler.beforeInit(this);
207         $objectMap.put("$NumberEditor0", $NumberEditor0);
208         createComputedDataColor();
209         createWeightUnit();
210         // inline creation of $NumberEditor0
211         setName("$NumberEditor0");
212         
213         $completeSetup();
214         handler.afterInit(this);
215     }
216 
217 }