summaryrefslogtreecommitdiffstats
path: root/logo/src/xlogo/kernel/DrawPanel.java
diff options
context:
space:
mode:
Diffstat (limited to 'logo/src/xlogo/kernel/DrawPanel.java')
-rw-r--r--logo/src/xlogo/kernel/DrawPanel.java1166
1 files changed, 583 insertions, 583 deletions
diff --git a/logo/src/xlogo/kernel/DrawPanel.java b/logo/src/xlogo/kernel/DrawPanel.java
index 10e61ae..803baa8 100644
--- a/logo/src/xlogo/kernel/DrawPanel.java
+++ b/logo/src/xlogo/kernel/DrawPanel.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;
@@ -48,7 +48,7 @@ import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.Transparency;
-import javax.vecmath.Color3f;
+import org.jogamp.vecmath.Color3f;
import java.awt.FontMetrics;
import java.awt.Stroke;
@@ -71,7 +71,7 @@ import java.awt.image.CropImageFilter;
import java.awt.image.ReplicateScaleFilter;
import java.awt.image.FilteredImageSource;
-import com.sun.j3d.utils.geometry.Text2D;
+import org.jogamp.java3d.utils.geometry.Text2D;
import javax.swing.ImageIcon;
import javax.swing.SwingUtilities;
@@ -82,10 +82,10 @@ import java.math.BigDecimal;
import javax.swing.JPanel;
import javax.imageio.ImageIO;
-import javax.media.j3d.*;
-import javax.vecmath.Vector3d;
-import javax.vecmath.Matrix3d;
-import javax.vecmath.Point3d;
+import org.jogamp.java3d.*;
+import org.jogamp.vecmath.Vector3d;
+import org.jogamp.vecmath.Matrix3d;
+import org.jogamp.vecmath.Point3d;
import java.util.Stack;
import java.util.Set;
@@ -108,16 +108,16 @@ import xlogo.kernel.gui.*;
import xlogo.kernel.perspective.*;
/**
* Title : XLogo
- * Description : XLogo is an interpreter for the Logo
+ * Description : XLogo is an interpreter for the Logo
* programming language
* @author Loïc Le Coq
*/
public class DrawPanel extends JPanel implements MouseMotionListener,MouseListener {
- public static final LogoTypeNull nullType=new LogoTypeNull();
+ public static final LogoTypeNull nullType=new LogoTypeNull();
private static final long serialVersionUID = 1L;
public Turtle tortue;
- public Turtle[] tortues;
-
+ public Turtle[] tortues;
+
/**
* When a turtle is active on screen, its number is added to this stack
* @uml.property name="tortues_visibles"
@@ -146,7 +146,7 @@ import xlogo.kernel.perspective.*;
protected static final int WINDOW_CLOSE=2;
/**
* Perspective MODE <br>
- * The screen is a projection of the 3D universe
+ * The screen is a projection of the 3D universe
*/
protected static final int WINDOW_3D=3;
@@ -156,15 +156,15 @@ import xlogo.kernel.perspective.*;
public final static boolean MODE_ANIMATION=false;
/** Classic mode */
public final static boolean MODE_CLASSIC=true;
-
+
/**
- * default predefined colors
+ * default predefined colors
*/
public static final Color[] defaultColors={Color.BLACK,Color.RED,Color.GREEN,Color.YELLOW,Color.BLUE,
Color.MAGENTA,Color.CYAN,Color.WHITE,Color.GRAY,Color.LIGHT_GRAY,new Color(128,0,0),new Color(0,128,0),
new Color(0,0,128),new Color(255,128,0),Color.PINK,new Color(128,0,255),new Color(153,102,0)};
-
+
/**
* The id for the drawing font (with primitive label)
* @uml.property name="police_etiquette"
@@ -176,9 +176,9 @@ import xlogo.kernel.perspective.*;
*/
private Color couleurfond = Color.white;
private Shape shape=null;
- private Line2D line;
+ private Line2D line;
private Rectangle2D rec;
- private Application cadre;
+ private final Application cadre;
/** This Image is used for Buffering the drawing*/
public static BufferedImage dessin;
/**
@@ -189,22 +189,22 @@ import xlogo.kernel.perspective.*;
/** The scale for the zoom*/
public static double zoom=1;
-
+
/**
* All Gui Objects on the drawing area are stored in the GuiMap gm
* @uml.property name="gm"
* @uml.associationEnd multiplicity="(1 1)"
*/
- private GuiMap gm;
+ private final GuiMap gm;
/**
* The Stroke for the triangle turtle
* @uml.property name="crayon_triangle"
*/
- private BasicStroke crayon_triangle = new BasicStroke(1);
+ private final BasicStroke crayon_triangle = new BasicStroke(1);
/**
* Tools for 3D Mode
* @uml.property name="w3d"
- * @uml.associationEnd
+ * @uml.associationEnd
*/
private World3D w3d=null;
/**
@@ -216,7 +216,7 @@ import xlogo.kernel.perspective.*;
protected final static int record3D_LINE=2;
protected final static int record3D_POINT=3;
protected final static int record3D_TEXT=4;
-
+
/**
* Boolean that indicates if the interpreter is recording polygon in 2D Mode
*/
@@ -224,10 +224,10 @@ import xlogo.kernel.perspective.*;
private final static int record2D_NONE=0;
private final static int record2D_POLYGON=1;
private Vector<Point2D.Double> stackTriangle;
-
-
+
+
protected static Element3D poly;
-
+
private double[] coords;
private double oldx;
private double oldy;
@@ -250,11 +250,11 @@ import xlogo.kernel.perspective.*;
* @uml.property name="possouris"
*/
private String possouris="[ 0 0 ] "; // Coordonnées du point du dernier événement souris
-
+
/**
* Notify if a mouse event has occured
* @uml.property name="lissouris"
- */
+ */
private boolean lissouris=false; //Indique si un événement souris est intervenu depuis le debut du programme
/**
* The rectangular selection zone
@@ -271,7 +271,7 @@ import xlogo.kernel.perspective.*;
* @uml.property name="origine"
*/
Point origine;
- public DrawPanel(Application cadre){
+ public DrawPanel(final Application cadre){
this.gm= cadre.getKernel().getWorkspace().getGuiMap();
setLayout(null);
this.setPreferredSize(new Dimension(
@@ -286,54 +286,54 @@ import xlogo.kernel.perspective.*;
* This method is used to draw for primitive "forward"
* @param arg LogoType which represents the number of steps to move
*/
- protected LogoType av(LogoType number){
+ protected LogoType av(final LogoType number){
if (number.isException()) return number;
- LogoNumber ln=(LogoNumber)number;
+ final LogoNumber ln=(LogoNumber)number;
return av(ln.getValue());
-
+
}
/**
* This method is used to draw for primitive "backward"
* @param arg LogoType which represents the number of steps to move
*/
- protected LogoType re(LogoType number){
+ protected LogoType re(final LogoType number){
if (number.isException()) return number;
- LogoNumber ln=(LogoNumber)number;
+ final LogoNumber ln=(LogoNumber)number;
return av(-ln.getValue());
-
+
}
/**
* This method is used to draw for primitive "right"
* @param arg LogoType which represents the number of steps to rotate
*/
- protected LogoType td(LogoType number){
+ protected LogoType td(final LogoType number){
if (number.isException()) return number;
- LogoNumber ln=(LogoNumber)number;
+ final LogoNumber ln=(LogoNumber)number;
return td(ln.getValue());
-
+
} /**
* This method is used to draw for primitive "left"
* @param arg LogoType which represents the number of steps to rotate
*/
- protected LogoType tg(LogoType number){
+ protected LogoType tg(final LogoType number){
if (number.isException()) return number;
- LogoNumber ln=(LogoNumber)number;
+ final LogoNumber ln=(LogoNumber)number;
return td(-ln.getValue());
-
+
}
-
+
/**
* This method is used to draw for primitive "forward" and "backward"
* @param arg Number of steps
*/
- protected LogoType av(double arg) {
+ protected LogoType av(final double arg) {
// Graphics2D g=(Graphics2D)dessin.getGraphics();
-
+
oldx = tortue.corX;
oldy = tortue.corY;
if (DrawPanel.WINDOW_MODE == DrawPanel.WINDOW_CLASSIC) { //mode fenetre
montrecacheTortue(false);
-
+
tortue.corX = tortue.corX + arg
* Math.cos(tortue.angle);
tortue.corY = tortue.corY - arg
@@ -358,15 +358,15 @@ import xlogo.kernel.perspective.*;
}
else if (oldx==tortue.corX){
if (oldy<tortue.corY){
- x2=oldx;y2=oldy;x1=tortue.corX;y1=tortue.corY;
+ x2=oldx;y2=oldy;x1=tortue.corX;y1=tortue.corY;
}
- else{
+ else{
x1=oldx;y1=oldy;x2=tortue.corX;y2=tortue.corY;
}
}
-
+
line.setLine(x1,y1,x2,y2);
-
+
/*
// perpendicular vector
nx=y1-y2;
@@ -379,20 +379,20 @@ import xlogo.kernel.perspective.*;
gp.moveTo((float)(x1-vx*factor-nx*factor),
(float)(y1-vy*factor-ny*factor));
gp.lineTo((float)(x1-vx*factor+nx*factor),
- (float)(y1-vy*factor+ny*factor));
+ (float)(y1-vy*factor+ny*factor));
gp.lineTo((float)(x2+vx*factor+nx*factor),
(float)(y2+vy*factor+ny*factor));
gp.lineTo((float)(x2+vx*factor-nx*factor),
(float)(y2+vy*factor-ny*factor));
gp.lineTo((float)(x1-vx*factor-nx*factor),
- (float)(y1-vy*factor-ny*factor));
+ (float)(y1-vy*factor-ny*factor));
}
else{
float width=tortue.getPenWidth()+0.5f;
gp.moveTo((float)(x1-width),
(float)(y1-width));
gp.lineTo((float)(x1+width),
- (float)(y1-width));
+ (float)(y1-width));
gp.lineTo((float)(x1+width),
(float)(y1+width));
gp.lineTo((float)(x1-width),
@@ -401,12 +401,12 @@ import xlogo.kernel.perspective.*;
(float)(y1-width));
}
shape=gp;*/
- tryRecord2DMode(tortue.corX,tortue.corY);
+ tryRecord2DMode(tortue.corX,tortue.corY);
//g.draw(line);
- //if (!tortue.isVisible())
+ //if (!tortue.isVisible())
// clip();
//g.dispose();
-
+
for (int i = 0; i < 7; i++) {// TODO find other solution for this hack
g.draw(line);
clip();
@@ -418,7 +418,7 @@ import xlogo.kernel.perspective.*;
} else if (DrawPanel.WINDOW_MODE == DrawPanel.WINDOW_CLOSE) { //mode clos
try {
trace_ferme(oldx, oldy, arg);
- } catch (LogoError e) {
+ } catch (final LogoError e) {
}
}
else if (DrawPanel.WINDOW_MODE==DrawPanel.WINDOW_3D){
@@ -426,17 +426,17 @@ import xlogo.kernel.perspective.*;
tortue.X=tortue.X+arg*tortue.getRotationMatrix()[0][1];
tortue.Y=tortue.Y+arg*tortue.getRotationMatrix()[1][1];
tortue.Z=tortue.Z+arg*tortue.getRotationMatrix()[2][1];
-
+
double tmp[]=new double[3];
tmp[0]=tortue.X;
tmp[1]=tortue.Y;
tmp[2]=tortue.Z;
-
+
tmp=this.toScreenCoord(tmp,true);
tortue.corX = tmp[0];
tortue.corY = tmp[1];
-
+
if (tortue.isPenDown()) {
if (tortue.isPenReverse()) {
g.setColor(couleurfond);
@@ -455,15 +455,15 @@ import xlogo.kernel.perspective.*;
}
else if (oldx==tortue.corX){
if (oldy<tortue.corY){
- x2=oldx;y2=oldy;x1=tortue.corX;y1=tortue.corY;
+ x2=oldx;y2=oldy;x1=tortue.corX;y1=tortue.corY;
}
- else{
+ else{
x1=oldx;y1=oldy;x2=tortue.corX;y2=tortue.corY;
}
}
-
+
line.setLine(x1,y1,x2,y2);
-
+
g.draw(line);
g.draw(line);
g.draw(line);
@@ -478,7 +478,7 @@ import xlogo.kernel.perspective.*;
* This method is used for drawing with primitive "right" or "left"
* @param arg The angle to rotate
*/
- protected LogoType td(double arg) {
+ protected LogoType td(final double arg) {
// System.out.println(tortue.angle);
if (tortue.isVisible())
montrecacheTortue(false);
@@ -488,7 +488,7 @@ import xlogo.kernel.perspective.*;
}
else{
tortue.setRotationMatrix(w3d.multiply(tortue.getRotationMatrix(),w3d.rotationZ(-arg)));
- double[] tmp=w3d.rotationToEuler(tortue.getRotationMatrix());
+ final double[] tmp=w3d.rotationToEuler(tortue.getRotationMatrix());
tortue.heading=tmp[2];
tortue.roll=tmp[1];
tortue.pitch=tmp[0];
@@ -496,20 +496,20 @@ import xlogo.kernel.perspective.*;
if (tortue.isVisible())
montrecacheTortue(true);
Interprete.operande = false;
-
+
return DrawPanel.nullType;
}
/**
* This method is used for drawing with primitive "rightroll" or "leftroll"
* @param arg
*/
- protected void rightroll(double arg) {
+ protected void rightroll(final double arg) {
// System.out.println(tortue.angle);
if (tortue.isVisible())
montrecacheTortue(false);
if (enabled3D()){
tortue.setRotationMatrix(w3d.multiply(tortue.getRotationMatrix(),w3d.rotationY(-arg)));
- double[] tmp=w3d.rotationToEuler(tortue.getRotationMatrix());
+ final double[] tmp=w3d.rotationToEuler(tortue.getRotationMatrix());
tortue.heading=tmp[2];
tortue.roll=tmp[1];
tortue.pitch=tmp[0];
@@ -517,18 +517,18 @@ import xlogo.kernel.perspective.*;
if (tortue.isVisible())
montrecacheTortue(true);
Interprete.operande = false;
- }
+ }
/**
* This method is used for drawing with primitive "uppitch" or "downpitch"
* @param arg
*/
- protected void uppitch(double arg) {
+ protected void uppitch(final double arg) {
// System.out.println(tortue.angle);
if (tortue.isVisible())
montrecacheTortue(false);
if (enabled3D()){
tortue.setRotationMatrix(w3d.multiply(tortue.getRotationMatrix(),w3d.rotationX(arg)));
- double[] tmp=w3d.rotationToEuler(tortue.getRotationMatrix());
+ final double[] tmp=w3d.rotationToEuler(tortue.getRotationMatrix());
tortue.heading=tmp[2];
tortue.roll=tmp[1];
tortue.pitch=tmp[0];
@@ -539,9 +539,9 @@ import xlogo.kernel.perspective.*;
}
/**
* This method set the turtle's Roll
- * @param arg The new roll
+ * @param arg The new roll
*/
- protected void setRoll(double arg){
+ protected void setRoll(final double arg){
if (tortue.isVisible())
montrecacheTortue(false);
tortue.roll=arg;
@@ -552,9 +552,9 @@ import xlogo.kernel.perspective.*;
}
/**
* This method set the turtle's heading
- * @param arg The new heading
+ * @param arg The new heading
*/
- protected void setHeading(double arg){
+ protected void setHeading(final double arg){
if (tortue.isVisible())
montrecacheTortue(false);
tortue.heading=arg;
@@ -567,7 +567,7 @@ import xlogo.kernel.perspective.*;
* This method set the turtle's pitch
* @param arg The new pitch
*/
- protected void setPitch(double arg){
+ protected void setPitch(final double arg){
if (tortue.isVisible())
montrecacheTortue(false);
tortue.pitch=arg;
@@ -577,18 +577,18 @@ import xlogo.kernel.perspective.*;
Interprete.operande=false;
}
/**
- *
+ *
* This method set the turtle's orientation
* @param arg The new orientation
* @throws LogoError If the list doesn't contain three numbers
*/
- protected void setOrientation(String arg) throws LogoError{
+ protected void setOrientation(final String arg) throws LogoError{
initCoords();
if (tortue.isVisible())
montrecacheTortue(false);
- extractCoords(arg,Utils.primitiveName("3d.setorientation"));
+ extractCoords(arg,Utils.primitiveName("3d.setorientation"));
tortue.roll = coords[0];
- tortue.pitch = coords[1];
+ tortue.pitch = coords[1];
tortue.heading = coords[2];
tortue.setRotationMatrix(w3d.EulerToRotation(-tortue.roll, tortue.pitch, -tortue.heading));
if (tortue.isVisible())
@@ -603,7 +603,7 @@ import xlogo.kernel.perspective.*;
if (!enabled3D())
fpos("0 0");
else fpos("0 0 0");
- } catch (LogoError e) {
+ } catch (final LogoError e) {
}
if (tortue.isVisible())
montrecacheTortue(false);
@@ -611,24 +611,24 @@ import xlogo.kernel.perspective.*;
tortue.angle = Math.PI / 2;
tortue.roll=0;
tortue.pitch=0;
- if (enabled3D())
+ if (enabled3D())
tortue.setRotationMatrix(w3d.EulerToRotation(-tortue.roll, tortue.pitch, -tortue.heading));
if (tortue.isVisible())
montrecacheTortue(true);
}
-
-
+
+
/**
* Primitive distance
- * @param liste The coords
+ * @param liste The coords
* @param nom
* @return The distance from the turtle position to this point
* @throws LogoError If bad format list
*/
- protected double distance(String liste) throws LogoError {
-
+ protected double distance(final String liste) throws LogoError {
+
initCoords();
- extractCoords(liste,Utils.primitiveName("distance"));
+ extractCoords(liste,Utils.primitiveName("distance"));
double distance;
if (!enabled3D()){
coords=this.toScreenCoord(coords,false);
@@ -639,23 +639,23 @@ import xlogo.kernel.perspective.*;
+ Math.pow(tortue.Y - coords[1], 2)+Math.pow(tortue.Z - coords[2], 2));
return distance;
}
- protected double[] vers3D(String liste) throws LogoError{
- double[] tmp=new double [3];
+ protected double[] vers3D(final String liste) throws LogoError{
+ final double[] tmp=new double [3];
initCoords();
extractCoords(liste,Utils.primitiveName("vers"));
tmp[0]=coords[0]-tortue.X;
tmp[1]=coords[1]-tortue.Y;
tmp[2]=coords[2]-tortue.Z;
- double length=Math.sqrt(Math.pow(tmp[0],2)+Math.pow(tmp[1],2)+Math.pow(tmp[2],2));
+ final double length=Math.sqrt(Math.pow(tmp[0],2)+Math.pow(tmp[1],2)+Math.pow(tmp[2],2));
if (length==0) return tmp;
tmp[0]=tmp[0]/length;
tmp[1]=tmp[1]/length;
tmp[2]=tmp[2]/length;
- double heading=Math.acos(tmp[1]);
- double f=Math.sin(heading);
- double tr_x=-tmp[0]/f;
- double tr_y=-tmp[2]/f;
- double roll=Math.atan2(tr_y, tr_x);
+ final double heading=Math.acos(tmp[1]);
+ final double f=Math.sin(heading);
+ final double tr_x=-tmp[0]/f;
+ final double tr_y=-tmp[2]/f;
+ final double roll=Math.atan2(tr_y, tr_x);
tmp[0]=-Math.toDegrees(roll);
tmp[1]=0;
tmp[2]=-Math.toDegrees(heading);
@@ -664,16 +664,16 @@ import xlogo.kernel.perspective.*;
}
return tmp;
}
-
+
/**
- * Primitive towards in 2D MODE
+ * Primitive towards in 2D MODE
* @param liste the coordinate for the point
- * @return the rotation angle
+ * @return the rotation angle
* @throws LogoError if Bad format List
*/
- protected double vers2D(String liste) throws LogoError{
+ protected double vers2D(final String liste) throws LogoError{
initCoords();
- extractCoords(liste,Utils.primitiveName("vers"));
+ extractCoords(liste,Utils.primitiveName("vers"));
double angle;
coords=this.toScreenCoord(coords, false);
if (tortue.corY == coords[1]) {
@@ -683,13 +683,13 @@ import xlogo.kernel.perspective.*;
angle = 0;
else
angle = 270;
- }
+ }
else if (tortue.corX == coords[0]) {
if (tortue.corY > coords[1])
angle = 0;
else
angle = 180;
- }
+ }
else {
angle = Math.toDegrees(Math.atan(Math
.abs(coords[0] - tortue.corX)
@@ -702,22 +702,22 @@ import xlogo.kernel.perspective.*;
else if (coords[0] < tortue.corX && coords[1] < tortue.corY)
angle = 360 - angle; // 4eme quadrant
}
- return angle;
+ return angle;
}
/**
* Draw with the primitive "setposition" in 2D mode or 3D
* @param liste The list with the coordinates to move
* @throws LogoError If the coordinates are invalid
*/
- protected void fpos(String liste) throws LogoError {
+ protected void fpos(final String liste) throws LogoError {
initCoords();
oldx = tortue.corX;
oldy = tortue.corY;
- extractCoords(liste,Utils.primitiveName("drawing.fpos"));
+ extractCoords(liste,Utils.primitiveName("drawing.fpos"));
montrecacheTortue(false);
if (enabled3D()) {
tortue.X = coords[0];
- tortue.Y = coords[1];
+ tortue.Y = coords[1];
tortue.Z = coords[2];
}
coords=toScreenCoord(coords,true);
@@ -741,9 +741,9 @@ import xlogo.kernel.perspective.*;
}
else if (oldx==tortue.corX){
if (oldy<tortue.corY){
- x2=oldx;y2=oldy;x1=tortue.corX;y1=tortue.corY;
+ x2=oldx;y2=oldy;x1=tortue.corX;y1=tortue.corY;
}
- else{
+ else{
x1=oldx;y1=oldy;x2=tortue.corX;y2=tortue.corY;
}
}
@@ -754,9 +754,9 @@ import xlogo.kernel.perspective.*;
}
montrecacheTortue(true);
}
- public void drawEllipseArc(double xAxis,double yAxis, double angleRotation,double xCenter,double yCenter, double angleStart, double angleExtent){
+ public void drawEllipseArc(final double xAxis,final double yAxis, final double angleRotation,final double xCenter,final double yCenter, final double angleStart, final double angleExtent){
montrecacheTortue(false);
- arc=new Arc2D.Double(-xAxis,-yAxis,2*xAxis,2*yAxis,angleStart,angleExtent,Arc2D.Double.OPEN);
+ arc=new Arc2D.Double(-xAxis,-yAxis,2*xAxis,2*yAxis,angleStart,angleExtent,Arc2D.OPEN);
if (tortue.isPenReverse()) {
g.setColor(couleurfond);
g.setXORMode(tortue.couleurcrayon);
@@ -764,8 +764,8 @@ import xlogo.kernel.perspective.*;
g.setColor(tortue.couleurcrayon);
g.setPaintMode();
}
- double tmpx=WSManager.getUserConfig().getImageWidth()/2+xCenter;
- double tmpy=WSManager.getUserConfig().getImageHeight()/2-yCenter;
+ final double tmpx=WSManager.getUserConfig().getImageWidth()/2+xCenter;
+ final double tmpy=WSManager.getUserConfig().getImageHeight()/2-yCenter;
g.translate(tmpx, tmpy);
g.rotate(-angleRotation);
g.draw(arc);
@@ -782,11 +782,11 @@ import xlogo.kernel.perspective.*;
* @param rayon The radius
* @param pangle Starting angle
* @param fangle End angle
- * @throws LogoError
+ * @throws LogoError
*/
- protected void arc(double rayon, double pangle, double fangle) throws LogoError {
+ protected void arc(final double rayon, double pangle, double fangle) throws LogoError {
// Put fangle and pangle between 0 and 360
- fangle = ((90 - fangle) % 360);
+ fangle = ((90 - fangle) % 360);
pangle = ((90 - pangle) % 360);
if (fangle<0) fangle+=360;
if (pangle<0) pangle+=360;
@@ -796,7 +796,7 @@ import xlogo.kernel.perspective.*;
montrecacheTortue(false);
if (null==arc) arc=new Arc2D.Double();
if (!enabled3D()){
- if (DrawPanel.WINDOW_MODE==DrawPanel.WINDOW_WRAP) centers=new Vector<Point2D.Double>();
+ if (DrawPanel.WINDOW_MODE==DrawPanel.WINDOW_WRAP) centers=new Vector<Point2D.Double>();
arc2D(tortue.corX,tortue.corY,rayon,fangle,angle);
/* if (null==gp) gp=new GeneralPath();
@@ -816,14 +816,14 @@ import xlogo.kernel.perspective.*;
tortue.corY-rayon-tortue.getPenWidth(),
2*(rayon+tortue.getPenWidth()),2*(rayon+tortue.getPenWidth()));*/
clip();
-
+
}
else{
arcCircle3D(rayon,fangle,angle);
}
- montrecacheTortue(true);
+ montrecacheTortue(true);
}
- private void arc2D(double x, double y, double radius,double fangle, double angle){
+ private void arc2D(final double x, final double y, final double radius,final double fangle, final double angle){
arc.setArcByCenter(x,y,radius,
fangle,angle, Arc2D.OPEN);
if (tortue.isPenReverse()) {
@@ -835,11 +835,11 @@ import xlogo.kernel.perspective.*;
}
g.draw(arc);
clip();
-
- UserConfig uc = WSManager.getUserConfig();
- int w = uc.getImageWidth();
- int h = uc.getImageHeight();
-
+
+ final UserConfig uc = WSManager.getUserConfig();
+ final int w = uc.getImageWidth();
+ final int h = uc.getImageHeight();
+
if (DrawPanel.WINDOW_MODE==DrawPanel.WINDOW_WRAP){
if (x+radius>w&& x<=w){
pt=new Point2D.Double(-w+x,y);
@@ -871,13 +871,13 @@ import xlogo.kernel.perspective.*;
}
}
}
-
-
- private void arcCircle3D(double radius,double angleStart,double angleExtent) throws LogoError{
+
+
+ private void arcCircle3D(final double radius,final double angleStart,final double angleExtent) throws LogoError{
if (null==arc) arc=new Arc2D.Double();
arc.setArcByCenter(0,0,radius,
angleStart,angleExtent, Arc2D.OPEN);
- Shape s=transformShape(arc);
+ final Shape s=transformShape(arc);
if (tortue.isPenReverse()) {
g.setColor(couleurfond);
g.setXORMode(tortue.couleurcrayon);
@@ -890,25 +890,25 @@ import xlogo.kernel.perspective.*;
recordArcCircle3D(radius,angleStart,angleExtent);
}
}
-
-
+
+
/**
- *
- * returns the color for the pixel "ob"
+ *
+ * returns the color for the pixel "ob"
* @param liste: The list containing the coordinates of the pixel
* @return Color of this pixel
- * @throws LogoError If the list doesn't contain coordinates
+ * @throws LogoError If the list doesn't contain coordinates
*/
- protected Color guessColorPoint(String liste) throws LogoError {
- UserConfig uc = WSManager.getUserConfig();
- int w = uc.getImageWidth();
- int h = uc.getImageHeight();
+ protected Color guessColorPoint(final String liste) throws LogoError {
+ final UserConfig uc = WSManager.getUserConfig();
+ final int w = uc.getImageWidth();
+ final int h = uc.getImageHeight();
initCoords();
extractCoords(liste,Utils.primitiveName("tc"));
coords=toScreenCoord(coords,false);
int couleur = -1;
- int x=(int)coords[0];
- int y=(int)coords[1];
+ final int x=(int)coords[0];
+ final int y=(int)coords[1];
if (0 < x && x < w && 0 < y && y < h) {
couleur = DrawPanel.dessin.getRGB(x, y);
}
@@ -917,26 +917,26 @@ import xlogo.kernel.perspective.*;
/**
* This method draw a circle from the turtle position on the drawing area
* @param radius The radius of the circle
- * @throws LogoError
+ * @throws LogoError
*/
- protected void circle(double radius) throws LogoError {
+ protected void circle(final double radius) throws LogoError {
montrecacheTortue(false);
if (null==arc) arc=new Arc2D.Double();
if (!enabled3D()){
- if (DrawPanel.WINDOW_MODE==DrawPanel.WINDOW_WRAP) centers=new Vector<Point2D.Double>();
+ if (DrawPanel.WINDOW_MODE==DrawPanel.WINDOW_WRAP) centers=new Vector<Point2D.Double>();
circle2D(tortue.corX,tortue.corY,radius);
/* if (null==clipArc) clipArc=new Arc2D.Double();
clipArc.setArcByCenter(tortue.corX,tortue.corY,
rayon+2+tortue.getPenWidth(),0,360, Arc2D.OPEN);*/
}
- else{
+ else{
circle3D(radius);
}
montrecacheTortue(true); // on efface la tortue si elle st visible
}
/**
* This method draws a circle in 2D mode in WRAP mode, makes recursion to draw all circle part on the screen
- * @param x x circle center
+ * @param x x circle center
* @param y y circle center
* @param circle radius
* @uml.property name="pt"
@@ -946,14 +946,14 @@ import xlogo.kernel.perspective.*;
* @uml.property name="centers"
*/
private Vector <Point2D.Double> centers;
- private void circle2D(double x,double y, double radius){
- UserConfig uc = WSManager.getUserConfig();
- int w = uc.getImageWidth();
- int h = uc.getImageHeight();
-
+ private void circle2D(final double x,final double y, final double radius){
+ final UserConfig uc = WSManager.getUserConfig();
+ final int w = uc.getImageWidth();
+ final int h = uc.getImageHeight();
+
arc.setArcByCenter(x,y,radius,
0,360, Arc2D.OPEN);
-
+
if (tortue.isPenReverse()) {
g.setColor(couleurfond);
g.setXORMode(tortue.couleurcrayon);
@@ -992,18 +992,18 @@ import xlogo.kernel.perspective.*;
circle2D(x,-h+y,radius);
}
}
- }
+ }
}
-
+
/**
* used for drawing with primitive "dot"
* @param liste The list with the dot coordinates
* @throws LogoError If the list is invalid coordinates
*/
- protected void point(String liste) throws LogoError {
- UserConfig uc = WSManager.getUserConfig();
- int w = uc.getImageWidth();
- int h = uc.getImageHeight();
+ protected void point(final String liste) throws LogoError {
+ final UserConfig uc = WSManager.getUserConfig();
+ final int w = uc.getImageWidth();
+ final int h = uc.getImageHeight();
initCoords();
extractCoords(liste,Utils.primitiveName("drawing.point"));
coords=toScreenCoord(coords,true);
@@ -1012,32 +1012,32 @@ import xlogo.kernel.perspective.*;
if (tortue.isPenReverse()) {
g.setColor(couleurfond);
g.setXORMode(tortue.couleurcrayon);
-
+
} else {
g.setColor(tortue.couleurcrayon);
g.setPaintMode();
- }
+ }
if (rec==null) rec=new Rectangle2D.Double();
// High quality
if (uc.getQuality()==DrawQuality.HIGH){
- double width=tortue.getPenWidth();
+ final double width=tortue.getPenWidth();
rec.setRect(coords[0]-width+0.5,coords[1]-width+0.5,
2*width,2*width);
}
// Normal or Low Quality
else{
// penWidth is 2k or 2k+1??
- int intWidth=(int)(2*tortue.getPenWidth()+0.5);
+ final int intWidth=(int)(2*tortue.getPenWidth()+0.5);
if (intWidth%2==1){
- double width=tortue.getPenWidth()-0.5;
+ final double width=tortue.getPenWidth()-0.5;
// System.out.println(coords[0]+" "+coords[1]);
rec.setRect(coords[0]-width,coords[1]-width,
2*width+1,2*width+1);
}
else {
- double width=tortue.getPenWidth();
+ final double width=tortue.getPenWidth();
rec.setRect(coords[0]-width,coords[1]-width,
- 2*width,2*width);
+ 2*width,2*width);
}
}
if (uc.getPenShape()==PenShape.SQUARE){ // MAKE ENUM
@@ -1051,22 +1051,22 @@ import xlogo.kernel.perspective.*;
clip();
}
}
-
-
-
+
+
+
/**
- * @throws LogoError
- *
+ * @throws LogoError
+ *
*/
- private void circle3D(double radius) throws LogoError{
-
+ private void circle3D(final double radius) throws LogoError{
+
// In camera world,
// the circle is the intersection of
// - a plane with the following equation: ax+by+cz+d=0 <-> f(x,y,z)=0
// - and a sphere with the following equation: (x-tx)^2+(y-ty)^2+(z-tz)^2=R^2 <-> g(x,y,z)=0
// I found the cone equation resolving f(x/lambda,y/lambda,z/lambda)=0=g(x/lambda,y/lambda,z/lambda)
-
- double[] v=new double[3];
+
+ final double[] v=new double[3];
for(int i=0;i<3;i++){
v[i]=tortue.getRotationMatrix()[i][2];
}
@@ -1075,42 +1075,42 @@ import xlogo.kernel.perspective.*;
v[2]+=w3d.zCamera;
w3d.toCameraWorld(v);
// Now v contains coordinates of a normal vector to the plane in camera world coordinates
- double a=v[0];
- double b=v[1];
- double c=v[2];
-
+ final double a=v[0];
+ final double b=v[1];
+ final double c=v[2];
+
// We convert the turtle coordinates
v[0]=tortue.X;
v[1]=tortue.Y;
v[2]=tortue.Z;
w3d.toCameraWorld(v);
-
- double x=v[0];
- double y=v[1];
- double z=v[2];
+
+ final double x=v[0];
+ final double y=v[1];
+ final double z=v[2];
// We calculate the number d for the plane equation
- double d=-a*x-b*y-c*z;
-
+ final double d=-a*x-b*y-c*z;
+
// We have to work with Bigdecimal because of precision problems
-
- BigDecimal[] big=new BigDecimal[6];
- BigDecimal bx=new BigDecimal(x);
- BigDecimal by=new BigDecimal(y);
- BigDecimal bz=new BigDecimal(z);
- BigDecimal ba=new BigDecimal(a);
- BigDecimal bb=new BigDecimal(b);
- BigDecimal bc=new BigDecimal(c);
- BigDecimal bd=new BigDecimal(d);
- BigDecimal deux=new BigDecimal("2");
- BigDecimal screenDistance=new BigDecimal(w3d.screenDistance);
- BigDecimal bradius=new BigDecimal(String.valueOf(radius));
-
+
+ final BigDecimal[] big=new BigDecimal[6];
+ final BigDecimal bx=new BigDecimal(x);
+ final BigDecimal by=new BigDecimal(y);
+ final BigDecimal bz=new BigDecimal(z);
+ final BigDecimal ba=new BigDecimal(a);
+ final BigDecimal bb=new BigDecimal(b);
+ final BigDecimal bc=new BigDecimal(c);
+ final BigDecimal bd=new BigDecimal(d);
+ final BigDecimal deux=new BigDecimal("2");
+ final BigDecimal screenDistance=new BigDecimal(w3d.screenDistance);
+ final BigDecimal bradius=new BigDecimal(String.valueOf(radius));
+
// Now we calculate the coefficient for the conic ax^2+bxy+cy^2+dx+ey+f=0
// Saved in an array
-
+
// lambda=(x*x+y*y+z*z-radius*radius);
- BigDecimal lambda=bx.pow(2).add(by.pow(2)).add(bz.pow(2)).subtract(bradius.pow(2));
-
+ final BigDecimal lambda=bx.pow(2).add(by.pow(2)).add(bz.pow(2)).subtract(bradius.pow(2));
+
// x^2 coeff
// d*d+2*d*x*a+a*a*lambda;
big[0]=bd.pow(2).add(bd.multiply(bx).multiply(ba).multiply(deux)).add(ba.pow(2).multiply(lambda));
@@ -1135,25 +1135,25 @@ import xlogo.kernel.perspective.*;
}
}
/**
- * This method records this circle in the polygon's List
+ * This method records this circle in the polygon's List
* @param radius The circle's radius
* @param angleStart The starting Angle
* @param angleExtent The angle for the sector
- * @throws LogoError
+ * @throws LogoError
*/
- public void recordArcCircle3D(double radius,double angleStart,double angleExtent) throws LogoError{
- double[][] d=tortue.getRotationMatrix();
- Matrix3d m=new Matrix3d(d[0][0],d[0][1],d[0][2],d[1][0],d[1][1],d[1][2],d[2][0],d[2][1],d[2][2]);
+ public void recordArcCircle3D(final double radius,final double angleStart,final double angleExtent) throws LogoError{
+ final double[][] d=tortue.getRotationMatrix();
+ final Matrix3d m=new Matrix3d(d[0][0],d[0][1],d[0][2],d[1][0],d[1][1],d[1][2],d[2][0],d[2][1],d[2][2]);
// Vector X
- Point3d v1=new Point3d(radius/1000,0,0);
- Transform3D t=new Transform3D(m,new Vector3d(),1);
+ final Point3d v1=new Point3d(radius/1000,0,0);
+ final Transform3D t=new Transform3D(m,new Vector3d(),1);
t.transform(v1);
// Vector Y
- Point3d v2=new Point3d(0,radius/1000,0);
+ final Point3d v2=new Point3d(0,radius/1000,0);
t.transform(v2);
// Turtle position
- Point3d pos=new Point3d(tortue.X/1000,tortue.Y/1000,tortue.Z/1000);
+ final Point3d pos=new Point3d(tortue.X/1000,tortue.Y/1000,tortue.Z/1000);
int indexMax=(int)angleExtent;
if (indexMax!=angleExtent) indexMax+=2;
else indexMax+=1;
@@ -1168,28 +1168,28 @@ import xlogo.kernel.perspective.*;
}
for(int i=0;i<indexMax-1;i++){
- Point3d tmp1=new Point3d(v1);
+ final Point3d tmp1=new Point3d(v1);
tmp1.scale(Math.cos(Math.toRadians(angleStart+i)));
- Point3d tmp2=new Point3d(v2);
- tmp2.scale(Math.sin(Math.toRadians(angleStart+i)));
+ final Point3d tmp2=new Point3d(v2);
+ tmp2.scale(Math.sin(Math.toRadians(angleStart+i)));
tmp1.add(tmp2);
tmp1.add(pos);
DrawPanel.poly.addVertex(tmp1, tortue.couleurcrayon);
}
- Point3d tmp1=new Point3d(v1);
+ final Point3d tmp1=new Point3d(v1);
tmp1.scale(Math.cos(Math.toRadians(angleStart+angleExtent)));
- Point3d tmp2=new Point3d(v2);
- tmp2.scale(Math.sin(Math.toRadians(angleStart+angleExtent)));
+ final Point3d tmp2=new Point3d(v2);
+ tmp2.scale(Math.sin(Math.toRadians(angleStart+angleExtent)));
tmp1.add(tmp2);
tmp1.add(pos);
DrawPanel.poly.addVertex(tmp1, tortue.couleurcrayon);
}
-
+
/**
- * Load an image and draw it on the drawing area
+ * Load an image and draw it on the drawing area
* @param image The image to draw
*/
- protected void chargeimage(BufferedImage image) {
+ protected void chargeimage(final BufferedImage image) {
if (tortue.isVisible())
montrecacheTortue(false);
g.setPaintMode();
@@ -1215,17 +1215,17 @@ import xlogo.kernel.perspective.*;
* @param oldy The Y turtle location
* @return the number of steps (Recursive dichotomy)
*/
- private double trouve_longueur(double mini, double maxi, double oldx, double oldy) {
- UserConfig uc = WSManager.getUserConfig();
- int w = uc.getImageWidth();
- int h = uc.getImageHeight();
+ private double trouve_longueur(final double mini, final double maxi, final double oldx, final double oldy) {
+ final UserConfig uc = WSManager.getUserConfig();
+ final int w = uc.getImageWidth();
+ final int h = uc.getImageHeight();
// renvoie la longueur dont on peut encore avancer
if (Math.abs(maxi - mini) < 0.5){
return (mini);}
else {
- double milieu = (mini + maxi) / 2;
- double nx = oldx + milieu * Math.cos(tortue.angle);
- double ny = oldy - milieu * Math.sin(tortue.angle);
+ final double milieu = (mini + maxi) / 2;
+ final double nx = oldx + milieu * Math.cos(tortue.angle);
+ final double ny = oldy - milieu * Math.sin(tortue.angle);
if (nx < 0 || nx > w|| ny < 0 || ny > h)
return trouve_longueur(mini, milieu, oldx, oldy);
else
@@ -1238,16 +1238,16 @@ import xlogo.kernel.perspective.*;
* @param oldx X position
* @param oldy Y position
*/
- private void trace_enroule(double arg, double oldx, double oldy) {
- UserConfig uc = WSManager.getUserConfig();
- int w = uc.getImageWidth();
- int h = uc.getImageHeight();
-
+ private void trace_enroule(double arg, final double oldx, final double oldy) {
+ final UserConfig uc = WSManager.getUserConfig();
+ final int w = uc.getImageWidth();
+ final int h = uc.getImageHeight();
+
boolean re = false;
if (arg < 0) {
re = true;
}
- double diagonale=Math.sqrt(Math.pow(w,2)+Math.pow(h,2))+1;
+ final double diagonale=Math.sqrt(Math.pow(w,2)+Math.pow(h,2))+1;
double longueur;
if (re)
longueur = trouve_longueur(0, -diagonale, oldx, oldy);
@@ -1266,7 +1266,7 @@ import xlogo.kernel.perspective.*;
if (uc.getTurtleSpeed() != 0) {
try {
Thread.sleep(uc.getTurtleSpeed() * 5);
- } catch (InterruptedException e) {
+ } catch (final InterruptedException e) {
}
}
if (tortue.isVisible())
@@ -1315,14 +1315,14 @@ import xlogo.kernel.perspective.*;
* @param arg The length to forward
* @throws LogoError
*/
- private void trace_ferme(double oldx, double oldy, double arg) throws LogoError {
- UserConfig uc = WSManager.getUserConfig();
- int w = uc.getImageWidth();
- int h = uc.getImageHeight();
-
+ private void trace_ferme(final double oldx, final double oldy, final double arg) throws LogoError {
+ final UserConfig uc = WSManager.getUserConfig();
+ final int w = uc.getImageWidth();
+ final int h = uc.getImageHeight();
+
boolean re = false;
double longueur;
- double diagonale=Math.sqrt(Math.pow(w,2)+Math.pow(h,2))+1;
+ final double diagonale=Math.sqrt(Math.pow(w,2)+Math.pow(h,2))+1;
if (arg < 0)
re = true;
if (re)
@@ -1348,9 +1348,9 @@ import xlogo.kernel.perspective.*;
* @param prim The calling primitive
* @throws LogoError If List isn't a list coordinate
*/
-
- private void extractCoords(String liste,String prim)throws LogoError{
- StringTokenizer st = new StringTokenizer(liste);
+
+ private void extractCoords(final String liste,final String prim)throws LogoError{
+ final StringTokenizer st = new StringTokenizer(liste);
try {
for(int i=0;i<coords.length;i++){
coords[i]=1;
@@ -1366,8 +1366,8 @@ import xlogo.kernel.perspective.*;
}
coords[i] = coords[i] * Double.parseDouble(element);
}
-
- } catch (NumberFormatException e) {
+
+ } catch (final NumberFormatException e) {
throw new LogoError(prim
+ " " + Logo.messages.getString("n_aime_pas") + liste
+ Logo.messages.getString("comme_parametre"));
@@ -1378,11 +1378,11 @@ import xlogo.kernel.perspective.*;
+ Logo.messages.getString("comme_parametre"));
}
/**
- * This method sets the drawing area to perspective mode
+ * This method sets the drawing area to perspective mode
*/
-
+
protected void perspective(){
- UserConfig uc = WSManager.getUserConfig();
+ final UserConfig uc = WSManager.getUserConfig();
if (!enabled3D()) {
uc.setDrawXAxis(false);
uc.setDrawYAxis(false);
@@ -1391,14 +1391,14 @@ import xlogo.kernel.perspective.*;
montrecacheTortue(false);
DrawPanel.WINDOW_MODE=DrawPanel.WINDOW_3D;
w3d=new World3D();
- montrecacheTortue(true);
+ montrecacheTortue(true);
}
}
/**
* This method sets the drawing area to Wrap, Close or Window mode
* @param id The window Mode
*/
- protected void setWindowMode(int id){
+ protected void setWindowMode(final int id){
if (DrawPanel.WINDOW_MODE!=id) {
montrecacheTortue(false);
DrawPanel.WINDOW_MODE=id;
@@ -1406,52 +1406,52 @@ import xlogo.kernel.perspective.*;
montrecacheTortue(true);
}
}
-
-
+
+
/**
* This method converts the coordinates contained in "coords" towards the coords on the drawing area
*/
- double[] toScreenCoord(double[] coord,boolean drawPoly){
+ double[] toScreenCoord(final double[] coord,final boolean drawPoly){
// If Mode perspective is active
if (enabled3D()){
- // w3d.toScreenCoord(coord);
+ // w3d.toScreenCoord(coord);
// camera world
// If we have to record the polygon coordinates
if (DrawPanel.record3D!=DrawPanel.record3D_NONE&&DrawPanel.record3D!=DrawPanel.record3D_TEXT&&drawPoly){
-
+
DrawPanel.poly.addVertex(new Point3d(coord[0]/1000,coord[1]/1000,coord[2]/1000),tortue.couleurcrayon);
- }
-
+ }
+
w3d.toCameraWorld(coord);
-
+
// Convert to screen Coordinates
- w3d.cameraToScreen(coord);
+ w3d.cameraToScreen(coord);
}
// Mode2D
else {
- UserConfig uc = WSManager.getUserConfig();
- int w = uc.getImageWidth();
- int h = uc.getImageHeight();
+ final UserConfig uc = WSManager.getUserConfig();
+ final int w = uc.getImageWidth();
+ final int h = uc.getImageHeight();
coord[0]=w/2+coord[0];
coord[1]=h/2-coord[1];
}
return coord;
}
-
-
+
+
/**
* This method creates an instance of coord with the valid size:<br>
* size 2 for 2D coordinates<br>
* size 3 for 3D coordinates
*/
-
+
private void initCoords(){
if (null==coords) coords=new double[2];
if (enabled3D()){
if (coords.length!=3) coords=new double[3];
- }
+ }
else {
if (coords.length!=2) coords=new double[2];
}
@@ -1468,7 +1468,7 @@ import xlogo.kernel.perspective.*;
g.setXORMode(couleurfond);
g.setColor(tortue.couleurcrayon);
tortue.drawTriangle();
- BasicStroke crayon_actuel = (BasicStroke) g.getStroke();
+ final BasicStroke crayon_actuel = (BasicStroke) g.getStroke();
if (crayon_actuel.getLineWidth() == 1)
g.draw(tortue.triangle);
else {
@@ -1478,10 +1478,10 @@ import xlogo.kernel.perspective.*;
}
} else {
g.setXORMode(couleurfond);
- double angle = Math.PI / 2 - tortue.angle;
- float x = (float) (tortue.corX * Math.cos(angle) + tortue.corY
+ final double angle = Math.PI / 2 - tortue.angle;
+ final float x = (float) (tortue.corX * Math.cos(angle) + tortue.corY
* Math.sin(angle));
- float y = (float) (-tortue.corX * Math.sin(angle) + tortue.corY
+ final float y = (float) (-tortue.corX * Math.sin(angle) + tortue.corY
* Math.cos(angle));
g.rotate(angle);
g.drawImage(tortue.tort, (int) x - tortue.largeur / 2,
@@ -1495,25 +1495,25 @@ import xlogo.kernel.perspective.*;
tortue.gabarit * 2);
*/
clip();
-
+
/* clip((int) (tortue.corX - tortue.gabarit),
(int) (tortue.corY - tortue.gabarit),
tortue.gabarit * 2, tortue.gabarit * 2);*/
}
/**
* When the turtle has to be redrawn, this method erase the turtle on the drawing screen
- *
+ *
*/
- protected void montrecacheTortue(boolean b) {
+ protected void montrecacheTortue(final boolean b) {
g.setColor(couleurfond);
for (int i = 0; i < tortues_visibles.size(); i++) {
- int id = Integer.parseInt(tortues_visibles.get(i));
+ final int id = Integer.parseInt(tortues_visibles.get(i));
// Turtle triangle
if (null == tortues[id].tort) {
g.setXORMode(couleurfond);
g.setColor(tortues[id].couleurmodedessin);
tortues[id].drawTriangle();
- BasicStroke crayon_actuel = (BasicStroke) g.getStroke();
+ final BasicStroke crayon_actuel = (BasicStroke) g.getStroke();
if (crayon_actuel.getLineWidth() == 1)
g.draw(tortues[id].triangle);
else {
@@ -1524,10 +1524,10 @@ import xlogo.kernel.perspective.*;
} else {
// Image turtle
g.setXORMode(couleurfond);
- double angle = Math.PI / 2 - tortues[id].angle;
- float x = (float) (tortues[id].corX * Math.cos(angle) + tortues[id].corY
+ final double angle = Math.PI / 2 - tortues[id].angle;
+ final float x = (float) (tortues[id].corX * Math.cos(angle) + tortues[id].corY
* Math.sin(angle));
- float y = (float) (-tortues[id].corX * Math.sin(angle) + tortues[id].corY
+ final float y = (float) (-tortues[id].corX * Math.sin(angle) + tortues[id].corY
* Math.cos(angle));
g.rotate(angle);
g.drawImage(tortues[id].tort, (int) x
@@ -1544,9 +1544,9 @@ import xlogo.kernel.perspective.*;
if (b) clip();
}
}
-
-
-
+
+
+
/* private void montrecacheTortue() {
// Graphics2D g=(Graphics2D)dessin.getGraphics();
g.setColor(couleurfond);
@@ -1584,7 +1584,7 @@ import xlogo.kernel.perspective.*;
tortues[id].corY - tortues[id].gabarit,
tortues[id].gabarit * 2,
tortues[id].gabarit * 2);
-
+
clip();
// g.dispose();
}
@@ -1595,10 +1595,10 @@ import xlogo.kernel.perspective.*;
*/
protected void videecran() {
// Delete all Gui Component
- Set<String> set=gm.keySet();
- Iterator<String> it=set.iterator();
+ final Set<String> set=gm.keySet();
+ final Iterator<String> it=set.iterator();
while(it.hasNext()){
- String element=it.next();
+ final String element=it.next();
gui=gm.get(element).getGuiObject();
it.remove();
if (SwingUtilities.isEventDispatchThread()){
@@ -1610,15 +1610,15 @@ import xlogo.kernel.perspective.*;
SwingUtilities.invokeAndWait(new Runnable(){
public void run(){
remove(gui);
- validate();
+ validate();
}
});
}
- catch(Exception e){}
+ catch(final Exception e){}
}
}
-
-
+
+
// Delete List Polygon in 3D mode
// DrawPanel.listPoly=new Vector<Shape3D>();
// DrawPanel.listText=new Vector<TransformGroup>();
@@ -1627,18 +1627,18 @@ import xlogo.kernel.perspective.*;
cadre.getViewer3D().clearScreen();
System.gc();
}
-
- UserConfig uc = WSManager.getUserConfig();
- int w = uc.getImageWidth();
- int h = uc.getImageHeight();
-
+
+ final UserConfig uc = WSManager.getUserConfig();
+ final int w = uc.getImageWidth();
+ final int h = uc.getImageHeight();
+
g.setPaintMode();
couleurfond=uc.getScreencolor();
g.setColor(uc.getScreencolor());
g.fillRect(0, 0, w,h);
stopRecord2DPolygon();
-
- // Draw Grid
+
+ // Draw Grid
g.setStroke(new BasicStroke(1));
drawGrid();
drawXAxis();
@@ -1647,10 +1647,10 @@ import xlogo.kernel.perspective.*;
if (null == tortues[0])
tortues[0] = new Turtle(cadre);
// The active turtle will be the turtle 0
- tortue = tortues[0];
+ tortue = tortues[0];
tortue.id = 0;
// We delete all other turtles
- for (int i = 1; i < tortues.length; i++) {
+ for (int i = 1; i < tortues.length; i++) {
tortues[i] = null;
}
tortues_visibles.removeAllElements();
@@ -1663,16 +1663,16 @@ import xlogo.kernel.perspective.*;
montrecacheTortue(true);
// Update the selection frame
updateColorSelection();
-
+
}
/**
* Primitive wash
*/
protected void nettoie() {
- UserConfig uc = WSManager.getUserConfig();
- int w = uc.getImageWidth();
- int h = uc.getImageHeight();
-
+ final UserConfig uc = WSManager.getUserConfig();
+ final int w = uc.getImageWidth();
+ final int h = uc.getImageHeight();
+
stopRecord2DPolygon();
g.setPaintMode();
g.setColor(couleurfond);
@@ -1707,10 +1707,10 @@ import xlogo.kernel.perspective.*;
* @param couleur_frontiere
* @return
*/
-
- private int bornes_remplis_zone(int x, int y, int increment, int couleur_frontiere) {
- UserConfig uc = WSManager.getUserConfig();
- int w = uc.getImageWidth();
+
+ private int bornes_remplis_zone(int x, final int y, final int increment, final int couleur_frontiere) {
+ final UserConfig uc = WSManager.getUserConfig();
+ final int w = uc.getImageWidth();
// System.out.println(x+" "+y);
while (!meme_couleur(DrawPanel.dessin.getRGB(x, y) ,couleur_frontiere)) {
DrawPanel.dessin.setRGB(x, y, couleur_frontiere);
@@ -1726,7 +1726,7 @@ import xlogo.kernel.perspective.*;
* @param col2 The second color
* @return true or false
*/
- private boolean meme_couleur(int col1,int col2){
+ private boolean meme_couleur(final int col1,final int col2){
/* if (Config.quality==Logo.QUALITY_HIGH){
int rouge1 = (col1 >> 16) & 0xFF;
int vert1 = (col1 >> 8) & 0xFF;
@@ -1764,7 +1764,7 @@ import xlogo.kernel.perspective.*;
else bleu=false;
}
- return rouge&&bleu&&vert;
+ return rouge&&bleu&&vert;
// if (Math.abs(rouge1-rouge2)<tolerance&&Math.abs(vert1-vert2)<tolerance&&Math.abs(bleu1-bleu2)<tolerance&&Math.abs(rouge1+bleu1+vert1-rouge2-bleu2-vert2)<450)
// return true;
// else return false;
@@ -1778,25 +1778,25 @@ import xlogo.kernel.perspective.*;
*/
protected void rempliszone() {
montrecacheTortue(false);
- int x = (int) (tortue.corX + 0.5);
- int y = (int) (tortue.corY + 0.5);
- UserConfig uc = WSManager.getUserConfig();
- int w = uc.getImageWidth();
- int h = uc.getImageHeight();
+ final int x = (int) (tortue.corX + 0.5);
+ final int y = (int) (tortue.corY + 0.5);
+ final UserConfig uc = WSManager.getUserConfig();
+ final int w = uc.getImageWidth();
+ final int h = uc.getImageHeight();
if (x > 0 & x < w & y > 0 & y < h) {
- int couleur_origine = DrawPanel.dessin.getRGB(x, y);
- int couleur_frontiere = tortue.couleurcrayon.getRGB();
+ final int couleur_origine = DrawPanel.dessin.getRGB(x, y);
+ final int couleur_frontiere = tortue.couleurcrayon.getRGB();
// System.out.println(couleur_origine+" " +couleur_frontiere);
- Stack<Point> pile_germes = new Stack<Point>();
- boolean couleurs_differentes = !meme_couleur(couleur_origine,couleur_frontiere);
+ final Stack<Point> pile_germes = new Stack<Point>();
+ final boolean couleurs_differentes = !meme_couleur(couleur_origine,couleur_frontiere);
if (couleurs_differentes)
pile_germes.push(new Point(x, y));
while (!pile_germes.isEmpty()) {
- Point p = pile_germes.pop();
- int xgerme = p.x;
- int ygerme = p.y;
- int xmax = bornes_remplis_zone(xgerme, ygerme, 1,
+ final Point p = pile_germes.pop();
+ final int xgerme = p.x;
+ final int ygerme = p.y;
+ final int xmax = bornes_remplis_zone(xgerme, ygerme, 1,
couleur_frontiere);
int xmin=0;
if (xgerme>0) xmin = bornes_remplis_zone(xgerme - 1, ygerme, -1,
@@ -1840,10 +1840,10 @@ import xlogo.kernel.perspective.*;
* @param couleur_origine
* @return
*/
- private int bornes_remplis(int x, int y, int increment, int couleur_crayon,
- int couleur_origine) {
- UserConfig uc = WSManager.getUserConfig();
- int w = uc.getImageWidth();
+ private int bornes_remplis(int x, final int y, final int increment, final int couleur_crayon,
+ final int couleur_origine) {
+ final UserConfig uc = WSManager.getUserConfig();
+ final int w = uc.getImageWidth();
while (DrawPanel.dessin.getRGB(x, y) == couleur_origine) {
DrawPanel.dessin.setRGB(x, y, couleur_crayon);
x = x + increment;
@@ -1857,26 +1857,26 @@ import xlogo.kernel.perspective.*;
*/
protected void remplis() {
montrecacheTortue(false);
- int x = (int) (tortue.corX + 0.5);
- int y = (int) (tortue.corY + 0.5);
- UserConfig uc = WSManager.getUserConfig();
- int w = uc.getImageWidth();
- int h = uc.getImageHeight();
-
+ final int x = (int) (tortue.corX + 0.5);
+ final int y = (int) (tortue.corY + 0.5);
+ final UserConfig uc = WSManager.getUserConfig();
+ final int w = uc.getImageWidth();
+ final int h = uc.getImageHeight();
+
if (x > 0 & x < w & y > 0 & y < h) {
- int couleur_origine = DrawPanel.dessin.getRGB(x, y);
- int couleur_crayon = tortue.couleurcrayon.getRGB();
+ final int couleur_origine = DrawPanel.dessin.getRGB(x, y);
+ final int couleur_crayon = tortue.couleurcrayon.getRGB();
if (x > 0 & x < w & y > 0 & y < h) {
- Stack<Point> pile_germes = new Stack<Point>();
- boolean couleurs_differentes = !(couleur_origine == couleur_crayon);
+ final Stack<Point> pile_germes = new Stack<Point>();
+ final boolean couleurs_differentes = !(couleur_origine == couleur_crayon);
if (couleurs_differentes)
pile_germes.push(new Point(x, y));
while (!pile_germes.isEmpty()) {
- Point p = pile_germes.pop();
- int xgerme = p.x;
- int ygerme = p.y;
+ final Point p = pile_germes.pop();
+ final int xgerme = p.x;
+ final int ygerme = p.y;
// System.out.println(xgerme+" "+ygerme);
- int xmax = bornes_remplis(xgerme, ygerme, 1, couleur_crayon,
+ final int xmax = bornes_remplis(xgerme, ygerme, 1, couleur_crayon,
couleur_origine);
int xmin=0;
if (xgerme>0) xmin = bornes_remplis(xgerme - 1, ygerme, -1,
@@ -1917,11 +1917,11 @@ import xlogo.kernel.perspective.*;
* Primitive "label"
* @param mot The word to write on the drawing area
*/
- protected void etiquette(String mot) {
+ protected void etiquette(final String mot) {
// Graphics2D g = (Graphics2D) Ardoise.dessin.getGraphics();
montrecacheTortue(false);
if (!enabled3D()){
- double angle = Math.PI / 2 - tortue.angle;
+ final double angle = Math.PI / 2 - tortue.angle;
if(DrawPanel.WINDOW_MODE==DrawPanel.WINDOW_WRAP) centers=new Vector<Point2D.Double>();
etiquette2D(tortue.corX,tortue.corY,angle,mot);
/* g.rotate(angle);
@@ -1937,56 +1937,56 @@ import xlogo.kernel.perspective.*;
g.rotate(-angle);*/
}
else{
- FontRenderContext frc=g.getFontRenderContext();
- GlyphVector gv=g.getFont().createGlyphVector(frc, mot);
- Shape outline=gv.getOutline(0, 0);
- Shape s=transformShape(outline);
+ final FontRenderContext frc=g.getFontRenderContext();
+ final GlyphVector gv=g.getFont().createGlyphVector(frc, mot);
+ final Shape outline=gv.getOutline(0, 0);
+ final Shape s=transformShape(outline);
g.setPaintMode();
g.setColor(tortue.couleurcrayon);
g.fill(s);
if (record3D==DrawPanel.record3D_TEXT){
- Text2D text=new Text2D(
- mot,new Color3f(tortue.couleurcrayon), UserConfig.fontes[police_etiquette].getName(),
+ final Text2D text=new Text2D(
+ mot,new Color3f(tortue.couleurcrayon.getRGBColorComponents(null)), UserConfig.fontes[police_etiquette].getName(),
tortue.police,Font.PLAIN);
-
+
text.setRectangleScaleFactor(0.001f);
- Appearance appear=text.getAppearance();
- PolygonAttributes pa=new PolygonAttributes();
+ final Appearance appear=text.getAppearance();
+ final PolygonAttributes pa=new PolygonAttributes();
pa.setCullFace(PolygonAttributes.CULL_NONE);
pa.setBackFaceNormalFlip(true);
appear.setPolygonAttributes(pa);
text.setAppearance(appear);
// if (null==DrawPanel.listText) DrawPanel.listText=new Vector<TransformGroup>();
- TransformGroup tg=new TransformGroup();
- double[][] d=tortue.getRotationMatrix();
- Matrix3d m=new Matrix3d(d[0][0],d[0][1],d[0][2],d[1][0],d[1][1],d[1][2],d[2][0],d[2][1],d[2][2]);
- Transform3D t=new Transform3D(m,new Vector3d(tortue.X/1000,tortue.Y/1000,tortue.Z/1000),1);
+ final TransformGroup tg=new TransformGroup();
+ final double[][] d=tortue.getRotationMatrix();
+ final Matrix3d m=new Matrix3d(d[0][0],d[0][1],d[0][2],d[1][0],d[1][1],d[1][2],d[2][0],d[2][1],d[2][2]);
+ final Transform3D t=new Transform3D(m,new Vector3d(tortue.X/1000,tortue.Y/1000,tortue.Z/1000),1);
tg.setTransform(t);
tg.addChild(text);
cadre.getViewer3D().add2DText(tg);
// DrawPanel.listText.add(tg);
}
-
-
+
+
}
montrecacheTortue(true);
if (classicMode) repaint();
}
- private void etiquette2D(double x,double y, double angle, String word){
+ private void etiquette2D(final double x,final double y, final double angle, final String word){
if (word.length()==0) return;
-
+
g.setPaintMode();
g.setColor(tortue.couleurcrayon);
- Font f= UserConfig.fontes[police_etiquette]
+ final Font f= UserConfig.fontes[police_etiquette]
.deriveFont((float) tortue.police);
- g.setFont(f);
+ g.setFont(f);
g.translate(x, y);
g.rotate(angle);
- FontRenderContext frc = g.getFontRenderContext();
- TextLayout layout = new TextLayout(word, f, frc);
- Rectangle2D bounds = layout.getBounds();
- float height=(float)bounds.getHeight();
- float width=(float)bounds.getWidth();
+ final FontRenderContext frc = g.getFontRenderContext();
+ final TextLayout layout = new TextLayout(word, f, frc);
+ final Rectangle2D bounds = layout.getBounds();
+ final float height=(float)bounds.getHeight();
+ final float width=(float)bounds.getWidth();
float x1=0,y1=0;
switch(tortue.getLabelHorizontalAlignment()){
case Turtle.LABEL_HORIZONTAL_ALIGNMENT_LEFT:
@@ -2015,20 +2015,20 @@ import xlogo.kernel.perspective.*;
g.rotate(-angle);
g.translate(-x, -y);
if (DrawPanel.WINDOW_MODE==DrawPanel.WINDOW_WRAP){
- Rectangle2D.Double rec=new Rectangle2D.Double(0,0,width,height);
- AffineTransform at=new AffineTransform();
+ final Rectangle2D.Double rec=new Rectangle2D.Double(0,0,width,height);
+ final AffineTransform at=new AffineTransform();
at.translate(x, y);
at.rotate(angle);
- Rectangle2D bound =at.createTransformedShape(rec).getBounds2D();
- double right= bound.getX()+bound.getWidth()-x;
- double left= x-bound.getX();
- double up=y-bound.getY();
- double down=bound.getY()+bound.getHeight()-y;
-
- UserConfig uc = WSManager.getUserConfig();
- int w = uc.getImageWidth();
- int h = uc.getImageHeight();
-
+ final Rectangle2D bound =at.createTransformedShape(rec).getBounds2D();
+ final double right= bound.getX()+bound.getWidth()-x;
+ final double left= x-bound.getX();
+ final double up=y-bound.getY();
+ final double down=bound.getY()+bound.getHeight()-y;
+
+ final UserConfig uc = WSManager.getUserConfig();
+ final int w = uc.getImageWidth();
+ final int h = uc.getImageHeight();
+
if (x+right>w&& x<=w){
pt=new Point2D.Double(-w+x,y);
if (! centers.contains(pt)) {
@@ -2059,20 +2059,20 @@ import xlogo.kernel.perspective.*;
}
}
}
-
+
/**
- * This method transform a plane 2D shape in the shape corresponding to the turtle plane
+ * This method transform a plane 2D shape in the shape corresponding to the turtle plane
* @param s the first shape
* @return the new shape after transformation
*/
- private Shape transformShape(Shape s){
- PathIterator it=s.getPathIterator(null);
- double[] d=new double[6];
+ private Shape transformShape(final Shape s){
+ final PathIterator it=s.getPathIterator(null);
+ final double[] d=new double[6];
double[][] coor=new double[3][1];
- GeneralPath gp=new GeneralPath();
- double[] end=new double[3];
- double[] ctl1=new double[3];
- double[] ctl2=new double[3];
+ final GeneralPath gp=new GeneralPath();
+ final double[] end=new double[3];
+ final double[] ctl1=new double[3];
+ final double[] ctl2=new double[3];
boolean b=false;
while(!it.isDone()){
it.next();
@@ -2088,7 +2088,7 @@ import xlogo.kernel.perspective.*;
end[1]=coor[1][0]+tortue.Y;
end[2]=coor[2][0]+tortue.Z;
w3d.toScreenCoord(end);
-
+
if (id==PathIterator.SEG_MOVETO)
gp.moveTo((float)end[0], (float)end[1]);
else if (id==PathIterator.SEG_LINETO)
@@ -2108,7 +2108,7 @@ import xlogo.kernel.perspective.*;
Point2D p=null;
if (s instanceof Arc2D.Double)
p=((Arc2D.Double)s).getStartPoint();
- else if (s instanceof GeneralPath)
+ else if (s instanceof GeneralPath)
p=((GeneralPath)s).getCurrentPoint();
coor[0][0]=p.getX();
coor[1][0]=-p.getY();
@@ -2129,8 +2129,8 @@ import xlogo.kernel.perspective.*;
ctl1[2]=coor[2][0]+tortue.Z;
w3d.toScreenCoord(ctl1);
if(id==PathIterator.SEG_QUADTO){
- QuadCurve2D qc=new QuadCurve2D.Double(gp.getCurrentPoint().getX(),gp.getCurrentPoint().getY()
- ,end[0], end[1],ctl1[0], ctl1[1]);
+ final QuadCurve2D qc=new QuadCurve2D.Double(gp.getCurrentPoint().getX(),gp.getCurrentPoint().getY()
+ ,end[0], end[1],ctl1[0], ctl1[1]);
gp.append(qc, true);}
else if (id==PathIterator.SEG_CUBICTO){
coor[0][0]=d[4];
@@ -2141,15 +2141,15 @@ import xlogo.kernel.perspective.*;
ctl2[0]=coor[0][0]+tortue.X;
ctl2[1]=coor[1][0]+tortue.Y;
ctl2[2]=coor[2][0]+tortue.Z;
-
+
w3d.toScreenCoord(ctl2);
- CubicCurve2D qc=new CubicCurve2D.Double(gp.getCurrentPoint().getX(),gp.getCurrentPoint().getY()
- ,end[0], end[1],ctl1[0], ctl1[1],ctl2[0], ctl2[1]);
+ final CubicCurve2D qc=new CubicCurve2D.Double(gp.getCurrentPoint().getX(),gp.getCurrentPoint().getY()
+ ,end[0], end[1],ctl1[0], ctl1[1],ctl2[0], ctl2[1]);
gp.append(qc, true);
}
}
}
- return gp;
+ return gp;
}
public World3D getWorld3D(){
return w3d;
@@ -2158,7 +2158,7 @@ import xlogo.kernel.perspective.*;
* primitive setscreencolor
* @param color The Color of the nackground screen
*/
- protected void fcfg(Color color) {
+ protected void fcfg(final Color color) {
couleurfond=color;
updateColorSelection();
if (enabled3D()){
@@ -2172,7 +2172,7 @@ import xlogo.kernel.perspective.*;
* Primitive setpencolor
* @param color The pen Color
*/
- protected void fcc(Color color) {
+ protected void fcc(final Color color) {
if (tortue.isVisible()&&null==tortue.tort) montrecacheTortue(false);
tortue.couleurcrayon = color;
tortue.couleurmodedessin = color;
@@ -2186,7 +2186,7 @@ import xlogo.kernel.perspective.*;
* @param name The translated name for the primitive "guiposition"
* @throws LogoError If coordinates list is invalid
*/
- protected void guiposition(String id, String liste,String name) throws LogoError{
+ protected void guiposition(final String id, final String liste,final String name) throws LogoError{
if (guiExist(id)){
initCoords();
extractCoords(liste,name);
@@ -2195,13 +2195,13 @@ import xlogo.kernel.perspective.*;
}
}
/**
- * Draw the Gui object refered with "id"
+ * Draw the Gui object refered with "id"
* @param id The Gui Object Id
* @throws LogoError If this object doesn't exist
*/
- protected void guiDraw(String id) throws LogoError{
+ protected void guiDraw(final String id) throws LogoError{
if (guiExist(id)){
- GuiComponent gc=gm.get(id);
+ final GuiComponent gc=gm.get(id);
add(gc.getGuiObject());
validate();
repaint();
@@ -2210,7 +2210,7 @@ import xlogo.kernel.perspective.*;
}
/**
* @uml.property name="gui"
- * @uml.associationEnd
+ * @uml.associationEnd
*/
private javax.swing.JComponent gui;
/**
@@ -2218,8 +2218,8 @@ import xlogo.kernel.perspective.*;
* @param id The Gui Object id
* @throws LogoError
*/
-
- protected void guiRemove(String id) throws LogoError{
+
+ protected void guiRemove(final String id) throws LogoError{
if (guiExist(id)){
gui=gm.get(id).getGuiObject();
gm.remove(id);
@@ -2232,21 +2232,21 @@ import xlogo.kernel.perspective.*;
SwingUtilities.invokeAndWait(new Runnable(){
public void run(){
remove(gui);
- validate();
+ validate();
}
});
}
- catch(Exception e){}
+ catch(final Exception e){}
}
repaint();
}
}
- private StringBuffer extractList(String list) throws LogoError{
- StringBuffer sb=new StringBuffer();
+ private StringBuffer extractList(final String list) throws LogoError{
+ final StringBuffer sb=new StringBuffer();
int compteur=0;
int i=0;
while(list.length()!=0){
- char c=list.charAt(i);
+ final char c=list.charAt(i);
if (c=='[') compteur++;
else if (c==']') {
if (compteur==0) return sb;
@@ -2257,10 +2257,10 @@ import xlogo.kernel.perspective.*;
}
throw new LogoError("[ "+list+" "+Logo.messages.getString("pas_liste"));
}
-
- protected void guiAction(String id, String liste) throws LogoError{
+
+ protected void guiAction(final String id, String liste) throws LogoError{
if (guiExist(id)){
- GuiComponent gc=gm.get(id);
+ final GuiComponent gc=gm.get(id);
// If gc is a JButton
if (gc.isButton()){
((GuiButton)gc).setAction(Utils.decoupe(liste));
@@ -2276,14 +2276,14 @@ import xlogo.kernel.perspective.*;
while(liste.length()!=0){
if (liste.charAt(0)=='['){
liste=liste.substring(1).trim();
- StringBuffer sb=extractList(liste);
+ final StringBuffer sb=extractList(liste);
liste=liste.substring(sb.length()+1).trim();
((GuiMenu)gc).setAction(sb, i);
i++;
}
else throw new LogoError(liste.charAt(0)+" "+Logo.messages.getString("pas_liste"));
}
- GuiMenu gm=(GuiMenu)gc;
+ final GuiMenu gm=(GuiMenu)gc;
if (!gm.hasAction){
gm.hasAction=true;
((javax.swing.JComboBox)gc.getGuiObject()).addActionListener(gm);
@@ -2291,27 +2291,27 @@ import xlogo.kernel.perspective.*;
}
}
}
- private boolean guiExist(String id) throws LogoError{
+ private boolean guiExist(final String id) throws LogoError{
if (gm.containsKey(id.toLowerCase())) return true;
else throw new LogoError(Logo.messages.getString("no_gui")+" "+id);
}
// boolean access=false;
private void clip(){
if (classicMode){
-
+
//access=true;
// refresh();
-
+
repaint();
/* if (SwingUtilities.isEventDispatchThread()){
repaint();
}
else {
try {
-
+
SwingUtilities.invokeLater(new Runnable(){
public void run(){
- repaint();
+ repaint();
}
});
}
@@ -2326,13 +2326,13 @@ import xlogo.kernel.perspective.*;
}
}*/
}
- public void setQuality(DrawQuality q){
+ public void setQuality(final DrawQuality q){
/*
* Marko Zivkovic
* I improved all the qualities for one level. I introduced a super high quality that is assigned to "high"
* and dropped the low quality, which is now the old normal/default quality
*/
-
+
if (q==DrawQuality.HIGH){
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
@@ -2350,7 +2350,7 @@ import xlogo.kernel.perspective.*;
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}
}
- public void change_image_tortue(Application cadre, String chemin) {
+ public void change_image_tortue(final Application cadre, String chemin) {
if (tortue.isVisible())
montrecacheTortue(false);
if (chemin.equals("tortue0.png")) {
@@ -2367,12 +2367,12 @@ import xlogo.kernel.perspective.*;
tracker.addImage(tortue.tort, 0);
try {
tracker.waitForID(0);
- } catch (InterruptedException e1) {
+ } catch (final InterruptedException e1) {
}
- double largeur_ecran = Toolkit.getDefaultToolkit().getScreenSize()
+ final double largeur_ecran = Toolkit.getDefaultToolkit().getScreenSize()
.getWidth();
// On fait attention à la résolution de l'utilisateur
- double facteur = largeur_ecran / 1024.0;
+ final double facteur = largeur_ecran / 1024.0;
if ((int) (facteur + 0.001) != 1) {
tortue.largeur = tortue.tort.getWidth(cadre.getFrame());
@@ -2385,7 +2385,7 @@ import xlogo.kernel.perspective.*;
tracker.addImage(tortue.tort, 0);
try {
tracker.waitForID(0);
- } catch (InterruptedException e1) {
+ } catch (final InterruptedException e1) {
}
}
tortue.largeur = tortue.tort.getWidth(cadre.getFrame());
@@ -2397,8 +2397,8 @@ import xlogo.kernel.perspective.*;
montrecacheTortue(true);
}
- // animation
- protected void setAnimation(boolean predic){
+ // animation
+ protected void setAnimation(final boolean predic){
if (predic==classicMode){
if (predic) {
cadre.getHistoryPanel().active_animation();
@@ -2409,48 +2409,48 @@ import xlogo.kernel.perspective.*;
}
}
}
-
- protected void setGraphicsFont(Font f){
+
+ protected void setGraphicsFont(final Font f){
g.setFont(f);
}
protected Font getGraphicsFont(){
return g.getFont();
}
- protected void setStroke(Stroke st){
+ protected void setStroke(final Stroke st){
g.setStroke(st);
}
public Color getBackgroundColor(){
return couleurfond;
}
- protected void setBackgroundColor(Color c){
+ protected void setBackgroundColor(final Color c){
couleurfond=c;
}
protected void updateColorSelection(){
- float r=(255-couleurfond.getRed())/255;
- float v=(255-couleurfond.getGreen())/255;
- float b=(255-couleurfond.getBlue())/255;
+ final float r=(255-couleurfond.getRed())/255;
+ final float v=(255-couleurfond.getGreen())/255;
+ final float b=(255-couleurfond.getBlue())/255;
colorSelection=new Color(r,v,b,0.2f);
}
- public void setNumberOfTurtles(int max){
+ public void setNumberOfTurtles(final int max){
WSManager.getUserConfig().setMaxTurtles(max);
- Turtle[] tampon = tortues.clone();
+ final Turtle[] tampon = tortues.clone();
tortues = new Turtle[max];
- int borne_sup=Math.min(tampon.length,tortues.length);
+ final int borne_sup=Math.min(tampon.length,tortues.length);
for(int i=0;i<borne_sup;i++){
tortues[i]=tampon[i];
}
for(int i=tortues_visibles.size()-1;i>-1;i--){
- int integer=Integer.parseInt(tortues_visibles.get(i));
+ final int integer=Integer.parseInt(tortues_visibles.get(i));
if (integer>=max){
tortues_visibles.remove(i);
}
}
}
protected void initGraphics(){
- UserConfig uc = WSManager.getUserConfig();
- int w = uc.getImageWidth();
- int h = uc.getImageHeight();
-
+ final UserConfig uc = WSManager.getUserConfig();
+ final int w = uc.getImageWidth();
+ final int h = uc.getImageHeight();
+
police_etiquette=UserConfig.police_id(WSManager.getWorkspaceConfig().getFont());
// init all turtles
tortues = new Turtle[uc.getMaxTurtles()];
@@ -2459,7 +2459,7 @@ import xlogo.kernel.perspective.*;
tortues[0] = tortue;
tortue.id = 0;
tortues_visibles.push("0");
- for (int i = 1; i < tortues.length; i++) {
+ for (int i = 1; i < tortues.length; i++) {
// All other turtles are null
tortues[i] = null;
}
@@ -2472,9 +2472,9 @@ import xlogo.kernel.perspective.*;
if (!enabled3D()){
drawGrid();
drawXAxis();
- drawYAxis();
+ drawYAxis();
}
- MediaTracker tracker;
+ MediaTracker tracker;
if (0==uc.getActiveTurtle()) {
g.setXORMode(couleurfond);
tortue.drawTriangle();
@@ -2486,52 +2486,52 @@ import xlogo.kernel.perspective.*;
tracker=new MediaTracker(cadre.getFrame());
tracker.addImage(tortue.tort,0);
try{tracker.waitForID(0);}
- catch(InterruptedException e){}
+ catch(final InterruptedException e){}
if (tracker.checkID(0)) g.drawImage(tortue.tort, w/2 - tortue.largeur / 2,
h/2 - tortue.hauteur/2, this);
}
updateColorSelection();
}
-
- private void resizeAllGuiComponents(double d){
+
+ private void resizeAllGuiComponents(final double d){
// Resize all GuiComponent
- Set<String> set=gm.keySet();
- Iterator<String> it=set.iterator();
+ final Set<String> set=gm.keySet();
+ final Iterator<String> it=set.iterator();
while (it.hasNext()){
- String element=it.next();
- GuiComponent gui=gm.get(element);
+ final String element=it.next();
+ final GuiComponent gui=gm.get(element);
gui.getGuiObject().setSize((int)(gui.getOriginalWidth()*d),
(int)(gui.getOriginalHeight()*d) );
- Font f=gui.getGuiObject().getFont();
+ final Font f=gui.getGuiObject().getFont();
gui.getGuiObject().setFont(f.deriveFont((float)(WSManager.getWorkspaceConfig().getFont().getSize()*d)));
- double x=gui.getLocation().x/zoom;
- double y=gui.getLocation().y/zoom;
+ final double x=gui.getLocation().x/zoom;
+ final double y=gui.getLocation().y/zoom;
gui.setLocation((int)(x*d),(int)(y*d));
-
+
}
-
+
}
-
-
+
+
/**
* Make a zoom on the drawing area
* @param d The absolute factor
*/
- public void zoom(double d, boolean zoomIn){
+ public void zoom(double d, final boolean zoomIn){
// Disable zoom buttons
//cadre.setZoomEnabled(false); // TODO REMOVE ZOOM COMPLETELY?
-
- javax.swing.JViewport jv=cadre.scrollArea.getViewport();
+
+ final javax.swing.JViewport jv=cadre.scrollArea.getViewport();
Point p=jv.getViewPosition();
- Rectangle r=jv.getVisibleRect();
+ final Rectangle r=jv.getVisibleRect();
+
-
// If a selection rectangle is displaying on the drawing area
// And If zoomout has been pressed
- // Zooming on the rectangular selection
+ // Zooming on the rectangular selection
if (null!=selection&&cadre.commande_isEditable()&&zoomIn){
- int originalWidth=jv.getWidth();
- double width=selection.getWidth();
+ final int originalWidth=jv.getWidth();
+ final double width=selection.getWidth();
d=zoom*originalWidth/width;
p=selection.getLocation();
r.width=selection.width;
@@ -2542,11 +2542,11 @@ import xlogo.kernel.perspective.*;
}
// Resize all Gui Components on the drawing area
resizeAllGuiComponents(d);
-
- double oldZoom=zoom;
+
+ final double oldZoom=zoom;
zoom=d;
- /*
+ /*
* -------------------------------------
* | |
* | ------------------------- |
@@ -2558,46 +2558,46 @@ import xlogo.kernel.perspective.*;
* | ------------------------- |
* -------------------------------------
* */
-
- UserConfig uc = WSManager.getUserConfig();
- int w = uc.getImageWidth();
- int h = uc.getImageHeight();
-
- double dx=Math.min(r.width,w*oldZoom)/2;
- double dy=Math.min(r.height,h*oldZoom)/2;
- Point centerView=new Point((int)(p.x+dx),(int)(p.y+dy));
+
+ final UserConfig uc = WSManager.getUserConfig();
+ final int w = uc.getImageWidth();
+ final int h = uc.getImageHeight();
+
+ final double dx=Math.min(r.width,w*oldZoom)/2;
+ final double dy=Math.min(r.height,h*oldZoom)/2;
+ final Point centerView=new Point((int)(p.x+dx),(int)(p.y+dy));
// Dynamically modify the drawing Area size
setPreferredSize(new java.awt.Dimension(
(int)(w*zoom)
,(int)(h*zoom)));
- SwingUtilities.invokeLater(new PositionJViewport(jv,
+ SwingUtilities.invokeLater(new PositionJViewport(jv,
new Point((int)(centerView.x/oldZoom*zoom-dx),
- (int)(centerView.y/oldZoom*zoom-dy))));
+ (int)(centerView.y/oldZoom*zoom-dy))));
}
- private Color getTransparencyColor(int color,int trans){
- Color c=new Color(color);
+ private Color getTransparencyColor(final int color,final int trans){
+ final Color c=new Color(color);
return new Color(c.getRed(),c.getGreen(),c.getBlue(),trans);
}
/**
* Draw the horizontal axis
- */
+ */
private void drawXAxis(){
- UserConfig uc = WSManager.getUserConfig();
- int w = uc.getImageWidth();
- int h = uc.getImageHeight();
-
+ final UserConfig uc = WSManager.getUserConfig();
+ final int w = uc.getImageWidth();
+ final int h = uc.getImageHeight();
+
if (uc.isDrawXAxis()){
g.setColor(getTransparencyColor(uc.getAxisColor(),128));
g.drawLine(0,h/2,w,h/2);
for (int i=w/2%uc.getXAxis();i<w;i=i+uc.getXAxis()){
g.drawLine(i, h/2-2, i, h/2+2);
g.setFont(new Font("Dialog",Font.PLAIN,10));
- String tick=String.valueOf(i-w/2);
- FontMetrics fm=g.getFontMetrics();
- int back=fm.stringWidth(String.valueOf(tick))/2;
+ final String tick=String.valueOf(i-w/2);
+ final FontMetrics fm=g.getFontMetrics();
+ final int back=fm.stringWidth(String.valueOf(tick))/2;
// if the both axes are drawn, the zero has to translated
// So we don't draw the zero
if (i!=w/2||!uc.isDrawYAxis()) g.drawString(tick, i-back, h/2+20);
@@ -2606,19 +2606,19 @@ import xlogo.kernel.perspective.*;
}
/**
* Draw the vertical axis
- */
+ */
private void drawYAxis(){
- UserConfig uc = WSManager.getUserConfig();
- int w = uc.getImageWidth();
- int h = uc.getImageHeight();
-
+ final UserConfig uc = WSManager.getUserConfig();
+ final int w = uc.getImageWidth();
+ final int h = uc.getImageHeight();
+
if (uc.isDrawYAxis()){
g.setColor(getTransparencyColor(uc.getAxisColor(),128));
g.drawLine(w/2,0,w/2,h);
for (int i=h/2%uc.getYAxis();i<h;i=i+uc.getYAxis()){
g.drawLine( w/2-2, i, w/2+2,i);
g.setFont(new Font("Dialog",Font.PLAIN,10));
- String tick=String.valueOf(h/2-i);
+ final String tick=String.valueOf(h/2-i);
// If both axes are drawn, zero is translated
if (i==h/2&&uc.isDrawXAxis()) g.drawString("0", w/2+10, i-5);
else g.drawString(tick, w/2+10, i+5);
@@ -2626,10 +2626,10 @@ import xlogo.kernel.perspective.*;
}
}
private void drawGrid(){
- UserConfig uc = WSManager.getUserConfig();
- int w = uc.getImageWidth();
- int h = uc.getImageHeight();
-
+ final UserConfig uc = WSManager.getUserConfig();
+ final int w = uc.getImageWidth();
+ final int h = uc.getImageHeight();
+
if (uc.isDrawGrid()){
g.setStroke(new BasicStroke(1));
g.setColor(getTransparencyColor(uc.getGridColor(),100));
@@ -2647,13 +2647,13 @@ import xlogo.kernel.perspective.*;
try{
wait();
}
- catch(InterruptedException e){}
-
+ catch(final InterruptedException e){}
+
}
- protected synchronized void paintComponent(Graphics graph){
+ protected synchronized void paintComponent(final Graphics graph){
super.paintComponent(graph);
- Graphics2D g2d=(Graphics2D)graph;
+ final Graphics2D g2d=(Graphics2D)graph;
if (null==shape){
g2d.setClip(cadre.scrollArea.getViewport().getViewRect());
}
@@ -2684,18 +2684,18 @@ import xlogo.kernel.perspective.*;
lissouris=false;
return possouris;
}
- public void mousePressed(MouseEvent e){
- if (!Affichage.execution_lancee) {
+ public void mousePressed(final MouseEvent e){
+ if (!Affichage.execution_lancee) {
selection=new Rectangle();
origine=new Point(e.getPoint());
selection.setSize(0, 0);
}
}
- public void mouseReleased(MouseEvent e){}
- public void mouseClicked(MouseEvent ev){
- UserConfig uc = WSManager.getUserConfig();
- int w = uc.getImageWidth();
- int h = uc.getImageHeight();
+ public void mouseReleased(final MouseEvent e){}
+ public void mouseClicked(final MouseEvent ev){
+ final UserConfig uc = WSManager.getUserConfig();
+ final int w = uc.getImageWidth();
+ final int h = uc.getImageHeight();
if (!Affichage.execution_lancee){
selection=null;
origine=null;
@@ -2704,31 +2704,31 @@ import xlogo.kernel.perspective.*;
else{
lissouris=true;
bouton_souris=ev.getButton();
- Point point=ev.getPoint();
+ final Point point=ev.getPoint();
possouris="[ "+(point.x-w/2)+" "+(h/2-point.y)+" ] ";
}
}
- public void mouseExited(MouseEvent e){
+ public void mouseExited(final MouseEvent e){
}
- public void mouseEntered(MouseEvent e){
+ public void mouseEntered(final MouseEvent e){
}
// Select an export area
- public void mouseDragged(MouseEvent e){
+ public void mouseDragged(final MouseEvent e){
if (!Affichage.execution_lancee&&null!=selection){
// First, we test if we need to move the scrollbars
- Point pos=e.getPoint();
- javax.swing.JViewport jv=cadre.scrollArea.getViewport();
- Point viewPosition=jv.getViewPosition();
- Rectangle r=jv.getVisibleRect();
+ final Point pos=e.getPoint();
+ final javax.swing.JViewport jv=cadre.scrollArea.getViewport();
+ final Point viewPosition=jv.getViewPosition();
+ final Rectangle r=jv.getVisibleRect();
r.setLocation(viewPosition);
// Is the point visible on screen?
- boolean b=r.contains(pos);
-
- UserConfig uc = WSManager.getUserConfig();
- int w = uc.getImageWidth();
- int h = uc.getImageHeight();
-
+ final boolean b=r.contains(pos);
+
+ final UserConfig uc = WSManager.getUserConfig();
+ final int w = uc.getImageWidth();
+ final int h = uc.getImageHeight();
+
// Move the scroolPane if necessary
if (!b){
int x,y;
@@ -2740,26 +2740,26 @@ import xlogo.kernel.perspective.*;
else y=viewPosition.y;
jv.setViewPosition(new Point(x,y));
}
-
+
// Then , drawing the selection area
-
+
selection.setFrameFromDiagonal(origine, e.getPoint());
repaint();
}
}
- public void mouseMoved(MouseEvent ev) {
- UserConfig uc = WSManager.getUserConfig();
- int w = uc.getImageWidth();
- int h = uc.getImageHeight();
+ public void mouseMoved(final MouseEvent ev) {
+ final UserConfig uc = WSManager.getUserConfig();
+ final int w = uc.getImageWidth();
+ final int h = uc.getImageHeight();
lissouris = true;
bouton_souris = 0;
- Point point = ev.getPoint();
+ final Point point = ev.getPoint();
possouris = "[ " + (point.x - w / 2) + " " + (h / 2 - point.y) + " ] ";
}
- protected void addToGuiMap(GuiComponent gc) throws xlogo.kernel.LogoError {
+ protected void addToGuiMap(final GuiComponent gc) throws xlogo.kernel.LogoError {
gm.put(gc);
}
@@ -2776,9 +2776,9 @@ import xlogo.kernel.perspective.*;
* @param name The image name
* @param coords The upper left corner and the right bottom corner
*/
- protected void saveImage(String name, int[] coords){
- BufferedImage buffer=getImagePart(coords);
- String lowerName=name.toLowerCase();
+ protected void saveImage(String name, final int[] coords){
+ final BufferedImage buffer=getImagePart(coords);
+ final String lowerName=name.toLowerCase();
String format="png";
if (lowerName.endsWith(".jpg")||lowerName.endsWith(".jpeg")) {
format="jpg";
@@ -2788,17 +2788,17 @@ import xlogo.kernel.perspective.*;
}
name=WSManager.getUserConfig().getDefaultFolder()+File.separator+name;
try{
- File f=new File(name);
+ final File f=new File(name);
ImageIO.write(buffer, format, f);
}
- catch(IOException e){}
-
+ catch(final IOException e){}
+
}
/**
* Return a part of the drawing area as an image
* @return
*/
- private BufferedImage getImagePart(int[] coords){
+ private BufferedImage getImagePart(final int[] coords){
Image pic=DrawPanel.dessin;
if (zoom!=1){
pic=createImage(new FilteredImageSource(pic.getSource(),
@@ -2808,8 +2808,8 @@ import xlogo.kernel.perspective.*;
new CropImageFilter(coords[0],coords[1],coords[2],coords[3])));
return toBufferedImage(pic);
}
-
-
+
+
public BufferedImage getSelectionImage(){
Image pic=DrawPanel.dessin;
if (zoom!=1){
@@ -2817,10 +2817,10 @@ import xlogo.kernel.perspective.*;
new ReplicateScaleFilter((int)(dessin.getWidth()*zoom),(int)(dessin.getHeight()*zoom))));
}
if (null!=selection){
- int x=(int)(selection.getBounds().getX());
- int y=(int)(selection.getBounds().getY());
- int width=(int)(selection.getBounds().getWidth());
- int height=(int)(selection.getBounds().getHeight());
+ final int x=(int)(selection.getBounds().getX());
+ final int y=(int)(selection.getBounds().getY());
+ final int width=(int)(selection.getBounds().getWidth());
+ final int height=(int)(selection.getBounds().getHeight());
pic=createImage(new FilteredImageSource(pic.getSource(),
new CropImageFilter(x,y,width,height)));
}
@@ -2830,67 +2830,67 @@ import xlogo.kernel.perspective.*;
private BufferedImage toBufferedImage(Image image) {
if (image instanceof BufferedImage)
return (BufferedImage)image;
-
+
// This code ensures that all the pixels in the image are loaded
image = new ImageIcon(image).getImage();
-
-
+
+
// Create a buffered image with a format that's compatible with the screen
BufferedImage bimage = null;
- GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+ final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
try {
// Determine the type of transparency of the new buffered image
- int transparency = Transparency.OPAQUE;
-
+ final int transparency = Transparency.OPAQUE;
+
// Create the buffered image
- GraphicsDevice gs = ge.getDefaultScreenDevice();
- GraphicsConfiguration gc = gs.getDefaultConfiguration();
+ final GraphicsDevice gs = ge.getDefaultScreenDevice();
+ final GraphicsConfiguration gc = gs.getDefaultConfiguration();
bimage = gc.createCompatibleImage(
image.getWidth(null), image.getHeight(null), transparency);
- } catch (HeadlessException e) {
+ } catch (final HeadlessException e) {
// The system does not have a screen
}
-
+
if (bimage == null) {
// Create a buffered image using the default color model
- int type = BufferedImage.TYPE_INT_RGB;
+ final int type = BufferedImage.TYPE_INT_RGB;
bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
}
-
+
// Copy image to buffered image
- Graphics g = bimage.createGraphics();
-
+ final Graphics g = bimage.createGraphics();
+
// Paint the image onto the buffered image
g.drawImage(image, 0, 0, null);
g.dispose();
-
+
return bimage;
}
class PositionJViewport implements Runnable{
JViewport jv;
Point p;
- PositionJViewport(JViewport jv, Point p){
+ PositionJViewport(final JViewport jv, final Point p){
this.jv=jv;
this.p=p;
}
public void run(){
- revalidate();
+ revalidate();
//cadre.calculateMargin(); // TODO here is a zoom bug TODO maybe return this
// I have to add those two lines because of a bug I don't understand
// zoom 8 zoom 1 zoom 8
- // Sometimes after the method revalidate(), the left upper corner position
- // wasn't correct
+ // Sometimes after the method revalidate(), the left upper corner position
+ // wasn't correct
cadre.scrollArea.invalidate();
cadre.scrollArea.validate();
- // End Bug
-
+ // End Bug
+
jv.setViewPosition(p);
repaint();
-
+
//cadre.setZoomEnabled(true);
}
}
- private void tryRecord2DMode(double a, double b){
+ private void tryRecord2DMode(final double a, final double b){
if (DrawPanel.record2D==DrawPanel.record2D_POLYGON){
// FillPolygon mode
if (stackTriangle.size()==3){
@@ -2898,10 +2898,10 @@ import xlogo.kernel.perspective.*;
stackTriangle.add(new Point2D.Double(a,b));
}
else{
- stackTriangle.add(new Point2D.Double(a,b));
+ stackTriangle.add(new Point2D.Double(a,b));
}
if (stackTriangle.size()==3){
- GeneralPath gp=new GeneralPath();
+ final GeneralPath gp=new GeneralPath();
Line2D.Double ld=new Line2D.Double(stackTriangle.get(0),stackTriangle.get(1));
gp.append(ld,false);
ld=new Line2D.Double(stackTriangle.get(1),stackTriangle.get(2));