changeset 5501:29ce5c785087

RT-29577 FXML support for 3D meshes, lights, and materials Reviewed-by: ekrejcir
author Martin Sladecek <martin.sladecek@oracle.com>
date Wed, 23 Oct 2013 14:24:39 +0200
parents 6ac26131bcaf
children 7446c9bf91dd
files modules/fxml/src/main/java/com/sun/javafx/fxml/builder/TriangleMeshBuilder.java modules/fxml/src/test/java/javafx/fxml/FXMLLoader_BuilderTest.java modules/fxml/src/test/resources/javafx/fxml/builders_trianglemesh.fxml
diffstat 3 files changed, 100 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/modules/fxml/src/main/java/com/sun/javafx/fxml/builder/TriangleMeshBuilder.java	Wed Oct 23 13:29:25 2013 +0200
+++ b/modules/fxml/src/main/java/com/sun/javafx/fxml/builder/TriangleMeshBuilder.java	Wed Oct 23 14:24:39 2013 +0200
@@ -25,17 +25,17 @@
 
 package com.sun.javafx.fxml.builder;
 
+import javafx.scene.shape.TriangleMesh;
+import javafx.util.Builder;
+
 import java.util.Locale;
 import java.util.Map.Entry;
 import java.util.Set;
-import java.util.StringTokenizer;
 import java.util.TreeMap;
-import javafx.scene.shape.TriangleMesh;
-import javafx.util.Builder;
 
 public class TriangleMeshBuilder extends TreeMap<String, Object> implements Builder<TriangleMesh> {
 
-    private static final String VALUE_SEPARATOR = ",";
+    private static final String VALUE_SEPARATOR_REGEX = "[,\\s]+";
 
     private float[] points;
     private float[] texCoords;
@@ -64,32 +64,28 @@
     public Object put(String key, Object value) {
 
         if ("points".equalsIgnoreCase(key)) {
-            StringTokenizer tokenizer = new StringTokenizer((String) value, VALUE_SEPARATOR);
-            points = new float[tokenizer.countTokens()];
-            int counter = 0;
-            while (tokenizer.hasMoreTokens()) {
-                points[counter++] = Float.parseFloat(tokenizer.nextToken().trim());
+            String[] split = ((String) value).split(VALUE_SEPARATOR_REGEX);
+            points = new float[split.length];
+            for (int i = 0; i < split.length; ++i) {
+                points[i] = Float.parseFloat(split[i]);
             }
         } else if ("texcoords".equalsIgnoreCase(key)) {
-            StringTokenizer tokenizer = new StringTokenizer((String) value, VALUE_SEPARATOR);
-            texCoords = new float[tokenizer.countTokens()];
-            int counter = 0;
-            while (tokenizer.hasMoreTokens()) {
-                texCoords[counter++] = Float.parseFloat(tokenizer.nextToken().trim());
+            String[] split = ((String) value).split(VALUE_SEPARATOR_REGEX);
+            texCoords = new float[split.length];
+            for (int i = 0; i < split.length; ++i) {
+                texCoords[i] = Float.parseFloat(split[i]);
             }
         } else if ("faces".equalsIgnoreCase(key)) {
-            StringTokenizer tokenizer = new StringTokenizer((String) value, VALUE_SEPARATOR);
-            faces = new int[tokenizer.countTokens()];
-            int counter = 0;
-            while (tokenizer.hasMoreTokens()) {
-                faces[counter++] = Integer.parseInt(tokenizer.nextToken().trim());
+            String[] split = ((String) value).split(VALUE_SEPARATOR_REGEX);
+            faces = new int[split.length];
+            for (int i = 0; i < split.length; ++i) {
+                faces[i] = Integer.parseInt(split[i]);
             }
         } else if ("facesmoothinggroups".equalsIgnoreCase(key)) {
-            StringTokenizer tokenizer = new StringTokenizer((String) value, VALUE_SEPARATOR);
-            faceSmoothingGroups = new int[tokenizer.countTokens()];
-            int counter = 0;
-            while (tokenizer.hasMoreTokens()) {
-                faceSmoothingGroups[counter++] = Integer.parseInt(tokenizer.nextToken().trim());
+            String[] split = ((String) value).split(VALUE_SEPARATOR_REGEX);
+            faceSmoothingGroups = new int[split.length];
+            for (int i = 0; i < split.length; ++i) {
+                faceSmoothingGroups[i] = Integer.parseInt(split[i]);
             }
         }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/fxml/src/test/java/javafx/fxml/FXMLLoader_BuilderTest.java	Wed Oct 23 14:24:39 2013 +0200
@@ -0,0 +1,47 @@
+package javafx.fxml;
+/*
+ * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javafx.scene.shape.TriangleMesh;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+
+public class FXMLLoader_BuilderTest {
+
+    @Test
+    public void testTriangleMeshBuilder() throws IOException {
+        TriangleMesh mesh = FXMLLoader.load(getClass().getResource("builders_trianglemesh.fxml"));
+        float[] refFloatArray = {0f, 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f};
+        int[] refIntArray = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
+        assertArrayEquals(refIntArray, mesh.getFaces().toArray(new int[0]));
+        assertArrayEquals(refIntArray, mesh.getFaceSmoothingGroups().toArray(new int[0]));
+        assertArrayEquals(refFloatArray, mesh.getPoints().toArray(new float[0]), 1e-10f);
+        assertArrayEquals(refFloatArray, mesh.getTexCoords().toArray(new float[0]), 1e-10f);
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/fxml/src/test/resources/javafx/fxml/builders_trianglemesh.fxml	Wed Oct 23 14:24:39 2013 +0200
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
+DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+
+This code is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 2 only, as
+published by the Free Software Foundation.  Oracle designates this
+particular file as subject to the "Classpath" exception as provided
+by Oracle in the LICENSE file that accompanied this code.
+
+This code is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+version 2 for more details (a copy is included in the LICENSE file that
+accompanied this code).
+
+You should have received a copy of the GNU General Public License version
+2 along with this work; if not, write to the Free Software Foundation,
+Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+or visit www.oracle.com if you need additional information or have any
+questions.
+-->
+
+<?import javafx.scene.shape.TriangleMesh?>
+
+<TriangleMesh points="0 1 2 3 4 5 6 7 8 9"
+              texcoords="0,1    ,2,3,4,5,6,7,8,9"
+              faces="0 1 2 3 4
+                     5 6 7 8 9"
+              facesmoothinggroups="0,1,2,3,4,5 6 7 8 9"/>
\ No newline at end of file