jrubyfx-fxmlloader-master 0.4.master.2015.9.30-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,257 @@
1
+ require_relative './elts'
2
+
3
+ class StupidFixTODOInsets < Java::javafx::geometry::InsetsBuilder
4
+ def initialize()
5
+ super
6
+ end
7
+ add_method_signature :getLeft, [Java::double]
8
+ def getLeft()
9
+
10
+ end
11
+
12
+ add_method_signature :setLeft, [Java::java.lang.Void, Java::double]
13
+ def setLeft(value)
14
+ left(value)
15
+ end
16
+
17
+ add_method_signature :getRight, [Java::double]
18
+ def getRight()
19
+
20
+ end
21
+
22
+ add_method_signature :setRight, [Java::java.lang.Void, Java::double]
23
+ def setRight(value)
24
+ right(value)
25
+ end
26
+ add_method_signature :getBottom, [Java::double]
27
+ def getBottom()
28
+
29
+ end
30
+
31
+ add_method_signature :setBottom, [Java::java.lang.Void, Java::double]
32
+ def setBottom(value)
33
+ bottom(value)
34
+ end
35
+ add_method_signature :getTop, [Java::double]
36
+ def getTop()
37
+
38
+ end
39
+
40
+ add_method_signature :setTop, [Java::java.lang.Void, Java::double]
41
+ def setTop(value)
42
+ top(value)
43
+ end
44
+
45
+ def size
46
+ 990
47
+ end
48
+ def to_s
49
+ "the thingabmabomb"
50
+ end
51
+ def inspect
52
+ "whozamawhatzit"
53
+ end
54
+ end
55
+
56
+ class ValueElement < Element
57
+ attr_accessor :fx_id
58
+ @fx_id = nil;
59
+ def processStartElement
60
+ super
61
+
62
+ updateValue(constructValue());
63
+
64
+ if (value.is_a? Builder)
65
+ processInstancePropertyAttributes();
66
+ else
67
+ processValue();
68
+ end
69
+ end
70
+
71
+ def processEndElement()
72
+ super
73
+
74
+ # Build the value, if necessary
75
+ if (value.is_a? Builder)
76
+ updateValue(value.build());
77
+ processValue();
78
+ else
79
+ processInstancePropertyAttributes();
80
+ end
81
+ processEventHandlerAttributes();
82
+ # Process static property attributes
83
+ if (staticPropertyAttributes.length > 0)
84
+ for attribute in staticPropertyAttributes
85
+ processPropertyAttribute(attribute);
86
+ end
87
+ end
88
+ # Process static property elements
89
+ if (staticPropertyElements.length > 0)
90
+ for element in staticPropertyElements
91
+ RubyWrapperBeanAdapter.put(value, element.sourceType, element.name, element.value);
92
+ end
93
+ end
94
+
95
+ rnest -1
96
+ rputs value, ((rfx_id(value) && rfx_id_set?(value)) || rno_show?(value) ? "" : "end")
97
+ if (parent != nil)
98
+ if (parent.isCollection())
99
+ parent.add(value);
100
+ else
101
+ parent.set value
102
+ end
103
+ end
104
+ end
105
+
106
+ def getListValue( parent, listPropertyName, value)
107
+ # If possible, coerce the value to the list item type
108
+ if (parent.isTyped())
109
+ listType = parent.getValueAdapter().getGenericType(listPropertyName);
110
+
111
+ if (listType != nil)
112
+ itemType = RubyWrapperBeanAdapter.getGenericListItemType(listType);
113
+
114
+ if (itemType.is_a? ParameterizedType)
115
+ itemType = (itemType).getRawType();
116
+ end
117
+
118
+ value = RubyWrapperBeanAdapter.coerce(value,itemType);
119
+ end
120
+ end
121
+
122
+ return value;
123
+ end
124
+
125
+ def processValue()
126
+ # If this is the root element, update the value
127
+ if (parent == nil)
128
+ root = value;
129
+
130
+ # checking version of fx namespace - throw exception if not supported
131
+ fxNSURI = xmlStreamReader.getNamespaceContext().getNamespaceURI("fx");
132
+ if (fxNSURI != nil)
133
+ fxVersion = fxNSURI[(fxNSURI.rindex("/") + 1)..-1];
134
+ if (parentLoader.compareJFXVersions(FxmlLoader::FX_NAMESPACE_VERSION, fxVersion) < 0)
135
+ raise LoadException.new("Loading FXML document of version " + fxVersion + " by JavaFX runtime supporting version " + FxmlLoader::FX_NAMESPACE_VERSION);
136
+ end
137
+ end
138
+
139
+ # checking the version JavaFX API - print warning if not supported
140
+ defaultNSURI = xmlStreamReader.getNamespaceContext().getNamespaceURI("");
141
+ if (defaultNSURI != nil)
142
+ nsVersion = defaultNSURI[(defaultNSURI.rindex("/") + 1)..-1]
143
+ jfx_version = if defined? FXL::JAVAFX_VERSION
144
+ FXL::JAVAFX_VERSION
145
+ else
146
+ "http://javafx.com/javafx/2.2"
147
+ end
148
+ if (parentLoader.compareJFXVersions(jfx_version, nsVersion) < 0)
149
+ Logging.getJavaFXLogger().warning("Loading FXML document with JavaFX API of version " + nsVersion + " by JavaFX runtime of version " + FXL::JAVAFX_VERSION);
150
+ end
151
+ end
152
+ end
153
+
154
+ # Add the value to the namespace
155
+ if (@fx_id != nil)
156
+ parentLoader.namespace[@fx_id] = value
157
+
158
+ # If the value defines an ID property, set it
159
+ idProperty = value.java_class.annotation(IDProperty.java_class);
160
+
161
+ if (idProperty != nil)
162
+ properties = getProperties();
163
+ # set fx:id property value to Node.id only if Node.id was not
164
+ # already set when processing start element attributes
165
+ if (properties[idProperty.value] == nil)
166
+ properties[idProperty.value()]= @fx_id;
167
+ end
168
+ end
169
+ rputs value, "__local_fx_id_setter.call(#{@fx_id.inspect}, self)"
170
+ rfx_id value, @fx_id
171
+ # Set the controller field value
172
+ if (parentLoader.controller != nil)
173
+ field = parentLoader.controller.instance_variable_set("@" + @fx_id, value)
174
+ end
175
+ end
176
+ end
177
+
178
+ def processCharacters()
179
+ type = value.java_class
180
+ defaultProperty = type.getAnnotation(DefaultProperty.java_class);
181
+
182
+ # If the default property is a read-only list, add the value to it;
183
+ # otherwise, set the value as the default property
184
+ if (defaultProperty != nil)
185
+ text = xmlStreamReader.getText();
186
+ #TODO: FIX
187
+ text = extraneousWhitespacePattern.matcher(text).replaceAll(" ");
188
+
189
+ defaultPropertyName = defaultProperty.value();
190
+ valueAdapter = getValueAdapter();
191
+
192
+ if (valueAdapter.read_only?(defaultPropertyName) && List.class.isAssignableFrom(valueAdapter.getType(defaultPropertyName)))
193
+ list = valueAdapter.get(defaultPropertyName);
194
+ list.add(getListValue(self, defaultPropertyName, text));
195
+ else
196
+ valueAdapter.put(defaultPropertyName, text.strip);
197
+ end
198
+ else
199
+ throw LoadException.new(type.getName() + " does not have a default property.");
200
+ end
201
+ end
202
+
203
+ def processAttribute( prefix, localName, value)
204
+ if (prefix != nil && prefix == (FXL::FX_NAMESPACE_PREFIX))
205
+ if (localName == (FXL::FX_ID_ATTRIBUTE))
206
+ # Verify that ID is a valid identifier
207
+ if (value == (FXL::NULL_KEYWORD))
208
+ raise LoadException.new("Invalid identifier.");
209
+ end
210
+ #
211
+ # value.length.times do |i|
212
+ # # TODO: FIX
213
+ # if (!Java.java.lang.Character.java_send :isJavaIdentifierPart, [Java::char], value[i].to_java(:char))
214
+ # raise LoadException.new("Invalid identifier.");
215
+ # end
216
+ # end
217
+ @fx_id = value;
218
+
219
+ elsif (localName == (FXL::FX_CONTROLLER_ATTRIBUTE))
220
+ if (parentLoader.current.parent != nil)
221
+ raise LoadException.new(FXL::FX_NAMESPACE_PREFIX + ":" + FXL::FX_CONTROLLER_ATTRIBUTE + " can only be applied to root element.");
222
+ end
223
+
224
+ if (parentLoader.controller != nil)
225
+ raise LoadException.new("Controller value already specified.");
226
+ end
227
+
228
+ if (!staticLoad)
229
+ type = nil
230
+ begin
231
+ type = value.constantize_by
232
+ rescue ClassNotFoundException => exception
233
+ raise LoadException.new(exception);
234
+ end
235
+
236
+ begin
237
+ if (parentLoader.controllerFactory == nil)
238
+ # TODO: does this work?
239
+ parentLoader.controller = type.new
240
+ else
241
+ parentLoder.controller = (parentLoader.controllerFactory.call(type));
242
+ end
243
+ rescue InstantiationException => exception
244
+ raise LoadException.new(exception);
245
+ rescue IllegalAccessException => exception
246
+ raise LoadException.new(exception);
247
+ end
248
+ end
249
+ else
250
+ raise LoadException.new("Invalid attribute.");
251
+ end
252
+ else
253
+ super(prefix, localName, value);
254
+ end
255
+ end
256
+
257
+ end