summaryrefslogtreecommitdiffstats
path: root/logo/src/xlogo/kernel/perspective/LightDialog.java
diff options
context:
space:
mode:
Diffstat (limited to 'logo/src/xlogo/kernel/perspective/LightDialog.java')
-rw-r--r--logo/src/xlogo/kernel/perspective/LightDialog.java157
1 files changed, 79 insertions, 78 deletions
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);
}
-
+
}
-
+
}