001    /**
002       ##############################################################################
003       ##                                                                          ##
004       ## Appearance3DChooser                                                      ##
005       ##                                                                          ##
006       ## Copyright (C) 2009  Frederic Roudaut  <frederic.roudaut@free.fr>         ##
007       ##                                                                          ##
008       ##                                                                          ##
009       ## The Basic View Model has been found on Internet. Nevertheless, I do not  ##
010       ## know where, thus if you have any idea, tell me and I will add a          ##
011       ## reference for it.                                                        ##
012       ##                                                                          ##
013       ##                                                                          ##
014       ## This program is free software: you can redistribute it and/or modify     ##
015       ## it under the terms of the GNU General Public License as published by     ##
016       ## the Free Software Foundation, either version 3 of the License, or        ##
017       ## (at your option) any later version.                                      ##
018       ##                                                                          ##
019       ## This program is distributed in the hope that it will be useful,          ##
020       ## but WITHOUT ANY WARRANTY; without even the implied warranty of           ##
021       ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            ##
022       ## GNU General Public License for more details.                             ##
023       ##                                                                          ##
024       ## You should have received a copy of the GNU General Public License        ##
025       ## along with this program.  If not, see <http://www.gnu.org/licenses/>.    ##
026       ##                                                                          ##
027       ##                                                                          ##
028       ##############################################################################
029    **/
030    
031    
032    package com.appearance3Dchooser;
033    
034    
035    import java.awt.*;
036    
037    import javax.swing.*;
038    import javax.swing.border.*;
039    import java.awt.event.*;
040    import javax.swing.event.*;
041    import java.util.Vector;
042    import java.util.Iterator;
043    import java.util.BitSet;
044    import java.net.URL;
045    
046    
047    // Java 3D Packages
048    import com.sun.j3d.utils.geometry.*;
049    import com.sun.j3d.utils.image.TextureLoader;
050    import javax.media.j3d.*;
051    import javax.vecmath.*;
052    
053    
054    /**
055     * Panel creation for having a Rendering View.
056     * 
057     */
058    public class RenderingViewPanel extends JPanel implements ActionListener, ChangeListener
059    {
060        private static final long serialVersionUID = 1L;
061    
062        public static final float SPINNER_COORDINATE_MIN = -100.0f;
063        public static final float SPINNER_COORDINATE_MAX = 100.0f;
064        public static final float SPINNER_COORDINATE_INIT = 0.0f;
065        public static final float SPINNER_COORDINATE_STEP = 0.10f;
066        public static final float SPINNER_ANGLE_MIN = 0.0f;
067        public static final float SPINNER_ANGLE_MAX = 180.0f;
068        public static final float SPINNER_ANGLE_INIT = 180.0f;
069        public static final float SPINNER_ANGLE_STEP = 0.10f;
070        public static final float SPINNER_CONCENTRATION_MIN = 0.0f;
071        public static final float SPINNER_CONCENTRATION_MAX = 128.0f;
072        public static final float SPINNER_CONCENTRATION_INIT = 0.0f;
073        public static final float SPINNER_CONCENTRATION_STEP = 0.10f;
074        public static final int SPINNER_COLOR_MIN = 0;
075        public static final int SPINNER_COLOR_MAX = 255;
076        public static final int SPINNER_COLOR_INIT = 128;    
077        public static final int SPINNER_COLOR_STEP = 1;
078        public static final int SPINNER_BACKGROUNDCOLOR_R_INIT = 180;
079            public static final int SPINNER_BACKGROUNDCOLOR_G_INIT = 180;
080            public static final int SPINNER_BACKGROUNDCOLOR_B_INIT = 120;
081    
082        protected Switch objectsSwitch;
083        protected Switch axisFrontend;
084        protected BranchGroup scene; 
085        protected TransformGroup sceneTransform;
086        protected SceneView vueTop;
087        protected SceneView vueFront;
088        protected SceneView vueLeft;
089        protected SceneView vueRight;
090        protected SceneView bigVue;
091    
092        protected JRadioButton antialiasingButton;
093        protected JRadioButton axisButton;    
094        protected JSpinner backgroundColorRSpinner, backgroundColorGSpinner, backgroundColorBSpinner;
095        protected JRadioButton bigVueButton;
096        protected JRadioButton boxButton;
097        protected JRadioButton sphereButton;
098        protected JRadioButton cylinderButton;
099        protected JRadioButton coneButton;    
100        protected JRadioButton addAmbientLightButton;
101        protected JRadioButton addDirectionalLightButton;
102        protected JRadioButton addSpotLightButton;
103        protected JRadioButton addPointLightButton;
104    
105        protected JPanel scenePanel;
106        protected JPanel addingLightPanel;
107        protected JPanel lightsPanel = new JPanel();                
108        protected JScrollPane lightsPanelScrollPane;
109        protected JFrame bigVueFrame;
110    
111        public static final int LIGHTPANEL_X = 415;
112        public static final int LIGHTPANEL_Y = 370;
113        protected int NbLignsLights = 0;    
114        protected GridBagConstraints lightsConstraint = new GridBagConstraints();
115        protected Texture texture;
116        protected URL DefaultTexture;
117        protected TextureAttributes textureAttributes;
118        protected Transform3D textureTransform;    
119        protected Background background;
120    
121        protected Vector ambientLightsVector;
122        protected Vector directionalLightsVector;
123        protected Vector pointLightsVector;
124        protected Vector spotLightsVector;
125        
126        private Appearance appearanceObjects = new Appearance();
127    
128        /**
129         * Constructor for creating a rendering view panel
130         * @param DefaultTextureName Default Texture File.
131         */    
132        public RenderingViewPanel(URL DefaultTextureName) {
133              
134            DefaultTexture = DefaultTextureName;
135    
136            GridBagConstraints c = new GridBagConstraints();
137            this.setLayout(new GridBagLayout());
138            c.gridx = 0; c.gridy = 0;
139            c.weightx = 0; c.weighty = 0; 
140            c.insets = new Insets(0,0,0,10);
141            c.fill = GridBagConstraints.CENTER;
142            c.anchor = GridBagConstraints.CENTER;
143            this.add(makeScenePanel(),c);
144            c.gridx = 0; c.gridy = 1; 
145            this.add(makeObjectChooserPanel(),c);
146            c.gridx = 1; c.gridy = 0; 
147            c.insets = new Insets(10,0,0,0);
148            this.add(makeLightsPanel(),c);
149            c.gridx = 1; c.gridy = 1; 
150            this.add(makeAddingLightsPanel(),c);
151            initLights();
152        }
153    
154        /**
155         * Panel creation for adding new lights.
156         * 
157         */
158        protected JPanel makeAddingLightsPanel()
159        {
160            addingLightPanel = new JPanel();
161            GridBagConstraints c = new GridBagConstraints();
162            addingLightPanel.setLayout(new GridBagLayout());
163    
164            c.gridx = 0; c.gridy = 0;
165            c.gridheight = 2;
166            c.insets = new Insets(0,0,0,25);
167            JLabel addAddLightLabel = new JLabel(Info.ressources.getObject("ADD").toString()+":");
168            addingLightPanel.add(addAddLightLabel,c);
169    
170            c.gridx = 1; 
171            c.gridheight = 1;
172            c.anchor = GridBagConstraints.CENTER;
173            c.fill = GridBagConstraints.CENTER;
174            c.insets = new Insets(0,0,0,20);
175            addAmbientLightButton = new JRadioButton();
176            addAmbientLightButton.setSelected(false);
177            addAmbientLightButton.addActionListener(this);
178            addingLightPanel.add(addAmbientLightButton,c);
179            
180            c.gridx = 2; 
181            addPointLightButton = new JRadioButton();
182            addPointLightButton.setSelected(false);
183            addPointLightButton.addActionListener(this);
184            addingLightPanel.add(addPointLightButton,c);
185            
186            c.gridx = 3; 
187            addDirectionalLightButton = new JRadioButton();
188            addDirectionalLightButton.setSelected(false);
189            addDirectionalLightButton.addActionListener(this);
190            addingLightPanel.add(addDirectionalLightButton,c);
191            
192            c.gridx = 4; 
193            addSpotLightButton = new JRadioButton();
194            addSpotLightButton.setSelected(false);
195            addSpotLightButton.addActionListener(this);
196            addingLightPanel.add(addSpotLightButton,c);
197    
198            c.gridx = 1; c.gridy = 1;
199            JLabel addAmbientLightLabel = new JLabel(Info.ressources.getObject("Ambient").toString());
200            addingLightPanel.add(addAmbientLightLabel,c);
201            
202            c.gridx = 2; 
203            JLabel addPointLightLabel = new JLabel(Info.ressources.getObject("Point").toString());
204            addingLightPanel.add(addPointLightLabel,c);
205            
206            c.gridx = 3; 
207            JLabel addDirectionalLightLabel = new JLabel(Info.ressources.getObject("Directional").toString());
208            addingLightPanel.add(addDirectionalLightLabel,c);
209            
210            c.gridx = 4; 
211            JLabel addSpotLightLabel = new JLabel(Info.ressources.getObject("Spot").toString());
212            addingLightPanel.add(addSpotLightLabel,c);
213    
214            return addingLightPanel;
215        }
216    
217    
218    
219        /**
220         * Panel creation for controlling lights in the scene.
221         * 
222         */
223        protected JScrollPane makeLightsPanel()
224        {
225            lightsPanel.setLayout(new GridBagLayout());     
226            lightsConstraint.weightx = 0; lightsConstraint.weighty = 0; 
227            lightsConstraint.insets = new Insets(0,0,0,0);
228            lightsConstraint.fill = GridBagConstraints.WEST;
229            lightsConstraint.anchor = GridBagConstraints.WEST;
230            lightsConstraint.gridx = 0;
231            lightsConstraint.gridy = NbLignsLights; 
232            lightsConstraint.insets = new Insets(0,0,0,0);
233            
234            // add a button to set antialiasing
235            antialiasingButton = new JRadioButton(Info.ressources.getObject("Antialiasing").toString());
236            lightsConstraint.gridwidth =2;
237            antialiasingButton.setSelected(false);
238            antialiasingButton.addActionListener(this);
239            lightsPanel.add(antialiasingButton,lightsConstraint);   
240            NbLignsLights++;
241    
242            // add a button to set Axis
243            axisButton = new JRadioButton(Info.ressources.getObject("Axis").toString());
244            lightsConstraint.gridx ++;
245            axisButton.setSelected(false);
246            axisButton.addActionListener(this);
247            lightsPanel.add(axisButton,lightsConstraint);   
248    
249            // add a button to show the big view
250            bigVueButton = new JRadioButton(Info.ressources.getObject("Big_View").toString());
251            lightsConstraint.gridx +=2;
252            bigVueButton.setSelected(false);
253            bigVueButton.addActionListener(this);
254            lightsPanel.add(bigVueButton,lightsConstraint); 
255    
256            lightsConstraint.gridwidth =1;
257            NbLignsLights++;
258    
259            // add a Label for the Background Color                         
260            // Background Color             
261            JLabel backgroundColorLabel = new JLabel(Info.ressources.getObject("Background_Color").toString()+":");
262            lightsConstraint.gridy ++;
263            lightsConstraint.gridx = 0; 
264            lightsConstraint.anchor = GridBagConstraints.WEST;
265            lightsConstraint.insets = new Insets(10,20,0,0);
266            lightsPanel.add(backgroundColorLabel,lightsConstraint);
267            lightsConstraint.insets = new Insets(10,0,0,0);
268            lightsConstraint.anchor = GridBagConstraints.WEST;
269    
270            JLabel backgroundColorR = new JLabel(Info.ressources.getObject("R").toString());
271            lightsConstraint.gridx ++;
272            lightsConstraint.insets = new Insets(10,10,0,5);
273            lightsPanel.add(backgroundColorR,lightsConstraint);
274            lightsConstraint.insets = new Insets(10,0,0,0);
275    
276            SpinnerModel backgroundColorSpinnerRModel = new SpinnerNumberModel(SPINNER_BACKGROUNDCOLOR_R_INIT, //initial value
277                            SPINNER_COLOR_MIN, //min
278                            SPINNER_COLOR_MAX, //max
279                            SPINNER_COLOR_STEP); //step
280            backgroundColorRSpinner = new JSpinner(backgroundColorSpinnerRModel);
281            ((JSpinner.DefaultEditor)backgroundColorRSpinner.getEditor()).getTextField().setColumns(3);
282            backgroundColorRSpinner.addChangeListener(this);
283            lightsConstraint.gridx ++;
284            lightsPanel.add(backgroundColorRSpinner,lightsConstraint);
285    
286            JLabel backgroundColorG = new JLabel(Info.ressources.getObject("G").toString());
287            lightsConstraint.gridx++;
288            lightsConstraint.insets = new Insets(10,10,0,5);
289            lightsPanel.add(backgroundColorG,lightsConstraint);
290            lightsConstraint.insets = new Insets(10,0,0,0);
291    
292            SpinnerModel backgroundColorSpinnerGModel = new SpinnerNumberModel(SPINNER_BACKGROUNDCOLOR_G_INIT , //initial value
293                            SPINNER_COLOR_MIN, //min
294                            SPINNER_COLOR_MAX, //max
295                            SPINNER_COLOR_STEP); //step
296            backgroundColorGSpinner = new JSpinner(backgroundColorSpinnerGModel);
297            ((JSpinner.DefaultEditor)backgroundColorGSpinner.getEditor()).getTextField().setColumns(3);
298            backgroundColorGSpinner.addChangeListener(this);
299            lightsConstraint.gridx ++;
300            lightsPanel.add(backgroundColorGSpinner,lightsConstraint);
301    
302            JLabel backgroundColorB = new JLabel(Info.ressources.getObject("B").toString());
303            lightsConstraint.gridx++;
304            lightsConstraint.insets = new Insets(10,10,0,5);
305            lightsPanel.add(backgroundColorB,lightsConstraint);
306            lightsConstraint.insets = new Insets(10,0,0,0);
307    
308            SpinnerModel backgroundColorSpinnerBModel = new SpinnerNumberModel(SPINNER_BACKGROUNDCOLOR_B_INIT , //initial value
309                            SPINNER_COLOR_MIN, //min
310                            SPINNER_COLOR_MAX, //max
311                            SPINNER_COLOR_STEP); //step
312            backgroundColorBSpinner = new JSpinner(backgroundColorSpinnerBModel);
313            ((JSpinner.DefaultEditor)backgroundColorBSpinner.getEditor()).getTextField().setColumns(3);
314            backgroundColorBSpinner.addChangeListener(this);
315            lightsConstraint.gridx++;
316            lightsPanel.add(backgroundColorBSpinner,lightsConstraint);
317    
318            NbLignsLights += 3;
319                    
320            ambientLightsVector = new Vector();
321            directionalLightsVector = new Vector();
322            pointLightsVector = new Vector();
323            spotLightsVector = new Vector();
324    
325            CreateAmbientLightControl();
326            CreateDirectionalLightControl();
327            CreatePointLightControl();
328            CreateSpotLightControl();
329             
330            lightsPanelScrollPane = new JScrollPane(lightsPanel);
331            lightsPanelScrollPane.setPreferredSize(new Dimension(LIGHTPANEL_X, LIGHTPANEL_Y));
332            return lightsPanelScrollPane;   
333        }
334    
335        /**
336         * Panel creation for controlling an Ambient light in the scene.
337         * 
338         */
339        private void CreateAmbientLightControl()
340        {
341            // Ambient Light        
342            JRadioButton ambientLightButton = new JRadioButton(Info.ressources.getObject("Ambient_Light").toString());
343            ambientLightButton.setSelected(false);
344            ambientLightButton.addActionListener(this);
345            lightsConstraint.gridx = 0;
346            lightsConstraint.gridy = NbLignsLights; 
347            lightsPanel.add(ambientLightButton,lightsConstraint);   
348            
349            JLabel ambientLightsColor = new JLabel(Info.ressources.getObject("Color").toString()+":");
350            lightsConstraint.gridy ++;
351            lightsConstraint.anchor = GridBagConstraints.EAST;
352            lightsConstraint.insets = new Insets(0,0,0,10);
353            lightsPanel.add(ambientLightsColor,lightsConstraint);
354            lightsConstraint.insets = new Insets(0,0,0,0);
355            lightsConstraint.anchor = GridBagConstraints.WEST;
356    
357            JLabel ambientLightsColorR = new JLabel(Info.ressources.getObject("R").toString());
358            lightsConstraint.gridx ++;
359            lightsConstraint.insets = new Insets(0,10,0,5);
360            lightsPanel.add(ambientLightsColorR,lightsConstraint);
361            lightsConstraint.insets = new Insets(0,0,0,0);
362    
363            SpinnerModel ambientLightsSpinnerRModel = new SpinnerNumberModel(SPINNER_COLOR_INIT, //initial value
364                                                                             SPINNER_COLOR_MIN, //min
365                                                                             SPINNER_COLOR_MAX, //max
366                                                                             SPINNER_COLOR_STEP); //step
367            JSpinner ambientLightsColorRSpinner = new JSpinner(ambientLightsSpinnerRModel);
368            ((JSpinner.DefaultEditor)ambientLightsColorRSpinner.getEditor()).getTextField().setColumns(3);
369            ambientLightsColorRSpinner.addChangeListener(this);
370            lightsConstraint.gridx ++;
371            lightsPanel.add(ambientLightsColorRSpinner,lightsConstraint);
372            
373            JLabel ambientLightsColorG = new JLabel(Info.ressources.getObject("G").toString());
374            lightsConstraint.gridx++;
375            lightsConstraint.insets = new Insets(0,10,0,5);
376            lightsPanel.add(ambientLightsColorG,lightsConstraint);
377            lightsConstraint.insets = new Insets(0,0,0,0);
378    
379            SpinnerModel ambientLightsSpinnerGModel = new SpinnerNumberModel(SPINNER_COLOR_INIT, //initial value
380                                                                             SPINNER_COLOR_MIN, //min
381                                                                             SPINNER_COLOR_MAX, //max
382                                                                             SPINNER_COLOR_STEP); //step
383            JSpinner ambientLightsColorGSpinner = new JSpinner(ambientLightsSpinnerGModel);
384            ((JSpinner.DefaultEditor)ambientLightsColorGSpinner.getEditor()).getTextField().setColumns(3);
385            ambientLightsColorGSpinner.addChangeListener(this);
386            lightsConstraint.gridx ++;
387            lightsPanel.add(ambientLightsColorGSpinner,lightsConstraint);
388    
389            JLabel ambientLightsColorB = new JLabel(Info.ressources.getObject("B").toString());
390            lightsConstraint.gridx++;
391            lightsConstraint.insets = new Insets(0,10,0,5);
392            lightsPanel.add(ambientLightsColorB,lightsConstraint);
393            lightsConstraint.insets = new Insets(0,0,0,0);
394    
395            SpinnerModel ambientLightsSpinnerBModel = new SpinnerNumberModel(SPINNER_COLOR_INIT, //initial value
396                                                                             SPINNER_COLOR_MIN, //min
397                                                                             SPINNER_COLOR_MAX, //max
398                                                                             SPINNER_COLOR_STEP); //step
399            JSpinner ambientLightsColorBSpinner = new JSpinner(ambientLightsSpinnerBModel);
400            ((JSpinner.DefaultEditor)ambientLightsColorBSpinner.getEditor()).getTextField().setColumns(3);
401            ambientLightsColorBSpinner.addChangeListener(this);
402            lightsConstraint.gridx++;
403            lightsPanel.add(ambientLightsColorBSpinner,lightsConstraint);
404            
405            ambientLightsVector.add(new AmbientLightObject(ambientLightButton, 
406                                                           ambientLightsColorRSpinner, 
407                                                           ambientLightsColorGSpinner, 
408                                                           ambientLightsColorBSpinner,
409                                                           sceneTransform
410                                                           ));
411            NbLignsLights += 3;
412        }
413        
414    
415        /**
416         * Panel creation for controlling a Directional light in the scene.
417         * 
418         */
419        private void CreateDirectionalLightControl()
420        {
421            // Directional Light 
422            JRadioButton directionalLightButton = new JRadioButton(Info.ressources.getObject("Directional_Light").toString());
423            directionalLightButton.setSelected(false);
424            directionalLightButton.addActionListener(this);
425            lightsConstraint.gridx = 0; 
426            lightsConstraint.gridy = NbLignsLights;
427            lightsPanel.add(directionalLightButton,lightsConstraint);
428    
429            JLabel directionalLightsColor = new JLabel(Info.ressources.getObject("Color").toString()+":");
430            lightsConstraint.gridy ++;
431            lightsConstraint.anchor = GridBagConstraints.EAST;
432            lightsConstraint.insets = new Insets(0,0,0,10);
433            lightsPanel.add(directionalLightsColor,lightsConstraint);
434            lightsConstraint.anchor = GridBagConstraints.WEST;
435            lightsConstraint.insets = new Insets(0,0,0,0);
436    
437            JLabel directionalLightsColorR = new JLabel(Info.ressources.getObject("R").toString());
438            lightsConstraint.gridx ++;
439            lightsConstraint.insets = new Insets(0,10,0,5);
440            lightsPanel.add(directionalLightsColorR,lightsConstraint);
441            lightsConstraint.insets = new Insets(0,0,0,0);
442    
443            SpinnerModel directionalLightsSpinnerRModel = new SpinnerNumberModel(SPINNER_COLOR_INIT, //initial value
444                                                                                 SPINNER_COLOR_MIN, //min
445                                                                                 SPINNER_COLOR_MAX, //max
446                                                                                 SPINNER_COLOR_STEP); //step      
447            JSpinner directionalLightsColorRSpinner = new JSpinner(directionalLightsSpinnerRModel);
448            ((JSpinner.DefaultEditor)directionalLightsColorRSpinner.getEditor()).getTextField().setColumns(3);
449            directionalLightsColorRSpinner.addChangeListener(this);
450            lightsConstraint.gridx++;
451            lightsPanel.add(directionalLightsColorRSpinner,lightsConstraint);
452    
453            JLabel directionalLightsColorG = new JLabel(Info.ressources.getObject("G").toString());
454            lightsConstraint.gridx ++;
455            lightsConstraint.insets = new Insets(0,10,0,5);
456            lightsPanel.add(directionalLightsColorG,lightsConstraint);
457            lightsConstraint.insets = new Insets(0,0,0,0);
458            
459            SpinnerModel directionalLightsSpinnerGModel = new SpinnerNumberModel(SPINNER_COLOR_INIT, //initial value
460                                                                                 SPINNER_COLOR_MIN, //min
461                                                                                 SPINNER_COLOR_MAX, //max
462                                                                                 SPINNER_COLOR_STEP); //step      
463            JSpinner directionalLightsColorGSpinner = new JSpinner(directionalLightsSpinnerGModel);
464            ((JSpinner.DefaultEditor)directionalLightsColorGSpinner.getEditor()).getTextField().setColumns(3);
465            directionalLightsColorGSpinner.addChangeListener(this);
466            lightsConstraint.gridx++;
467            lightsPanel.add(directionalLightsColorGSpinner,lightsConstraint);
468    
469            JLabel directionalLightsColorB = new JLabel(Info.ressources.getObject("B").toString());
470            lightsConstraint.gridx ++;
471            lightsConstraint.insets = new Insets(0,10,0,5);
472            lightsPanel.add(directionalLightsColorB,lightsConstraint);
473            lightsConstraint.insets = new Insets(0,0,0,0);
474    
475            SpinnerModel directionalLightsSpinnerBModel = new SpinnerNumberModel(SPINNER_COLOR_INIT, //initial value
476                                                                                 SPINNER_COLOR_MIN, //min
477                                                                                 SPINNER_COLOR_MAX, //max
478                                                                                 SPINNER_COLOR_STEP); //step      
479            JSpinner directionalLightsColorBSpinner = new JSpinner(directionalLightsSpinnerBModel);
480            ((JSpinner.DefaultEditor)directionalLightsColorBSpinner.getEditor()).getTextField().setColumns(3);
481            directionalLightsColorBSpinner.addChangeListener(this);
482            lightsConstraint.gridx ++;
483            lightsPanel.add(directionalLightsColorBSpinner,lightsConstraint);
484    
485            JLabel directionalLightsDirection = new JLabel(Info.ressources.getObject("Direction").toString()+":");
486            lightsConstraint.gridx = 0;
487            lightsConstraint.gridy ++;
488            lightsConstraint.anchor = GridBagConstraints.EAST;
489            lightsConstraint.insets = new Insets(0,0,0,10);
490            lightsPanel.add(directionalLightsDirection,lightsConstraint);
491            lightsConstraint.anchor = GridBagConstraints.WEST;
492            lightsConstraint.insets = new Insets(0,0,0,0);
493    
494            JLabel directionalLightsDirectionX = new JLabel("X");
495            lightsConstraint.gridx ++;
496            lightsConstraint.insets = new Insets(0,10,0,5);
497            lightsPanel.add(directionalLightsDirectionX,lightsConstraint);
498            lightsConstraint.insets = new Insets(0,0,0,0);
499    
500            SpinnerModel directionalLightsSpinnerXModel = new SpinnerNumberModel(Float.valueOf(SPINNER_COORDINATE_INIT), //initial value
501                                                                                 Float.valueOf(SPINNER_COORDINATE_MIN), //min
502                                                                                 Float.valueOf(SPINNER_COORDINATE_MAX), //max
503                                                                                 Float.valueOf(SPINNER_COORDINATE_STEP)); //step
504            JSpinner directionalLightsDirectionXSpinner = new JSpinner(directionalLightsSpinnerXModel);
505            ((JSpinner.DefaultEditor)directionalLightsDirectionXSpinner.getEditor()).getTextField().setColumns(3);
506            directionalLightsDirectionXSpinner.addChangeListener(this);
507            lightsConstraint.gridx++;
508            lightsPanel.add(directionalLightsDirectionXSpinner,lightsConstraint);
509    
510            JLabel directionalLightsDirectionY = new JLabel("Y");
511            lightsConstraint.gridx ++;
512            lightsConstraint.insets = new Insets(0,10,0,5);
513            lightsPanel.add(directionalLightsDirectionY,lightsConstraint);
514            lightsConstraint.insets = new Insets(0,0,0,0);
515            
516            SpinnerModel directionalLightsSpinnerYModel = new SpinnerNumberModel(Float.valueOf(-0.5f), //initial value
517                                                                                 Float.valueOf(SPINNER_COORDINATE_MIN), //min
518                                                                                 Float.valueOf(SPINNER_COORDINATE_MAX), //max
519                                                                                 Float.valueOf(SPINNER_COORDINATE_STEP)); //step
520            JSpinner directionalLightsDirectionYSpinner = new JSpinner(directionalLightsSpinnerYModel);
521            ((JSpinner.DefaultEditor)directionalLightsDirectionYSpinner.getEditor()).getTextField().setColumns(3);
522            directionalLightsDirectionYSpinner.addChangeListener(this);
523            lightsConstraint.gridx++;
524            lightsPanel.add(directionalLightsDirectionYSpinner,lightsConstraint);
525    
526            JLabel directionalLightsDirectionZ = new JLabel("Z");
527            lightsConstraint.gridx ++;
528            lightsConstraint.insets = new Insets(0,10,0,5);
529            lightsPanel.add(directionalLightsDirectionZ,lightsConstraint);
530            lightsConstraint.insets = new Insets(0,0,0,0);
531    
532            SpinnerModel directionalLightsSpinnerZModel = new SpinnerNumberModel(Float.valueOf(-0.1f), //initial value
533                                                                                 Float.valueOf(SPINNER_COORDINATE_MIN), //min
534                                                                                 Float.valueOf(SPINNER_COORDINATE_MAX), //max
535                                                                                 Float.valueOf(SPINNER_COORDINATE_STEP)); //step
536            JSpinner directionalLightsDirectionZSpinner = new JSpinner(directionalLightsSpinnerZModel);
537            ((JSpinner.DefaultEditor)directionalLightsDirectionZSpinner.getEditor()).getTextField().setColumns(3);
538            directionalLightsDirectionZSpinner.addChangeListener(this);
539            lightsConstraint.gridx ++;
540            lightsPanel.add(directionalLightsDirectionZSpinner,lightsConstraint);
541            
542            directionalLightsVector.add(new DirectionalLightObject(directionalLightButton, 
543                                                                   directionalLightsColorRSpinner, 
544                                                                   directionalLightsColorGSpinner, 
545                                                                   directionalLightsColorBSpinner,
546                                                                   directionalLightsDirectionXSpinner,
547                                                                   directionalLightsDirectionYSpinner,
548                                                                   directionalLightsDirectionZSpinner,
549                                                                   sceneTransform
550                                                                   ));
551            NbLignsLights += 4;
552            
553        }
554    
555    
556        /**
557         * Panel creation for controlling a Point light in the scene.
558         * 
559         */
560        private void CreatePointLightControl()
561        {
562            // Point Light
563            JRadioButton pointLightButton = new JRadioButton(Info.ressources.getObject("Point_Light").toString());
564            pointLightButton.setSelected(false);
565            pointLightButton.addActionListener(this);
566            lightsConstraint.gridx = 0; 
567            lightsConstraint.gridy = NbLignsLights;
568            lightsPanel.add(pointLightButton,lightsConstraint);
569    
570            JLabel pointLightsColor = new JLabel(Info.ressources.getObject("Color").toString()+":");
571            lightsConstraint.gridy ++;
572            lightsConstraint.anchor = GridBagConstraints.EAST;
573            lightsConstraint.insets = new Insets(0,0,0,10);
574            lightsPanel.add(pointLightsColor,lightsConstraint);
575            lightsConstraint.anchor = GridBagConstraints.WEST;
576            lightsConstraint.insets = new Insets(0,0,0,0);
577    
578            JLabel pointLightsColorR = new JLabel(Info.ressources.getObject("R").toString());
579            lightsConstraint.gridx ++;
580            lightsConstraint.insets = new Insets(0,10,0,5);
581            lightsPanel.add(pointLightsColorR,lightsConstraint);
582            lightsConstraint.insets = new Insets(0,0,0,0);
583    
584            SpinnerModel pointLightsSpinnerRModel = new SpinnerNumberModel(SPINNER_COLOR_INIT, //initial value
585                                                                           SPINNER_COLOR_MIN, //min
586                                                                           SPINNER_COLOR_MAX, //max
587                                                                           SPINNER_COLOR_STEP); //step      
588            JSpinner pointLightsColorRSpinner = new JSpinner(pointLightsSpinnerRModel);
589            ((JSpinner.DefaultEditor)pointLightsColorRSpinner.getEditor()).getTextField().setColumns(3);
590            pointLightsColorRSpinner.addChangeListener(this);
591            lightsConstraint.gridx++;
592            lightsPanel.add(pointLightsColorRSpinner,lightsConstraint);
593    
594            JLabel pointLightsColorG = new JLabel(Info.ressources.getObject("G").toString());
595            lightsConstraint.gridx ++;
596            lightsConstraint.insets = new Insets(0,10,0,5);
597            lightsPanel.add(pointLightsColorG,lightsConstraint);
598            lightsConstraint.insets = new Insets(0,0,0,0);
599            
600            SpinnerModel pointLightsSpinnerGModel = new SpinnerNumberModel(SPINNER_COLOR_INIT, //initial value
601                                                                           SPINNER_COLOR_MIN, //min
602                                                                           SPINNER_COLOR_MAX, //max
603                                                                           SPINNER_COLOR_STEP); //step      
604            JSpinner pointLightsColorGSpinner = new JSpinner(pointLightsSpinnerGModel);
605            ((JSpinner.DefaultEditor)pointLightsColorGSpinner.getEditor()).getTextField().setColumns(3);
606            pointLightsColorGSpinner.addChangeListener(this);
607            lightsConstraint.gridx++;
608            lightsPanel.add(pointLightsColorGSpinner,lightsConstraint);
609    
610            JLabel pointLightsColorB = new JLabel(Info.ressources.getObject("B").toString());
611            lightsConstraint.gridx ++;
612            lightsConstraint.insets = new Insets(0,10,0,5);
613            lightsPanel.add(pointLightsColorB,lightsConstraint);
614            lightsConstraint.insets = new Insets(0,0,0,0);
615    
616            SpinnerModel pointLightsSpinnerBModel = new SpinnerNumberModel(SPINNER_COLOR_INIT, //initial value
617                                                                           SPINNER_COLOR_MIN, //min
618                                                                           SPINNER_COLOR_MAX, //max
619                                                                           SPINNER_COLOR_STEP); //step      
620            JSpinner pointLightsColorBSpinner = new JSpinner(pointLightsSpinnerBModel);
621            ((JSpinner.DefaultEditor)pointLightsColorBSpinner.getEditor()).getTextField().setColumns(3);
622            pointLightsColorBSpinner.addChangeListener(this);
623            lightsConstraint.gridx ++;
624            lightsPanel.add(pointLightsColorBSpinner,lightsConstraint);
625            
626            JLabel pointLightsPosition = new JLabel(Info.ressources.getObject("Position").toString()+":");
627            lightsConstraint.gridx = 0;
628            lightsConstraint.gridy ++;
629            lightsConstraint.anchor = GridBagConstraints.EAST;
630            lightsConstraint.insets = new Insets(0,0,0,10);
631            lightsPanel.add(pointLightsPosition,lightsConstraint);
632            lightsConstraint.anchor = GridBagConstraints.WEST;
633            lightsConstraint.insets = new Insets(0,0,0,0);
634    
635            JLabel pointLightsPositionX = new JLabel("X");
636            lightsConstraint.gridx ++;
637            lightsConstraint.insets = new Insets(0,10,0,5);
638            lightsPanel.add(pointLightsPositionX,lightsConstraint);
639            lightsConstraint.insets = new Insets(0,0,0,0);
640    
641            SpinnerModel pointLightsSpinnerXModel = new SpinnerNumberModel(Float.valueOf(SPINNER_COORDINATE_INIT), //initial value
642                                                                           Float.valueOf(SPINNER_COORDINATE_MIN), //min
643                                                                           Float.valueOf(SPINNER_COORDINATE_MAX), //max
644                                                                           Float.valueOf(SPINNER_COORDINATE_STEP)); //step
645            JSpinner pointLightsPositionXSpinner = new JSpinner(pointLightsSpinnerXModel);
646            ((JSpinner.DefaultEditor)pointLightsPositionXSpinner.getEditor()).getTextField().setColumns(3);
647            pointLightsPositionXSpinner.addChangeListener(this);
648            lightsConstraint.gridx++;
649            lightsPanel.add(pointLightsPositionXSpinner,lightsConstraint);
650    
651            JLabel pointLightsPositionY = new JLabel("Y");
652            lightsConstraint.gridx ++;
653            lightsConstraint.insets = new Insets(0,10,0,5);
654            lightsPanel.add(pointLightsPositionY,lightsConstraint);
655            lightsConstraint.insets = new Insets(0,0,0,0);
656            
657            SpinnerModel pointLightsSpinnerYModel = new SpinnerNumberModel(Float.valueOf(SPINNER_COORDINATE_INIT), //initial value
658                                                                           Float.valueOf(SPINNER_COORDINATE_MIN), //min
659                                                                           Float.valueOf(SPINNER_COORDINATE_MAX), //max
660                                                                           Float.valueOf(SPINNER_COORDINATE_STEP)); //step
661            JSpinner pointLightsPositionYSpinner = new JSpinner(pointLightsSpinnerYModel);
662            ((JSpinner.DefaultEditor)pointLightsPositionYSpinner.getEditor()).getTextField().setColumns(3);
663            pointLightsPositionYSpinner.addChangeListener(this);
664            lightsConstraint.gridx++;
665            lightsPanel.add(pointLightsPositionYSpinner,lightsConstraint);
666    
667            JLabel pointLightsPositionZ = new JLabel("Z");
668            lightsConstraint.gridx ++;
669            lightsConstraint.insets = new Insets(0,10,0,5);
670            lightsPanel.add(pointLightsPositionZ,lightsConstraint);
671            lightsConstraint.insets = new Insets(0,0,0,0);
672    
673            SpinnerModel pointLightsSpinnerZModel = new SpinnerNumberModel(Float.valueOf(1.5f), //initial value
674                                                                           Float.valueOf(SPINNER_COORDINATE_MIN), //min
675                                                                           Float.valueOf(SPINNER_COORDINATE_MAX), //max
676                                                                           Float.valueOf(SPINNER_COORDINATE_STEP)); //step
677            JSpinner pointLightsPositionZSpinner = new JSpinner(pointLightsSpinnerZModel);
678            ((JSpinner.DefaultEditor)pointLightsPositionZSpinner.getEditor()).getTextField().setColumns(3);
679            pointLightsPositionZSpinner.addChangeListener(this);
680            lightsConstraint.gridx ++;
681            lightsPanel.add(pointLightsPositionZSpinner,lightsConstraint);
682            
683            JLabel pointLightsAttenuation = new JLabel(Info.ressources.getObject("Attenuation").toString()+":");
684            lightsConstraint.gridx = 0; lightsConstraint.gridy ++;
685            lightsConstraint.anchor = GridBagConstraints.EAST;
686            lightsConstraint.insets = new Insets(0,0,0,10);
687            lightsPanel.add(pointLightsAttenuation,lightsConstraint);
688            lightsConstraint.anchor = GridBagConstraints.WEST;
689            lightsConstraint.insets = new Insets(0,0,0,0);
690    
691            JLabel pointLightsAttenuationX = new JLabel("X");
692            lightsConstraint.gridx ++;
693            lightsConstraint.insets = new Insets(0,10,0,5);
694            lightsPanel.add(pointLightsAttenuationX,lightsConstraint);
695            lightsConstraint.insets = new Insets(0,0,0,0);
696    
697            SpinnerModel pointLightsSpinnerXAttenuationModel = new SpinnerNumberModel(Float.valueOf(SPINNER_COORDINATE_INIT), //initial value
698                                                                                      Float.valueOf(SPINNER_COORDINATE_MIN), //min
699                                                                                      Float.valueOf(SPINNER_COORDINATE_MAX), //max
700                                                                                      Float.valueOf(SPINNER_COORDINATE_STEP)); //step
701            JSpinner pointLightsAttenuationXSpinner = new JSpinner(pointLightsSpinnerXAttenuationModel);
702            ((JSpinner.DefaultEditor)pointLightsAttenuationXSpinner.getEditor()).getTextField().setColumns(3);
703            pointLightsAttenuationXSpinner.addChangeListener(this);
704            lightsConstraint.gridx++;
705            lightsPanel.add(pointLightsAttenuationXSpinner,lightsConstraint);
706    
707            JLabel pointLightsAttenuationY = new JLabel("Y");
708            lightsConstraint.gridx ++;
709            lightsConstraint.insets = new Insets(0,10,0,5);
710            lightsPanel.add(pointLightsAttenuationY,lightsConstraint);
711            lightsConstraint.insets = new Insets(0,0,0,0);
712            
713            SpinnerModel pointLightsSpinnerYAttenuationModel = new SpinnerNumberModel(Float.valueOf(0.5f), //initial value
714                                                                                      Float.valueOf(SPINNER_COORDINATE_MIN), //min
715                                                                                      Float.valueOf(SPINNER_COORDINATE_MAX), //max
716                                                                                      Float.valueOf(SPINNER_COORDINATE_STEP)); //step
717            JSpinner pointLightsAttenuationYSpinner = new JSpinner(pointLightsSpinnerYAttenuationModel);
718            ((JSpinner.DefaultEditor)pointLightsAttenuationYSpinner.getEditor()).getTextField().setColumns(3);
719            pointLightsAttenuationYSpinner.addChangeListener(this);
720            lightsConstraint.gridx++;
721            lightsPanel.add(pointLightsAttenuationYSpinner,lightsConstraint);
722    
723            JLabel pointLightsAttenuationZ = new JLabel("Z");
724            lightsConstraint.gridx ++;
725            lightsConstraint.insets = new Insets(0,10,0,5);
726            lightsPanel.add(pointLightsAttenuationZ,lightsConstraint);
727            lightsConstraint.insets = new Insets(0,0,0,0);
728    
729            SpinnerModel pointLightsSpinnerZAttenuationModel = new SpinnerNumberModel(Float.valueOf(1.0f), //initial value
730                                                                                      Float.valueOf(SPINNER_COORDINATE_MIN), //min
731                                                                                      Float.valueOf(SPINNER_COORDINATE_MAX), //max
732                                                                                      Float.valueOf(SPINNER_COORDINATE_STEP)); //step
733            JSpinner pointLightsAttenuationZSpinner = new JSpinner(pointLightsSpinnerZAttenuationModel);
734            ((JSpinner.DefaultEditor)pointLightsAttenuationZSpinner.getEditor()).getTextField().setColumns(3);
735            pointLightsAttenuationZSpinner.addChangeListener(this);
736            lightsConstraint.gridx ++;
737            lightsPanel.add(pointLightsAttenuationZSpinner,lightsConstraint);
738    
739            pointLightsVector.add(new PointLightObject(pointLightButton, 
740                                                       pointLightsColorRSpinner, 
741                                                       pointLightsColorGSpinner, 
742                                                       pointLightsColorBSpinner,
743                                                       pointLightsPositionXSpinner,
744                                                       pointLightsPositionYSpinner,
745                                                       pointLightsPositionZSpinner,
746                                                       pointLightsAttenuationXSpinner,
747                                                       pointLightsAttenuationYSpinner,
748                                                       pointLightsAttenuationZSpinner,
749                                                       sceneTransform
750                                                       ));
751    
752            NbLignsLights += 5;
753        }
754    
755    
756    
757        /**
758         * Panel creation for controlling a Spot light in the scene.
759         * 
760         */
761        private void CreateSpotLightControl()
762        {
763            // Spot Light 
764            JRadioButton spotLightButton = new JRadioButton(Info.ressources.getObject("Spot_Light").toString());
765            spotLightButton.setSelected(false);
766            spotLightButton.addActionListener(this);
767            lightsConstraint.gridx = 0; 
768            lightsConstraint.gridy = NbLignsLights;
769            lightsPanel.add(spotLightButton,lightsConstraint);
770    
771            JLabel spotLightsColor = new JLabel(Info.ressources.getObject("Color").toString()+":");
772            lightsConstraint.gridy ++;
773            lightsConstraint.anchor = GridBagConstraints.EAST;
774            lightsConstraint.insets = new Insets(0,0,0,10);
775            lightsPanel.add(spotLightsColor,lightsConstraint);
776            lightsConstraint.anchor = GridBagConstraints.WEST;
777            lightsConstraint.insets = new Insets(0,0,0,0);
778    
779            JLabel spotLightsColorR = new JLabel(Info.ressources.getObject("R").toString());
780            lightsConstraint.gridx ++;
781            lightsConstraint.insets = new Insets(0,10,0,5);
782            lightsPanel.add(spotLightsColorR,lightsConstraint);
783            lightsConstraint.insets = new Insets(0,0,0,0);
784    
785            SpinnerModel spotLightsSpinnerRModel = new SpinnerNumberModel(SPINNER_COLOR_INIT, //initial value
786                                                                          SPINNER_COLOR_MIN, //min
787                                                                          SPINNER_COLOR_MAX, //max
788                                                                          SPINNER_COLOR_STEP); //step      
789            JSpinner spotLightsColorRSpinner = new JSpinner(spotLightsSpinnerRModel);
790            ((JSpinner.DefaultEditor)spotLightsColorRSpinner.getEditor()).getTextField().setColumns(3);
791            spotLightsColorRSpinner.addChangeListener(this);
792            lightsConstraint.gridx++;
793            lightsPanel.add(spotLightsColorRSpinner,lightsConstraint);
794    
795            JLabel spotLightsColorG = new JLabel(Info.ressources.getObject("G").toString());
796            lightsConstraint.gridx ++;
797            lightsConstraint.insets = new Insets(0,10,0,5);
798            lightsPanel.add(spotLightsColorG,lightsConstraint);
799            lightsConstraint.insets = new Insets(0,0,0,0);
800            
801            SpinnerModel spotLightsSpinnerGModel = new SpinnerNumberModel(SPINNER_COLOR_INIT, //initial value
802                                                                          SPINNER_COLOR_MIN, //min
803                                                                          SPINNER_COLOR_MAX, //max
804                                                                          SPINNER_COLOR_STEP); //step      
805            JSpinner spotLightsColorGSpinner = new JSpinner(spotLightsSpinnerGModel);
806            ((JSpinner.DefaultEditor)spotLightsColorGSpinner.getEditor()).getTextField().setColumns(3);
807            spotLightsColorGSpinner.addChangeListener(this);
808            lightsConstraint.gridx++;
809            lightsPanel.add(spotLightsColorGSpinner,lightsConstraint);
810    
811            JLabel spotLightsColorB = new JLabel(Info.ressources.getObject("B").toString());
812            lightsConstraint.gridx ++;
813            lightsConstraint.insets = new Insets(0,10,0,5);
814            lightsPanel.add(spotLightsColorB,lightsConstraint);
815            lightsConstraint.insets = new Insets(0,0,0,0);
816    
817            SpinnerModel spotLightsSpinnerBModel = new SpinnerNumberModel(SPINNER_COLOR_INIT, //initial value
818                                                                          SPINNER_COLOR_MIN, //min
819                                                                          SPINNER_COLOR_MAX, //max
820                                                                          SPINNER_COLOR_STEP); //step      
821            JSpinner spotLightsColorBSpinner = new JSpinner(spotLightsSpinnerBModel);
822            ((JSpinner.DefaultEditor)spotLightsColorBSpinner.getEditor()).getTextField().setColumns(3);
823            spotLightsColorBSpinner.addChangeListener(this);
824            lightsConstraint.gridx ++;
825            lightsPanel.add(spotLightsColorBSpinner,lightsConstraint);
826    
827            JLabel spotLightsPosition = new JLabel(Info.ressources.getObject("Position").toString()+":");
828            lightsConstraint.gridx = 0;
829            lightsConstraint.gridy ++;
830            lightsConstraint.anchor = GridBagConstraints.EAST;
831            lightsConstraint.insets = new Insets(0,0,0,10);
832            lightsPanel.add(spotLightsPosition,lightsConstraint);
833            lightsConstraint.anchor = GridBagConstraints.WEST;
834            lightsConstraint.insets = new Insets(0,0,0,0);
835    
836            JLabel spotLightsPositionX = new JLabel("X");
837            lightsConstraint.gridx ++;
838            lightsConstraint.insets = new Insets(0,10,0,5);
839            lightsPanel.add(spotLightsPositionX,lightsConstraint);
840            lightsConstraint.insets = new Insets(0,0,0,0);
841    
842            SpinnerModel spotLightsSpinnerXModel = new SpinnerNumberModel(Float.valueOf(SPINNER_COORDINATE_INIT), //initial value
843                                                                          Float.valueOf(SPINNER_COORDINATE_MIN), //min
844                                                                          Float.valueOf(SPINNER_COORDINATE_MAX), //max
845                                                                          Float.valueOf(SPINNER_COORDINATE_STEP)); //step
846            JSpinner spotLightsPositionXSpinner = new JSpinner(spotLightsSpinnerXModel);
847            ((JSpinner.DefaultEditor)spotLightsPositionXSpinner.getEditor()).getTextField().setColumns(3);
848            spotLightsPositionXSpinner.addChangeListener(this);
849            lightsConstraint.gridx++;
850            lightsPanel.add(spotLightsPositionXSpinner,lightsConstraint);
851    
852            JLabel spotLightsPositionY = new JLabel("Y");
853            lightsConstraint.gridx ++;
854            lightsConstraint.insets = new Insets(0,10,0,5);
855            lightsPanel.add(spotLightsPositionY,lightsConstraint);
856            lightsConstraint.insets = new Insets(0,0,0,0);
857            
858            SpinnerModel spotLightsSpinnerYModel = new SpinnerNumberModel(Float.valueOf(1.7f), //initial value
859                                                                          Float.valueOf(SPINNER_COORDINATE_MIN), //min
860                                                                          Float.valueOf(SPINNER_COORDINATE_MAX), //max
861                                                                          Float.valueOf(SPINNER_COORDINATE_STEP)); //step
862            JSpinner spotLightsPositionYSpinner = new JSpinner(spotLightsSpinnerYModel);
863            ((JSpinner.DefaultEditor)spotLightsPositionYSpinner.getEditor()).getTextField().setColumns(3);
864            spotLightsPositionYSpinner.addChangeListener(this);
865            lightsConstraint.gridx++;
866            lightsPanel.add(spotLightsPositionYSpinner,lightsConstraint);
867    
868            JLabel spotLightsPositionZ = new JLabel("Z");
869            lightsConstraint.gridx ++;
870            lightsConstraint.insets = new Insets(0,10,0,5);
871            lightsPanel.add(spotLightsPositionZ,lightsConstraint);
872            lightsConstraint.insets = new Insets(0,0,0,0);
873    
874            SpinnerModel spotLightsSpinnerZModel = new SpinnerNumberModel(Float.valueOf(1.5f), //initial value
875                                                                          Float.valueOf(SPINNER_COORDINATE_MIN), //min
876                                                                          Float.valueOf(SPINNER_COORDINATE_MAX), //max
877                                                                          Float.valueOf(SPINNER_COORDINATE_STEP)); //step
878            JSpinner spotLightsPositionZSpinner = new JSpinner(spotLightsSpinnerZModel);
879            ((JSpinner.DefaultEditor)spotLightsPositionZSpinner.getEditor()).getTextField().setColumns(3);
880            spotLightsPositionZSpinner.addChangeListener(this);
881            lightsConstraint.gridx ++;
882            lightsPanel.add(spotLightsPositionZSpinner,lightsConstraint);
883            
884            JLabel spotLightsAttenuation = new JLabel(Info.ressources.getObject("Attenuation").toString()+":");
885            lightsConstraint.gridx = 0; lightsConstraint.gridy ++;
886            lightsConstraint.anchor = GridBagConstraints.EAST;
887            lightsConstraint.insets = new Insets(0,0,0,10);
888            lightsPanel.add(spotLightsAttenuation,lightsConstraint);
889            lightsConstraint.anchor = GridBagConstraints.WEST;
890            lightsConstraint.insets = new Insets(0,0,0,0);
891    
892            JLabel spotLightsAttenuationX = new JLabel("X");
893            lightsConstraint.gridx ++;
894            lightsConstraint.insets = new Insets(0,10,0,5);
895            lightsPanel.add(spotLightsAttenuationX,lightsConstraint);
896            lightsConstraint.insets = new Insets(0,0,0,0);
897    
898            SpinnerModel spotLightsSpinnerXAttenuationModel = new SpinnerNumberModel(Float.valueOf(SPINNER_COORDINATE_INIT), //initial value
899                                                                                     Float.valueOf(SPINNER_COORDINATE_MIN), //min
900                                                                                     Float.valueOf(SPINNER_COORDINATE_MAX), //max
901                                                                                     Float.valueOf(SPINNER_COORDINATE_STEP)); //step
902            JSpinner spotLightsAttenuationXSpinner = new JSpinner(spotLightsSpinnerXAttenuationModel);
903            ((JSpinner.DefaultEditor)spotLightsAttenuationXSpinner.getEditor()).getTextField().setColumns(3);
904            spotLightsAttenuationXSpinner.addChangeListener(this);
905            lightsConstraint.gridx++;
906            lightsPanel.add(spotLightsAttenuationXSpinner,lightsConstraint);
907    
908            JLabel spotLightsAttenuationY = new JLabel("Y");
909            lightsConstraint.gridx ++;
910            lightsConstraint.insets = new Insets(0,10,0,5);
911            lightsPanel.add(spotLightsAttenuationY,lightsConstraint);
912            lightsConstraint.insets = new Insets(0,0,0,0);
913            
914            SpinnerModel spotLightsSpinnerYAttenuationModel = new SpinnerNumberModel(Float.valueOf(SPINNER_COORDINATE_INIT), //initial value
915                                                                                     Float.valueOf(SPINNER_COORDINATE_MIN), //min
916                                                                                     Float.valueOf(SPINNER_COORDINATE_MAX), //max
917                                                                                     Float.valueOf(SPINNER_COORDINATE_STEP)); //step
918            JSpinner spotLightsAttenuationYSpinner = new JSpinner(spotLightsSpinnerYAttenuationModel);
919            ((JSpinner.DefaultEditor)spotLightsAttenuationYSpinner.getEditor()).getTextField().setColumns(3);
920            spotLightsAttenuationYSpinner.addChangeListener(this);
921            lightsConstraint.gridx++;
922            lightsPanel.add(spotLightsAttenuationYSpinner,lightsConstraint);
923    
924            JLabel spotLightsAttenuationZ = new JLabel("Z");
925            lightsConstraint.gridx ++;
926            lightsConstraint.insets = new Insets(0,10,0,5);
927            lightsPanel.add(spotLightsAttenuationZ,lightsConstraint);
928            lightsConstraint.insets = new Insets(0,0,0,0);
929    
930            SpinnerModel spotLightsSpinnerZAttenuationModel = new SpinnerNumberModel(Float.valueOf(1.5f), //initial value
931                                                                                     Float.valueOf(SPINNER_COORDINATE_MIN), //min
932                                                                                     Float.valueOf(SPINNER_COORDINATE_MAX), //max
933                                                                                     Float.valueOf(SPINNER_COORDINATE_STEP)); //step
934            JSpinner spotLightsAttenuationZSpinner = new JSpinner(spotLightsSpinnerZAttenuationModel);
935            ((JSpinner.DefaultEditor)spotLightsAttenuationZSpinner.getEditor()).getTextField().setColumns(3);
936            spotLightsAttenuationZSpinner.addChangeListener(this);
937            lightsConstraint.gridx ++;
938            lightsPanel.add(spotLightsAttenuationZSpinner,lightsConstraint);
939    
940            JLabel spotLightsDirection = new JLabel(Info.ressources.getObject("Direction").toString()+":");
941            lightsConstraint.gridx = 0;
942            lightsConstraint.gridy ++;
943            lightsConstraint.anchor = GridBagConstraints.EAST;
944            lightsConstraint.insets = new Insets(0,0,0,10);
945            lightsPanel.add(spotLightsDirection,lightsConstraint);
946            lightsConstraint.anchor = GridBagConstraints.WEST;
947            lightsConstraint.insets = new Insets(0,0,0,0);
948    
949            JLabel spotLightsDirectionX = new JLabel("X");
950            lightsConstraint.gridx ++;
951            lightsConstraint.insets = new Insets(0,10,0,5);
952            lightsPanel.add(spotLightsDirectionX,lightsConstraint);
953            lightsConstraint.insets = new Insets(0,0,0,0);
954    
955            SpinnerModel spotLightsSpinnerXDirectionModel = new SpinnerNumberModel(Float.valueOf(SPINNER_COORDINATE_INIT), //initial value
956                                                                                   Float.valueOf(SPINNER_COORDINATE_MIN), //min
957                                                                                   Float.valueOf(SPINNER_COORDINATE_MAX), //max
958                                                                                   Float.valueOf(SPINNER_COORDINATE_STEP)); //step
959            JSpinner spotLightsDirectionXSpinner = new JSpinner(spotLightsSpinnerXDirectionModel);
960            ((JSpinner.DefaultEditor)spotLightsDirectionXSpinner.getEditor()).getTextField().setColumns(3);
961            spotLightsDirectionXSpinner.addChangeListener(this);
962            lightsConstraint.gridx++;
963            lightsPanel.add(spotLightsDirectionXSpinner,lightsConstraint);
964    
965            JLabel spotLightsDirectionY = new JLabel("Y");
966            lightsConstraint.gridx ++;
967            lightsConstraint.insets = new Insets(0,10,0,5);
968            lightsPanel.add(spotLightsDirectionY,lightsConstraint);
969            lightsConstraint.insets = new Insets(0,0,0,0);
970            
971            SpinnerModel spotLightsSpinnerYDirectionModel = new SpinnerNumberModel(Float.valueOf(SPINNER_COORDINATE_INIT), //initial value
972                                                                                   Float.valueOf(SPINNER_COORDINATE_MIN), //min
973                                                                                   Float.valueOf(SPINNER_COORDINATE_MAX), //max
974                                                                                   Float.valueOf(SPINNER_COORDINATE_STEP)); //step
975            JSpinner spotLightsDirectionYSpinner = new JSpinner(spotLightsSpinnerYDirectionModel);
976            ((JSpinner.DefaultEditor)spotLightsDirectionYSpinner.getEditor()).getTextField().setColumns(3);
977            spotLightsDirectionYSpinner.addChangeListener(this);
978            lightsConstraint.gridx++;
979            lightsPanel.add(spotLightsDirectionYSpinner,lightsConstraint);
980    
981            JLabel spotLightsDirectionZ = new JLabel("Z");
982            lightsConstraint.gridx ++;
983            lightsConstraint.insets = new Insets(0,10,0,5);
984            lightsPanel.add(spotLightsDirectionZ,lightsConstraint);
985            lightsConstraint.insets = new Insets(0,0,0,0);
986    
987            SpinnerModel spotLightsSpinnerZDirectionModel = new SpinnerNumberModel(Float.valueOf(SPINNER_COORDINATE_INIT), //initial value
988                                                                                   Float.valueOf(SPINNER_COORDINATE_MIN), //min
989                                                                                   Float.valueOf(SPINNER_COORDINATE_MAX), //max
990                                                                                   Float.valueOf(SPINNER_COORDINATE_STEP)); //step
991            JSpinner spotLightsDirectionZSpinner = new JSpinner(spotLightsSpinnerZDirectionModel);
992            ((JSpinner.DefaultEditor)spotLightsDirectionZSpinner.getEditor()).getTextField().setColumns(3);
993            spotLightsDirectionZSpinner.addChangeListener(this);
994            lightsConstraint.gridx ++;
995            lightsPanel.add(spotLightsDirectionZSpinner,lightsConstraint);
996    
997            JLabel spotLightsSpreadAngle = new JLabel(Info.ressources.getObject("SpreadAngle").toString()+":");
998            lightsConstraint.anchor = GridBagConstraints.EAST;
999            lightsConstraint.insets = new Insets(0,0,0,10);
1000            lightsConstraint.gridx = 0;
1001            lightsConstraint.gridy ++;
1002            lightsPanel.add(spotLightsSpreadAngle,lightsConstraint);
1003            lightsConstraint.anchor = GridBagConstraints.WEST;
1004            lightsConstraint.insets = new Insets(0,0,0,0);
1005            lightsConstraint.gridx +=2;
1006    
1007            SpinnerModel spotLightsSpinnerSpreadAngleModel = new SpinnerNumberModel(Float.valueOf(SPINNER_ANGLE_INIT), //initial value
1008                                                                                    Float.valueOf(SPINNER_ANGLE_MIN), //min
1009                                                                                    Float.valueOf(SPINNER_ANGLE_MAX), //max
1010                                                                                    Float.valueOf(SPINNER_ANGLE_STEP)); //step
1011            JSpinner spotLightsSpreadAngleSpinner = new JSpinner(spotLightsSpinnerSpreadAngleModel);
1012            ((JSpinner.DefaultEditor)spotLightsSpreadAngleSpinner.getEditor()).getTextField().setColumns(3);
1013            spotLightsSpreadAngleSpinner.addChangeListener(this);
1014            lightsPanel.add(spotLightsSpreadAngleSpinner,lightsConstraint);
1015    
1016            JLabel spotLightsConcentration = new JLabel(Info.ressources.getObject("Concentration").toString()+":");
1017            lightsConstraint.anchor = GridBagConstraints.EAST;
1018            lightsConstraint.insets = new Insets(0,0,0,10);
1019            lightsConstraint.gridx = 0;
1020            lightsConstraint.gridy ++;
1021            lightsPanel.add(spotLightsConcentration,lightsConstraint);
1022            lightsConstraint.anchor = GridBagConstraints.WEST;
1023            lightsConstraint.insets = new Insets(0,0,0,0);
1024            lightsConstraint.gridx +=2;
1025    
1026            SpinnerModel spotLightsSpinnerConcentrationModel = new SpinnerNumberModel(Float.valueOf(SPINNER_CONCENTRATION_INIT), //initial value
1027                                                                                      Float.valueOf(SPINNER_CONCENTRATION_MIN), //min
1028                                                                                      Float.valueOf(SPINNER_CONCENTRATION_MAX), //max
1029                                                                                      Float.valueOf(SPINNER_CONCENTRATION_STEP)); //step
1030            JSpinner spotLightsConcentrationSpinner = new JSpinner(spotLightsSpinnerConcentrationModel);
1031            ((JSpinner.DefaultEditor)spotLightsConcentrationSpinner.getEditor()).getTextField().setColumns(3);
1032            spotLightsConcentrationSpinner.addChangeListener(this);
1033            lightsPanel.add(spotLightsConcentrationSpinner,lightsConstraint);
1034            
1035            
1036            spotLightsVector.add(new SpotLightObject(spotLightButton, 
1037                                                     spotLightsColorRSpinner, 
1038                                                     spotLightsColorGSpinner, 
1039                                                     spotLightsColorBSpinner,
1040                                                     spotLightsPositionXSpinner,
1041                                                     spotLightsPositionYSpinner,
1042                                                     spotLightsPositionZSpinner,
1043                                                     spotLightsAttenuationXSpinner,
1044                                                     spotLightsAttenuationYSpinner,
1045                                                     spotLightsAttenuationZSpinner,
1046                                                     spotLightsDirectionXSpinner,
1047                                                     spotLightsDirectionYSpinner,
1048                                                     spotLightsDirectionZSpinner,
1049                                                     spotLightsSpreadAngleSpinner,
1050                                                     spotLightsConcentrationSpinner,
1051                                                     sceneTransform
1052                                                     ));
1053    
1054            NbLignsLights += 8;
1055        }
1056    
1057    
1058        /**
1059         * Panel for the 3D scene.
1060         * 
1061         */
1062        protected JPanel makeScenePanel()
1063        {
1064            scenePanel = new JPanel();
1065            scenePanel.setLayout(new GridLayout(2, 2));
1066            scenePanel.setPreferredSize(new Dimension(350, 350));
1067            
1068            // Creation of Universe and Local for the 3D scene and the cameras
1069            VirtualUniverse universe = new VirtualUniverse();
1070            Locale locale = new Locale(universe);
1071    
1072            // Creation of the Views 
1073            // Front View
1074            vueFront = new SceneView();
1075            TransformGroup vpTG = vueFront.getViewPlatformTransformGroup();
1076            Transform3D transform = new Transform3D();
1077            transform.setTranslation(new Vector3f(0f, 0f, 3.7f));
1078            vpTG.setTransform(transform);
1079    
1080            // Right View
1081            vueRight = new SceneView();
1082            vpTG = vueRight.getViewPlatformTransformGroup();
1083            transform = new Transform3D();
1084            transform.setTranslation(new Vector3f(-3.7f, 0f, 0f));
1085            Transform3D transform2 = new Transform3D();
1086            transform2.rotY(-Math.PI / 2.0);
1087            transform.mul(transform2);
1088            vpTG.setTransform(transform);
1089    
1090            // Left View
1091            vueLeft = new SceneView();
1092            vpTG = vueLeft.getViewPlatformTransformGroup();
1093            transform = new Transform3D();
1094            transform.setTranslation(new Vector3f(3.7f, 0f, 0f));
1095            transform2 = new Transform3D();
1096            transform2.rotY(Math.PI / 2.0);
1097            transform.mul(transform2);
1098            vpTG.setTransform(transform);
1099    
1100            // Top View
1101            vueTop = new SceneView();
1102            vpTG = vueTop.getViewPlatformTransformGroup();
1103            transform = new Transform3D();
1104            transform.setTranslation(new Vector3f(0f, 3.7f, 0f));   
1105            transform2 = new Transform3D();
1106            transform2.rotX(-Math.PI / 2.0);
1107            transform.mul(transform2);
1108            vpTG.setTransform(transform);
1109            
1110            // Big View 
1111            bigVue = new SceneView();
1112            vpTG = bigVue.getViewPlatformTransformGroup();
1113            transform = new Transform3D();
1114            transform.setTranslation(new Vector3f(0f, 0f, 3.7f));
1115    
1116            /*transform.setTranslation(new Vector3f(-2.4f, 1.7f, 1.7f));
1117              transform2 = new Transform3D();
1118              transform2.rotX(-Math.PI / 4.0);
1119              transform.mul(transform2);
1120              transform2 = new Transform3D();
1121              transform2.rotY(-Math.PI / 4.0);
1122              transform.mul(transform2);    */
1123            vpTG.setTransform(transform);
1124    
1125            // Attach the views to the locale object
1126            locale.addBranchGraph(vueFront.getParent());
1127            locale.addBranchGraph(vueRight.getParent());
1128            locale.addBranchGraph(vueLeft.getParent());
1129            locale.addBranchGraph(vueTop.getParent());
1130            locale.addBranchGraph(bigVue.getParent());
1131    
1132            // 3D Scene Creation        
1133            scene = createSceneGraph(vueTop.getCanvas3D(),
1134                                     vueRight.getCanvas3D(),
1135                                     vueLeft.getCanvas3D(),
1136                                     vueFront.getCanvas3D(),
1137                                     bigVue.getCanvas3D());
1138                    
1139            // Compilation of the 3D Scene
1140            scene.compile();
1141    
1142            // Attach the Scene to the locale object
1143            locale.addBranchGraph(scene);
1144    
1145            // Add all the canvas 3D (correspondant a chaque vue) to the main frame
1146            // Top view
1147            JPanel panelTop = new JPanel();
1148            panelTop.setLayout(new BorderLayout());
1149            TitledBorder borderTop = new TitledBorder(new EtchedBorder(),
1150                                                      Info.ressources.getObject("Top_View").toString());
1151            panelTop.setBorder(borderTop);
1152            panelTop.add(vueTop.getCanvas3D(), BorderLayout.CENTER);
1153    
1154            // Right view
1155            JPanel panelRight = new JPanel();
1156            panelRight.setLayout(new BorderLayout());
1157            TitledBorder borderRight = new TitledBorder(new EtchedBorder(),
1158                                                        Info.ressources.getObject("Right_View").toString());
1159            panelRight.setBorder(borderRight);
1160            panelRight.add(vueRight.getCanvas3D(), BorderLayout.CENTER);
1161    
1162            // Left View
1163            JPanel panelLeft = new JPanel();
1164            panelLeft.setLayout(new BorderLayout());
1165            TitledBorder borderLeft = new TitledBorder(new EtchedBorder(),
1166                                                       Info.ressources.getObject("Left_View").toString());
1167            panelLeft.setBorder(borderLeft);
1168            panelLeft.add(vueLeft.getCanvas3D(), BorderLayout.CENTER);
1169    
1170            // Front View
1171            JPanel panelFront = new JPanel();
1172            panelFront.setLayout(new BorderLayout());
1173            TitledBorder borderFront = new TitledBorder(new EtchedBorder(),
1174                                                        Info.ressources.getObject("Front_View").toString());
1175            panelFront.setBorder(borderFront);
1176            panelFront.add(vueFront.getCanvas3D(), BorderLayout.CENTER);
1177    
1178            // Add all the 4 vues to the main Frame
1179            scenePanel.add(panelTop);
1180            scenePanel.add(panelRight);
1181            scenePanel.add(panelLeft);
1182            scenePanel.add(panelFront);
1183    
1184            // Big view
1185            JPanel panelBigVue = new JPanel();
1186            panelBigVue.setLayout(new BorderLayout());
1187            TitledBorder borderBigVue = new TitledBorder(new EtchedBorder(),Info.ressources.getObject("Big_View").toString());
1188            panelBigVue.setBorder(borderBigVue);
1189            panelBigVue.add(bigVue.getCanvas3D(), BorderLayout.CENTER);
1190    
1191            // Add the Big View to a dedicated Frame
1192            bigVueFrame = new JFrame();
1193            bigVueFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
1194            bigVueFrame.add(panelBigVue);
1195    
1196            Dimension d = new Dimension(550, 550);
1197            bigVueFrame.setSize(d);
1198            //bigVueFrame.setResizable(false);
1199            bigVueFrame.setVisible(false);       
1200    
1201            return scenePanel;
1202        }
1203    
1204    
1205        /**
1206         * Panel creation for choosing the object in the Scene : Cube, Cylinder, Sphere, Cone.
1207         * 
1208         */
1209        protected JPanel makeObjectChooserPanel()
1210        {
1211            JPanel objectChooserPanel = new JPanel();
1212    
1213            boxButton = new JRadioButton(Info.ressources.getObject("Cube").toString());
1214            boxButton.setSelected(true);
1215            boxButton.addActionListener(this);
1216    
1217            sphereButton = new JRadioButton(Info.ressources.getObject("Sphere").toString());
1218            sphereButton.addActionListener(this);
1219    
1220            cylinderButton = new JRadioButton(Info.ressources.getObject("Cylinder").toString());
1221            cylinderButton.addActionListener(this);
1222    
1223            coneButton = new JRadioButton(Info.ressources.getObject("Cone").toString());
1224            coneButton.addActionListener(this);
1225    
1226            //Group the Objects selection buttons.
1227            ButtonGroup group = new ButtonGroup();
1228            group.add(boxButton);
1229            group.add(sphereButton);
1230            group.add(cylinderButton);
1231            group.add(coneButton);      
1232    
1233            //Attach the Objects selection buttons
1234            objectChooserPanel.add(boxButton);
1235            objectChooserPanel.add(sphereButton);
1236            objectChooserPanel.add(cylinderButton);
1237            objectChooserPanel.add(coneButton);
1238    
1239            return objectChooserPanel;
1240        }
1241    
1242    
1243        /**
1244         * redraw all the rendering panels
1245         * 
1246         */
1247        public void repaint()
1248        {
1249            super.repaint();   
1250            validate(); 
1251            if(lightsPanel!=null)
1252                lightsPanel.repaint();
1253            if(lightsPanelScrollPane!=null)
1254                lightsPanelScrollPane.repaint();
1255            if(scenePanel!=null)
1256                scenePanel.repaint();
1257        }
1258    
1259        
1260        /**
1261         * run when the user modifies a light parameter on a running light. It permits to update the scene based on the user choice.     
1262         * @param e the associated event
1263         * 
1264         */
1265        public void stateChanged(ChangeEvent e) 
1266        {
1267            Object source = e.getSource();
1268            
1269            if(source == backgroundColorRSpinner || source == backgroundColorGSpinner || source == backgroundColorBSpinner)
1270            {
1271                    setBackgroundColor(new Color3f((float)(Integer)backgroundColorRSpinner.getModel().getValue() /255, 
1272                                    (float)(Integer)backgroundColorGSpinner.getModel().getValue() /255,
1273                                    (float)(Integer)backgroundColorBSpinner.getModel().getValue() /255));
1274            }
1275    
1276            else
1277            {
1278            // Look at Selection Button First
1279            // And then if it is set, look at parameters inside
1280            // Then the event may not be found if the associated Selection Button is not set
1281            // This algorithm should be quicker
1282    
1283            // Look at Ambient Lights Button
1284            for (Iterator it = ambientLightsVector.iterator(); it.hasNext();) 
1285                {
1286                    AmbientLightObject obj = (AmbientLightObject)it.next();
1287                    if(obj.getButton().isSelected())
1288                        {
1289                            if(source == obj.getColorRSpinner() || source == obj.getColorGSpinner() || source == obj.getColorBSpinner())
1290                                {
1291                                    obj.updateColor();
1292                                    return;
1293                                }                   
1294                        }                           
1295                }
1296    
1297            // Look at Directional Lights Button
1298            for (Iterator it = directionalLightsVector.iterator(); it.hasNext();) 
1299                {
1300                    DirectionalLightObject obj = (DirectionalLightObject)it.next();
1301                    if(obj.getButton().isSelected())
1302                        {
1303                            if(source == obj.getColorRSpinner() || source == obj.getColorGSpinner() || source == obj.getColorBSpinner())
1304                                {
1305                                    obj.updateColor();
1306                                    return;
1307                                }
1308                            else if (source == obj.getDirectionXSpinner() || source == obj.getDirectionYSpinner() || source == obj.getDirectionZSpinner())
1309                                {
1310                                    obj.updateDirection();
1311                                    return;
1312                                }                   
1313                        }                           
1314                }
1315    
1316            // Look at Point Lights Button
1317            for (Iterator it = pointLightsVector.iterator(); it.hasNext();) 
1318                {
1319                    PointLightObject obj = (PointLightObject)it.next();
1320                    if(obj.getButton().isSelected())
1321                        {
1322                            if(source == obj.getColorRSpinner() || source == obj.getColorGSpinner() || source == obj.getColorBSpinner())
1323                                {
1324                                    obj.updateColor();
1325                                    return;
1326                                }
1327                            
1328                            else if (source == obj.getPositionXSpinner() || source == obj.getPositionYSpinner() || source == obj.getPositionZSpinner())
1329                                {
1330                                    obj.updatePosition();
1331                                    return;
1332                                }                   
1333    
1334                            else if (source == obj.getAttenuationXSpinner() || source == obj.getAttenuationYSpinner() || source == obj.getAttenuationZSpinner())
1335                                {
1336                                    obj.updateAttenuation();
1337                                    return;
1338                                }                   
1339                        }                           
1340                }
1341    
1342            // Look at Spot Lights Button
1343            for (Iterator it = spotLightsVector.iterator(); it.hasNext();) 
1344                {
1345                    SpotLightObject obj = (SpotLightObject)it.next();
1346                    if(obj.getButton().isSelected())
1347                        {
1348                            if(source == obj.getColorRSpinner() || source == obj.getColorGSpinner() || source == obj.getColorBSpinner())
1349                                {
1350                                    obj.updateColor();
1351                                    return;
1352                                }
1353                            
1354                            else if (source == obj.getPositionXSpinner() || source == obj.getPositionYSpinner() || source == obj.getPositionZSpinner())
1355                                {
1356                                    obj.updatePosition();
1357                                    return;
1358                                }                   
1359    
1360                            else if (source == obj.getAttenuationXSpinner() || source == obj.getAttenuationYSpinner() || source == obj.getAttenuationZSpinner())
1361                                {
1362                                    obj.updateAttenuation();
1363                                    return;
1364                                }                   
1365    
1366                            else if (source == obj.getDirectionXSpinner() || source == obj.getDirectionYSpinner() || source == obj.getDirectionZSpinner())
1367                                {
1368                                    obj.updateDirection();
1369                                    return;
1370                                }                   
1371    
1372                            else if (source == obj.getSpreadAngleSpinner())
1373                                {
1374                                    obj.updateSpreadAngle();
1375                                    return;
1376                                }                   
1377                            
1378                            else if (source == obj.getConcentrationSpinner())
1379                                {
1380                                    obj.updateConcentration();
1381                                    return;
1382                                }                   
1383                        }                           
1384                }
1385            }
1386        }
1387    
1388    
1389     
1390        /**
1391         * run when the user chooses another object in the scene or wants a 3D Axis, Antialiasing or a Big View.
1392         * @param e the associated event
1393         * 
1394         */
1395        public void actionPerformed(ActionEvent e) 
1396        {
1397            Object source = e.getSource();
1398            
1399            if(source == boxButton)
1400                setObject(0);
1401            else if (source == sphereButton)
1402                setObject(1);
1403            else if (source == cylinderButton)
1404                setObject(2);
1405            else if (source == coneButton)
1406                setObject(3);
1407            else if (source == antialiasingButton)
1408                setSceneAntialiasing(antialiasingButton.isSelected());
1409            else if (source == axisButton)
1410                showAxis();
1411            else if (source == bigVueButton)
1412                bigVueFrame.setVisible(bigVueButton.isSelected());
1413            else if (source == addAmbientLightButton)
1414                {
1415                    CreateAmbientLightControl();
1416                    addAmbientLightButton.setSelected(false);
1417                    repaint();      
1418                }
1419            else if (source == addPointLightButton)
1420                {
1421                    CreatePointLightControl();
1422                    addPointLightButton.setSelected(false);         
1423                    repaint();
1424                }
1425            else if (source == addDirectionalLightButton)
1426                {
1427                    CreateDirectionalLightControl();
1428                    addDirectionalLightButton.setSelected(false);
1429                    repaint();
1430                }
1431            else if (source == addSpotLightButton)
1432                {
1433                    CreateSpotLightControl();
1434                    addSpotLightButton.setSelected(false);
1435                    repaint();
1436                }
1437    
1438            else 
1439                {
1440                    // Look at Ambient Lights Button
1441                    for (Iterator it = ambientLightsVector.iterator(); it.hasNext();) 
1442                        {
1443                            AmbientLightObject obj = (AmbientLightObject)it.next();
1444                            if(source == obj.getButton())
1445                                {
1446                                    if(obj.getButton().isSelected()) 
1447                                        obj.set(true);                                  
1448                                    else
1449                                        obj.set(false);                                 
1450                                        
1451                                    return;                        
1452                                }                                   
1453                        }
1454    
1455                    // Look at Directional Lights Button
1456                    for (Iterator it = directionalLightsVector.iterator(); it.hasNext();) 
1457                        {
1458                            DirectionalLightObject obj = (DirectionalLightObject) it.next();
1459                            if(source == obj.getButton())
1460                                {
1461                                    if(obj.getButton().isSelected())         
1462                                        obj.set(true);                                  
1463                                    else
1464                                        obj.set(false);                                 
1465    
1466                                    return;
1467                                }                                   
1468                        }
1469    
1470                    // Look at Point Lights Button
1471                    for (Iterator it = pointLightsVector.iterator(); it.hasNext();) 
1472                        {
1473                            PointLightObject obj = (PointLightObject) it.next();
1474                            if(source == obj.getButton())
1475                                {
1476                                    if(obj.getButton().isSelected())         
1477                                        obj.set(true);                                  
1478                                    else
1479                                        obj.set(false);                                 
1480    
1481                                    return;
1482                                }                                   
1483                        }
1484    
1485                    // Look at Spot Lights Button
1486                    for (Iterator it = spotLightsVector.iterator(); it.hasNext();) 
1487                        {
1488                            SpotLightObject obj = (SpotLightObject) it.next();
1489                            if(source == obj.getButton())
1490                                {
1491                                    if(obj.getButton().isSelected())         
1492                                        obj.set(true);                                  
1493                                    else
1494                                        obj.set(false);                                 
1495    
1496                                    return;
1497                                }                                   
1498                        }
1499                    
1500                }
1501        }
1502    
1503    
1504        /**
1505         * 3D Scene Creation.
1506         * @param top Top canvas.
1507         * @param right Right canvas.
1508         * @param left Left canvas. 
1509         * @param front Front canvas. 
1510         * @param big Big canvas. 
1511         * @return 3D Scene.
1512         */
1513        public BranchGroup createSceneGraph(Canvas3D top,
1514                                            Canvas3D right,
1515                                            Canvas3D left,
1516                                            Canvas3D front,
1517                                            Canvas3D big                                    
1518                                            ) {
1519            
1520            // Creation of the parent object
1521            BranchGroup parent = new BranchGroup();
1522    
1523            // Creation of the scene transform
1524            sceneTransform = new TransformGroup();
1525            
1526            sceneTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
1527            sceneTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
1528            sceneTransform.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
1529            sceneTransform.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
1530    
1531            BoundingSphere infiniteBounds = new BoundingSphere( new Point3d(), Double.MAX_VALUE );
1532    
1533            // Creation mouse rotation behaviour
1534            // MouseRotate rotate = new MouseRotate(sceneTransform);
1535            CustomMouseRotate rotate = new CustomMouseRotate(sceneTransform,
1536                                                             top,
1537                                                             right,
1538                                                             left,
1539                                                             front,
1540                                                             big
1541                                                             );
1542            rotate.setSchedulingBounds(infiniteBounds);
1543            rotate.setEnable(true);
1544            parent.addChild(rotate);
1545    
1546            // Creation mouse translation behaviour
1547            // MouseTranslate translate = new MouseTranslate(sceneTransform);
1548            CustomMouseTranslate translate = new CustomMouseTranslate(sceneTransform,
1549                                                                      top,
1550                                                                      right,
1551                                                                      left,
1552                                                                      front,
1553                                                                      big
1554                                                                      );           
1555            translate.setSchedulingBounds(infiniteBounds);
1556            translate.setEnable(true);
1557            parent.addChild(translate);
1558    
1559            // Creation mouse zoom behaviour
1560            // MouseZoom zoom = new MouseZoom(sceneTransform);
1561            CustomMouseZoom zoom = new CustomMouseZoom(sceneTransform,
1562                                                       top,
1563                                                       right,
1564                                                       left,
1565                                                       front,
1566                                                       big                                             
1567                                                       );
1568            zoom.setSchedulingBounds(infiniteBounds);
1569            zoom.setEnable(true);
1570            parent.addChild(zoom);
1571    
1572            // Scene objects Creation 
1573            objectsSwitch = new Switch();   
1574            objectsSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);
1575            appearanceObjects.setCapability(Appearance.ALLOW_TEXTURE_WRITE);
1576            appearanceObjects.setCapability(Appearance.ALLOW_TEXGEN_WRITE);
1577            appearanceObjects.setCapability(Appearance.ALLOW_TEXTURE_ATTRIBUTES_WRITE);     
1578            appearanceObjects.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
1579            appearanceObjects.setCapability(Appearance.ALLOW_MATERIAL_WRITE);
1580            appearanceObjects.setCapability(Appearance.ALLOW_RENDERING_ATTRIBUTES_WRITE);
1581            appearanceObjects.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE);                
1582            
1583            Material m = new Material();    
1584            m.setCapability(Material.ALLOW_COMPONENT_WRITE);        
1585            appearanceObjects.setMaterial(m);
1586            
1587            TransparencyAttributes t = new TransparencyAttributes();
1588            t.setCapability(TransparencyAttributes.ALLOW_BLEND_FUNCTION_WRITE);     
1589            t.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);       
1590            t.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);      
1591            appearanceObjects.setTransparencyAttributes(t);
1592                                    
1593            createTexture();
1594    
1595            //ColorCube cube = new ColorCube(0.3);
1596            com.sun.j3d.utils.geometry.Box box = new com.sun.j3d.utils.geometry.Box(0.5f,0.5f,0.5f, Primitive.GENERATE_TEXTURE_COORDS 
1597                                                                                    + Primitive.GENERATE_NORMALS, appearanceObjects);
1598            Sphere sphere = new Sphere(0.6f,Primitive.GENERATE_TEXTURE_COORDS + Primitive.GENERATE_NORMALS, 30, appearanceObjects);
1599            Cylinder cylinder = new Cylinder(0.5f,1.0f,Primitive.GENERATE_TEXTURE_COORDS + Primitive.GENERATE_NORMALS,appearanceObjects);
1600            Cone cone = new Cone(0.5f,1.2f,Primitive.GENERATE_TEXTURE_COORDS + Primitive.GENERATE_NORMALS,appearanceObjects);               
1601    
1602            objectsSwitch.addChild(box);
1603            objectsSwitch.addChild(sphere);
1604            objectsSwitch.addChild(cylinder);
1605            objectsSwitch.addChild(cone);
1606    
1607            objectsSwitch.setWhichChild(0);
1608            sceneTransform.addChild(objectsSwitch);
1609        
1610            // Create Axis
1611            createAxis();
1612            sceneTransform.addChild(axisFrontend);
1613    
1614            // Add to the Scene root
1615            parent.addChild(sceneTransform);
1616            
1617            // Create the Background Color
1618            createBackground();                             
1619            parent.addChild(background);
1620            
1621    
1622            return parent;
1623        }
1624    
1625        /**
1626             *
1627             * Background creation for the scene objects.
1628             * 
1629             */
1630            protected void createBackground()
1631            {       
1632                    // Create application bounds
1633                    BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0,
1634                                    0.0), // Center
1635                                    1000.0); // Extent
1636                    Color3f color = new Color3f((float) SPINNER_BACKGROUNDCOLOR_R_INIT /255,
1637                                    (float)SPINNER_BACKGROUNDCOLOR_G_INIT /255,
1638                                    (float)SPINNER_BACKGROUNDCOLOR_B_INIT /255) ;
1639                    // Set the background color and its application bounds
1640                    background = new Background();
1641                    background.setColor(color);
1642                    background.setCapability(Background.ALLOW_COLOR_WRITE);
1643                    background.setApplicationBounds(worldBounds);
1644            }
1645            
1646        /**
1647             *
1648             * Set the Background color.
1649             * @param c the Color to set.
1650             * 
1651             */
1652            protected void setBackgroundColor(Color3f c)
1653            {       
1654                    background.setColor(c);
1655            }
1656            
1657        /**
1658         *
1659         * Texture creation for the scene objects
1660         * 
1661         */
1662        protected void createTexture()
1663        {   
1664            URL urlTexture = null;
1665    
1666            try
1667                {                                                   
1668                    urlTexture = DefaultTexture;
1669                    texture = new TextureLoader(urlTexture, this).getTexture();
1670                }
1671            catch (Exception ex1) {
1672                System.err.println("Error : Cannot load Texture File : " + DefaultTexture);
1673            }
1674           
1675            textureTransform = new Transform3D();           
1676            textureAttributes = new TextureAttributes();                        
1677            textureAttributes.setCapability(TextureAttributes.ALLOW_BLEND_COLOR_WRITE);
1678            textureAttributes.setCapability(TextureAttributes.ALLOW_MODE_WRITE);
1679            textureAttributes.setCapability(TextureAttributes.ALLOW_COMBINE_WRITE);
1680            textureAttributes.setCapability(TextureAttributes.ALLOW_TRANSFORM_WRITE);
1681            textureAttributes.setTextureTransform(textureTransform);            
1682            textureAttributes.setTextureMode(TextureAttributes.REPLACE);                       
1683            appearanceObjects.setTextureAttributes(textureAttributes);
1684                    
1685            texture.setCapability(Texture.ALLOW_ENABLE_WRITE);
1686            texture.setCapability(Texture.ALLOW_IMAGE_WRITE);       
1687    
1688            appearanceObjects.setTexture(texture);  
1689            texture.setEnable(false);
1690        }
1691    
1692    
1693        /**
1694         * Show a defined object. Ie Sphere, Cone, Cylinder or Cube
1695         * @param i object number to draw
1696         */
1697        public void setObject(int i)
1698        {
1699            if(i>3) i= 0;
1700            objectsSwitch.setWhichChild(i);     
1701        }
1702    
1703    
1704        /**
1705         *
1706         * 3D Axis Creation for the scene. Each axis is 1.0 in length.
1707         * 
1708         */
1709        protected void createAxis() 
1710        {   
1711            TransformGroup axisFrontendTG = new TransformGroup();   
1712            
1713            axisFrontend = new Switch();    
1714            axisFrontend.setWhichChild(Switch.CHILD_MASK);
1715            axisFrontend.setCapability(Switch.ALLOW_SWITCH_WRITE);
1716            LineArray la = new LineArray(6,LineArray.COORDINATES|LineArray.COLOR_3);
1717            Point3f origin = new Point3f(0.0f,0.0f,0.0f);
1718            Point3f x = new Point3f(1.0f,0.0f,0.0f);
1719            Point3f y = new Point3f(0.0f,1.0f,0.0f);
1720            Point3f z = new Point3f(0.0f,0.0f,1.0f);
1721            Point3f coords[] = {origin, x, origin, y, origin, z};       
1722            la.setCoordinates(0,coords);       
1723            
1724            Color3f red = new Color3f(1.0f, 0.0f, 0.0f);
1725            Color3f green = new Color3f(0.0f, 1.0f, 0.0f);
1726            Color3f blue = new Color3f(0.0f, 0.0f, 1.0f);
1727    
1728            Color3f [] colors = {red,red, green,green, blue,blue};
1729            la.setColors(0,colors);
1730    
1731            LineAttributes laAttr = new LineAttributes();
1732            laAttr.setLineAntialiasingEnable(true);
1733            laAttr.setLineWidth(2.0f);
1734            Appearance laApp = new Appearance();
1735            laApp.setLineAttributes(laAttr);
1736            Shape3D axisShape = new Shape3D(la, laApp);
1737            axisFrontendTG.addChild(axisShape);
1738    
1739            //Font3D font3D = new Font3D(new Font("Helvetica", Font.PLAIN, 1),new FontExtrusion());
1740            Font3D font3D = new Font3D(new Font("Dialog", Font.BOLD, 1), new FontExtrusion());
1741            Text3D text3DX = new Text3D(font3D, "X", new Point3f(5.3f, -0.3f, -0.12f));
1742            text3DX.setAlignment(Text3D.ALIGN_CENTER);
1743            Shape3D XShape = new Shape3D();
1744            XShape.setGeometry(text3DX);                       
1745            Text3D text3DY = new Text3D(font3D, "Y", new Point3f(0.0f, 5.1f, -0.12f));
1746            text3DY.setAlignment(Text3D.ALIGN_CENTER);
1747            Shape3D YShape = new Shape3D();
1748            YShape.setGeometry(text3DY);     
1749            Text3D text3DZ = new Text3D(font3D, "Z", new Point3f(0.0f, -0.3f, 5.1f));
1750            text3DZ.setAlignment(Text3D.ALIGN_CENTER);
1751            Shape3D ZShape = new Shape3D();
1752            ZShape.setGeometry(text3DZ);
1753    
1754            Transform3D scale3D = new Transform3D();
1755            scale3D.setScale(new Vector3d(0.2f,0.2f,0.2f));
1756            TransformGroup tgScale = new TransformGroup();
1757            tgScale.setTransform(scale3D);
1758            tgScale.addChild(XShape);
1759            tgScale.addChild(YShape);
1760            tgScale.addChild(ZShape);
1761            axisFrontendTG.addChild(tgScale);
1762            axisFrontend.addChild(axisFrontendTG);  
1763                    
1764        }
1765    
1766    
1767        /**
1768         * Hide or Show the 3D Axis in the Scene.
1769         */
1770        public void showAxis() {
1771            BitSet visibilityMask = axisFrontend.getChildMask();
1772            visibilityMask.flip(0);
1773            axisFrontend.setChildMask(visibilityMask);
1774        }
1775    
1776            /**
1777             * Set some default lights.
1778             */
1779            public void initLights()  
1780            {
1781            Iterator it;
1782                    
1783                    // Set the Ambient Lights Button
1784                    it = ambientLightsVector.iterator();            
1785                    if (it.hasNext()) 
1786                    {
1787                            AmbientLightObject obj = (AmbientLightObject)it.next();
1788                            obj.getButton().setSelected(true);                      
1789                            obj.set(true);                                          
1790                    }
1791                    
1792                    // Set the Directional Lights Button
1793                    it = directionalLightsVector.iterator();                
1794                    if (it.hasNext()) 
1795                    {
1796                            DirectionalLightObject obj = (DirectionalLightObject)it.next();
1797                            obj.getButton().setSelected(true);                      
1798                            obj.set(true);                                          
1799                    }
1800                    
1801                    // Set the Point Lights Button
1802                    it = pointLightsVector.iterator();              
1803                    if (it.hasNext()) 
1804                    {
1805                            PointLightObject obj = (PointLightObject)it.next();
1806                            obj.getButton().setSelected(true);                      
1807                            obj.set(true);                                          
1808                    }
1809                    
1810                    // Set the Spot Lights Button
1811                    it = spotLightsVector.iterator();               
1812                    if (it.hasNext()) 
1813                    {
1814                            SpotLightObject obj = (SpotLightObject)it.next();
1815                            obj.getButton().setSelected(true);                      
1816                            obj.set(true);                                          
1817                    }
1818            }
1819    
1820        /**
1821         * Set Antialiasing on the scene.
1822         * @param on true if requested, false otherwise.
1823         */
1824        public void setSceneAntialiasing(boolean on)
1825        {
1826            vueTop.getView().setSceneAntialiasingEnable(on);        
1827            vueFront.getView().setSceneAntialiasingEnable(on);      
1828            vueLeft.getView().setSceneAntialiasingEnable(on);       
1829            vueRight.getView().setSceneAntialiasingEnable(on);      
1830            bigVue.getView().setSceneAntialiasingEnable(on);        
1831            //repaint();    
1832        }
1833    
1834    
1835        /**
1836         * Set the Ambient Color for the Scene objects.
1837         * @param c the Ambient Color to set.
1838         */
1839        public void setObjectsAmbientColor(Color3f c)
1840        {   
1841            appearanceObjects.getMaterial().setAmbientColor(c);
1842            //repaint();
1843        }
1844    
1845        /**
1846         * Set the Diffuse Color for the Scene objects.
1847         * @param c the Diffuse Color to set.
1848         */
1849        public void setObjectsDiffuseColor(Color3f c)
1850        {   
1851            appearanceObjects.getMaterial().setDiffuseColor(c);
1852            //repaint();
1853        }
1854    
1855        /**
1856         * Set the Specular Color for the Scene objects.
1857         * @param c the Specular Color to set.
1858         */
1859        public void setObjectsSpecularColor(Color3f c)
1860        {   
1861            appearanceObjects.getMaterial().setSpecularColor(c);
1862            //repaint();
1863        }
1864    
1865        /**
1866         * Set the Emissive Color for the Scene objects.
1867         * @param c the Emissive Color to set.
1868         */
1869        public void setObjectsEmissiveColor(Color3f c)
1870        {   
1871            appearanceObjects.getMaterial().setEmissiveColor(c);
1872            //repaint();
1873        }   
1874    
1875        /**
1876         * Set or Uset the lighting for the Scene objects.
1877         * @param b true if lighting is set, false otherwise.
1878         */
1879        public void setObjectsLighting(boolean b)
1880        {
1881            appearanceObjects.getMaterial().setLightingEnable(b);           
1882            //repaint();    
1883        }
1884    
1885        /**
1886         * Set the Shininess for the Scene objects.
1887         * @param s the Shininess.
1888         */
1889        public void setObjectsShininess(float s)
1890        {
1891            appearanceObjects.getMaterial().setShininess(s);
1892            //repaint();
1893        }
1894    
1895        /**
1896         * Set the Transparency value for the Scene objects.
1897         * @param s the Transparency value.
1898         */
1899        public void setObjectsTransparency(float s)
1900        {
1901            appearanceObjects.getTransparencyAttributes().setTransparency(s);
1902            //repaint();
1903        }
1904    
1905        /**
1906         * Set the Transparency mode for the Scene objects.
1907         * @param m the Transparency Mode.
1908         */
1909        public void setObjectsTransparencyMode(int m)
1910        {
1911            appearanceObjects.getTransparencyAttributes().setTransparencyMode(m);
1912            //repaint();
1913        }
1914    
1915        /**
1916         * Set the Transparency Src Blend Function for the Scene objects.
1917         * @param f the Transparency Src Blend Function.
1918         */
1919        public void setObjectsTransparencySrcBlendFunction(int f)
1920        {
1921            appearanceObjects.getTransparencyAttributes().setSrcBlendFunction(f);
1922            //repaint();
1923        }
1924    
1925        /**
1926         * Set the Transparency Dst Blend Function for the Scene objects.
1927         * @param f the Transparency Dst Blend Function.
1928         */
1929        public void setObjectsTransparencyDstBlendFunction(int f)
1930        {
1931            appearanceObjects.getTransparencyAttributes().setDstBlendFunction(f);
1932            //repaint();
1933        }
1934        
1935    
1936        /**
1937         * Set the Texture on the Scene objects.
1938         * @param urlTexture the Texture URL.
1939         */
1940        public void setTexture(URL urlTexture)
1941        {
1942            
1943            try {             
1944                /*TextureLoader loader = new TextureLoader(urlTexture, this);
1945                  texture.setImage(0,  loader.getTexture().getImage(0)); 
1946                  texture.setEnable(true);*/
1947                // Recreate the texture because of a bug in some version for updating image 
1948                // with a different size in the Texture Class
1949                
1950                TextureLoader loader = new TextureLoader(urlTexture, this);
1951                texture = loader.getTexture();
1952                texture.setCapability(Texture.ALLOW_ENABLE_WRITE);
1953                texture.setCapability(Texture.ALLOW_IMAGE_WRITE);           
1954            
1955                appearanceObjects.setTexture(texture);
1956    
1957            }
1958            catch (Exception ex1) {
1959                System.err.println("Error : Cannot load texture File : " + urlTexture);
1960            }       
1961            
1962            //repaint();            
1963        }
1964    
1965        
1966        /**
1967         * Unset the Texture use on the Scene objects.
1968         */
1969        public void unsetTexture()
1970        {
1971            try {   
1972                appearanceObjects.getTexture().setEnable(false);
1973            }
1974            
1975            catch (Exception ex1) {     
1976            }
1977            
1978            //repaint();
1979        }
1980    
1981    
1982        /**
1983         * Set the Texture transform to use on the Scene objects.
1984         * @param t the Texture transform.
1985         */
1986        public void setTextureTransform(Transform3D t)
1987        {
1988            textureTransform = t;
1989            textureAttributes.setTextureTransform(textureTransform);    
1990            //repaint();
1991        }
1992    
1993    
1994        /**
1995         * Set the Texture Perspective Correction Mode to use on the Scene objects.
1996         * @param m the Texture Perspective Correction Mode.
1997         */
1998        public void setObjectsTexturePerspectiveCorrectionMode(int m)
1999        {
2000            textureAttributes.setPerspectiveCorrectionMode(m);      
2001        }
2002    
2003    
2004        /**
2005         * Set the Texture Mode to use on the Scene objects.
2006         * @param m the Texture Mode.
2007         */
2008        public void setObjectsTextureMode(int m)
2009        {
2010            textureAttributes.setTextureMode(m);    
2011        }
2012    
2013    
2014        /**
2015         * Set the Texture COMBINE Mode for the RGB Components of the output color to use on the Scene objects.
2016         * @param m the Texture COMBINE Mode.
2017         */
2018        public void setObjectsTextureCombineRGBMode(int m)
2019        {
2020            textureAttributes.setCombineRgbMode(m); 
2021        }
2022    
2023        
2024        /**
2025         * Set the Texture COMBINE Source for the RGB Components to use on the Scene objects.
2026         * @param s the Texture COMBINE Source.
2027         */
2028        public void setObjectsTextureCombineRGBSource(int []s)
2029        {
2030            textureAttributes.setCombineRgbSource(0,s[0]);  
2031            textureAttributes.setCombineRgbSource(1,s[1]);  
2032            textureAttributes.setCombineRgbSource(2,s[2]);  
2033        }
2034    
2035    
2036        /**
2037         * Set the Texture COMBINE Function for the RGB Components to use on the Scene objects.
2038         * @param f the Texture COMBINE Function.
2039         */
2040        public void setObjectsTextureCombineRGBFunction(int []f)
2041        {
2042            textureAttributes.setCombineRgbFunction(0,f[0]);        
2043            textureAttributes.setCombineRgbFunction(1,f[1]);        
2044            textureAttributes.setCombineRgbFunction(2,f[2]);        
2045        }
2046    
2047    
2048        /**
2049         * Set the Texture COMBINE Scale for the RGB Components of the output color to use on the Scene objects.
2050         * @param m the Texture COMBINE Scale.
2051         */
2052        public void setObjectsTextureCombineRGBScale(int m)
2053        {
2054            textureAttributes.setCombineRgbScale(m);        
2055        }
2056    
2057    
2058        /**
2059         * Set the Texture COMBINE Mode for the Alpha Components of the output color to use on the Scene objects.
2060         * @param m the Texture COMBINE Mode.
2061         */
2062        public void setObjectsTextureCombineAlphaMode(int m)
2063        {
2064            textureAttributes.setCombineAlphaMode(m);       
2065        }
2066    
2067    
2068        /**
2069         * Set the Texture COMBINE Source for the Alpha Components to use on the Scene objects.
2070         * @param s the Texture COMBINE Source.
2071         */
2072        public void setObjectsTextureCombineAlphaSource(int []s)
2073        {
2074            textureAttributes.setCombineAlphaSource(0,s[0]);        
2075            textureAttributes.setCombineAlphaSource(1,s[1]);        
2076            textureAttributes.setCombineAlphaSource(2,s[2]);        
2077        }
2078    
2079    
2080        /**
2081         * Set the Texture COMBINE Function for the Alpha Components to use on the Scene objects.
2082         * @param f the Texture COMBINE Function.
2083         */
2084        public void setObjectsTextureCombineAlphaFunction(int []f)
2085        {
2086            textureAttributes.setCombineAlphaFunction(0,f[0]);      
2087            textureAttributes.setCombineAlphaFunction(1,f[1]);      
2088            textureAttributes.setCombineAlphaFunction(2,f[2]);      
2089        }
2090    
2091    
2092        /**
2093         * Set the Texture COMBINE Scale for the Alpha Components of the output color to use on the Scene objects.
2094         * @param m the Texture COMBINE Scale.
2095         */
2096        public void setObjectsTextureCombineAlphaScale(int m)
2097        {
2098            textureAttributes.setCombineAlphaScale(m);      
2099        }
2100    
2101    
2102        /**
2103         * Set the Texture Blend Color to use on the Scene objects.
2104         * @param r the R value of the Texture Blend Color.
2105         * @param g the G value of the Texture Blend Color.
2106         * @param b the B value of the Texture Blend Color.
2107         * @param a the Alpha value of the Texture Blend Color.
2108         */
2109        public void setObjectsTextureBlendColor(float r, float g, float b, float a)
2110        {   
2111            textureAttributes.setTextureBlendColor(r,g,b,a);
2112        }
2113    
2114    
2115        /**
2116         * Main method for a Test purpose.
2117         * @param args arguments used for the call.
2118         */
2119        public static void main(String[] args) {
2120            JFrame frame = new JFrame();
2121            RenderingViewPanel renderingViewPanel = 
2122                new RenderingViewPanel((new Info()).getClass().getResource("resources/DefaultTexture.png"));
2123            frame.add(renderingViewPanel);  
2124        }
2125    }
2126    
2127    
2128    /**
2129     * Class used to Create a View in the 3D Scene 
2130     */
2131    class SceneView {
2132    
2133        private static final long serialVersionUID = 1L;
2134    
2135        // PhysicalBody and PhysicalEnvironment are common to all instances    
2136        protected static final PhysicalBody physBody = new PhysicalBody();
2137        protected static final PhysicalEnvironment physEnv =
2138            new PhysicalEnvironment();
2139    
2140        protected BranchGroup parent = null;
2141        protected TransformGroup vpTG = null;
2142        protected ViewPlatform viewPlatform = null;
2143        protected View view = null;
2144        protected Canvas3D canvas = null;   
2145    
2146        /**
2147         * Default constructor to create a point of view in the 3D Scene.
2148         */
2149        public SceneView() {
2150    
2151            // Graphical configuration creation
2152            GraphicsConfigTemplate3D gconfigTemplate = new GraphicsConfigTemplate3D();
2153            GraphicsConfiguration gconfig =
2154                GraphicsEnvironment.getLocalGraphicsEnvironment().
2155                getDefaultScreenDevice().getBestConfiguration(gconfigTemplate);
2156    
2157            // Creation of the 3D canvas, the viewPlatform and the related view object
2158            canvas = new Canvas3D(gconfig);   
2159    
2160            viewPlatform = new ViewPlatform();      
2161            view = new View();
2162    
2163            // Initialisation of the view object
2164            view.addCanvas3D(canvas);
2165            view.attachViewPlatform(viewPlatform);
2166            view.setPhysicalBody(physBody);
2167            view.setPhysicalEnvironment(physEnv);
2168    
2169    
2170            // Creation of the transformation for the camera
2171            vpTG = new TransformGroup();
2172            vpTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
2173            vpTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
2174            vpTG.addChild(viewPlatform);
2175    
2176    
2177            // Creation of the parent object 
2178            parent = new BranchGroup();     
2179            parent.addChild(vpTG);
2180        }
2181    
2182    
2183        /**
2184         * Give a reference on the camera transformation group (viewPlatform).
2185         * @return reference on the camera transformation group (viewPlatform).
2186         */
2187        public TransformGroup getViewPlatformTransformGroup() {
2188            return vpTG;
2189        }
2190    
2191        /**
2192         * Give a reference on the parent object.
2193         * @return a reference on the parent object..
2194         */
2195        public BranchGroup getParent() {
2196            return parent;
2197        }
2198    
2199        /**
2200         * Give a reference on the 3D canvas.
2201         * @return a reference on the 3D canvas.
2202         */
2203        public Canvas3D getCanvas3D() {
2204            return canvas;
2205        }
2206    
2207        /**
2208         * Give a reference on the view.
2209         * @return reference on the view.
2210         */
2211        public View getView() {
2212            return view;
2213        }
2214    }    
2215     
2216    
2217    
2218    /**
2219     * Class representing an Ambient light in the 3D Scene.
2220     * Parameters for controlling this Ambient light are set in a separate control light Panel.
2221     */
2222    class AmbientLightObject
2223    {
2224    
2225        private static final long serialVersionUID = 1L;
2226    
2227        private JRadioButton ambientLightButton;
2228        private JSpinner ambientLightsColorRSpinner; 
2229        private JSpinner ambientLightsColorGSpinner; 
2230        private JSpinner ambientLightsColorBSpinner;
2231        private BranchGroup light;
2232        private TransformGroup sceneTransform;
2233    
2234        /**
2235         * Constructor for having an Ambient light in the 3D Scene.
2236         * @param ambientLightButton the JRadioButton to set or unset this light.
2237         * @param ambientLightsColorRSpinner a spinner to control the R Value of the light.
2238         * @param ambientLightsColorGSpinner a spinner to control the G Value of the light.
2239         * @param ambientLightsColorBSpinner a spinner to control the B Value of the light.
2240         * @param sceneTransform the transformation for the lights. 
2241         *
2242         */
2243        public AmbientLightObject(JRadioButton ambientLightButton, 
2244                                  JSpinner ambientLightsColorRSpinner, 
2245                                  JSpinner ambientLightsColorGSpinner, 
2246                                  JSpinner ambientLightsColorBSpinner,
2247                                  TransformGroup sceneTransform
2248                                  )
2249        {
2250            this.ambientLightButton = ambientLightButton;
2251            this.ambientLightsColorRSpinner = ambientLightsColorRSpinner;
2252            this.ambientLightsColorGSpinner = ambientLightsColorGSpinner;
2253            this.ambientLightsColorBSpinner = ambientLightsColorBSpinner;
2254            this.sceneTransform = sceneTransform;
2255    
2256            // Create an Ambient light
2257            light = new BranchGroup();      
2258            light.setCapability(BranchGroup.ALLOW_DETACH);
2259            BoundingSphere infiniteBounds = new BoundingSphere(new Point3d(), Double.MAX_VALUE);
2260            AmbientLight ambientLight = new AmbientLight(new Color3f( (float)(Integer)ambientLightsColorRSpinner.getModel().getValue() /255, 
2261                                                                      (float)(Integer)ambientLightsColorGSpinner.getModel().getValue() /255, 
2262                                                                      (float)(Integer)ambientLightsColorBSpinner.getModel().getValue() /255 )
2263                                                         );
2264            ambientLight.setInfluencingBounds(infiniteBounds);
2265            ambientLight.setCapability(Light.ALLOW_COLOR_WRITE);
2266            light.addChild(ambientLight);           
2267        }    
2268    
2269        /**
2270         *
2271         * Get the JRadioButton to set or unset this light.
2272         *
2273         */
2274        public JRadioButton getButton()
2275        {
2276            return ambientLightButton;
2277        }
2278    
2279        /**
2280         *
2281         * Get the spinner to control the R Value of the light.
2282         *
2283         */
2284        public JSpinner getColorRSpinner()
2285        {
2286            return ambientLightsColorRSpinner;
2287        }
2288    
2289        /**
2290         *
2291         * Get the spinner to control the G Value of the light.
2292         *
2293         */
2294        public JSpinner getColorGSpinner()
2295        {
2296            return ambientLightsColorGSpinner;
2297        }
2298    
2299        /**
2300         *
2301         * Get the spinner to control the B Value of the light.
2302         *
2303         */
2304        public JSpinner getColorBSpinner()
2305        {
2306            return ambientLightsColorBSpinner;
2307        }
2308    
2309        /**
2310         *
2311         * Set or unset the light.
2312         *
2313         */
2314        public void set(boolean on)
2315        {
2316            if (on)
2317                sceneTransform.addChild(light);
2318            else      
2319                light.detach();
2320        }
2321    
2322    
2323        /**
2324         *
2325         * Update the light color according to the associated Spinners values.
2326         * Called when an event is detected on the corresponding Spinner.
2327         *
2328         */
2329        public void updateColor()
2330        {
2331            ((AmbientLight)light.getChild(0)).setColor(new Color3f( (float)(Integer)ambientLightsColorRSpinner.getModel().getValue() /255, 
2332                                                                    (float)(Integer)ambientLightsColorGSpinner.getModel().getValue() /255, 
2333                                                                    (float)(Integer)ambientLightsColorBSpinner.getModel().getValue() /255 ));
2334            
2335            /*
2336              System.out.println("AMBIANT LIGHT - Update Color (" + 
2337              (Integer)ambientLightsColorRSpinner.getModel().getValue() + ", " + 
2338              (Integer)ambientLightsColorGSpinner.getModel().getValue() + ", " +
2339              (Integer)ambientLightsColorBSpinner.getModel().getValue() + ")");
2340            */
2341    
2342        }
2343    }
2344    
2345    
2346    /**
2347     * Class representing a Directional light in the 3D Scene.
2348     * Parameters for controlling this Directional light are set in a separate control light Panel.
2349     */
2350    class DirectionalLightObject
2351    {
2352        private static final long serialVersionUID = 1L;
2353    
2354        private JRadioButton directionalLightButton;
2355        private JSpinner directionalLightsColorRSpinner; 
2356        private JSpinner directionalLightsColorGSpinner; 
2357        private JSpinner directionalLightsColorBSpinner;
2358        private JSpinner directionalLightsDirectionXSpinner;
2359        private JSpinner directionalLightsDirectionYSpinner;
2360        private JSpinner directionalLightsDirectionZSpinner;  
2361        private BranchGroup light;
2362        private TransformGroup sceneTransform;
2363    
2364    
2365        /**
2366         * Constructor for having a Directional light in the 3D Scene.
2367         * @param directionalLightButton the JRadioButton to set or unset this light.
2368         * @param directionalLightsColorRSpinner a spinner to control the R Value of the light.
2369         * @param directionalLightsColorGSpinner a spinner to control the G Value of the light.
2370         * @param directionalLightsColorBSpinner a spinner to control the B Value of the light.
2371         * @param directionalLightsDirectionXSpinner a spinner to control the light direction according the X axis.
2372         * @param directionalLightsDirectionYSpinner a spinner to control the light direction according the Y axis.
2373         * @param directionalLightsDirectionZSpinner a spinner to control the light direction according the Z axis.
2374         * @param sceneTransform the transformation for the lights. 
2375         *
2376         */
2377        public DirectionalLightObject(JRadioButton directionalLightButton, 
2378                                      JSpinner directionalLightsColorRSpinner, 
2379                                      JSpinner directionalLightsColorGSpinner, 
2380                                      JSpinner directionalLightsColorBSpinner,
2381                                      JSpinner directionalLightsDirectionXSpinner,
2382                                      JSpinner directionalLightsDirectionYSpinner,
2383                                      JSpinner directionalLightsDirectionZSpinner,                            
2384                                      TransformGroup sceneTransform
2385                                      )
2386        {
2387            this.directionalLightButton = directionalLightButton;
2388            this.directionalLightsColorRSpinner = directionalLightsColorRSpinner;
2389            this.directionalLightsColorGSpinner = directionalLightsColorGSpinner;
2390            this.directionalLightsColorBSpinner = directionalLightsColorBSpinner;
2391            this.directionalLightsDirectionXSpinner = directionalLightsDirectionXSpinner;
2392            this.directionalLightsDirectionYSpinner = directionalLightsDirectionYSpinner;
2393            this.directionalLightsDirectionZSpinner = directionalLightsDirectionZSpinner;
2394            this.sceneTransform = sceneTransform;
2395    
2396            // Create a Directional light
2397            light = new BranchGroup();      
2398            light.setCapability(BranchGroup.ALLOW_DETACH);
2399            BoundingSphere infiniteBounds = new BoundingSphere(new Point3d(), Double.MAX_VALUE);
2400            DirectionalLight directionalLight = new DirectionalLight(new Color3f( (float)(Integer)directionalLightsColorRSpinner.getModel().getValue() /255, 
2401                                                                                  (float)(Integer)directionalLightsColorGSpinner.getModel().getValue() /255, 
2402                                                                                  (float)(Integer)directionalLightsColorBSpinner.getModel().getValue() /255), 
2403                                                                     new Vector3f((Float)directionalLightsDirectionXSpinner.getModel().getValue(), 
2404                                                                                  (Float)directionalLightsDirectionYSpinner.getModel().getValue(), 
2405                                                                                  (Float)directionalLightsDirectionZSpinner.getModel().getValue())
2406                                                                     );
2407            directionalLight.setInfluencingBounds(infiniteBounds);
2408            directionalLight.setCapability(Light.ALLOW_COLOR_WRITE);
2409            directionalLight.setCapability(DirectionalLight.ALLOW_DIRECTION_WRITE);
2410            light.addChild(directionalLight);       
2411        }    
2412    
2413        /**
2414         *
2415         * Get the JRadioButton to set or unset this light.
2416         *
2417         */
2418        public JRadioButton getButton()
2419        {
2420            return directionalLightButton;
2421        }
2422    
2423        /**
2424         *
2425         * Get the spinner to control the R Value of the light.
2426         *
2427         */
2428        public JSpinner getColorRSpinner()
2429        {
2430            return directionalLightsColorRSpinner;
2431        }
2432    
2433        /**
2434         *
2435         * Get the spinner to control the G Value of the light.
2436         *
2437         */
2438        public JSpinner getColorGSpinner()
2439        {
2440            return directionalLightsColorGSpinner;
2441        }
2442    
2443        /**
2444         *
2445         * Get the spinner to control the B Value of the light.
2446         *
2447         */
2448        public JSpinner getColorBSpinner()
2449        {
2450            return directionalLightsColorBSpinner;
2451        }
2452    
2453        /**
2454         *
2455         * Get the spinner to control the X Direction of the light.
2456         *
2457         */
2458        public JSpinner getDirectionXSpinner()
2459        {
2460            return directionalLightsDirectionXSpinner;
2461        }
2462            
2463        /**
2464         *
2465         * Get the spinner to control the Y Direction of the light.
2466         *
2467         */
2468        public JSpinner getDirectionYSpinner()
2469        {
2470            return directionalLightsDirectionYSpinner;
2471        }
2472    
2473        /**
2474         *
2475         * Get the spinner to control the Z Direction of the light.
2476         *
2477         */
2478        public JSpinner getDirectionZSpinner()
2479        {
2480            return directionalLightsDirectionZSpinner;
2481        }
2482            
2483        /**
2484         *
2485         * Set or unset the light.
2486         *
2487         */
2488        public void set(boolean on)
2489        {
2490            if (on)
2491                sceneTransform.addChild(light);
2492            else
2493                light.detach();
2494        }
2495    
2496    
2497        /**
2498         *
2499         * Update the light color according to the associated Spinners values.
2500         * Called when an event is detected on the corresponding Spinner.
2501         *
2502         */
2503        public void updateColor()
2504        {
2505            ((DirectionalLight)light.getChild(0)).setColor(new Color3f( 
2506                                                                       (float)(Integer)directionalLightsColorRSpinner.getModel().getValue() /255, 
2507                                                                       (float)(Integer)directionalLightsColorGSpinner.getModel().getValue() /255, 
2508                                                                       (float)(Integer)directionalLightsColorBSpinner.getModel().getValue() /255 ));
2509    
2510            /*
2511              System.out.println("DIRECTIONAL LIGHT - Update Color (" + 
2512              (Integer)directionalLightsColorRSpinner.getModel().getValue() + ", " + 
2513              (Integer)directionalLightsColorGSpinner.getModel().getValue() + ", " +
2514              (Integer)directionalLightsColorBSpinner.getModel().getValue() + ")");
2515            */
2516        }
2517    
2518    
2519        /**
2520         *
2521         * Update the light direction according to the associated Spinners values.
2522         * Called when an event is detected on the corresponding Spinner.
2523         *
2524         */   
2525        public void updateDirection()
2526        {
2527            ((DirectionalLight)light.getChild(0)).setDirection(new Vector3f(
2528                                                                            (Float)directionalLightsDirectionXSpinner.getModel().getValue(), 
2529                                                                            (Float)directionalLightsDirectionYSpinner.getModel().getValue(), 
2530                                                                            (Float)directionalLightsDirectionZSpinner.getModel().getValue()));
2531    
2532            /*
2533              System.out.println("DIRECTIONAL LIGHT - Update Direction (" + 
2534              (Float)directionalLightsDirectionXSpinner.getModel().getValue() + ", " + 
2535              (Float)directionalLightsDirectionYSpinner.getModel().getValue() + ", " +
2536              (Float)directionalLightsDirectionZSpinner.getModel().getValue() + ")");
2537            */
2538    
2539        }
2540    }
2541    
2542    
2543    
2544    /**
2545     * Class representing a Point light in the 3D Scene.
2546     * Parameters for controlling this Point light are set in a separate control light Panel.
2547     */
2548    class PointLightObject
2549    {
2550        private static final long serialVersionUID = 1L;
2551    
2552        private JRadioButton pointLightButton;
2553        private JSpinner pointLightsColorRSpinner; 
2554        private JSpinner pointLightsColorGSpinner; 
2555        private JSpinner pointLightsColorBSpinner;
2556        private JSpinner pointLightsPositionXSpinner;
2557        private JSpinner pointLightsPositionYSpinner;
2558        private JSpinner pointLightsPositionZSpinner;
2559        private JSpinner pointLightsAttenuationXSpinner;
2560        private JSpinner pointLightsAttenuationYSpinner;
2561        private JSpinner pointLightsAttenuationZSpinner;
2562        private BranchGroup light;
2563        private TransformGroup sceneTransform;
2564            
2565    
2566        /**
2567         * Constructor for having a Point light in the 3D Scene.
2568         * @param pointLightButton the JRadioButton to set or unset this light.
2569         * @param pointLightsColorRSpinner a spinner to control the R Value of the light.
2570         * @param pointLightsColorGSpinner a spinner to control the G Value of the light.
2571         * @param pointLightsColorBSpinner a spinner to control the B Value of the light.
2572         * @param pointLightsPositionXSpinner a spinner to control the light position according the X axis.
2573         * @param pointLightsPositionYSpinner a spinner to control the light position according the Y axis.
2574         * @param pointLightsPositionZSpinner a spinner to control the light position according the Z axis.
2575         * @param pointLightsAttenuationXSpinner a spinner to control the light attenuation according the X axis.
2576         * @param pointLightsAttenuationYSpinner a spinner to control the light attenuation according the Y axis.
2577         * @param pointLightsAttenuationZSpinner a spinner to control the light attenuation according the Z axis.
2578         * @param sceneTransform the transformation for the lights. 
2579         *
2580         */
2581        public PointLightObject(JRadioButton pointLightButton, 
2582                                JSpinner pointLightsColorRSpinner, 
2583                                JSpinner pointLightsColorGSpinner, 
2584                                JSpinner pointLightsColorBSpinner,
2585                                JSpinner pointLightsPositionXSpinner,
2586                                JSpinner pointLightsPositionYSpinner,
2587                                JSpinner pointLightsPositionZSpinner,
2588                                JSpinner pointLightsAttenuationXSpinner,
2589                                JSpinner pointLightsAttenuationYSpinner,
2590                                JSpinner pointLightsAttenuationZSpinner,
2591                                TransformGroup sceneTransform
2592                                )
2593        {
2594            this.pointLightButton = pointLightButton;
2595            this.pointLightsColorRSpinner = pointLightsColorRSpinner;
2596            this.pointLightsColorGSpinner = pointLightsColorGSpinner;
2597            this.pointLightsColorBSpinner = pointLightsColorBSpinner;
2598            this.pointLightsPositionXSpinner = pointLightsPositionXSpinner;
2599            this.pointLightsPositionYSpinner = pointLightsPositionYSpinner;
2600            this.pointLightsPositionZSpinner = pointLightsPositionZSpinner;
2601            this.pointLightsAttenuationXSpinner = pointLightsAttenuationXSpinner;
2602            this.pointLightsAttenuationYSpinner = pointLightsAttenuationYSpinner;
2603            this.pointLightsAttenuationZSpinner = pointLightsAttenuationZSpinner;
2604            this.sceneTransform = sceneTransform;
2605    
2606            // Create a Point light
2607            light = new BranchGroup();      
2608            light.setCapability(BranchGroup.ALLOW_DETACH);
2609            BoundingSphere infiniteBounds = new BoundingSphere(new Point3d(), Double.MAX_VALUE);
2610            PointLight pointLight = new PointLight(new Color3f( (float)(Integer)pointLightsColorRSpinner.getModel().getValue() /255, 
2611                                                                (float)(Integer)pointLightsColorGSpinner.getModel().getValue() /255, 
2612                                                                (float)(Integer)pointLightsColorBSpinner.getModel().getValue() /255), 
2613                                                   new Point3f((Float)pointLightsPositionXSpinner.getModel().getValue(), 
2614                                                               (Float)pointLightsPositionYSpinner.getModel().getValue(), 
2615                                                               (Float)pointLightsPositionZSpinner.getModel().getValue()),
2616                                                   new Point3f((Float)pointLightsAttenuationXSpinner.getModel().getValue(), 
2617                                                               (Float)pointLightsAttenuationYSpinner.getModel().getValue(), 
2618                                                               (Float)pointLightsAttenuationZSpinner.getModel().getValue())
2619                                                   );
2620            pointLight.setInfluencingBounds(infiniteBounds);
2621            pointLight.setCapability(Light.ALLOW_COLOR_WRITE);
2622            pointLight.setCapability(PointLight.ALLOW_POSITION_WRITE);
2623            pointLight.setCapability(PointLight.ALLOW_ATTENUATION_WRITE);
2624            light.addChild(pointLight);     
2625        }    
2626    
2627        /**
2628         *
2629         * Get the JRadioButton to set or unset this light.
2630         *
2631         */
2632        public JRadioButton getButton()
2633        {
2634            return pointLightButton;
2635        }
2636    
2637        /**
2638         *
2639         * Get the spinner to control the R Value of the light.
2640         *
2641         */
2642        public JSpinner getColorRSpinner()
2643        {
2644            return pointLightsColorRSpinner;
2645        }
2646    
2647        /**
2648         *
2649         * Get the spinner to control the G Value of the light.
2650         *
2651         */
2652        public JSpinner getColorGSpinner()
2653        {
2654            return pointLightsColorGSpinner;
2655        }
2656    
2657        /**
2658         *
2659         * Get the spinner to control the B Value of the light.
2660         *
2661         */
2662        public JSpinner getColorBSpinner()
2663        {
2664            return pointLightsColorBSpinner;
2665        }
2666    
2667        /**
2668         *
2669         * Get the spinner to control the X Position of the light.
2670         *
2671         */
2672        public JSpinner getPositionXSpinner()
2673        {
2674            return pointLightsPositionXSpinner;
2675        }
2676            
2677        /**
2678         *
2679         * Get the spinner to control the Y Position of the light.
2680         *
2681         */
2682        public JSpinner getPositionYSpinner()
2683        {
2684            return pointLightsPositionYSpinner;
2685        }
2686    
2687        /**
2688         *
2689         * Get the spinner to control the Z Position of the light.
2690         *
2691         */
2692        public JSpinner getPositionZSpinner()
2693        {
2694            return pointLightsPositionZSpinner;
2695        }
2696    
2697        /**
2698         *
2699         * Get the spinner to control the X Attenuation of the light.
2700         *
2701         */
2702        public JSpinner getAttenuationXSpinner()
2703        {
2704            return pointLightsAttenuationXSpinner;
2705        }
2706            
2707        /**
2708         *
2709         * Get the spinner to control the Y Attenuation of the light.
2710         *
2711         */
2712        public JSpinner getAttenuationYSpinner()
2713        {
2714            return pointLightsAttenuationYSpinner;
2715        }
2716    
2717        /**
2718         *
2719         * Get the spinner to control the Z Attenuation of the light.
2720         *
2721         */
2722        public JSpinner getAttenuationZSpinner()
2723        {
2724            return pointLightsAttenuationZSpinner;
2725        }
2726            
2727        /**
2728         *
2729         * Set or unset the light.
2730         *
2731         */
2732        public void set(boolean on)
2733        {
2734            if (on)
2735                sceneTransform.addChild(light);
2736            else
2737                light.detach();
2738        }
2739    
2740        /**
2741         *
2742         * Update the light color according to the associated Spinners values.
2743         * Called when an event is detected on the corresponding Spinner.
2744         *
2745         */
2746        public void updateColor()
2747        {
2748            ((PointLight)light.getChild(0)).setColor(new Color3f( 
2749                                                                 (float)(Integer)pointLightsColorRSpinner.getModel().getValue() /255, 
2750                                                                 (float)(Integer)pointLightsColorGSpinner.getModel().getValue() /255, 
2751                                                                 (float)(Integer)pointLightsColorBSpinner.getModel().getValue() /255 ));
2752    
2753            /*
2754              System.out.println("POINT LIGHT - Update Color (" + 
2755              (Integer)pointLightsColorRSpinner.getModel().getValue() + ", " + 
2756              (Integer)pointLightsColorGSpinner.getModel().getValue() + ", " +
2757              (Integer)pointLightsColorBSpinner.getModel().getValue() + ")");
2758            */
2759        }
2760        
2761        /**
2762         *
2763         * Update the light position according to the associated Spinners values.
2764         * Called when an event is detected on the corresponding Spinner.
2765         *
2766         */   
2767        public void updatePosition()
2768        {
2769            ((PointLight)light.getChild(0)).setPosition(new Point3f(
2770                                                                    (Float)pointLightsPositionXSpinner.getModel().getValue(), 
2771                                                                    (Float)pointLightsPositionYSpinner.getModel().getValue(), 
2772                                                                    (Float)pointLightsPositionZSpinner.getModel().getValue()));
2773    
2774            /*
2775              System.out.println("POINT LIGHT - Update Position (" + 
2776              (Float)pointLightsPositionXSpinner.getModel().getValue() + ", " + 
2777              (Float)pointLightsPositionYSpinner.getModel().getValue() + ", " +
2778              (Float)pointLightsPositionZSpinner.getModel().getValue() + ")");
2779            */
2780        }
2781    
2782        /**
2783         *
2784         * Update the light attenuation according to the associated Spinners values.
2785         * Called when an event is detected on the corresponding Spinner.
2786         *
2787         */   
2788        public void updateAttenuation()
2789        {
2790            ((PointLight)light.getChild(0)).setAttenuation(new Point3f(
2791                                                                       (Float)pointLightsAttenuationXSpinner.getModel().getValue(), 
2792                                                                       (Float)pointLightsAttenuationYSpinner.getModel().getValue(), 
2793                                                                       (Float)pointLightsAttenuationZSpinner.getModel().getValue()));
2794            
2795            /*
2796              System.out.println("POINT LIGHT - Update Attenuation (" + 
2797              (Float)pointLightsAttenuationXSpinner.getModel().getValue() + ", " + 
2798              (Float)pointLightsAttenuationYSpinner.getModel().getValue() + ", " +
2799              (Float)pointLightsAttenuationZSpinner.getModel().getValue() + ")");
2800            */
2801        }
2802    }
2803    
2804    
2805    /**
2806     * Class representing a Spot light in the 3D Scene.
2807     * Parameters for controlling this Spot light are set in a separate control light Panel.
2808     */
2809    class SpotLightObject
2810    {
2811        private static final long serialVersionUID = 1L;
2812    
2813        private JRadioButton spotLightButton;
2814        private JSpinner spotLightsColorRSpinner; 
2815        private JSpinner spotLightsColorGSpinner; 
2816        private JSpinner spotLightsColorBSpinner;
2817        private JSpinner spotLightsPositionXSpinner;
2818        private JSpinner spotLightsPositionYSpinner;
2819        private JSpinner spotLightsPositionZSpinner;
2820        private JSpinner spotLightsAttenuationXSpinner;
2821        private JSpinner spotLightsAttenuationYSpinner;
2822        private JSpinner spotLightsAttenuationZSpinner;
2823        private JSpinner spotLightsDirectionXSpinner;
2824        private JSpinner spotLightsDirectionYSpinner;
2825        private JSpinner spotLightsDirectionZSpinner;
2826        private JSpinner spotLightsSpreadAngleSpinner;
2827        private JSpinner spotLightsConcentrationSpinner;
2828     
2829        private BranchGroup light;
2830        private TransformGroup sceneTransform;
2831    
2832        /**
2833         * Constructor for having a Spot light in the 3D Scene.
2834         * @param spotLightButton the JRadioButton to set or unset this light.
2835         * @param spotLightsColorRSpinner a spinner to control the R Value of the light.
2836         * @param spotLightsColorGSpinner a spinner to control the G Value of the light.
2837         * @param spotLightsColorBSpinner a spinner to control the B Value of the light.
2838         * @param spotLightsPositionXSpinner a spinner to control the light position according the X axis.
2839         * @param spotLightsPositionYSpinner a spinner to control the light position according the Y axis.
2840         * @param spotLightsPositionZSpinner a spinner to control the light position according the Z axis.
2841         * @param spotLightsAttenuationXSpinner a spinner to control the light attenuation according the X axis.
2842         * @param spotLightsAttenuationYSpinner a spinner to control the light attenuation according the Y axis.
2843         * @param spotLightsAttenuationZSpinner a spinner to control the light attenuation according the Z axis.
2844         * @param spotLightsDirectionXSpinner a spinner to control the light direction according the X axis.
2845         * @param spotLightsDirectionYSpinner a spinner to control the light direction according the Y axis.
2846         * @param spotLightsDirectionZSpinner a spinner to control the light direction according the Z axis.
2847         * @param spotLightsSpreadAngleSpinner a spinner to control the Spread Angle of the light.
2848         * @param spotLightsConcentrationSpinner a spinner to control the Concentration of the light.
2849         * @param sceneTransform the transformation for the lights. 
2850         *
2851         */ 
2852        public SpotLightObject(JRadioButton spotLightButton, 
2853                               JSpinner spotLightsColorRSpinner, 
2854                               JSpinner spotLightsColorGSpinner, 
2855                               JSpinner spotLightsColorBSpinner,
2856                               JSpinner spotLightsPositionXSpinner,
2857                               JSpinner spotLightsPositionYSpinner,
2858                               JSpinner spotLightsPositionZSpinner,
2859                               JSpinner spotLightsAttenuationXSpinner,
2860                               JSpinner spotLightsAttenuationYSpinner,
2861                               JSpinner spotLightsAttenuationZSpinner,
2862                               JSpinner spotLightsDirectionXSpinner,
2863                               JSpinner spotLightsDirectionYSpinner,
2864                               JSpinner spotLightsDirectionZSpinner,
2865                               JSpinner spotLightsSpreadAngleSpinner,
2866                               JSpinner spotLightsConcentrationSpinner,
2867                               TransformGroup sceneTransform
2868                               )
2869        {
2870            this.spotLightButton = spotLightButton;
2871            this.spotLightsColorRSpinner = spotLightsColorRSpinner;
2872            this.spotLightsColorGSpinner = spotLightsColorGSpinner;
2873            this.spotLightsColorBSpinner = spotLightsColorBSpinner;
2874            this.spotLightsPositionXSpinner = spotLightsPositionXSpinner;
2875            this.spotLightsPositionYSpinner = spotLightsPositionYSpinner;
2876            this.spotLightsPositionZSpinner = spotLightsPositionZSpinner;
2877            this.spotLightsAttenuationXSpinner = spotLightsAttenuationXSpinner;
2878            this.spotLightsAttenuationYSpinner = spotLightsAttenuationYSpinner;
2879            this.spotLightsAttenuationZSpinner = spotLightsAttenuationZSpinner;
2880            this.spotLightsDirectionXSpinner = spotLightsDirectionXSpinner;
2881            this.spotLightsDirectionYSpinner = spotLightsDirectionYSpinner;
2882            this.spotLightsDirectionZSpinner = spotLightsDirectionZSpinner;
2883            this.spotLightsSpreadAngleSpinner = spotLightsSpreadAngleSpinner;
2884            this.spotLightsConcentrationSpinner = spotLightsConcentrationSpinner;
2885            this.sceneTransform = sceneTransform;
2886            
2887            light = new BranchGroup();      
2888            light.setCapability(BranchGroup.ALLOW_DETACH);
2889            BoundingSphere infiniteBounds = new BoundingSphere(new Point3d(), Double.MAX_VALUE);
2890            SpotLight spotLight = new SpotLight(new Color3f( (float)(Integer)spotLightsColorRSpinner.getModel().getValue() /255, 
2891                                                             (float)(Integer)spotLightsColorGSpinner.getModel().getValue() /255, 
2892                                                             (float)(Integer)spotLightsColorBSpinner.getModel().getValue() /255), 
2893                                                new Point3f((Float)spotLightsPositionXSpinner.getModel().getValue(), 
2894                                                            (Float)spotLightsPositionYSpinner.getModel().getValue(), 
2895                                                            (Float)spotLightsPositionZSpinner.getModel().getValue()),
2896                                                new Point3f((Float)spotLightsAttenuationXSpinner.getModel().getValue(), 
2897                                                            (Float)spotLightsAttenuationYSpinner.getModel().getValue(), 
2898                                                            (Float)spotLightsAttenuationZSpinner.getModel().getValue()),
2899                                                new Vector3f((Float)spotLightsDirectionXSpinner.getModel().getValue(), 
2900                                                             (Float)spotLightsDirectionYSpinner.getModel().getValue(), 
2901                                                             (Float)spotLightsDirectionZSpinner.getModel().getValue()),
2902                                                new Double(Math.toRadians((Float)spotLightsSpreadAngleSpinner.getModel().getValue())).floatValue(),
2903                                                (Float)spotLightsConcentrationSpinner.getModel().getValue()
2904                                                );
2905            spotLight.setInfluencingBounds(infiniteBounds);
2906            spotLight.setCapability(Light.ALLOW_COLOR_WRITE);
2907            spotLight.setCapability(SpotLight.ALLOW_POSITION_WRITE);
2908            spotLight.setCapability(SpotLight.ALLOW_ATTENUATION_WRITE);
2909        spotLight.setCapability(SpotLight.ALLOW_DIRECTION_WRITE);
2910        spotLight.setCapability(SpotLight.ALLOW_SPREAD_ANGLE_WRITE);
2911        spotLight.setCapability(SpotLight.ALLOW_CONCENTRATION_WRITE);
2912            light.addChild(spotLight);      
2913        }    
2914    
2915        /**
2916         *
2917         * Get the JRadioButton to set or unset this light.
2918         *
2919         */
2920        public JRadioButton getButton()
2921        {
2922            return spotLightButton;
2923        }
2924    
2925        /**
2926         *
2927         * Get the spinner to control the R Value of the light.
2928         *
2929         */
2930        public JSpinner getColorRSpinner()
2931        {
2932            return spotLightsColorRSpinner;
2933        }
2934    
2935        /**
2936         *
2937         * Get the spinner to control the G Value of the light.
2938         *
2939         */
2940        public JSpinner getColorGSpinner()
2941        {
2942            return spotLightsColorGSpinner;
2943        }
2944    
2945        /**
2946         *
2947         * Get the spinner to control the B Value of the light.
2948         *
2949         */
2950        public JSpinner getColorBSpinner()
2951        {
2952            return spotLightsColorBSpinner;
2953        }
2954    
2955        /**
2956         *
2957         * Get the spinner to control the X Position of the light.
2958         *
2959         */
2960        public JSpinner getPositionXSpinner()
2961        {
2962            return spotLightsPositionXSpinner;
2963        }
2964            
2965        /**
2966         *
2967         * Get the spinner to control the Y Position of the light.
2968         *
2969         */
2970        public JSpinner getPositionYSpinner()
2971        {
2972            return spotLightsPositionYSpinner;
2973        }
2974    
2975        /**
2976         *
2977         * Get the spinner to control the Z Position of the light.
2978         *
2979         */
2980        public JSpinner getPositionZSpinner()
2981        {
2982            return spotLightsPositionZSpinner;
2983        }
2984        
2985        /**
2986         *
2987         * Get the spinner to control the X Direction of the light.
2988         *
2989         */
2990        public JSpinner getDirectionXSpinner()
2991        {
2992            return spotLightsDirectionXSpinner;
2993        }
2994            
2995        /**
2996         *
2997         * Get the spinner to control the Y Direction of the light.
2998         *
2999         */
3000        public JSpinner getDirectionYSpinner()
3001        {
3002            return spotLightsDirectionYSpinner;
3003        }
3004    
3005        /**
3006         *
3007         * Get the spinner to control the Z Direction of the light.
3008         *
3009         */
3010        public JSpinner getDirectionZSpinner()
3011        {
3012            return spotLightsDirectionZSpinner;
3013        }
3014    
3015        /**
3016         *
3017         * Get the spinner to control the X Attenuation of the light.
3018         *
3019         */
3020        public JSpinner getAttenuationXSpinner()
3021        {
3022            return spotLightsAttenuationXSpinner;
3023        }
3024            
3025        /**
3026         *
3027         * Get the spinner to control the Y Attenuation of the light.
3028         *
3029         */
3030        public JSpinner getAttenuationYSpinner()
3031        {
3032            return spotLightsAttenuationYSpinner;
3033        }
3034    
3035        /**
3036         *
3037         * Get the spinner to control the Z Attenuation of the light.
3038         *
3039         */
3040        public JSpinner getAttenuationZSpinner()
3041        {
3042            return spotLightsAttenuationZSpinner;
3043        }
3044    
3045        /**
3046         *
3047         * Get the spinner to control the Spread Angle of the light.
3048         *
3049         */
3050        public JSpinner getSpreadAngleSpinner()
3051        {
3052            return spotLightsSpreadAngleSpinner;
3053        }
3054        
3055        /**
3056         *
3057         * Get the spinner to control the Concentration of the light.
3058         *
3059         */
3060        public JSpinner getConcentrationSpinner()
3061        {
3062            return spotLightsConcentrationSpinner;
3063        }
3064            
3065        /**
3066         *
3067         * Set or unset the light.
3068         *
3069         */
3070        public void set(boolean on)
3071        {
3072            if (on)
3073                sceneTransform.addChild(light);
3074            else
3075                light.detach();
3076        }
3077    
3078        /**
3079         *
3080         * Update the light color according to the associated Spinners values.
3081         * Called when an event is detected on the corresponding Spinner.
3082         *
3083         */
3084        public void updateColor()
3085        {
3086            ((SpotLight)light.getChild(0)).setColor(new Color3f( 
3087                                                                (float)(Integer)spotLightsColorRSpinner.getModel().getValue() /255, 
3088                                                                (float)(Integer)spotLightsColorGSpinner.getModel().getValue() /255, 
3089                                                                (float)(Integer)spotLightsColorBSpinner.getModel().getValue() /255 ));
3090    
3091            /*
3092              System.out.println("SPOT LIGHT - Update Color (" + 
3093              (Integer)spotLightsColorRSpinner.getModel().getValue() + ", " + 
3094              (Integer)spotLightsColorGSpinner.getModel().getValue() + ", " +
3095              (Integer)spotLightsColorBSpinner.getModel().getValue() + ")");
3096            */
3097        }
3098        
3099        /**
3100         *
3101         * Update the light position according to the associated Spinners values.
3102         * Called when an event is detected on the corresponding Spinner.
3103         *
3104         */   
3105        public void updatePosition()
3106        {
3107            ((SpotLight)light.getChild(0)).setPosition(new Point3f(
3108                                                                   (Float)spotLightsPositionXSpinner.getModel().getValue(), 
3109                                                                   (Float)spotLightsPositionYSpinner.getModel().getValue(), 
3110                                                                   (Float)spotLightsPositionZSpinner.getModel().getValue()));
3111            
3112            /*
3113              System.out.println("SPOT LIGHT - Update Position (" + 
3114              (Float)spotLightsPositionXSpinner.getModel().getValue() + ", " + 
3115              (Float)spotLightsPositionYSpinner.getModel().getValue() + ", " +
3116              (Float)spotLightsPositionZSpinner.getModel().getValue() + ")");
3117            */
3118        }
3119    
3120        /**
3121         *
3122         * Update the light attenuation according to the associated Spinners values.
3123         * Called when an event is detected on the corresponding Spinner.
3124         *
3125         */   
3126        public void updateAttenuation()
3127        {
3128            ((SpotLight)light.getChild(0)).setAttenuation(new Point3f(
3129                                                                      (Float)spotLightsAttenuationXSpinner.getModel().getValue(), 
3130                                                                      (Float)spotLightsAttenuationYSpinner.getModel().getValue(), 
3131                                                                      (Float)spotLightsAttenuationZSpinner.getModel().getValue()));
3132    
3133            /*
3134              System.out.println("SPOT LIGHT - Update Attenuation (" + 
3135              (Float)spotLightsAttenuationXSpinner.getModel().getValue() + ", " + 
3136              (Float)spotLightsAttenuationYSpinner.getModel().getValue() + ", " +
3137              (Float)spotLightsAttenuationZSpinner.getModel().getValue() + ")");
3138            */
3139        }
3140    
3141        /**
3142         *
3143         * Update the light direction according to the associated Spinners values.
3144         * Called when an event is detected on the corresponding Spinner.
3145         *
3146         */   
3147        public void updateDirection()
3148        {
3149            ((SpotLight)light.getChild(0)).setDirection(new Vector3f(
3150                                                                     (Float)spotLightsDirectionXSpinner.getModel().getValue() , 
3151                                                                     (Float)spotLightsDirectionYSpinner.getModel().getValue() , 
3152                                                                     (Float)spotLightsDirectionZSpinner.getModel().getValue() ));
3153    
3154            /*
3155              System.out.println("SPOT LIGHT - Update Direction (" + 
3156              (Float)spotLightsDirectionXSpinner.getModel().getValue() + ", " + 
3157              (Float)spotLightsDirectionYSpinner.getModel().getValue() + ", " +
3158              (Float)spotLightsDirectionZSpinner.getModel().getValue() + ")");
3159            */      
3160        }
3161    
3162        /**
3163         *
3164         * Update the light spread angle according to the associated Spinner value.
3165         * Called when an event is detected on the corresponding Spinner.
3166         *
3167         */   
3168        public void updateSpreadAngle()
3169        {
3170            ((SpotLight)light.getChild(0)).setSpreadAngle(new Double(Math.toRadians((Float)spotLightsSpreadAngleSpinner.getModel().getValue())).floatValue());
3171    
3172            /*
3173              System.out.println("SPOT LIGHT - Update Spread Angle (" 
3174              + new Double(Math.toRadians((Float)spotLightsSpreadAngleSpinner.getModel().getValue())).floatValue() 
3175              + ")");
3176            */                                            
3177        }
3178    
3179        /**
3180         *
3181         * Update the light concentration according to the associated Spinner value.
3182         * Called when an event is detected on the corresponding Spinner.
3183         *
3184         */   
3185        public void updateConcentration()
3186        {
3187            ((SpotLight)light.getChild(0)).setConcentration((Float)spotLightsConcentrationSpinner.getModel().getValue() );
3188            /*
3189              System.out.println("SPOT LIGHT - Update Concentration (" + (Float)spotLightsConcentrationSpinner.getModel().getValue() + ")");
3190            */
3191        }
3192    }
3193    
3194    
3195    
3196    
3197    
3198