diff options
Diffstat (limited to 'logo')
-rw-r--r-- | logo/src/Lanceur.java | 148 | ||||
-rw-r--r-- | logo/src/xlogo/kernel/perspective/ElementLine.java | 206 | ||||
-rw-r--r-- | logo/src/xlogo/kernel/perspective/ElementPoint.java | 74 | ||||
-rw-r--r-- | logo/src/xlogo/kernel/perspective/ElementPolygon.java | 88 | ||||
-rw-r--r-- | logo/src/xlogo/kernel/perspective/LightDialog.java | 157 | ||||
-rw-r--r-- | logo/src/xlogo/kernel/perspective/Viewer3D.java | 208 |
6 files changed, 441 insertions, 440 deletions
diff --git a/logo/src/Lanceur.java b/logo/src/Lanceur.java index 3298c55..205e161 100644 --- a/logo/src/Lanceur.java +++ b/logo/src/Lanceur.java @@ -24,7 +24,7 @@ /** Title : XLogo * Description : XLogo is an interpreter for the Logo * programming language - * + * * @author Loïc Le Coq */ import java.io.*; @@ -34,15 +34,15 @@ import java.util.Calendar; /** * @author loic - * + * * This class extracts the file tmp_xlogo.jar from the main archive * in the temporary file's directory * and then launch the command: <br> * java -D-jar -Xmx64m -Djava.library.path=path_to_tmp -cp path_to_tmp * tmp_xlogo.jar<br> * <br> - * XLogo executes with a predefined heap size for the Virtual Machine * - * + * XLogo executes with a predefined heap size for the Virtual Machine * + * * @author Marko Zivkovic * The maximum heap size property is now fixed 128MB. In the future, the application preferences should be used. * Command line arguments are ignored, because this application is GUI-based and for @@ -50,7 +50,7 @@ import java.util.Calendar; */ public class Lanceur { private static int DEFAULT_MEMORY_ALLOC = 128; - + /** * The process which contains the XLogo application */ @@ -59,48 +59,48 @@ public class Lanceur { * The temporary folder which contains all files to start XLogo */ private File tmpFolder = null; - + /** * Main method - * + * * @param args * The path toward "lgo" files */ - public static void main(String[] args) { + public static void main(final String[] args) { new Lanceur(); } - + Lanceur() { // Look for old files from XLogo crash cleanTmp(); // Look for the memory that should be allocated to the JVM heap size //Preferences prefs = Preferences.systemRoot().node(PROPERTIES_PREFIX); TODO this does not work ... :-( //int memory = prefs.getInt("appMemory", DEFAULT_MEMORY_ALLOC); - int memory = DEFAULT_MEMORY_ALLOC; - + final int memory = DEFAULT_MEMORY_ALLOC; + // extract application in the java.io.tmp directory extractApplication(); startApplicationProcess(memory); restorePath(); deleteTmpFiles(); } - - private void startApplicationProcess(int memoire) { + + private void startApplicationProcess(final int memoire) { try { // Add the tmp to the path - String newPath = tmpFolder.getAbsolutePath(); - + final String newPath = tmpFolder.getAbsolutePath(); + String javaLibraryPath = newPath + File.pathSeparatorChar + System.getProperty("java.library.path"); // Bug when launching under Windows with java webstart javaLibraryPath = javaLibraryPath.replaceAll("\"", ""); System.out.println("Path: " + javaLibraryPath + "\n"); - String[] commande = new String[5]; + final String[] commande = new String[5]; commande[0] = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java"; commande[1] = "-jar"; commande[2] = "-Xmx" + memoire + "m"; commande[3] = "-Djava.library.path=" + javaLibraryPath; commande[4] = Library.TMP_XLOGO.getFile(tmpFolder).getAbsolutePath(); - + System.out.println("<----- Starting XLogo ---->"); String cmd = ""; for (int i = 0; i < commande.length; i++) { @@ -113,26 +113,26 @@ public class Lanceur { startStreamForward(p.getErrorStream()); p.waitFor(); } - catch (Exception e) { + catch (final Exception e) { System.out.println(e); } } - + private void restorePath() { - String pathToFolder = tmpFolder.getAbsolutePath(); - String path = System.getProperty("java.library.path"); - StringTokenizer st = new StringTokenizer(path, File.pathSeparator); + final String pathToFolder = tmpFolder.getAbsolutePath(); + final String path = System.getProperty("java.library.path"); + final StringTokenizer st = new StringTokenizer(path, File.pathSeparator); String newPath = ""; while (st.hasMoreTokens()) { if (!newPath.equals("")) newPath += File.pathSeparator; - String element = st.nextToken(); + final String element = st.nextToken(); if (!element.equals(pathToFolder)) newPath += element; } System.setProperty("java.library.path", newPath); } - + /** * Used to catch application streams and write them to System.out * @param stream @@ -147,7 +147,7 @@ public class Lanceur { while ((line = reader.readLine()) != null) System.out.println(line); } - catch (IOException e) { + catch (final IOException e) { System.out.println(e.toString()); } finally { @@ -155,69 +155,69 @@ public class Lanceur { try { reader.close(); } - catch (IOException e) {} + catch (final IOException e) {} } } }.start(); } - + /** * This method checks for unused old XLogo files in temporary directory<br> * If it found files older than 24 hours with the prefix tmp_xlogo, these * files are deleted. */ private void cleanTmp() { - String path = System.getProperty("java.io.tmpdir"); - File f = new File(path); - File[] files = f.listFiles(); + final String path = System.getProperty("java.io.tmpdir"); + final File f = new File(path); + final File[] files = f.listFiles(); if (null != files) { for (int i = 0; i < files.length; i++) { try { if (files[i].getName().startsWith("tmp_xlogo")) { - long fileTime = files[i].lastModified(); - long time = Calendar.getInstance().getTimeInMillis(); + final long fileTime = files[i].lastModified(); + final long time = Calendar.getInstance().getTimeInMillis(); // Delete file if it's more than 24 hours old if (time - fileTime > 24 * 3600 * 1000) { if (files[i].isDirectory()) deleteDirectory(files[i]); files[i].delete(); - + } } } - catch (Exception e) { + catch (final Exception e) { e.printStackTrace(); } } } } - + /** * This method extracts the file tmp_xlogo.jar from the archive and copy it * into the temporary directory. */ private void extractApplication() { initTmpFolder(); - - for (Library lib : Library.values()) { + + for (final Library lib : Library.values()) { if (lib.getPath() == null){ copy2Tmp(lib); } } // extract the native driver for java 3d in this folder - String osName = System.getProperty("os.name").toLowerCase(); - String arch = System.getProperty("os.arch"); + final String osName = System.getProperty("os.name").toLowerCase(); + final String arch = System.getProperty("os.arch"); System.out.println("Operating system: " + osName); System.out.println("Architecture: " + arch); - + // Linux //InputStream lib; } - + private void initTmpFolder() { // Create in the "java.io.tmpdir" a directory called tmp_xlogo int i = 0; - String tmpPath = System.getProperty("java.io.tmpdir") + File.separator + "tmp_xlogo"; + final String tmpPath = System.getProperty("java.io.tmpdir") + File.separator + "tmp_xlogo"; while (true) { tmpFolder = new File(tmpPath + i); if (!tmpFolder.exists()) @@ -225,38 +225,38 @@ public class Lanceur { else i++; } - + System.out.println("Creating tmp_xlogo directory - success: " + tmpFolder.mkdir()); } - - private void copy2Tmp(Library lib) { + + private void copy2Tmp(final Library lib) { // extract the jar file in this folder - InputStream src = Lanceur.class.getResourceAsStream(lib.getResourcePath()); - File file = lib.getFile(tmpFolder); + final InputStream src = Lanceur.class.getResourceAsStream(lib.getResourcePath()); + final File file = lib.getFile(tmpFolder); System.out.println("Get library " + lib.getResourcePath()); System.out.println("Copying " + lib.getLibraryName() + " - success: " + copy(src, file)); } - + private void deleteTmpFiles() { System.out.println("Closing XLogo. Cleaning tmp file"); - for (Library lib : Library.values()) { - File file = lib.getFile(tmpFolder); + for (final Library lib : Library.values()) { + final File file = lib.getFile(tmpFolder); if (file.exists()) { file.delete(); } } tmpFolder.delete(); } - + /** * This method copy the file tmp_xlogo.jar from the archive to the file * Destination. - * + * * @param destination * The output file * @return true if success, false otherwise */ - private boolean copy(InputStream src, File destination) { + private boolean copy(final InputStream src, final File destination) { boolean resultat = false; // Declaration des flux java.io.FileOutputStream destinationFile = null; @@ -264,10 +264,10 @@ public class Lanceur { // Création du fichier : destination.createNewFile(); // Ouverture des flux - + destinationFile = new java.io.FileOutputStream(destination); // Lecture par segment de 0.5Mo - byte buffer[] = new byte[512 * 1024]; + final byte buffer[] = new byte[512 * 1024]; int nbLecture; while ((nbLecture = src.read(buffer)) != -1) { destinationFile.write(buffer, 0, nbLecture); @@ -275,33 +275,33 @@ public class Lanceur { // Copie réussie resultat = true; } - catch (java.io.FileNotFoundException f) {} - catch (java.io.IOException e) {} + catch (final java.io.FileNotFoundException f) {} + catch (final java.io.IOException e) {} finally { // Quoi qu'il arrive, on ferme les flux try { src.close(); } - catch (Exception e) {} + catch (final Exception e) {} try { destinationFile.close(); } - catch (Exception e) {} + catch (final Exception e) {} } return (resultat); } - + /** * Delete a the directory created by Logo in /tmp - * + * * @param path * The Directory path * @return true if success */ - private boolean deleteDirectory(File path) { + private boolean deleteDirectory(final File path) { boolean resultat = true; if (path.exists()) { - File[] files = path.listFiles(); + final File[] files = path.listFiles(); if (null != files) { for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { @@ -316,7 +316,7 @@ public class Lanceur { resultat &= path.delete(); return (resultat); } - + /** * These represent libraries that should be packed into the new temporary jar. * @author Marko @@ -337,34 +337,34 @@ public class Lanceur { private String path; private String libName; - - Library(String jarName) { + + Library(final String jarName) { this.libName = jarName; } - - Library(String path, String libName) { + + Library(final String path, final String libName) { this.path = path; this.libName = libName; } - + public String getPath() { return path; } - + public String getLibraryName() { return libName; } - + public String getResourcePath() { if (path != null){ return path + libName; } else { return libName; } - + } - - public File getFile(File location) { + + public File getFile(final File location) { return new File(location.getAbsolutePath() + File.separator + libName); } } diff --git a/logo/src/xlogo/kernel/perspective/ElementLine.java b/logo/src/xlogo/kernel/perspective/ElementLine.java index 6a80557..09a0108 100644 --- a/logo/src/xlogo/kernel/perspective/ElementLine.java +++ b/logo/src/xlogo/kernel/perspective/ElementLine.java @@ -1,29 +1,29 @@ /* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loic Le Coq * Copyright (C) 2013 Marko Zivkovic - * + * * Contact Information: marko88zivkovic at gmail dot com - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. This program 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 for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the Free - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. This program 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 for more details. You should have received a copy of the + * GNU General Public License along with this program; if not, write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. - * - * + * + * * This Java source code belongs to XLogo4Schools, written by Marko Zivkovic * during his Bachelor thesis at the computer science department of ETH Zurich, * in the year 2013 and/or during future work. - * + * * It is a reengineered version of XLogo written by Loic Le Coq, published * under the GPL License at http://xlogo.tuxfamily.org/ - * + * * Contents of this file were initially written by Loic Le Coq, - * modifications, extensions, refactorings might have been applied by Marko Zivkovic + * modifications, extensions, refactorings might have been applied by Marko Zivkovic */ package xlogo.kernel.perspective; @@ -50,7 +50,7 @@ import javax.vecmath.Vector3d; import xlogo.kernel.LogoError; /** - * + * * @author Marko Zivkovic - I decoupled this from Application * */ @@ -58,20 +58,20 @@ public class ElementLine extends Element3D { /** * This float stores the line Width for each 3D line - * + * * @uml.property name="lineWidth" */ - private float lineWidth; - - public ElementLine(Viewer3D v3d, float lineWidth) + private final float lineWidth; + + public ElementLine(final Viewer3D v3d, final float lineWidth) { super(v3d); this.lineWidth = lineWidth; //app.getKernel().getActiveTurtle().getPenWidth(); } - + public void addToScene() throws LogoError { - int size = vertex.size(); + final int size = vertex.size(); if (size > 1) { if (lineWidth == 0.5) @@ -80,25 +80,25 @@ public class ElementLine extends Element3D createComplexLine(size); } } - + /** * This method draws a line with width 1 - * + * * @param size */ - private void createSimpleLine(int size) + private void createSimpleLine(final int size) { - int[] tab = { size }; - LineStripArray line = new LineStripArray(size, LineStripArray.COORDINATES | LineStripArray.COLOR_3, tab); + final int[] tab = { size }; + final LineStripArray line = new LineStripArray(size, GeometryArray.COORDINATES | GeometryArray.COLOR_3, tab); for (int i = 0; i < size; i++) { line.setCoordinate(i, vertex.get(i)); // System.out.println("sommet "+(2*i-1)+" "+vertex.get(i).x+" "+vertex.get(i).y+" "+vertex.get(i).z+" "); line.setColor(i, new Color3f(color.get(i))); } - Shape3D s = new Shape3D(line); - Appearance appear = new Appearance(); - Material mat = new Material(new Color3f(1.0f, 1.0f, 1.0f), new Color3f(0.0f, 0f, 0f), new Color3f(1f, 1.0f, + final Shape3D s = new Shape3D(line); + final Appearance appear = new Appearance(); + final Material mat = new Material(new Color3f(1.0f, 1.0f, 1.0f), new Color3f(0.0f, 0f, 0f), new Color3f(1f, 1.0f, 1.0f), new Color3f(1f, 1f, 1f), 64); appear.setMaterial(mat); appear.setLineAttributes(new LineAttributes(2 * lineWidth, LineAttributes.PATTERN_SOLID, false)); @@ -115,27 +115,27 @@ public class ElementLine extends Element3D * } */ } - + /** * This method draws a sequence of lines with a width different from 1 * Draws a cylinder around the line - * + * * @param size */ - - private void createComplexLine(int size) + + private void createComplexLine(final int size) { for (int i = 0; i < size - 1; i++) { createLine(vertex.get(i), vertex.get(i + 1), new Color3f(color.get(i + 1))); } - + } - + /** * This method creates an elementary line with a width different from 1 * It draws a cylinder around the line and two spheres on each extremities - * + * * @param p1 * the first point * @param p2 @@ -143,93 +143,93 @@ public class ElementLine extends Element3D * @param color * the sphere color */ - private void createLine(Point3d p1, Point3d p2, Color3f color) + private void createLine(final Point3d p1, final Point3d p2, final Color3f color) { // create a new CylinderTransformer between the two atoms - CylinderTransformer cT = new CylinderTransformer(p1, p2); - + final CylinderTransformer cT = new CylinderTransformer(p1, p2); + // get the length - double length = cT.getLength(); - float radius = lineWidth / 1000; + final double length = cT.getLength(); + final float radius = lineWidth / 1000; // holds the translation - Transform3D transform1 = new Transform3D(); + final Transform3D transform1 = new Transform3D(); // ...move the coordinates there transform1.setTranslation(cT.getTranslation()); - + // get the axis and angle for rotation - AxisAngle4d rotation = cT.getAxisAngle(); - Transform3D transform2 = new Transform3D(); + final AxisAngle4d rotation = cT.getAxisAngle(); + final Transform3D transform2 = new Transform3D(); transform2.setRotation(rotation); - + // combine the translation and rotation into transform1 transform1.mul(transform2); - + // create a new Cylinder - Appearance appear = new Appearance(); - Material mat = new Material(new Color3f(1.0f, 1.0f, 1.0f), color, new Color3f(1f, 1.0f, 1.0f), new Color3f(1f, + final Appearance appear = new Appearance(); + final Material mat = new Material(new Color3f(1.0f, 1.0f, 1.0f), color, new Color3f(1f, 1.0f, 1.0f), new Color3f(1f, 1f, 1f), 64); appear.setMaterial(mat); - PolygonAttributes pa = new PolygonAttributes(); + final PolygonAttributes pa = new PolygonAttributes(); pa.setCullFace(PolygonAttributes.CULL_NONE); pa.setBackFaceNormalFlip(true); appear.setPolygonAttributes(pa); - Cylinder cyl = new Cylinder(radius, (float) length, appear); - + final Cylinder cyl = new Cylinder(radius, (float) length, appear); + // and add it to the TransformGroup - TransformGroup tg = new TransformGroup(); + final TransformGroup tg = new TransformGroup(); tg.setTransform(transform1); tg.addChild(cyl); v3d.add2DText(tg); - + // Add Sphere to the line extremities. - Sphere sphere1 = new Sphere(radius, appear); - TransformGroup tg2 = new TransformGroup(); - Transform3D transform3 = new Transform3D(); + final Sphere sphere1 = new Sphere(radius, appear); + final TransformGroup tg2 = new TransformGroup(); + final Transform3D transform3 = new Transform3D(); transform3.setTranslation(new Vector3d(p1)); tg2.setTransform(transform3); tg2.addChild(sphere1); v3d.add2DText(tg2); - - Sphere sphere2 = new Sphere(radius, appear); - TransformGroup tg3 = new TransformGroup(); - Transform3D transform4 = new Transform3D(); + + final Sphere sphere2 = new Sphere(radius, appear); + final TransformGroup tg3 = new TransformGroup(); + final Transform3D transform4 = new Transform3D(); transform4.setTranslation(new Vector3d(p2)); tg3.setTransform(transform4); tg3.addChild(sphere2); v3d.add2DText(tg3); - + } - + public boolean isLine() { return true; } - + public boolean isPoint() { return false; } - + public boolean isPolygon() { return false; } - + public boolean isText() { return false; } - + /** * A class to calculate the length and transformations necessary to produce * a cylinder to connect two points. Useful for Java3D and VRML where a * cylinder object is created aligned along the y-axis. - * + * * @author Alastair Hill */ class CylinderTransformer { - + /** point A */ private final Point3d pointA; /** point B */ @@ -240,7 +240,7 @@ public class ElementLine extends Element3D private double angle; /** * the axis around which to rotate the cylinder - * + * */ private Vector3d axis; /** @@ -250,119 +250,119 @@ public class ElementLine extends Element3D private Vector3d translation; /** * The length of the cylinder required to join the two points - * + * */ private double length; - + /** * Creates a new instance of CylinderTransformer - * + * * @param a * point a * @param b * point b */ - CylinderTransformer(Point3d a, Point3d b) + CylinderTransformer(final Point3d a, final Point3d b) { pointA = a; pointB = b; - + // carry out the calculations doCalculations(); } - + /** * Carries out the necessary calculations so that values may be returned */ private void doCalculations() { length = pointA.distance(pointB); - - double[] arrayA = new double[3]; + + final double[] arrayA = new double[3]; pointA.get(arrayA); - double[] arrayB = new double[3]; + final double[] arrayB = new double[3]; pointB.get(arrayB); - double[] arrayMid = new double[3]; - + final double[] arrayMid = new double[3]; + for (int i = 0; i < arrayA.length; i++) { arrayMid[i] = (arrayA[i] + arrayB[i]) / 2f; } - + // the translation needed is translation = new Vector3d(arrayMid); - + // the initial orientation of the bond is in the y axis - Vector3d init = new Vector3d(0.0f, 1.0f, 0.0f); - + final Vector3d init = new Vector3d(0.0f, 1.0f, 0.0f); + // the vector needed is the same as that from a to b - Vector3d needed = new Vector3d(pointB.x - pointA.x, pointB.y - pointA.y, pointB.z - pointA.z); - + final Vector3d needed = new Vector3d(pointB.x - pointA.x, pointB.y - pointA.y, pointB.z - pointA.z); + // so the angle to rotate the bond by is: angle = needed.angle(init); - + // and the axis to rotate by is the cross product of the initial and // needed vectors - ie the vector orthogonal to them both axis = new Vector3d(); axis.cross(init, needed); } - + /** * Returns the angle (in radians) through which to rotate the cylinder - * + * * @return the angle. */ double getAngle() { return angle; } - + /** * The axis around which the cylinder must be rotated - * + * * @return the axis */ Vector3d getAxis() { return axis; } - + /** * The length required for the cylinder to join the two points - * + * * @return the length */ double getLength() { return length; } - + /** * The translation required to move the cylinder to the midpoint of the * two points - * + * * @return the translation */ Vector3d getTranslation() { return translation; } - + /** * Generates a (pretty) string representation of the the * CylinderTransformer - * + * * @return the string representation */ public String toString() { return "tr: " + translation + ", ax: " + axis + ", an: " + angle + ", le: " + length; } - + /** * Generates the required axis and angle combined into an AxisAngle4f * object - * + * * @return the axis and angle */ public AxisAngle4d getAxisAngle() @@ -370,5 +370,5 @@ public class ElementLine extends Element3D return new AxisAngle4d(axis.x, axis.y, axis.z, angle); } } - + } diff --git a/logo/src/xlogo/kernel/perspective/ElementPoint.java b/logo/src/xlogo/kernel/perspective/ElementPoint.java index b89fcd8..670dee3 100644 --- a/logo/src/xlogo/kernel/perspective/ElementPoint.java +++ b/logo/src/xlogo/kernel/perspective/ElementPoint.java @@ -1,29 +1,29 @@ /* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loic Le Coq * Copyright (C) 2013 Marko Zivkovic - * + * * Contact Information: marko88zivkovic at gmail dot com - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. This program 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 for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the Free - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. This program 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 for more details. You should have received a copy of the + * GNU General Public License along with this program; if not, write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. - * - * + * + * * This Java source code belongs to XLogo4Schools, written by Marko Zivkovic * during his Bachelor thesis at the computer science department of ETH Zurich, * in the year 2013 and/or during future work. - * + * * It is a reengineered version of XLogo written by Loic Le Coq, published * under the GPL License at http://xlogo.tuxfamily.org/ - * + * * Contents of this file were initially written by Loic Le Coq, - * modifications, extensions, refactorings might have been applied by Marko Zivkovic + * modifications, extensions, refactorings might have been applied by Marko Zivkovic */ package xlogo.kernel.perspective; @@ -50,22 +50,22 @@ import com.sun.j3d.utils.geometry.Sphere; public class ElementPoint extends Element3D { float pointWidth; - - public ElementPoint(Viewer3D v3d, float pointWidth) + + public ElementPoint(final Viewer3D v3d, final float pointWidth) { super(v3d); this.pointWidth = pointWidth; //app.getKernel().getActiveTurtle().getPenWidth(); } - + public void addToScene() throws LogoError { if (vertex.size() == 0) return; if (pointWidth == 0.5) { - int[] tab = new int[1]; + final int[] tab = new int[1]; tab[0] = vertex.size(); - PointArray point = new PointArray(vertex.size(), PointArray.COORDINATES | PointArray.COLOR_3); + final PointArray point = new PointArray(vertex.size(), GeometryArray.COORDINATES | GeometryArray.COLOR_3); for (int i = 0; i < vertex.size(); i++) { point.setCoordinate(i, vertex.get(i)); @@ -79,51 +79,51 @@ public class ElementPoint extends Element3D { createBigPoint(vertex.get(i), new Color3f(color.get(i))); } - + } } - - private void createBigPoint(Point3d p, Color3f color) + + private void createBigPoint(final Point3d p, final Color3f color) { // Add a Sphere to main 3D scene. - Appearance appear = new Appearance(); - Material mat = new Material(new Color3f(1.0f, 1.0f, 1.0f), color,// new + final Appearance appear = new Appearance(); + final Material mat = new Material(new Color3f(1.0f, 1.0f, 1.0f), color,// new // Color3f(0.0f,0f,0f), new Color3f(1f, 1.0f, 1.0f), new Color3f(1f, 1f, 1f), 64); appear.setMaterial(mat); - PolygonAttributes pa = new PolygonAttributes(); + final PolygonAttributes pa = new PolygonAttributes(); pa.setCullFace(PolygonAttributes.CULL_NONE); pa.setBackFaceNormalFlip(true); appear.setPolygonAttributes(pa); - - Sphere sphere = new Sphere(pointWidth / 1000, appear); - - TransformGroup tg = new TransformGroup(); - Transform3D transform = new Transform3D(); + + final Sphere sphere = new Sphere(pointWidth / 1000, appear); + + final TransformGroup tg = new TransformGroup(); + final Transform3D transform = new Transform3D(); transform.setTranslation(new Vector3d(p)); tg.setTransform(transform); tg.addChild(sphere); v3d.add2DText(tg); } - + public boolean isLine() { return false; } - + public boolean isPoint() { return true; } - + public boolean isPolygon() { return false; } - + public boolean isText() { return false; } - + } diff --git a/logo/src/xlogo/kernel/perspective/ElementPolygon.java b/logo/src/xlogo/kernel/perspective/ElementPolygon.java index 8ae2168..71ba5c3 100644 --- a/logo/src/xlogo/kernel/perspective/ElementPolygon.java +++ b/logo/src/xlogo/kernel/perspective/ElementPolygon.java @@ -1,36 +1,36 @@ /* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loic Le Coq * Copyright (C) 2013 Marko Zivkovic - * + * * Contact Information: marko88zivkovic at gmail dot com - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. This program 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 for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the Free - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. This program 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 for more details. You should have received a copy of the + * GNU General Public License along with this program; if not, write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. - * - * + * + * * This Java source code belongs to XLogo4Schools, written by Marko Zivkovic * during his Bachelor thesis at the computer science department of ETH Zurich, * in the year 2013 and/or during future work. - * + * * It is a reengineered version of XLogo written by Loic Le Coq, published * under the GPL License at http://xlogo.tuxfamily.org/ - * + * * Contents of this file were initially written by Loic Le Coq, - * modifications, extensions, refactorings might have been applied by Marko Zivkovic + * modifications, extensions, refactorings might have been applied by Marko Zivkovic */ /** * Title : XLogo * Description : XLogo is an interpreter for the Logo * programming language - * + * * @author Loïc Le Coq */ package xlogo.kernel.perspective; @@ -49,33 +49,33 @@ import xlogo.kernel.LogoError; /** * This class represent A polygon surface in 3D mode - * + * * @author loic - * + * * @author Marko Zivkovic - I decoupled this from Application */ public class ElementPolygon extends Element3D { - public ElementPolygon(Viewer3D v3d) + public ElementPolygon(final Viewer3D v3d) { super(v3d); } - + /** * This method calculates all attributes for polygon and add it to the * Polygon's list */ public void addToScene() throws LogoError { - + if (vertex.size() < 3) throw new LogoError(Logo.messages.getString("error.3d.3vertex")); - + // Create normal vector - - Point3d origine = vertex.get(0); + + final Point3d origine = vertex.get(0); // System.out.println(" origine "+origine.x+" "+origine.y+" "+origine.z); - + Point3d point1; Vector3f vec1 = null; Vector3f vec2 = null; @@ -117,61 +117,61 @@ public class ElementPolygon extends Element3D if (null == vec2) throw new LogoError(Logo.messages.getString("error.3d.emptypolygon")); } - + // Create Geometry - - int[] tab = new int[1]; + + final int[] tab = new int[1]; tab[0] = vertex.size(); - TriangleFanArray tfa = new TriangleFanArray(vertex.size(), TriangleFanArray.COORDINATES - | TriangleFanArray.COLOR_3 | TriangleFanArray.NORMALS, tab); + final TriangleFanArray tfa = new TriangleFanArray(vertex.size(), GeometryArray.COORDINATES + | GeometryArray.COLOR_3 | GeometryArray.NORMALS, tab); // TriangleFanArray tfa2=new // TriangleFanArray(vertex.size(),TriangleFanArray.COORDINATES|TriangleFanArray.COLOR_3|TriangleFanArray.NORMALS,tab); for (int i = 0; i < vertex.size(); i++) { - + tfa.setCoordinate(i, vertex.get(i)); // tfa2.setCoordinate(i, vertex.get(vertex.size()-1-i)); tfa.setColor(i, new Color3f(color.get(i))); // tfa2.setColor(i, new Color3f(color.get(color.size()-i-1))); - + tfa.setNormal(i, vec2); // tfa2.setNormal(i, vec1); - + } - - Shape3D s = new Shape3D(tfa); - Appearance appear = new Appearance(); - Material mat = new Material(new Color3f(1.0f, 1.0f, 1.0f), new Color3f(0.0f, 0f, 0f), new Color3f(1f, 1.0f, + + final Shape3D s = new Shape3D(tfa); + final Appearance appear = new Appearance(); + final Material mat = new Material(new Color3f(1.0f, 1.0f, 1.0f), new Color3f(0.0f, 0f, 0f), new Color3f(1f, 1.0f, 1.0f), new Color3f(1f, 1f, 1f), 64); appear.setMaterial(mat); - PolygonAttributes pa = new PolygonAttributes(); + final PolygonAttributes pa = new PolygonAttributes(); pa.setCullFace(PolygonAttributes.CULL_NONE); pa.setBackFaceNormalFlip(true); appear.setPolygonAttributes(pa); - + s.setAppearance(appear); v3d.add3DObject(s); // DrawPanel.listPoly.add(s); // DrawPanel.listPoly.add(new Shape3D(tfa2)); // System.out.println(DrawPanel.listPoly.size()+" "+vertex.get(i).x+" "+vertex.get(i).y+" "+vertex.get(i).z); } - + public boolean isPoint() { return false; } - + public boolean isPolygon() { return true; } - + public boolean isLine() { return false; } - + public boolean isText() { return false; diff --git a/logo/src/xlogo/kernel/perspective/LightDialog.java b/logo/src/xlogo/kernel/perspective/LightDialog.java index 3638213..bd54658 100644 --- a/logo/src/xlogo/kernel/perspective/LightDialog.java +++ b/logo/src/xlogo/kernel/perspective/LightDialog.java @@ -1,29 +1,29 @@ /* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loic Le Coq * Copyright (C) 2013 Marko Zivkovic - * + * * Contact Information: marko88zivkovic at gmail dot com - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. This program 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 for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the Free - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. This program 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 for more details. You should have received a copy of the + * GNU General Public License along with this program; if not, write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. - * - * + * + * * This Java source code belongs to XLogo4Schools, written by Marko Zivkovic * during his Bachelor thesis at the computer science department of ETH Zurich, * in the year 2013 and/or during future work. - * + * * It is a reengineered version of XLogo written by Loic Le Coq, published * under the GPL License at http://xlogo.tuxfamily.org/ - * + * * Contents of this file were initially written by Loic Le Coq, - * modifications, extensions, refactorings might have been applied by Marko Zivkovic + * modifications, extensions, refactorings might have been applied by Marko Zivkovic */ package xlogo.kernel.perspective; @@ -40,6 +40,7 @@ import javax.vecmath.Color3f; import javax.vecmath.Tuple3f; import javax.vecmath.Point3f; import javax.vecmath.Vector3f; +import org.jogamp.vecmath.Vector3f; import javax.swing.BorderFactory; import javax.swing.JDialog; import javax.swing.JComboBox; @@ -57,38 +58,38 @@ import xlogo.storage.WSManager; public class LightDialog extends JDialog implements ActionListener { private static final long serialVersionUID = 1L; - private String[] type = { Logo.messages.getString("3d.light.none"), + private final String[] type = { Logo.messages.getString("3d.light.none"), Logo.messages.getString("3d.light.ambient"), Logo.messages.getString("3d.light.directional"), Logo.messages.getString("3d.light.point"), Logo.messages.getString("3d.light.spot") }; - + private JComboBox comboType; - + PanelColor panelColor; - + private PanelPosition panelPosition; - + private PanelPosition panelDirection; - + private PanelAngle panelAngle; - + private JLabel labelType; - + private JButton ok; - + private JButton refresh; - - private Viewer3D viewer3d; - - private MyLight light; - - LightDialog(Viewer3D viewer3d, MyLight light, String title) + + private final Viewer3D viewer3d; + + private final MyLight light; + + LightDialog(final Viewer3D viewer3d, final MyLight light, final String title) { super(viewer3d, title, true); this.viewer3d = viewer3d; this.light = light; initGui(); } - + private void initGui() { getContentPane().setLayout(new GridBagLayout()); @@ -103,27 +104,27 @@ public class LightDialog extends JDialog implements ActionListener else panelColor = new PanelColor(Color.white); panelColor.setBackground(comboType.getBackground()); - + panelPosition = new PanelPosition(Logo.messages.getString("3d.light.position"), light.getPosition()); panelDirection = new PanelPosition(Logo.messages.getString("3d.light.direction"), light.getDirection()); panelAngle = new PanelAngle(light.getAngle()); ok = new JButton(Logo.messages.getString("pref.ok")); refresh = new JButton(Logo.messages.getString("3d.light.apply")); - - Font font = WSManager.getWorkspaceConfig().getFont(); - + + final Font font = WSManager.getWorkspaceConfig().getFont(); + labelType.setFont(font); comboType.setFont(font); ok.setFont(font); refresh.setFont(font); - + comboType.addActionListener(this); comboType.setActionCommand("combo"); ok.addActionListener(this); ok.setActionCommand("ok"); refresh.addActionListener(this); refresh.setActionCommand("refresh"); - + getContentPane().add( labelType, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, @@ -158,12 +159,12 @@ public class LightDialog extends JDialog implements ActionListener new Insets(0, 0, 0, 0), 0, 0)); selectComponents(); setVisible(true); - + } - - public void actionPerformed(ActionEvent e) + + public void actionPerformed(final ActionEvent e) { - String cmd = e.getActionCommand(); + final String cmd = e.getActionCommand(); // The selected item in the combo Box has changed if (cmd.equals("combo")) selectComponents(); @@ -179,7 +180,7 @@ public class LightDialog extends JDialog implements ActionListener updateLight(); } } - + private void updateLight() { int t = comboType.getSelectedIndex(); @@ -197,12 +198,12 @@ public class LightDialog extends JDialog implements ActionListener light.createLight(); // System.out.println(c+" "+" "+p+" "+d); viewer3d.addNode(light); - + } - + private void selectComponents() { - int id = comboType.getSelectedIndex(); + final int id = comboType.getSelectedIndex(); // None if (id == MyLight.LIGHT_OFF) { @@ -244,21 +245,21 @@ public class LightDialog extends JDialog implements ActionListener panelAngle.setEnabled(true); } } - + class PanelAngle extends JPanel { private static final long serialVersionUID = 1L; private JLabel label; private JTextField angle; - private float angleValue; - - PanelAngle(float angleValue) + private final float angleValue; + + PanelAngle(final float angleValue) { this.angleValue = angleValue; - + initGui(); } - + private void initGui() { label = new JLabel(Logo.messages.getString("3d.light.angle")); @@ -268,14 +269,14 @@ public class LightDialog extends JDialog implements ActionListener add(label); add(angle); } - - public void setEnabled(boolean b) + + public void setEnabled(final boolean b) { super.setEnabled(b); label.setEnabled(b); angle.setEnabled(b); } - + /** * @return * @uml.property name="angleValue" @@ -284,36 +285,36 @@ public class LightDialog extends JDialog implements ActionListener { try { - float f = Float.parseFloat(angle.getText()); + final float f = Float.parseFloat(angle.getText()); return f; } - catch (NumberFormatException e) + catch (final NumberFormatException e) {} return MyLight.DEFAULT_ANGLE; } } - + class PanelPosition extends JPanel { private static final long serialVersionUID = 1L; - private String title; + private final String title; private JTextField Xpos; private JTextField Ypos; private JTextField Zpos; private JLabel sep1; private JLabel sep2; Tuple3f tuple; - - PanelPosition(String title, Tuple3f tuple) + + PanelPosition(final String title, final Tuple3f tuple) { this.title = title; this.tuple = tuple; initGui(); } - + private void initGui() { - TitledBorder tb = BorderFactory.createTitledBorder(title); + final TitledBorder tb = BorderFactory.createTitledBorder(title); tb.setTitleFont(WSManager.getWorkspaceConfig().getFont()); setBorder(tb); sep1 = new JLabel("x"); @@ -333,37 +334,37 @@ public class LightDialog extends JDialog implements ActionListener add(sep2); add(Zpos); } - + Point3f getPosition() { try { - float x = Float.parseFloat(Xpos.getText()); - float y = Float.parseFloat(Ypos.getText()); - float z = Float.parseFloat(Zpos.getText()); + final float x = Float.parseFloat(Xpos.getText()); + final float y = Float.parseFloat(Ypos.getText()); + final float z = Float.parseFloat(Zpos.getText()); return new Point3f(x / 1000, y / 1000, z / 1000); } - catch (NumberFormatException e) + catch (final NumberFormatException e) {} return (new Point3f(0, 0, 0)); } - + Vector3f getDirection() { try { - float x = Float.parseFloat(Xpos.getText()); - float y = Float.parseFloat(Ypos.getText()); - float z = Float.parseFloat(Zpos.getText()); + final float x = Float.parseFloat(Xpos.getText()); + final float y = Float.parseFloat(Ypos.getText()); + final float z = Float.parseFloat(Zpos.getText()); return new Vector3f(x / 1000, y / 1000, z / 1000); } - catch (NumberFormatException e) + catch (final NumberFormatException e) {} return (new Vector3f(0, 0, 0)); - + } - - public void setEnabled(boolean b) + + public void setEnabled(final boolean b) { super.setEnabled(b); sep1.setEnabled(b); @@ -372,7 +373,7 @@ public class LightDialog extends JDialog implements ActionListener Ypos.setEnabled(b); Zpos.setEnabled(b); } - + } - + } diff --git a/logo/src/xlogo/kernel/perspective/Viewer3D.java b/logo/src/xlogo/kernel/perspective/Viewer3D.java index 0b7a312..2ade695 100644 --- a/logo/src/xlogo/kernel/perspective/Viewer3D.java +++ b/logo/src/xlogo/kernel/perspective/Viewer3D.java @@ -1,29 +1,29 @@ /* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loic Le Coq * Copyright (C) 2013 Marko Zivkovic - * + * * Contact Information: marko88zivkovic at gmail dot com - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. This program 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 for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the Free - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. This program 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 for more details. You should have received a copy of the + * GNU General Public License along with this program; if not, write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. - * - * + * + * * This Java source code belongs to XLogo4Schools, written by Marko Zivkovic * during his Bachelor thesis at the computer science department of ETH Zurich, * in the year 2013 and/or during future work. - * + * * It is a reengineered version of XLogo written by Loic Le Coq, published * under the GPL License at http://xlogo.tuxfamily.org/ - * + * * Contents of this file were initially written by Loic Le Coq, - * modifications, extensions, refactorings might have been applied by Marko Zivkovic + * modifications, extensions, refactorings might have been applied by Marko Zivkovic */ package xlogo.kernel.perspective; @@ -80,9 +80,9 @@ import java.awt.event.ActionEvent; /** * This Frame displays the 3D main Scene - * + * * BG scene - * + * * BG backBranchGroup | BG Mylight (4) | BG * Background Light 1,2,3,4 Other objects */ @@ -95,13 +95,13 @@ public class Viewer3D extends JFrame implements ActionListener private final static String ACTION_LIGHT2 = "light2"; private final static String ACTION_LIGHT3 = "light3"; private final static String ACTION_FOG = "fog"; - + // To store the Light attributes private MyLight[] myLights; // To store the Fog attributes private MyFog myFog; // Gui Components - private ImageIcon iscreenshot = Utils.dimensionne_image("screenshot.png", this); + private final ImageIcon iscreenshot = Utils.dimensionne_image("screenshot.png", this); private JButton screenshot; private static final long serialVersionUID = 1L; private World3D w3d; @@ -117,33 +117,33 @@ public class Viewer3D extends JFrame implements ActionListener private Background back; private PanelLight panelLight; private PanelFog panelFog; - - public Viewer3D(World3D w3d, Color c) + + public Viewer3D(final World3D w3d, final Color c) { this.w3d = w3d; this.backgroundColor = new Color3f(c); initGui(); } - - public void actionPerformed(ActionEvent e) + + public void actionPerformed(final ActionEvent e) { - String cmd = e.getActionCommand(); + final String cmd = e.getActionCommand(); // Take a screenshot if (cmd.equals(Viewer3D.ACTION_SCREENSHOT)) { - WriteImage wi = new WriteImage(this, null); - int id = wi.chooseFile(); + final WriteImage wi = new WriteImage(this, null); + final int id = wi.chooseFile(); if (id == JFileChooser.APPROVE_OPTION) { - GraphicsContext3D ctx = canvas3D.getGraphicsContext3D(); - java.awt.Dimension scrDim = canvas3D.getSize(); - + final GraphicsContext3D ctx = canvas3D.getGraphicsContext3D(); + final java.awt.Dimension scrDim = canvas3D.getSize(); + // setting raster component - Raster ras = new Raster(new Point3f(-1.0f, -1.0f, -1.0f), Raster.RASTER_COLOR, 0, 0, scrDim.width, + final Raster ras = new Raster(new Point3f(-1.0f, -1.0f, -1.0f), Raster.RASTER_COLOR, 0, 0, scrDim.width, scrDim.height, new ImageComponent2D(ImageComponent.FORMAT_RGB, new BufferedImage(scrDim.width, scrDim.height, java.awt.image.BufferedImage.TYPE_INT_RGB)), null); ctx.readRaster(ras); - BufferedImage img = ras.getImage().getImage(); + final BufferedImage img = ras.getImage().getImage(); wi.setImage(img); wi.start(); } @@ -172,83 +172,83 @@ public class Viewer3D extends JFrame implements ActionListener else if (cmd.equals(Viewer3D.ACTION_FOG)) { new FogDialog(this, myFog, Logo.messages.getString("3d.fog")); - + } } - + public void setText() { setTitle(Logo.messages.getString("3d.viewer")); panelFog.setText(); panelLight.setText(); - + } - + private void initGui() { - this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); setIconImage(Toolkit.getDefaultToolkit().createImage(Utils.class.getResource("icone.png"))); - + // Creation d'un composant de classe Canvas3D permettant de visualiser // une scène 3D canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); // Création d'un univers 3D rattaché au composant 3D universe = new SimpleUniverse(canvas3D); - + // Install the camera at the valid position with correct orientation - TransformGroup tg = universe.getViewingPlatform().getViewPlatformTransform(); - Transform3D trans = new Transform3D(); + final TransformGroup tg = universe.getViewingPlatform().getViewPlatformTransform(); + final Transform3D trans = new Transform3D(); if (null == w3d) { w3d = new World3D(); } trans.setTranslation(new Vector3d(-w3d.xCamera / 1000, -w3d.yCamera / 1000, -w3d.zCamera / 1000)); - Transform3D rot = new Transform3D(); + final Transform3D rot = new Transform3D(); rot.lookAt(new Point3d(-w3d.xCamera / 1000, -w3d.yCamera / 1000, -w3d.zCamera / 1000), new Point3d(0, 0, 0), new Vector3d(0, 1, 0)); rot.invert(); trans.mul(rot); tg.setTransform(trans); - OrbitBehavior ob = new OrbitBehavior(canvas3D, OrbitBehavior.REVERSE_ALL); + final OrbitBehavior ob = new OrbitBehavior(canvas3D, OrbitBehavior.REVERSE_ALL); ob.setRotationCenter(new Point3d(0, 0, 0)); ob.setSchedulingBounds(new BoundingSphere(new Point3d(0, 0, 0), 2 * w3d.r / 1000)); universe.getViewingPlatform().setViewPlatformBehavior(ob); - + // Create the root of the branch graph scene = new BranchGroup(); branchManager = new BranchManager(); // scene.setName("Main Branch"); // We can add New BranchGroup dynamically in the main scene - scene.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND); + scene.setCapability(Group.ALLOW_CHILDREN_EXTEND); // We can remove BranchGroup dynamically in the main scene - scene.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE); - + scene.setCapability(Group.ALLOW_CHILDREN_WRITE); + // Configure and create background createBackground(); - + // Configure Lights initLights(); - + // Configure Fog myFog = new MyFog(MyFog.FOG_OFF, backgroundColor); scene.addChild(myFog); - + // Rattachement de la scène 3D à l'univers universe.addBranchGraph(scene); - - Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); - int width = d.width * 9 / 10; - int height = d.height * 9 / 10; + + final Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); + final int width = d.width * 9 / 10; + final int height = d.height * 9 / 10; setSize(width, height); getContentPane().setLayout(new GridBagLayout()); screenshot = new JButton(iscreenshot); screenshot.addActionListener(this); screenshot.setMaximumSize(new Dimension(100, 100)); screenshot.setActionCommand(Viewer3D.ACTION_SCREENSHOT); - + panelLight = new PanelLight(this); panelFog = new PanelFog(this); - + getContentPane().add( canvas3D, new GridBagConstraints(0, 0, 1, 3, 2.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, @@ -268,29 +268,29 @@ public class Viewer3D extends JFrame implements ActionListener setText(); getContentPane().validate(); } - + /** * This method adds a shape3D to the main scene - * + * * @param s * The Shape to add */ - public void add3DObject(Shape3D s) + public void add3DObject(final Shape3D s) { branchManager.add3DObject(s); } - - public void add2DText(TransformGroup tg) + + public void add2DText(final TransformGroup tg) { branchManager.add2DText(tg); } - + public void insertBranch() { branchManager.insertBranch(); branchManager = new BranchManager(); } - + /** * This methods adds two default PointLight int the 3d Scene */ @@ -298,14 +298,14 @@ public class Viewer3D extends JFrame implements ActionListener { myLights = new MyLight[4]; // First Default Point Light - Color3f color = new Color3f(1f, 1f, 1f); + final Color3f color = new Color3f(1f, 1f, 1f); Point3f pos = new Point3f((float) w3d.xCamera / 1000, (float) w3d.yCamera / 1000, (float) w3d.zCamera / 1000); myLights[0] = new MyLight(MyLight.LIGHT_POINT, color, pos); - + // Second default Point Light pos = new Point3f(-(float) w3d.xCamera / 1000, -(float) w3d.yCamera / 1000, -(float) w3d.zCamera / 1000); myLights[1] = new MyLight(MyLight.LIGHT_POINT, color, pos); - + myLights[2] = new MyLight(MyLight.LIGHT_OFF); myLights[3] = new MyLight(MyLight.LIGHT_OFF); for (int i = 0; i < 4; i++) @@ -314,26 +314,26 @@ public class Viewer3D extends JFrame implements ActionListener } addAllLights(scene); } - + /** * Add all lights in the main 3D scene */ - private void addAllLights(BranchGroup bg) + private void addAllLights(final BranchGroup bg) { for (int i = 0; i < 4; i++) { bg.addChild(myLights[i]); } } - + /** * add a light in the main scene */ - protected void addNode(Node l) + protected void addNode(final Node l) { scene.addChild(l); } - + /** * This methods erase all drawings on the 3D Viewer Drawing Area */ @@ -365,16 +365,16 @@ public class Viewer3D extends JFrame implements ActionListener * } * } */ - + } - - public void updateBackGround(Color c) + + public void updateBackGround(final Color c) { - backgroundColor = new Color3f(c); + backgroundColor = new Color3f(c.getRGBColorComponents(null)); backBranchgroup.detach(); createBackground(); } - + /** * This method creates the Background with the defined color */ @@ -382,67 +382,67 @@ public class Viewer3D extends JFrame implements ActionListener { backBranchgroup = new BranchGroup(); backBranchgroup.setCapability(BranchGroup.ALLOW_DETACH); - backBranchgroup.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE); - + backBranchgroup.setCapability(Group.ALLOW_CHILDREN_WRITE); + back = new Background(backgroundColor); back.setApplicationBounds(new BoundingSphere()); back.setCapability(Background.ALLOW_COLOR_WRITE); backBranchgroup.addChild(back); scene.addChild(backBranchgroup); } - + class BranchManager { BranchGroup bg; - + BranchManager() { bg = new BranchGroup(); bg.setCapability(BranchGroup.ALLOW_DETACH); } - + /** * This method adds a shape3D to the main scene - * + * * @param s * The Shape to add */ - void add3DObject(Shape3D s) + void add3DObject(final Shape3D s) { bg.addChild(s); } - - void add2DText(TransformGroup tg) + + void add2DText(final TransformGroup tg) { bg.addChild(tg); } - + void insertBranch() { bg.compile(); scene.addChild(bg); } } - + class PanelLight extends JPanel { private static final long serialVersionUID = 1L; private JButton[] buttonLights; - private Viewer3D viewer3d; - - PanelLight(Viewer3D viewer3d) + private final Viewer3D viewer3d; + + PanelLight(final Viewer3D viewer3d) { this.viewer3d = viewer3d; initGui(); } - + private void initGui() { buttonLights = new JButton[4]; setLayout(new GridLayout(2, 2, 10, 10)); for (int i = 0; i < 4; i++) { - ImageIcon ilight = Utils.dimensionne_image("light" + i + ".png", viewer3d); + final ImageIcon ilight = Utils.dimensionne_image("light" + i + ".png", viewer3d); buttonLights[i] = new JButton(ilight); add(buttonLights[i]); buttonLights[i].addActionListener(viewer3d); @@ -450,44 +450,44 @@ public class Viewer3D extends JFrame implements ActionListener } setText(); } - + void setText() { - TitledBorder tb = BorderFactory.createTitledBorder(Logo.messages.getString("3d.light")); + final TitledBorder tb = BorderFactory.createTitledBorder(Logo.messages.getString("3d.light")); tb.setTitleFont(WSManager.getWorkspaceConfig().getFont()); setBorder(tb); } } - + class PanelFog extends JPanel { - + private static final long serialVersionUID = 1L; private JButton buttonFog; - private Viewer3D viewer3d; - - PanelFog(Viewer3D viewer3d) + private final Viewer3D viewer3d; + + PanelFog(final Viewer3D viewer3d) { this.viewer3d = viewer3d; initGui(); } - + private void initGui() { - ImageIcon ifog =Utils.dimensionne_image("fog.png", viewer3d); + final ImageIcon ifog =Utils.dimensionne_image("fog.png", viewer3d); buttonFog = new JButton(ifog); buttonFog.setActionCommand(Viewer3D.ACTION_FOG); buttonFog.addActionListener(viewer3d); add(buttonFog); setText(); } - + void setText() { - TitledBorder tb = BorderFactory.createTitledBorder(Logo.messages.getString("3d.fog")); + final TitledBorder tb = BorderFactory.createTitledBorder(Logo.messages.getString("3d.fog")); tb.setTitleFont(WSManager.getWorkspaceConfig().getFont()); setBorder(tb); } } - + } |