001    /**
002       ##############################################################################
003       ##                                                                          ##
004       ## Appearance3DChooser                                                      ##
005       ##                                                                          ##
006       ## Copyright (C) 2009  ederic Roudaut  <ederic.roudaut@ee.>         ##
007       ##                                                                          ##
008       ##                                                                          ##
009       ## This program is ee software: you can redistribute it and/or modify     ##
010       ## it under the terms of the GNU General Public License as published by     ##
011       ## the ee Software Foundation, either version 3 of the License, or        ##
012       ## (at your option) any later version.                                      ##
013       ##                                                                          ##
014       ## This program is distributed in the hope that it will be useful,          ##
015       ## but WITHOUT ANY WARRANTY; without even the implied warranty of           ##
016       ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            ##
017       ## GNU General Public License for more details.                             ##
018       ##                                                                          ##
019       ## You should have received a copy of the GNU General Public License        ##
020       ## along with this program.  If not, see <http://www.gnu.org/licenses/>.    ##
021       ##                                                                          ##
022       ##############################################################################
023    **/
024    
025    
026    package com.appearance3Dchooser;
027    
028    import java.beans.PropertyChangeEvent;
029    import java.beans.PropertyChangeListener;
030    
031    import java.awt.*;
032    import java.awt.event.*;
033    import javax.swing.*;
034    import javax.swing.event.*;
035    import java.awt.image.BufferedImage;
036    import java.io.File;
037    
038    import javax.media.j3d.Transform3D;
039    import javax.vecmath.Vector3d;
040    import javax.vecmath.Vector3f;
041    import javax.vecmath.AxisAngle4d;
042    import javax.vecmath.Matrix3f;
043    import java.net.URL;
044    
045    
046    import javax.media.j3d.TextureAttributes;
047    
048    import com.colorpicker.swing.*;
049    
050    /**
051     * Panel creation for the Textures.
052     * 
053     */
054    public class TexturePane extends JTabbedPane implements ActionListener, ChangeListener
055    {
056        private static final long serialVersionUID = 1L;
057    
058        public static final String TEXTURE_FILE = "texture_file";
059        public static final String TEXTURE_USE = "texture_use";
060        public static final String TEXTURE_TRANSFORM = "texture_transform";
061        public static final String TEXTURE_PERPSPECTIVE_CORRECTION_MODE = "texture_perspective_correction_mode";
062        public static final String TEXTURE_MODE = "texture_mode";
063        public static final String TEXTURE_BLEND = "texture_blend";
064        public static final String TEXTURE_COMBINE_RGB_MODE = "texture_combine_rgb_mode";
065        public static final String TEXTURE_COMBINE_RGB_SOURCE = "texture_combine_rgb_source";
066        public static final String TEXTURE_COMBINE_RGB_FUNCTION = "texture_combine_rgb_function";
067        public static final String TEXTURE_COMBINE_RGB_SCALE = "texture_combine_rgb_scale";    
068        public static final String TEXTURE_COMBINE_ALPHA_MODE = "texture_combine_alpha_mode";
069        public static final String TEXTURE_COMBINE_ALPHA_SOURCE = "texture_combine_alpha_source";    
070        public static final String TEXTURE_COMBINE_ALPHA_FUNCTION = "texture_combine_alpha_function";    
071        public static final String TEXTURE_COMBINE_ALPHA_SCALE = "texture_combine_alpha_scale";    
072        
073        public static final int TEXTURE_MODE_MODULATE = 0;
074        public static final int TEXTURE_MODE_DECAL = 1;
075        public static final int TEXTURE_MODE_BLEND = 2;
076        public static final int TEXTURE_MODE_REPLACE = 3;
077        public static final int TEXTURE_MODE_COMBINE = 4;
078    
079        public static final int COMBINE_MODE_REPLACE = 0;
080        public static final int COMBINE_MODE_MODULATE = 1;
081        public static final int COMBINE_MODE_ADD = 2;
082        public static final int COMBINE_MODE_ADD_SIGNED = 3;
083        public static final int COMBINE_MODE_SUBTRACT = 4;
084        public static final int COMBINE_MODE_INTERPOLATE = 5;
085        public static final int COMBINE_MODE_DOT3 = 6;
086    
087        public static final int COMBINE_FUNCTION_SRC_ALPHA = 0;
088        public static final int COMBINE_FUNCTION_ONE_MINUS_SRC_ALPHA = 1;
089        public static final int COMBINE_FUNCTION_SRC_COLOR = 2; // not available for alpha
090        public static final int COMBINE_FUNCTION_ONE_MINUS_SRC_COLOR = 3; // not available for alpha
091    
092        
093        public static final int COMBINE_SOURCE_OBJECT_COLOR = 0;
094        public static final int COMBINE_SOURCE_TEXTURE_COLOR = 1;
095        public static final int COMBINE_SOURCE_CONSTANT_COLOR = 2;
096        public static final int COMBINE_SOURCE_PREVIOUS_TEXTURE_UNIT_STATE = 3;
097    
098        public static final int PERSPECTIVE_CORRECTION_MODE_FASTEST = 0;
099        public static final int PERSPECTIVE_CORRECTION_MODE_NICEST = 1;
100    
101        protected JTextField textureNameJText;
102        protected JButton fileChooserButton;
103        protected JButton OKButton;
104        protected JFileChooser fileChooser;
105        protected JRadioButton setTextureButton;
106        protected ImageIcon imageIcon;
107        protected URL textureName;  
108        protected URL DefaultTexture;
109        protected boolean useTexture=false;
110        protected Image image;
111        protected int textureMode = TEXTURE_MODE_REPLACE;
112        protected int perspectiveCorrectionMode = PERSPECTIVE_CORRECTION_MODE_NICEST;
113        protected int combineRGBMode = COMBINE_MODE_MODULATE;
114        protected int combineAlphaMode = COMBINE_MODE_MODULATE;
115        protected int combineRGBFunctionC0 = COMBINE_FUNCTION_SRC_COLOR;
116        protected int combineRGBFunctionC1 = COMBINE_FUNCTION_SRC_COLOR;
117        protected int combineRGBFunctionC2 = COMBINE_FUNCTION_SRC_COLOR;
118        protected int combineAlphaFunctionC0 = COMBINE_FUNCTION_SRC_ALPHA;
119        protected int combineAlphaFunctionC1 = COMBINE_FUNCTION_SRC_ALPHA;
120        protected int combineAlphaFunctionC2 = COMBINE_FUNCTION_SRC_ALPHA;
121        protected int combineRGBSourceC0 = COMBINE_SOURCE_TEXTURE_COLOR;
122        protected int combineRGBSourceC1 = COMBINE_SOURCE_PREVIOUS_TEXTURE_UNIT_STATE;
123        protected int combineRGBSourceC2 = COMBINE_SOURCE_CONSTANT_COLOR;
124        protected int combineAlphaSourceC0 = COMBINE_SOURCE_TEXTURE_COLOR;
125        protected int combineAlphaSourceC1 = COMBINE_SOURCE_PREVIOUS_TEXTURE_UNIT_STATE;
126        protected int combineAlphaSourceC2 = COMBINE_SOURCE_CONSTANT_COLOR;
127        protected int combineRGBScale = 0;
128        protected int combineAlphaScale = 0;    
129        protected Transform3D textureTransform;
130        protected boolean textureTransformUniformScale=false;    
131        protected float[] blendColor = {0.5f,0.5f,0.5f,0.5f};
132    
133        protected JComboBox listTextureMode;
134        protected JComboBox listCombineRGBMode;
135        protected JComboBox listCombineAlphaMode;
136        protected JComboBox listCombineRGBFunctionC0;
137        protected JComboBox listCombineRGBFunctionC1;
138        protected JComboBox listCombineRGBFunctionC2;
139        protected JComboBox listCombineAlphaFunctionC0;
140        protected JComboBox listCombineAlphaFunctionC1;
141        protected JComboBox listCombineAlphaFunctionC2;
142        protected JComboBox listCombineRGBSourceC0;
143        protected JComboBox listCombineRGBSourceC1;
144        protected JComboBox listCombineRGBSourceC2;
145        protected JComboBox listCombineAlphaSourceC0;
146        protected JComboBox listCombineAlphaSourceC1;
147        protected JComboBox listCombineAlphaSourceC2;
148        protected JComboBox listPerspectiveCorrectionMode;
149        protected JComboBox listCombineRGBScale;
150        protected JComboBox listCombineAlphaScale;
151        protected JSpinner textureSpinnerTransformRotZ;
152        protected JSpinner textureSpinnerTransformScaleX;
153        protected JSpinner textureSpinnerTransformScaleY;
154        protected JSpinner textureSpinnerTransformTranslatX;
155        protected JSpinner textureSpinnerTransformTranslatY;
156        protected JRadioButton textureButtonTransformReset;
157        protected JRadioButton textureButtonTransformUniformScale;
158    
159        protected JTabbedPane textureTabbedPane;
160        protected ColorPicker blendColorPicker;
161    
162    
163        /**
164         * Constructor for creating a Texture panel
165         * @param DefaultTextureName Default Texture URL.
166         */    
167        public TexturePane(URL DefaultTextureName)
168        {                   
169            setTabPlacement(JTabbedPane.LEFT);
170            DefaultTexture = DefaultTextureName;    
171            makeBasicTexturePane();
172            makeBlendColorPane();   
173            makeCombineModePane();
174        }
175    
176    
177        /**
178         * Basic parameters Panel for the Texture : use, don't use, Texture tranformation, Texture Mode, 
179         * Texture Perspective Correction Mode.
180         */        
181        private void makeBasicTexturePane ()
182        {           
183            // Panel For texture color
184            JPanel basicTexturePanel = new JPanel();    
185                    
186            GridBagConstraints c = new GridBagConstraints();
187    
188            basicTexturePanel.setLayout(new GridBagLayout());
189            
190            c.gridx = 0; c.gridy = 0;
191            c.weightx = 0; c.weighty = 0; 
192            c.insets = new Insets(0,0,0,0);
193            c.fill = GridBagConstraints.WEST;
194            c.anchor = GridBagConstraints.WEST;
195                    
196            setTextureButton = new JRadioButton(Info.ressources.getObject("Use_Texture").toString());
197    
198            setTextureButton.addActionListener(this);
199            basicTexturePanel.add(setTextureButton,c);
200    
201            c.gridx = 0; c.gridy ++;
202            JPanel fileChooserPanel = new JPanel();        
203            textureNameJText = new JTextField();
204            textureNameJText.addActionListener(this);
205            textureNameJText.setColumns(20);
206            fileChooserPanel.add(textureNameJText);        
207            fileChooserButton = new JButton(Info.ressources.getObject("Search").toString());
208            fileChooser = new JFileChooser();       
209            fileChooserButton.addActionListener(this);
210            fileChooserPanel.add(fileChooserButton);
211            OKButton = new JButton(Info.ressources.getObject("OK").toString());
212            OKButton.addActionListener(this);
213            fileChooserPanel.add(OKButton);
214            
215            basicTexturePanel.add(fileChooserPanel,c);      
216            
217            //Create the texture Transform
218            textureTransform = new Transform3D();
219            
220            // Create The Transform Panel
221            JPanel textureTransformPanel = new JPanel();                    
222            GridBagConstraints ct = new GridBagConstraints();
223            textureTransformPanel.setLayout(new GridBagLayout());
224            
225            ct.gridy = 0;
226            ct.weightx = 0; ct.weighty = 0; 
227            ct.insets = new Insets(0,0,0,0);
228            ct.fill = GridBagConstraints.EAST;
229            ct.anchor = GridBagConstraints.EAST;
230    
231            textureButtonTransformReset = new JRadioButton(Info.ressources.getObject("Reset").toString());
232            ct.gridx = 4;
233            textureTransformPanel.add(textureButtonTransformReset, ct);
234            textureButtonTransformReset.addActionListener(this);
235    
236            JLabel textureSpinnerTransformRotZLabel = new JLabel(Info.ressources.getObject("Rotation").toString());       
237            ct.gridy ++; ct.gridx = 0;
238            textureTransformPanel.add(textureSpinnerTransformRotZLabel, ct);
239    
240            SpinnerModel textureSpinnerModelTransformRotZ = new SpinnerNumberModel(Float.valueOf(0f), //initial value
241                                                                                   Float.valueOf(-360f), //min
242                                                                                   Float.valueOf(360f), //max
243                                                                                   Float.valueOf(0.1f)); //step
244            textureSpinnerTransformRotZ = new JSpinner(textureSpinnerModelTransformRotZ);
245            ((JSpinner.DefaultEditor)textureSpinnerTransformRotZ.getEditor()).getTextField().setColumns(3);
246            textureSpinnerTransformRotZ.addChangeListener(this);
247            ct.gridy ++; ct.gridx = 1;
248            textureTransformPanel.add(textureSpinnerTransformRotZ,ct);
249    
250            JLabel textureSpinnerTransformTranslatLabel = new JLabel(Info.ressources.getObject("Translation").toString());
251            ct.gridy ++; ct.gridx = 0;
252            textureTransformPanel.add(textureSpinnerTransformTranslatLabel, ct);
253    
254            JLabel textureSpinnerTransformTranslatXLabel = new JLabel("X");
255            ct.gridy ++;
256            ct.insets = new Insets(0,10,0,5);
257            textureTransformPanel.add(textureSpinnerTransformTranslatXLabel, ct);
258            ct.insets = new Insets(0,0,0,0);
259            SpinnerModel textureSpinnerModelTransformTranslatX = new SpinnerNumberModel(Float.valueOf(0f), //initial value
260                                                                                        Float.valueOf(-100f), //min
261                                                                                        Float.valueOf(100f), //max
262                                                                                        Float.valueOf(0.1f)); //step
263            textureSpinnerTransformTranslatX = new JSpinner(textureSpinnerModelTransformTranslatX);
264            ((JSpinner.DefaultEditor)textureSpinnerTransformTranslatX.getEditor()).getTextField().setColumns(3);
265            textureSpinnerTransformTranslatX.addChangeListener(this);
266            ct.gridx ++;
267            textureTransformPanel.add(textureSpinnerTransformTranslatX,ct);
268    
269            JLabel textureSpinnerTransformTranslatYLabel = new JLabel("Y");
270            ct.gridx ++;
271            ct.insets = new Insets(0,10,0,5);
272            textureTransformPanel.add(textureSpinnerTransformTranslatYLabel, ct);
273            ct.insets = new Insets(0,0,0,0);
274            SpinnerModel textureSpinnerModelTransformTranslatY = new SpinnerNumberModel(Float.valueOf(0f), //initial value
275                                                                                        Float.valueOf(-100f), //min
276                                                                                        Float.valueOf(100f), //max
277                                                                                        Float.valueOf(0.1f)); //step
278            textureSpinnerTransformTranslatY = new JSpinner(textureSpinnerModelTransformTranslatY);
279            ((JSpinner.DefaultEditor)textureSpinnerTransformTranslatY.getEditor()).getTextField().setColumns(3);
280            textureSpinnerTransformTranslatY.addChangeListener(this);
281            ct.gridx ++;
282            textureTransformPanel.add(textureSpinnerTransformTranslatY,ct);
283            
284            JLabel textureSpinnerTransformScaleLabel = new JLabel(Info.ressources.getObject("Scale").toString());
285            ct.gridy ++; ct.gridx = 0;
286            textureTransformPanel.add(textureSpinnerTransformScaleLabel, ct);
287            
288            textureButtonTransformUniformScale = new JRadioButton();
289            ct.gridy ++; 
290            textureTransformPanel.add(textureButtonTransformUniformScale, ct);
291            textureButtonTransformUniformScale.addActionListener(this);
292            JLabel textureButtonTransformUniformScaleLabel = new JLabel(Info.ressources.getObject("Uniforme").toString());
293            ct.gridx++;
294            textureTransformPanel.add(textureButtonTransformUniformScaleLabel, ct);
295            
296    
297    
298            JLabel textureSpinnerTransformScaleXLabel = new JLabel("X");
299            ct.gridy ++; ct.gridx = 0;
300            ct.insets = new Insets(0,10,0,5);
301            textureTransformPanel.add(textureSpinnerTransformScaleXLabel, ct);
302            ct.insets = new Insets(0,0,0,0);
303            SpinnerModel textureSpinnerModelTransformScaleX = new SpinnerNumberModel(Float.valueOf(1.0f), //initial value
304                                                                                     Float.valueOf(-100f), //min
305                                                                                     Float.valueOf(100f), //max
306                                                                                     Float.valueOf(0.1f)); //step
307            textureSpinnerTransformScaleX = new JSpinner(textureSpinnerModelTransformScaleX);
308            ((JSpinner.DefaultEditor)textureSpinnerTransformScaleX.getEditor()).getTextField().setColumns(3);
309            textureSpinnerTransformScaleX.addChangeListener(this);
310            ct.gridx ++;
311            textureTransformPanel.add(textureSpinnerTransformScaleX,ct);
312    
313            JLabel textureSpinnerTransformScaleYLabel = new JLabel("Y");
314            ct.gridx ++;
315            ct.insets = new Insets(0,10,0,5);
316            textureTransformPanel.add(textureSpinnerTransformScaleYLabel, ct);
317            ct.insets = new Insets(0,0,0,0);
318            SpinnerModel textureSpinnerModelTransformScaleY = new SpinnerNumberModel(Float.valueOf(1.0f), //initial value
319                                                                                     Float.valueOf(-100f), //min
320                                                                                     Float.valueOf(100f), //max
321                                                                                     Float.valueOf(0.1f)); //step
322    
323            textureSpinnerTransformScaleY = new JSpinner(textureSpinnerModelTransformScaleY);
324            ((JSpinner.DefaultEditor)textureSpinnerTransformScaleY.getEditor()).getTextField().setColumns(3);
325            textureSpinnerTransformScaleY.addChangeListener(this);
326            ct.gridx ++;
327            textureTransformPanel.add(textureSpinnerTransformScaleY,ct);
328    
329    
330    
331            //Add the Texture transform Panel
332            c.gridx=0; c.gridy++;
333            c.insets = new Insets(0,10,0,0);
334            textureTransformPanel.setBorder(BorderFactory.createTitledBorder(Info.ressources.getObject("Transform").toString()));
335            basicTexturePanel.add(textureTransformPanel,c);
336    
337            JLabel perspectiveCorrectionModeLabel = new JLabel(Info.ressources.getObject("Perspective_Correction_Mode").toString());
338            c.gridx=0;c.gridy ++;
339            c.insets = new Insets(10,10,0,0);
340            basicTexturePanel.add(perspectiveCorrectionModeLabel, c);
341    
342            String [] perspectiveCorrectionModeChoices = new String[2];
343            c.gridy++;
344            c.insets = new Insets(0,10,0,0);
345            perspectiveCorrectionModeChoices[PERSPECTIVE_CORRECTION_MODE_NICEST] = "NICEST";
346            perspectiveCorrectionModeChoices[PERSPECTIVE_CORRECTION_MODE_FASTEST] = "FASTEST";             
347            listPerspectiveCorrectionMode = new JComboBox(perspectiveCorrectionModeChoices);
348            listPerspectiveCorrectionMode.setSelectedIndex(perspectiveCorrectionMode);
349            listPerspectiveCorrectionMode.addActionListener(this);          
350            basicTexturePanel.add(listPerspectiveCorrectionMode, c);
351    
352    
353            JLabel textureModeLabel = new JLabel(Info.ressources.getObject("Texture_Mode").toString());
354            c.gridy ++;
355            c.insets = new Insets(10,10,0,0);
356            basicTexturePanel.add(textureModeLabel, c);
357            
358            c.gridy ++;c.gridx = 0;
359            c.insets = new Insets(0,10,0,0);
360            String [] textureModeChoices = new String[5];
361            textureModeChoices[TEXTURE_MODE_MODULATE] = "MODULATE";
362            textureModeChoices[TEXTURE_MODE_DECAL] = "DECAL";
363            textureModeChoices[TEXTURE_MODE_REPLACE] = "REPLACE";
364            textureModeChoices[TEXTURE_MODE_BLEND] = "BLEND";       
365            textureModeChoices[TEXTURE_MODE_COMBINE] = "COMBINE";       
366            listTextureMode = new JComboBox(textureModeChoices);
367            listTextureMode.setSelectedIndex(textureMode);
368            listTextureMode.addActionListener(this);                
369            basicTexturePanel.add(listTextureMode, c);
370            
371    
372            c.gridx = 1; c.gridy = 0;
373            c.gridheight = 15;
374            c.insets=new Insets(0,20,0,0);
375            c.fill = GridBagConstraints.EAST;
376            c.anchor = GridBagConstraints.EAST;             
377            JPanel imagePanel = createImagePanel();
378            basicTexturePanel.add(imagePanel,c);                    
379    
380            addTab(Info.ressources.getObject("Texture").toString(),basicTexturePanel);                      
381        }
382    
383    
384        /**
385         * COMBINE parameters Panel for the Texture.
386         */        
387        private void makeCombineModePane()
388        {           
389            // Panel For blend mode
390            JPanel combineModePanel = new JPanel();       
391            
392            GridBagConstraints c = new GridBagConstraints();
393            GridBagConstraints c2;
394    
395            combineModePanel.setLayout(new GridBagLayout());
396                    
397            c.weightx = 0; c.weighty = 0; 
398            c.fill = GridBagConstraints.WEST;
399            c.anchor = GridBagConstraints.WEST;                     
400    
401            // RGB Combine Mode     
402            c.insets = new Insets(0,0,0,20);
403            JLabel combineRGBModeLabel = new JLabel(Info.ressources.getObject("Combine_RGB_Mode").toString());
404            c.gridx=0;c.gridy =0;      
405            combineModePanel.add(combineRGBModeLabel, c);
406    
407            String [] combineRGBModeChoices = new String[7];        
408            combineRGBModeChoices[COMBINE_MODE_REPLACE] = "REPLACE";
409            combineRGBModeChoices[COMBINE_MODE_MODULATE] = "MODULATE";
410            combineRGBModeChoices[COMBINE_MODE_ADD] = "ADD";
411            combineRGBModeChoices[COMBINE_MODE_ADD_SIGNED] = "ADD_SIGNED";       
412            combineRGBModeChoices[COMBINE_MODE_SUBTRACT] = "SUBTRACT";       
413            combineRGBModeChoices[COMBINE_MODE_INTERPOLATE] = "INTERPOLATE";       
414            combineRGBModeChoices[COMBINE_MODE_DOT3] = "DOT3";       
415    
416            listCombineRGBMode = new JComboBox(combineRGBModeChoices);
417            listCombineRGBMode.setSelectedIndex(combineRGBMode);
418            listCombineRGBMode.addActionListener(this);     
419            c.gridy ++;     
420            c.insets = new Insets(0,10,0,20);
421            combineModePanel.add(listCombineRGBMode, c);
422                    
423            c.insets = new Insets(10,0,0,20);
424            JLabel combineRGBSourceLabel = new JLabel(Info.ressources.getObject("Combine_RGB_Source").toString());
425            c.gridy ++;     
426            combineModePanel.add(combineRGBSourceLabel, c);
427            c.insets = new Insets(0,10,0,20);
428            JPanel combineRGBSourcePanel = new JPanel();
429            combineRGBSourcePanel.setLayout(new GridBagLayout());
430            c2 = new GridBagConstraints();
431            c2.gridx = 0; c2.gridy = 0;
432            c2.insets = new Insets(0,0,0,5);
433    
434            JLabel combineRGBSourceLabelC0 = new JLabel("C0");
435            combineRGBSourcePanel.add(combineRGBSourceLabelC0, c2);
436            c2.gridx ++;
437            String [] combineRGBSourceChoices = new String[4];      
438            combineRGBSourceChoices[COMBINE_SOURCE_OBJECT_COLOR] = "OBJECT_COLOR";
439            combineRGBSourceChoices[COMBINE_SOURCE_TEXTURE_COLOR] = "TEXTURE_COLOR";
440            combineRGBSourceChoices[COMBINE_SOURCE_CONSTANT_COLOR] = "CONSTANT_COLOR";
441            combineRGBSourceChoices[COMBINE_SOURCE_PREVIOUS_TEXTURE_UNIT_STATE] = "PREVIOUS_TEXTURE_UNIT_STATE";       
442            listCombineRGBSourceC0 = new JComboBox(combineRGBSourceChoices);
443            listCombineRGBSourceC0.setSelectedIndex(combineRGBSourceC0);
444            listCombineRGBSourceC0.addActionListener(this);                 
445            combineRGBSourcePanel.add(listCombineRGBSourceC0, c2);
446            
447            c2.gridx = 0; c2.gridy ++;
448            JLabel combineRGBSourceLabelC1 = new JLabel("C1");
449            combineRGBSourcePanel.add(combineRGBSourceLabelC1, c2);
450            c2.gridx ++;
451            listCombineRGBSourceC1 = new JComboBox(combineRGBSourceChoices);
452            listCombineRGBSourceC1.setSelectedIndex(combineRGBSourceC1);
453            listCombineRGBSourceC1.addActionListener(this); 
454            combineRGBSourcePanel.add(listCombineRGBSourceC1, c2);
455    
456            c2.gridx = 0; c2.gridy ++;
457            JLabel combineRGBSourceLabelC2 = new JLabel("C2");
458            combineRGBSourcePanel.add(combineRGBSourceLabelC2, c2);
459            c2.gridx ++;
460            listCombineRGBSourceC2 = new JComboBox(combineRGBSourceChoices);
461            listCombineRGBSourceC2.setSelectedIndex(combineRGBSourceC2);
462            listCombineRGBSourceC2.addActionListener(this); 
463            combineRGBSourcePanel.add(listCombineRGBSourceC2, c2);
464    
465            c.gridy ++;     
466            combineModePanel.add(combineRGBSourcePanel, c);
467    
468            c.insets = new Insets(10,0,0,20);
469            JLabel combineRGBFunctionLabel = new JLabel(Info.ressources.getObject("Combine_RGB_Function").toString());
470            c.gridy ++;     
471            combineModePanel.add(combineRGBFunctionLabel, c);
472            c.insets = new Insets(0,10,0,20);
473            JPanel combineRGBFunctionPanel = new JPanel();
474            combineRGBFunctionPanel.setLayout(new GridBagLayout());
475            c2 = new GridBagConstraints();
476            c2.gridx = 0; c2.gridy = 0;
477            c2.insets = new Insets(0,0,0,5);
478            
479            JLabel combineRGBFunctionLabelC0 = new JLabel("C0");
480            combineRGBFunctionPanel.add(combineRGBFunctionLabelC0, c2);
481            c2.gridx ++;
482            String [] combineRGBFunctionChoices = new String[4];    
483            combineRGBFunctionChoices[COMBINE_FUNCTION_SRC_COLOR] = "SRC_COLOR";
484            combineRGBFunctionChoices[COMBINE_FUNCTION_ONE_MINUS_SRC_COLOR] = "ONE_MINUS_SRC_COLOR";
485            combineRGBFunctionChoices[COMBINE_FUNCTION_SRC_ALPHA] = "SRC_ALPHA";
486            combineRGBFunctionChoices[COMBINE_FUNCTION_ONE_MINUS_SRC_ALPHA] = "ONE_MINUS_SRC_ALPHA";       
487            listCombineRGBFunctionC0 = new JComboBox(combineRGBFunctionChoices);
488            listCombineRGBFunctionC0.setSelectedIndex(combineRGBFunctionC0);
489            listCombineRGBFunctionC0.addActionListener(this);       
490            combineRGBFunctionPanel.add(listCombineRGBFunctionC0, c2);      
491    
492            c2.gridx = 0; c2.gridy ++;
493            JLabel combineRGBFunctionLabelC1 = new JLabel("C1");
494            combineRGBFunctionPanel.add(combineRGBFunctionLabelC1, c2);
495            listCombineRGBFunctionC1 = new JComboBox(combineRGBFunctionChoices);
496            listCombineRGBFunctionC1.setSelectedIndex(combineRGBFunctionC1);        
497            listCombineRGBFunctionC1.addActionListener(this);               
498            c2.gridx ++;
499            combineRGBFunctionPanel.add(listCombineRGBFunctionC1, c2);      
500    
501            c2.gridx = 0; c2.gridy ++;
502            JLabel combineRGBFunctionLabelC2 = new JLabel("C2");
503            combineRGBFunctionPanel.add(combineRGBFunctionLabelC2, c2);
504            listCombineRGBFunctionC2 = new JComboBox(combineRGBFunctionChoices);
505            listCombineRGBFunctionC2.setSelectedIndex(combineRGBFunctionC2);
506            listCombineRGBFunctionC2.addActionListener(this);       
507            c2.gridx ++;
508            combineRGBFunctionPanel.add(listCombineRGBFunctionC2, c2);      
509    
510            c.gridy ++;     
511            combineModePanel.add(combineRGBFunctionPanel, c);
512    
513            c.insets = new Insets(10,0,0,20);
514            JLabel combineRGBScaleLabel = new JLabel(Info.ressources.getObject("Combine_RGB_Scale").toString());
515            c.gridy ++;     
516            combineModePanel.add(combineRGBScaleLabel, c);
517    
518            String [] combineRGBScaleChoices = new String[3];       
519            combineRGBScaleChoices[0] = "1";
520            combineRGBScaleChoices[1] = "2";
521            combineRGBScaleChoices[2] = "4";        
522            listCombineRGBScale = new JComboBox(combineRGBScaleChoices);
523            listCombineRGBScale.setSelectedIndex(combineRGBScale);
524            listCombineRGBScale.addActionListener(this);            
525            c.gridy ++;     
526            c.insets = new Insets(0,10,0,20);
527            combineModePanel.add(listCombineRGBScale, c);
528    
529            
530            // Alpha Combine Mode
531            c.insets = new Insets(0,20,0,0);
532            JLabel combineAlphaModeLabel = new JLabel(Info.ressources.getObject("Combine_Alpha_Mode").toString());
533            c.gridx=1;c.gridy =0;
534            combineModePanel.add(combineAlphaModeLabel, c);
535    
536            String [] combineAlphaModeChoices = new String[7];      
537            combineAlphaModeChoices[COMBINE_MODE_REPLACE] = "REPLACE";
538            combineAlphaModeChoices[COMBINE_MODE_MODULATE] = "MODULATE";
539            combineAlphaModeChoices[COMBINE_MODE_ADD] = "ADD";
540            combineAlphaModeChoices[COMBINE_MODE_ADD_SIGNED] = "ADD_SIGNED";       
541            combineAlphaModeChoices[COMBINE_MODE_SUBTRACT] = "SUBTRACT";       
542            combineAlphaModeChoices[COMBINE_MODE_INTERPOLATE] = "INTERPOLATE";       
543            combineAlphaModeChoices[COMBINE_MODE_DOT3] = "DOT3";       
544    
545            listCombineAlphaMode = new JComboBox(combineAlphaModeChoices);
546            listCombineAlphaMode.setSelectedIndex(combineAlphaMode);
547            listCombineAlphaMode.addActionListener(this);           
548            c.gridy ++;     
549            c.insets = new Insets(0,30,0,0);
550            combineModePanel.add(listCombineAlphaMode, c);
551            
552            c.insets = new Insets(10,20,0,0);
553            JLabel combineAlphaSourceLabel = new JLabel(Info.ressources.getObject("Combine_Alpha_Source").toString());
554            c.gridy ++;     
555            combineModePanel.add(combineAlphaSourceLabel, c);
556            
557            JPanel combineAlphaSourcePanel = new JPanel();
558            combineAlphaSourcePanel.setLayout(new GridBagLayout());
559            c2 = new GridBagConstraints();
560            c2.gridx = 0; c2.gridy = 0;
561            c2.insets = new Insets(0,0,0,5);
562    
563            String [] combineAlphaSourceChoices = new String[4];    
564            c.insets = new Insets(0,30,0,0);
565            combineAlphaSourceChoices[COMBINE_SOURCE_OBJECT_COLOR] = "OBJECT_COLOR";
566            combineAlphaSourceChoices[COMBINE_SOURCE_TEXTURE_COLOR] = "TEXTURE_COLOR";
567            combineAlphaSourceChoices[COMBINE_SOURCE_CONSTANT_COLOR] = "CONSTANT_COLOR";
568            combineAlphaSourceChoices[COMBINE_SOURCE_PREVIOUS_TEXTURE_UNIT_STATE] = "PREVIOUS_TEXTURE_UNIT_STATE";       
569            JLabel combineAlphaSourceLabelC0 = new JLabel("C0");
570            combineAlphaSourcePanel.add(combineAlphaSourceLabelC0, c2);
571            listCombineAlphaSourceC0 = new JComboBox(combineAlphaSourceChoices);
572            listCombineAlphaSourceC0.setSelectedIndex(combineAlphaSourceC0);
573            listCombineAlphaSourceC0.addActionListener(this);               
574            c2.gridx ++;
575            combineAlphaSourcePanel.add(listCombineAlphaSourceC0, c2);
576    
577            c2.gridx = 0; c2.gridy ++;
578            JLabel combineAlphaSourceLabelC1 = new JLabel("C1");
579            combineAlphaSourcePanel.add(combineAlphaSourceLabelC1, c2);
580            listCombineAlphaSourceC1 = new JComboBox(combineAlphaSourceChoices);
581            listCombineAlphaSourceC1.setSelectedIndex(combineAlphaSourceC1);
582            listCombineAlphaSourceC1.addActionListener(this);       
583            c2.gridx ++;
584            combineAlphaSourcePanel.add(listCombineAlphaSourceC1, c2);
585    
586            c2.gridx = 0; c2.gridy ++;
587            JLabel combineAlphaSourceLabelC2 = new JLabel("C2");
588            combineAlphaSourcePanel.add(combineAlphaSourceLabelC2, c2);
589            listCombineAlphaSourceC2 = new JComboBox(combineAlphaSourceChoices);
590            listCombineAlphaSourceC2.setSelectedIndex(combineAlphaSourceC2);
591            listCombineAlphaSourceC2.addActionListener(this);       
592            c2.gridx ++;
593            combineAlphaSourcePanel.add(listCombineAlphaSourceC2, c2);
594    
595            c.gridy ++;     
596            combineModePanel.add(combineAlphaSourcePanel, c);
597    
598            c.insets = new Insets(10,20,0,0);
599            JLabel combineAlphaFunctionLabel = new JLabel(Info.ressources.getObject("Combine_Alpha_Function").toString());
600            c.gridy ++;     
601            combineModePanel.add(combineAlphaFunctionLabel, c);
602            
603            JPanel combineAlphaFunctionPanel = new JPanel();
604            combineAlphaFunctionPanel.setLayout(new GridBagLayout());
605            c2 = new GridBagConstraints();
606            c2.gridx = 0; c2.gridy = 0;
607            c2.insets = new Insets(0,0,0,5);
608    
609            String [] combineAlphaFunctionChoices = new String[2];  
610            c.insets = new Insets(0,30,0,0);        
611            combineAlphaFunctionChoices[COMBINE_FUNCTION_SRC_ALPHA] = "SRC_ALPHA";
612            combineAlphaFunctionChoices[COMBINE_FUNCTION_ONE_MINUS_SRC_ALPHA] = "ONE_MINUS_SRC_ALPHA";       
613            JLabel combineAlphaFunctionLabelC0 = new JLabel("C0");
614            combineAlphaFunctionPanel.add(combineAlphaFunctionLabelC0, c2);
615            listCombineAlphaFunctionC0 = new JComboBox(combineAlphaFunctionChoices);
616            listCombineAlphaFunctionC0.setSelectedIndex(combineAlphaFunctionC0);
617            listCombineAlphaFunctionC0.addActionListener(this);     
618            c2.gridx ++;
619            combineAlphaFunctionPanel.add(listCombineAlphaFunctionC0, c2);
620            
621            c2.gridx = 0; c2.gridy ++;
622            JLabel combineAlphaFunctionLabelC1 = new JLabel("C1");
623            combineAlphaFunctionPanel.add(combineAlphaFunctionLabelC1, c2);
624            listCombineAlphaFunctionC1 = new JComboBox(combineAlphaFunctionChoices);
625            listCombineAlphaFunctionC1.setSelectedIndex(combineAlphaFunctionC1);
626            listCombineAlphaFunctionC1.addActionListener(this);             
627            c2.gridx ++;
628            combineAlphaFunctionPanel.add(listCombineAlphaFunctionC1, c2);
629    
630            c2.gridx = 0; c2.gridy ++;
631            JLabel combineAlphaFunctionLabelC2 = new JLabel("C2");
632            combineAlphaFunctionPanel.add(combineAlphaFunctionLabelC2, c2);
633            listCombineAlphaFunctionC2 = new JComboBox(combineAlphaFunctionChoices);
634            listCombineAlphaFunctionC2.setSelectedIndex(combineAlphaFunctionC2);
635            listCombineAlphaFunctionC2.addActionListener(this);     
636            c2.gridx ++;
637            combineAlphaFunctionPanel.add(listCombineAlphaFunctionC2, c2);
638    
639            c.gridy ++;     
640            combineModePanel.add(combineAlphaFunctionPanel, c);
641    
642            c.insets = new Insets(10,20,0,0);
643            JLabel combineAlphaScaleLabel = new JLabel(Info.ressources.getObject("Combine_Alpha_Scale").toString());
644            c.gridy ++;     
645            combineModePanel.add(combineAlphaScaleLabel, c);
646    
647            String [] combineAlphaScaleChoices = new String[3];
648            c.gridy ++;     
649            combineAlphaScaleChoices[0] = "1";
650            combineAlphaScaleChoices[1] = "2";
651            combineAlphaScaleChoices[2] = "4";      
652            listCombineAlphaScale = new JComboBox(combineAlphaScaleChoices);
653            listCombineAlphaScale.setSelectedIndex(combineAlphaScale);
654            listCombineAlphaScale.addActionListener(this);          
655            c.insets = new Insets(0,30,0,0);
656            combineModePanel.add(listCombineAlphaScale, c); 
657            
658            addTab("Combine",combineModePanel);                     
659        }
660    
661    
662        /**
663         * Blend Color Panel for the Texture.
664         */            
665        private void makeBlendColorPane()
666        {
667            // Panel For blend color
668            JPanel blendColorPanel = new JPanel();       
669            blendColorPanel.setLayout(new GridBagLayout());
670            GridBagConstraints c = new GridBagConstraints();
671            c.fill = GridBagConstraints.CENTER;
672            blendColorPicker = new ColorPicker(true,true);
673            blendColorPanel.add(blendColorPicker,c);        
674            // Init Blend Color to {0.5,0.5,0.5,0.5}
675            setTextureBlendColor(blendColor);
676    
677            blendColorPicker.addPropertyChangeListener(ColorPicker.HEX_COLOR_PROPERTY, new PropertyChangeListener() {
678                    public void propertyChange(PropertyChangeEvent evt) {
679                        float rgb[] = new float[4];
680                        rgb[0]=(float)blendColorPicker.getRGB()[0] / 255;
681                        rgb[1]=(float)blendColorPicker.getRGB()[1] / 255;
682                        rgb[2]=(float)blendColorPicker.getRGB()[2] / 255;   
683                        rgb[3]=blendColorPicker.getOpacity();
684                        updateTextureBlendColor(rgb);                   
685                        
686                    }});    
687    
688            blendColorPicker.addPropertyChangeListener(ColorPicker.OPACITY_PROPERTY, new PropertyChangeListener() {
689                    public void propertyChange(PropertyChangeEvent evt) {                           
690                        float rgb[] = new float[4];
691                        rgb[0]=(float)blendColorPicker.getRGB()[0] / 255;
692                        rgb[1]=(float)blendColorPicker.getRGB()[1] / 255;
693                        rgb[2]=(float)blendColorPicker.getRGB()[2] / 255;   
694                        rgb[3]=blendColorPicker.getOpacity();
695                        updateTextureBlendColor(rgb);
696                    }});    
697    
698            addTab("Blend",blendColorPanel);                        
699        }
700    
701        /**
702         * Panel creation for the texture image. A default image is used and shown here.
703         * @return the Panel created.
704         */                
705        public JPanel createImagePanel()
706        {
707            JPanel imagePanel = new JPanel();
708    
709            image = Toolkit.getDefaultToolkit().getImage(DefaultTexture);
710            /* Wait for the loading */
711            MediaTracker tracker=new MediaTracker(this);
712            tracker.addImage(image,0);
713            try {
714                tracker.waitForID(0);
715            }
716            catch(InterruptedException e) 
717                {}
718    
719            // Resize the image                     
720            BufferedImage imageResize = new BufferedImage(300, 350, BufferedImage.TYPE_INT_ARGB);                               
721            Graphics2D g = (Graphics2D) imageResize.getGraphics();
722            g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
723            g.drawImage(image, 0, 0, 300, 350, null);                               
724            image=imageResize;
725            
726            imageIcon = new ImageIcon(image);
727            JLabel imageLabel = new JLabel(imageIcon);
728            imagePanel.add(imageLabel,BorderLayout.EAST);
729            g.dispose();
730    
731            textureName = DefaultTexture;
732    
733            return imagePanel;
734        }
735    
736    
737        /**
738         * Update the texture image shown and the Texture itself.
739         * @param texture the new Texture File.
740         */                
741        public void updateImage(URL texture)
742        {
743            image = Toolkit.getDefaultToolkit().getImage(texture);
744            
745            /* Wait for the loading */
746            MediaTracker tracker=new MediaTracker(this);
747            tracker.addImage(image,0);
748            try {
749                tracker.waitForID(0);
750            }
751            catch(InterruptedException e) 
752                {}
753        
754            // Resize the image                     
755            BufferedImage imageResize = new BufferedImage(300, 350, BufferedImage.TYPE_INT_ARGB);                               
756            Graphics2D g = (Graphics2D) imageResize.getGraphics();
757            g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
758            g.drawImage(image, 0, 0, 300, 350, null);                                       
759            image=imageResize;      
760            
761            imageIcon.setImage(image);
762            g.dispose();
763            repaint();
764            
765            URL lastTextureName = textureName;
766            textureName = texture;
767            firePropertyChange(TEXTURE_FILE,lastTextureName,textureName);           
768        }
769    
770    
771        /**
772         * Called when a modification is done on the Texture transformation.
773         * @param e the related event.
774         */                
775        public void stateChanged(ChangeEvent e) 
776        {
777            Object source = e.getSource();
778            Transform3D lastTextureTransform = new Transform3D(textureTransform);   
779    
780            if(source == textureSpinnerTransformRotZ)
781                textureTransform.setRotation(new AxisAngle4d(new Vector3d(0,0,1),Math.toRadians((Float)textureSpinnerTransformRotZ.getValue())));
782            else if(source == textureSpinnerTransformTranslatX || source == textureSpinnerTransformTranslatY)
783                /*textureTransform.setTranslation(new Vector3d((float)(Math.round((Float)textureSpinnerTransformTranslatX.getValue()*10))/10,
784                  (float)(Math.round((Float)textureSpinnerTransformTranslatY.getValue()*10))/10,
785                  0.0f));  */
786                textureTransform.setTranslation(new Vector3d((Float)textureSpinnerTransformTranslatX.getValue(),
787                                                             (Float)textureSpinnerTransformTranslatY.getValue(),
788                                                             0.0f)); 
789            else if(source == textureSpinnerTransformScaleX || source == textureSpinnerTransformScaleY) 
790                {
791                    if(textureTransformUniformScale)
792                        {
793                            if(source == textureSpinnerTransformScaleX)
794                                textureSpinnerTransformScaleY.setValue((Float)textureSpinnerTransformScaleX.getValue());
795                            else if(source == textureSpinnerTransformScaleY)
796                                textureSpinnerTransformScaleX.setValue((Float)textureSpinnerTransformScaleY.getValue());
797                        }
798    
799                    textureTransform.setScale(new Vector3d((Float)textureSpinnerTransformScaleX.getValue(),
800                                                           (Float)textureSpinnerTransformScaleY.getValue(),
801                                                           1.0f));
802                }           
803            firePropertyChange(TEXTURE_TRANSFORM,lastTextureTransform,textureTransform);
804        }
805    
806    
807        /**
808         * Called when an action is performed : the OK button is clicked, the Texture is set or changed, the 
809         * Texture Mode or the Texture Perspective correction Mode is modified ...
810         * @param e the related action.
811         */                
812        public void actionPerformed(ActionEvent e) 
813        {
814            Object source = e.getSource();
815            if(source == fileChooserButton)
816                {                           
817                    int option = fileChooser.showOpenDialog(this);
818                    if (option == JFileChooser.APPROVE_OPTION) 
819                        {
820                            File fileOutput = fileChooser.getSelectedFile();
821                            textureNameJText.setText(fileOutput.getPath());                         
822                            try
823                                {           
824                                    updateImage(fileOutput.toURL());
825                                }
826                            catch (Exception f)
827                                {
828                                    System.err.println("Error : cannot use the Choosen image" + fileOutput.getPath());
829                                }
830                        }           
831                }
832    
833            else if(source == OKButton)
834                {                           
835                    if (textureNameJText.getText().compareTo("") ==0)
836                        updateImage(DefaultTexture);
837                    else
838                        {
839                            try
840                                {
841                                    File fileOutput = new File(textureNameJText.getText());                         
842                                    updateImage(fileOutput.toURL());
843                                }
844                            catch (Exception g)
845                                {
846                                    System.err.println("Error : cannot use the Choosen image : " +  textureNameJText.getText());
847                                }
848    
849                        }
850                }
851            
852            else if(source == setTextureButton)
853                {
854                    if(setTextureButton.isSelected() && textureNameJText.getText().compareTo("") == 0)
855                        updateImage(DefaultTexture);
856    
857                    firePropertyChange(TEXTURE_USE,useTexture,!useTexture); 
858                    useTexture=!useTexture;
859                }              
860    
861            else if(source == textureButtonTransformReset) 
862                {
863                    if(textureButtonTransformReset.isSelected())
864                        {
865                            Transform3D lastTextureTransform = new Transform3D(textureTransform);                                          
866                            textureButtonTransformReset.setSelected(false);
867                            textureTransform.setIdentity();
868                            textureSpinnerTransformRotZ.setValue(Float.valueOf(0.0f));
869                            textureSpinnerTransformScaleX.setValue(Float.valueOf(1.0f));
870                            textureSpinnerTransformScaleY.setValue(Float.valueOf(1.0f));
871                            textureSpinnerTransformTranslatX.setValue(Float.valueOf(0.0f));
872                            textureSpinnerTransformTranslatY.setValue(Float.valueOf(0.0f));                 
873                            firePropertyChange(TEXTURE_TRANSFORM,lastTextureTransform,textureTransform);            
874                        }
875                }   
876            
877            else if (source == textureButtonTransformUniformScale)
878                {           
879                    textureTransformUniformScale = textureButtonTransformUniformScale.isSelected();
880                }
881    
882            else if (source == listPerspectiveCorrectionMode)
883                {
884                    int lastPerspectiveCorrectionMode = perspectiveCorrectionMode;
885                    perspectiveCorrectionMode = (Integer) listPerspectiveCorrectionMode.getSelectedIndex();         
886                    firePropertyChange(TEXTURE_PERPSPECTIVE_CORRECTION_MODE,lastPerspectiveCorrectionMode, perspectiveCorrectionMode);
887                }   
888    
889            else if (source == listTextureMode)
890                {
891                    int lastTextureMode = textureMode;
892                    textureMode = (Integer) listTextureMode.getSelectedIndex();             
893                    firePropertyChange(TEXTURE_MODE,lastTextureMode, textureMode);          
894                }
895            
896            else if (source == listCombineRGBMode)
897                {
898                    int lastCombineRGBMode = combineRGBMode;
899                    combineRGBMode = (Integer) listCombineRGBMode.getSelectedIndex();       
900                    firePropertyChange(TEXTURE_COMBINE_RGB_MODE,lastCombineRGBMode, combineRGBMode);                                       
901                }
902    
903            else if (source == listCombineAlphaMode)
904                {
905                    int lastCombineAlphaMode = combineAlphaMode;
906                    combineAlphaMode = (Integer) listCombineAlphaMode.getSelectedIndex();   
907                    firePropertyChange(TEXTURE_COMBINE_ALPHA_MODE,lastCombineAlphaMode, combineAlphaMode);                                          
908                }
909            else if (source == listCombineRGBSourceC0)
910                {
911                    int lastCombineRGBSourceC0 = combineRGBSourceC0;
912                    combineRGBSourceC0 = (Integer) listCombineRGBSourceC0.getSelectedIndex();       
913                    firePropertyChange(TEXTURE_COMBINE_RGB_SOURCE, lastCombineRGBSourceC0, combineRGBSourceC0);   
914                }
915    
916            else if (source == listCombineRGBSourceC1)
917                {
918                    int lastCombineRGBSourceC1 = combineRGBSourceC1;
919                    combineRGBSourceC1 = (Integer) listCombineRGBSourceC1.getSelectedIndex();       
920                    firePropertyChange(TEXTURE_COMBINE_RGB_SOURCE, lastCombineRGBSourceC1, combineRGBSourceC1);   
921                }
922    
923            else if (source == listCombineRGBSourceC2)
924                {
925                    int lastCombineRGBSourceC2 = combineRGBSourceC2;
926                    combineRGBSourceC2 = (Integer) listCombineRGBSourceC2.getSelectedIndex();       
927                    firePropertyChange(TEXTURE_COMBINE_RGB_SOURCE, lastCombineRGBSourceC2, combineRGBSourceC2);   
928                }
929    
930            else if (source == listCombineAlphaSourceC0)
931                {
932                    int lastCombineAlphaSourceC0 = combineAlphaSourceC0;
933                    combineAlphaSourceC0 = (Integer) listCombineAlphaSourceC0.getSelectedIndex();   
934                    firePropertyChange(TEXTURE_COMBINE_ALPHA_SOURCE, lastCombineAlphaSourceC0, combineAlphaSourceC0);   
935                }
936    
937            else if (source == listCombineAlphaSourceC1)
938                {
939                    int lastCombineAlphaSourceC1 = combineAlphaSourceC1;
940                    combineAlphaSourceC1 = (Integer) listCombineAlphaSourceC1.getSelectedIndex();   
941                    firePropertyChange(TEXTURE_COMBINE_ALPHA_SOURCE, lastCombineAlphaSourceC1, combineAlphaSourceC1);   
942                }
943    
944            else if (source == listCombineAlphaSourceC2)
945                {
946                    int lastCombineAlphaSourceC2 = combineAlphaSourceC2;
947                    combineAlphaSourceC2 = (Integer) listCombineAlphaSourceC2.getSelectedIndex();   
948                    firePropertyChange(TEXTURE_COMBINE_ALPHA_SOURCE, lastCombineAlphaSourceC2, combineAlphaSourceC2);   
949                }
950    
951            else if (source == listCombineRGBFunctionC0)
952                {
953                    int lastCombineRGBFunctionC0 = combineRGBFunctionC0;
954                    combineRGBFunctionC0 = (Integer) listCombineRGBFunctionC0.getSelectedIndex();   
955                    firePropertyChange(TEXTURE_COMBINE_RGB_FUNCTION, lastCombineRGBFunctionC0, combineRGBFunctionC0);   
956                }
957    
958            else if (source == listCombineRGBFunctionC1)
959                {
960                    int lastCombineRGBFunctionC1 = combineRGBFunctionC1;
961                    combineRGBFunctionC1 = (Integer) listCombineRGBFunctionC1.getSelectedIndex();   
962                    firePropertyChange(TEXTURE_COMBINE_RGB_FUNCTION, lastCombineRGBFunctionC1, combineRGBFunctionC1);   
963                }
964    
965            else if (source == listCombineRGBFunctionC2)
966                {
967                    int lastCombineRGBFunctionC2 = combineRGBFunctionC2;
968                    combineRGBFunctionC2 = (Integer) listCombineRGBFunctionC2.getSelectedIndex();   
969                    firePropertyChange(TEXTURE_COMBINE_RGB_FUNCTION, lastCombineRGBFunctionC2, combineRGBFunctionC2);   
970                }
971    
972            else if (source == listCombineAlphaFunctionC0)
973                {
974                    int lastCombineAlphaFunctionC0 = combineAlphaFunctionC0;
975                    combineAlphaFunctionC0 = (Integer) listCombineAlphaFunctionC0.getSelectedIndex();       
976                    firePropertyChange(TEXTURE_COMBINE_ALPHA_FUNCTION, lastCombineAlphaFunctionC0, combineAlphaFunctionC0);   
977                }
978    
979            else if (source == listCombineAlphaFunctionC1)
980                {
981                    int lastCombineAlphaFunctionC1 = combineAlphaFunctionC1;
982                    combineAlphaFunctionC1 = (Integer) listCombineAlphaFunctionC1.getSelectedIndex();       
983                    firePropertyChange(TEXTURE_COMBINE_ALPHA_FUNCTION, lastCombineAlphaFunctionC1, combineAlphaFunctionC1);   
984                }
985    
986            else if (source == listCombineAlphaFunctionC2)
987                {
988                    int lastCombineAlphaFunctionC2 = combineAlphaFunctionC2;
989                    combineAlphaFunctionC2 = (Integer) listCombineAlphaFunctionC2.getSelectedIndex();       
990                    firePropertyChange(TEXTURE_COMBINE_ALPHA_FUNCTION, lastCombineAlphaFunctionC2, combineAlphaFunctionC2);   
991                }
992            
993            else if (source == listCombineRGBScale)
994                {
995                    int lastCombineRGBScale = combineRGBScale;
996                    combineRGBScale = (Integer) listCombineRGBScale.getSelectedIndex();     
997                    firePropertyChange(TEXTURE_COMBINE_RGB_SCALE, lastCombineRGBScale, combineRGBScale);   
998                }
999            
1000            else if (source == listCombineAlphaScale)
1001                {
1002                    int lastCombineAlphaScale = combineAlphaScale;
1003                    combineAlphaScale = (Integer) listCombineAlphaScale.getSelectedIndex(); 
1004                    firePropertyChange(TEXTURE_COMBINE_ALPHA_SCALE, lastCombineAlphaScale, combineAlphaScale);   
1005                }
1006    
1007        }
1008        
1009    
1010        /**
1011         * 
1012         * Give the current Texture file.
1013         * @return the Texture file.
1014         *
1015         */                
1016        public URL getTextureFile()
1017        {
1018            return textureName;
1019        }
1020    
1021        /**
1022         * 
1023         * Set the current Texture file.
1024         * @param f the Texture file to set.
1025         *
1026         */                
1027        public void setTextureFile(URL f)
1028        {
1029            updateImage(f); 
1030            textureNameJText.setText(f.getPath());
1031        }
1032    
1033        /**
1034         * 
1035         * Set the current default Texture file.
1036         * @param f the Texture default file to set.
1037         *
1038         */                
1039        public void setDefaultTextureFile(URL f)
1040        {
1041            updateImage(f); 
1042            DefaultTexture = f;     
1043        }
1044    
1045        /**
1046         * 
1047         * Check is the Texture is used.
1048         * @return true if the Texture is used, false otherwise.
1049         *
1050         */                
1051        public boolean isTextureSet()
1052        {
1053            return setTextureButton.isSelected();
1054        }
1055    
1056        /**
1057         * 
1058         * use or not the current Texture.
1059         * @param b true if the currect Texture has to be used, false otherwise.
1060         *
1061         */                
1062        public void setTextureUse(boolean b)
1063        {
1064            setTextureButton.setSelected(b);
1065            
1066            useTexture = b;
1067            if(b && textureNameJText.getText().compareTo("") ==0)
1068                updateImage(DefaultTexture);
1069    
1070            firePropertyChange(TEXTURE_USE,useTexture,!useTexture);         
1071        }
1072    
1073        /**
1074         * 
1075         * Get the current Texture transformation.
1076         * @return the current Texture transformation.
1077         *
1078         */                
1079        public Transform3D getTextureTransform()
1080        {
1081            return new Transform3D(textureTransform);
1082        }
1083    
1084        /**
1085         * 
1086         * Set the Texture transformation.
1087         * @param t the Texture transformation to use.
1088         *
1089         */                
1090        public void setTextureTransform(Transform3D t)
1091        {
1092            Transform3D lastTextureTransform = new Transform3D(textureTransform);
1093            textureTransform = new Transform3D(t);          
1094            Vector3f trans = new  Vector3f();
1095            Vector3d scale = new Vector3d();
1096            Matrix3f rot = new Matrix3f();
1097            textureTransform.get(trans);    
1098            textureTransform.get(rot);      
1099            textureTransform.getScale(scale);
1100            
1101            float [] transV = new float[3];
1102            double [] scaleV = new double[3];
1103            trans.get(transV);
1104            scale.get(scaleV);
1105    
1106            // If Sinus is >= 0 compute acos
1107            if (rot.getElement(1,0)>=0)      
1108                {
1109                    textureSpinnerTransformRotZ.setValue((float)Math.toDegrees(Math.acos(rot.getElement(0,0))));
1110                }
1111            else 
1112                // If Sinus is < 0; angle is 360 degres - acos
1113                {
1114                    textureSpinnerTransformRotZ.setValue((float) (360 - Math.toDegrees(Math.acos(rot.getElement(0,0)))));
1115                }
1116    
1117            textureSpinnerTransformTranslatX.setValue(transV[0]);
1118            textureSpinnerTransformTranslatY.setValue(transV[1]);
1119            textureSpinnerTransformScaleX.setValue((float)scaleV[0]);
1120            textureSpinnerTransformScaleY.setValue((float)scaleV[1]);
1121            
1122            firePropertyChange(TEXTURE_TRANSFORM,lastTextureTransform,textureTransform);    
1123        }
1124    
1125        /**
1126         * 
1127         * Get the current Texture scale transformation on the X axis.
1128         * @return the current Texture scale transformation on the X axis.
1129         *
1130         */                
1131        public float getTextureTransformScaleX()
1132        {
1133            return (Float)textureSpinnerTransformScaleX.getValue();
1134        }
1135    
1136        /**
1137         * 
1138         * Set the Texture scale transformation on the X axis.
1139         * @param v the Texture scale transformation on the X axis to use.
1140         *
1141         */                
1142        public void setTextureTransformScaleX(float v)
1143        {
1144            textureSpinnerTransformScaleX.setValue(v);
1145        }
1146    
1147        /**
1148         * 
1149         * Get the current Texture scale transformation on the Y axis.
1150         * @return the current Texture scale transformation on the Y axis.
1151         *
1152         */                
1153        public float getTextureTransformScaleY()
1154        {
1155            return (Float)textureSpinnerTransformScaleY.getValue();
1156        }
1157    
1158        /**
1159         * 
1160         * Set the Texture scale transformation on the Y axis.
1161         * @param v the Texture scale transformation on the Y axis to use.
1162         *
1163         */                
1164        public void setTextureTransformScaleY(float v)
1165        {
1166            textureSpinnerTransformScaleY.setValue(v);
1167        }
1168    
1169        /**
1170         * 
1171         * Get the current Texture translation transformation on the X axis.
1172         * @return the current Texture translation transformation on the X axis.
1173         *
1174         */                
1175        public float getTextureTransformTranslatX()
1176        {
1177            return (Float)textureSpinnerTransformTranslatX.getValue();
1178        }
1179    
1180        /**
1181         * 
1182         * Set the Texture translation transformation on the X axis.
1183         * @param v the Texture translation transformation on the X axis to use.
1184         *
1185         */                
1186        public void setTextureTransformTranslatX(float v)
1187        {
1188            textureSpinnerTransformTranslatX.setValue(v);
1189        }
1190    
1191        /**
1192         * 
1193         * Get the current Texture translation transformation on the Y axis.
1194         * @return the current Texture translation transformation on the Y axis.
1195         *
1196         */                
1197        public float getTextureTransformTranslatY()
1198        {
1199            return (Float)textureSpinnerTransformTranslatY.getValue();
1200        }
1201    
1202        /**
1203         * 
1204         * Set the Texture translation transformation on the Y axis.
1205         * @param v the Texture translation transformation on the Y axis to use.
1206         *
1207         */                
1208        public void setTextureTransformTranslatY(float v)
1209        {
1210            textureSpinnerTransformTranslatY.setValue(v);
1211        }
1212    
1213        /**
1214         * 
1215         * Get the current Texture rotation transformation on the Z axis.
1216         * @return the current Texture rotation transformation on the Z axis.
1217         *
1218         */                
1219        public float getTextureTransformRotZ()
1220        {                   
1221            return (float)Math.toRadians((Float)textureSpinnerTransformRotZ.getValue());
1222        }
1223    
1224        /**
1225         * 
1226         * Set the Texture rotation transformation on the Z axis.
1227         * @param v the Texture rotation transformation on the Z axis to use.
1228         *
1229         */                
1230        public void setTextureTransformRotZ(float v)
1231        {
1232            textureSpinnerTransformRotZ.setValue((float)Math.toDegrees(v));
1233        }
1234    
1235        /**
1236         * 
1237         * Get the current Texture Mode.
1238         * @return the current Texture Mode.
1239         *
1240         */                   
1241        public int getTextureMode()
1242        {
1243            return convertExternTextureMode(textureMode);    
1244        }
1245    
1246        /**
1247         * 
1248         * Set the Texture Mode.
1249         * @param m the Texture Mode to use.
1250         *
1251         */                
1252        public void setTextureMode(int m)
1253        {
1254            listTextureMode.setSelectedIndex(convertInternTextureMode(m));  
1255            textureMode = convertInternTextureMode(m);    
1256        }
1257            
1258        /**
1259         * 
1260         * Get the current Texture Perspective Correction Mode.
1261         * @return the current Texture Perspective Correction Mode.
1262         *
1263         */                
1264        public int getTexturePerspectiveCorrectionMode()
1265        {
1266            return convertExternPerspectiveCorrectionMode(perspectiveCorrectionMode);    
1267        }
1268    
1269        /**
1270         * 
1271         * Set the Texture Perspective Correction Mode.
1272         * @param m the Texture Perspective Correction Mode to use.
1273         *
1274         */                
1275        public void setTexturePerspectiveCorrectionMode(int m)
1276        {
1277            listPerspectiveCorrectionMode.setSelectedIndex(convertInternPerspectiveCorrectionMode(m));      
1278            perspectiveCorrectionMode = convertInternPerspectiveCorrectionMode(m);   
1279        }
1280    
1281        /**
1282         * 
1283         * Get the current Texture blend color.
1284         * @return the current Texture blend color.
1285         *
1286         */                
1287        public float [] getTextureBlendColor ()
1288        {
1289            return blendColor;
1290        }
1291    
1292        /**
1293         * 
1294         * Set the Texture blend color.
1295         * @param c the Texture blend color to use.
1296         *
1297         */                 
1298        public void setTextureBlendColor (float []c)
1299        {
1300            blendColorPicker.setRGB((int)(c[0] * 255), (int)(c[1] * 255), (int)(c[2] * 255));
1301            blendColorPicker.setOpacity(c[3]);      
1302            blendColor = c; 
1303        }
1304    
1305        /**
1306         * 
1307         * Get the current Texture Combine RGB Mode.
1308         * @return the current Texture Combine RGB Mode.
1309         *
1310         */                
1311        public int getTextureCombineRGBMode ()
1312        {
1313            return convertExternTextureCombineMode(combineRGBMode);
1314        }
1315    
1316        /**
1317         * 
1318         * Set the Texture Combine RGB Mode.
1319         * @param m the Texture Combine RGB Mode to use.
1320         *
1321         */                 
1322        public void setTextureCombineRGBMode (int m)
1323        {
1324            listCombineRGBMode.setSelectedIndex(convertInternTextureCombineMode(m));        
1325            combineRGBMode = convertInternTextureCombineMode(m);   
1326        }
1327    
1328        /**
1329         * 
1330         * Get the current Texture Combine RGB Source.
1331         * @return the current Texture Combine RGB Source (C0,C1,C2).
1332         *
1333         */                
1334        public int[] getTextureCombineRGBSource ()
1335        {
1336            int [] res = new int[3];
1337            res[0] = convertExternTextureCombineSource(combineRGBSourceC0);
1338            res[1] = convertExternTextureCombineSource(combineRGBSourceC1);
1339            res[2] = convertExternTextureCombineSource(combineRGBSourceC2);
1340            
1341            return res;
1342        }
1343    
1344        /**
1345         * 
1346         * Set the Texture Combine RGB Source.
1347         * @param c the Texture Combine RGB Source Mode (C0,C1,C2) to use.     
1348         *
1349         */                 
1350        public void setTextureCombineRGBSource (int []c)
1351        {
1352            listCombineRGBSourceC0.setSelectedIndex(convertInternTextureCombineSource(c[0]));       
1353            combineRGBSourceC0 = convertInternTextureCombineSource(c[0]);   
1354            listCombineRGBSourceC1.setSelectedIndex(convertInternTextureCombineSource(c[1]));       
1355            combineRGBSourceC1 = convertInternTextureCombineSource(c[1]);   
1356            listCombineRGBSourceC2.setSelectedIndex(convertInternTextureCombineSource(c[2]));       
1357            combineRGBSourceC2 = convertInternTextureCombineSource(c[2]);   
1358        }
1359    
1360        /**
1361         * 
1362         * Get the current Texture Combine RGB Function.
1363         * @return the current Texture Combine RGB Function (C0,C1,C2).
1364         *
1365         */                
1366        public int[] getTextureCombineRGBFunction ()
1367        {
1368            int [] res = new int[3];
1369            res[0] = convertExternTextureCombineFunction(combineRGBFunctionC0);
1370            res[1] = convertExternTextureCombineFunction(combineRGBFunctionC1);
1371            res[2] = convertExternTextureCombineFunction(combineRGBFunctionC2);
1372            
1373            return res;
1374        }
1375    
1376        /**
1377         * 
1378         * Set the Texture Combine RGB Function.
1379         * @param c the Texture Combine RGB Function Mode (C0,C1,C2) to use.     
1380         *
1381         */                 
1382        public void setTextureCombineRGBFunction (int []c)
1383        {
1384            listCombineRGBFunctionC0.setSelectedIndex(convertInternTextureCombineFunction(c[0]));   
1385            combineRGBFunctionC0 = convertInternTextureCombineFunction(c[0]);   
1386            listCombineRGBFunctionC1.setSelectedIndex(convertInternTextureCombineFunction(c[1]));   
1387            combineRGBFunctionC1 = convertInternTextureCombineFunction(c[1]);   
1388            listCombineRGBFunctionC2.setSelectedIndex(convertInternTextureCombineFunction(c[2]));   
1389            combineRGBFunctionC2 = convertInternTextureCombineFunction(c[2]);   
1390        }
1391    
1392        /**
1393         * 
1394         * Get the current Texture Combine RGB Scale Factor.
1395         * @return the current Texture Combine RGB Scale Factor.
1396         *
1397         */                
1398        public int getTextureCombineRGBScale ()
1399        {
1400            return convertExternTextureCombineScale(combineRGBScale);
1401        }
1402    
1403        /**
1404         * 
1405         * Set the Texture Combine RGB Scale Factor.
1406         * @param m the Texture Combine RGB Scale Factor to use.
1407         *
1408         */                 
1409        public void setTextureCombineRGBScale (int m)
1410        {
1411            listCombineRGBScale.setSelectedIndex(convertInternTextureCombineScale(m));      
1412            combineRGBScale = convertInternTextureCombineScale(m);   
1413        }
1414    
1415        /**
1416         * 
1417         * Get the current Texture Combine Alpha Mode.
1418         * @return the current Texture Combine Alpha Mode.
1419         *
1420         */                
1421        public int getTextureCombineAlphaMode ()
1422        {
1423            return convertExternTextureCombineMode(combineAlphaMode);
1424        }
1425    
1426        /**
1427         * 
1428         * Set the Texture Combine Alpha Mode.
1429         * @param m the Texture Combine Alpha Mode to use.
1430         *
1431         */                 
1432        public void setTextureCombineAlphaMode (int m)
1433        {
1434            listCombineAlphaMode.setSelectedIndex(convertInternTextureCombineMode(m));      
1435            combineAlphaMode = convertInternTextureCombineMode(m);   
1436        }
1437    
1438        /**
1439         * 
1440         * Get the current Texture Combine Alpha Source.
1441         * @return the current Texture Combine Alpha Source (C0,C1,C2).
1442         *
1443         */                
1444        public int[] getTextureCombineAlphaSource ()
1445        {
1446            int [] res = new int[3];
1447            res[0] = convertExternTextureCombineSource(combineAlphaSourceC0);
1448            res[1] = convertExternTextureCombineSource(combineAlphaSourceC1);
1449            res[2] = convertExternTextureCombineSource(combineAlphaSourceC2);
1450            
1451            return res;
1452        }
1453    
1454        /**
1455         * 
1456         * Set the Texture Combine Alpha Source.
1457         * @param c the Texture Combine Alpha Source Mode (C0,C1,C2) to use.
1458         *
1459         */                 
1460        public void setTextureCombineAlphaSource (int []c)
1461        {
1462            listCombineAlphaSourceC0.setSelectedIndex(convertInternTextureCombineSource(c[0]));     
1463            combineAlphaSourceC0 = convertInternTextureCombineSource(c[0]);   
1464            listCombineAlphaSourceC1.setSelectedIndex(convertInternTextureCombineSource(c[1]));     
1465            combineAlphaSourceC1 = convertInternTextureCombineSource(c[1]);   
1466            listCombineAlphaSourceC2.setSelectedIndex(convertInternTextureCombineSource(c[2]));     
1467            combineAlphaSourceC2 = convertInternTextureCombineSource(c[2]);   
1468        }
1469    
1470        /**
1471         * 
1472         * Get the current Texture Combine Alpha Function.
1473         * @return the current Texture Combine Alpha Function (C0,C1,C2).
1474         *
1475         */                
1476        public int[] getTextureCombineAlphaFunction ()
1477        {
1478            int [] res = new int[3];
1479            res[0] = convertExternTextureCombineFunction(combineAlphaFunctionC0);
1480            res[1] = convertExternTextureCombineFunction(combineAlphaFunctionC1);
1481            res[2] = convertExternTextureCombineFunction(combineAlphaFunctionC2);
1482            
1483            return res;
1484        }
1485    
1486        /**
1487         * 
1488         * Set the Texture Combine Alpha Function.
1489         * @param c the Texture Combine Alpha Function Mode (C0,C1,C2) to use.
1490         *
1491         */                 
1492        public void setTextureCombineAlphaFunction (int []c)
1493        {
1494            listCombineAlphaFunctionC0.setSelectedIndex(convertInternTextureCombineFunction(c[0])); 
1495            combineAlphaFunctionC0 = convertInternTextureCombineFunction(c[0]);   
1496            listCombineAlphaFunctionC1.setSelectedIndex(convertInternTextureCombineFunction(c[1])); 
1497            combineAlphaFunctionC1 = convertInternTextureCombineFunction(c[1]);   
1498            listCombineAlphaFunctionC2.setSelectedIndex(convertInternTextureCombineFunction(c[2])); 
1499            combineAlphaFunctionC2 = convertInternTextureCombineFunction(c[2]);   
1500        }
1501    
1502        /**
1503         * 
1504         * Get the current Texture Combine Alpha Scale Factor.
1505         * @return the current Texture Combine Alpha Scale Factor.
1506         *
1507         */                
1508        public int getTextureCombineAlphaScale ()
1509        {
1510            return convertExternTextureCombineScale(combineAlphaScale);
1511        }
1512    
1513        /**
1514         * 
1515         * Set the Texture Combine Alpha Scale Factor.
1516         * @param m the Texture Combine Alpha Scale Factor to use.
1517         *
1518         */                 
1519        public void setTextureCombineAlphaScale (int m)
1520        {
1521            listCombineAlphaScale.setSelectedIndex(convertInternTextureCombineScale(m));    
1522            combineAlphaScale = convertInternTextureCombineScale(m);   
1523        }
1524        
1525        /**
1526         * 
1527         * Update the Texture blend color. Called when a blend color parameter is modified.
1528         * @param b the (R,G,B,A) value of the new Texture blend color to use.
1529         *
1530         */                 
1531        private void updateTextureBlendColor (float []b)
1532        {
1533            float []lastBlend = blendColor;
1534            blendColor = b; 
1535            firePropertyChange(TEXTURE_BLEND,lastBlend,blendColor);
1536        }
1537    
1538        /**
1539         * 
1540         * Convert a Texture Perspective Correction Mode om TextureAttributes representation to Internal representation.
1541         * @param m a Texture Perspective Correction Mode in TextureAttributes representation.
1542         * @return a Texture Perspective Correction Mode in Internal representation.
1543         *
1544         */                 
1545        public static int convertInternPerspectiveCorrectionMode (int m)
1546        {
1547            switch (m)
1548                {
1549                case TextureAttributes.NICEST:
1550                    return PERSPECTIVE_CORRECTION_MODE_NICEST;
1551                case TextureAttributes.FASTEST:
1552                    return PERSPECTIVE_CORRECTION_MODE_FASTEST;     
1553                default :
1554                    return -1;
1555                }
1556        }
1557    
1558        /**
1559         * 
1560         * Convert a Texture Perspective Correction Mode om Internal representation to TextureAttributes representation.
1561         * @param m a Texture Perspective Correction Mode in Internal representation.
1562         * @return a Texture Perspective Correction Mode in TextureAttributes representation.
1563         *
1564         */                 
1565        public static int convertExternPerspectiveCorrectionMode (int m)
1566        {
1567            switch (m)
1568                {
1569                case PERSPECTIVE_CORRECTION_MODE_NICEST:
1570                    return TextureAttributes.NICEST;
1571                case PERSPECTIVE_CORRECTION_MODE_FASTEST:
1572                    return TextureAttributes.FASTEST;       
1573                default :
1574                    return -1;
1575                }
1576        }
1577    
1578        /**
1579         * 
1580         * Convert a Texture Mode om TextureAttributes representation to Internal representation.
1581         * @param m a Texture Mode in TextureAttributes representation.
1582         * @return a Texture Mode in Internal representation.
1583         *
1584         */                 
1585        public static int convertInternTextureMode (int m)
1586        {
1587            switch (m)
1588                {
1589                case TextureAttributes.MODULATE:
1590                    return TEXTURE_MODE_MODULATE;
1591                case TextureAttributes.DECAL:
1592                    return TEXTURE_MODE_DECAL;      
1593                case TextureAttributes.BLEND:
1594                    return TEXTURE_MODE_BLEND;      
1595                case TextureAttributes.REPLACE:
1596                    return TEXTURE_MODE_REPLACE;    
1597                case TextureAttributes.COMBINE:
1598                    return TEXTURE_MODE_COMBINE;    
1599                default :
1600                    return -1;
1601                }
1602        }
1603    
1604        /**
1605         * 
1606         * Convert a Texture Mode om Internal representation to TextureAttributes representation.
1607         * @param m a Texture Mode in Internal representation.
1608         * @return a Texture Mode in TextureAttributes representation.
1609         *
1610         */                 
1611        public static int convertExternTextureMode (int m)
1612        {
1613            switch (m)
1614                {
1615                case TEXTURE_MODE_MODULATE:
1616                    return TextureAttributes.MODULATE;
1617                case TEXTURE_MODE_DECAL:
1618                    return TextureAttributes.DECAL; 
1619                case TEXTURE_MODE_BLEND:
1620                    return TextureAttributes.BLEND; 
1621                case TEXTURE_MODE_REPLACE:
1622                    return TextureAttributes.REPLACE;       
1623                case TEXTURE_MODE_COMBINE:
1624                    return TextureAttributes.COMBINE;       
1625                default :
1626                    return -1;
1627                }
1628        }
1629    
1630        /**
1631         * 
1632         * Convert a Texture Combine RGB/Alpha Mode om TextureAttributes representation to Internal representation.
1633         * @param m a Texture Combine RGB/Alpha Mode in TextureAttributes representation.
1634         * @return a Texture Combine RGB/Alpha Mode in Internal representation.
1635         *
1636         */                 
1637        public static int convertInternTextureCombineMode (int m)
1638        {
1639            switch (m)
1640                {
1641                case TextureAttributes.COMBINE_REPLACE:
1642                    return COMBINE_MODE_REPLACE;
1643                case TextureAttributes.COMBINE_MODULATE:
1644                    return COMBINE_MODE_MODULATE;   
1645                case TextureAttributes.COMBINE_ADD:
1646                    return COMBINE_MODE_ADD;        
1647                case TextureAttributes.COMBINE_ADD_SIGNED:
1648                    return COMBINE_MODE_ADD_SIGNED; 
1649                case TextureAttributes.COMBINE_SUBTRACT:
1650                    return COMBINE_MODE_SUBTRACT;   
1651                case TextureAttributes.COMBINE_INTERPOLATE:
1652                    return COMBINE_MODE_INTERPOLATE;        
1653                case TextureAttributes.COMBINE_DOT3:
1654                    return COMBINE_MODE_DOT3;       
1655                default :
1656                    return -1;
1657                }
1658        }
1659    
1660        /**
1661         * 
1662         * Convert a Texture Combine RGB/Alpha Mode om Internal representation to TextureAttributes representation.
1663         * @param m a Texture Combine RGB/Alpha Mode in Internal representation.
1664         * @return a Texture Combine RGB/Alpha Mode in TextureAttributes representation.
1665         *
1666         */                 
1667        public static int convertExternTextureCombineMode (int m)
1668        {
1669            switch (m)
1670                {
1671                case COMBINE_MODE_REPLACE:
1672                    return TextureAttributes.COMBINE_REPLACE;
1673                case COMBINE_MODE_MODULATE:
1674                    return TextureAttributes.COMBINE_MODULATE;      
1675                case COMBINE_MODE_ADD:
1676                    return TextureAttributes.COMBINE_ADD;   
1677                case COMBINE_MODE_ADD_SIGNED:
1678                    return TextureAttributes.COMBINE_ADD_SIGNED;    
1679                case  COMBINE_MODE_SUBTRACT:
1680                    return TextureAttributes.COMBINE_SUBTRACT;      
1681                case COMBINE_MODE_INTERPOLATE:
1682                    return TextureAttributes.COMBINE_INTERPOLATE;   
1683                case COMBINE_MODE_DOT3:
1684                    return TextureAttributes.COMBINE_DOT3;  
1685                default :
1686                    return -1;
1687                }
1688        }
1689    
1690    
1691        /**
1692         * 
1693         * Convert a Texture Combine RGB/Alpha Color Source om TextureAttributes representation to Internal representation.
1694         * @param m a Texture Combine RGB/Alpha Color Source in TextureAttributes representation.
1695         * @return a Texture Combine RGB/Alpha Color Source in Internal representation.
1696         *
1697         */                 
1698        public static int convertInternTextureCombineSource (int m)
1699        {
1700            switch (m)
1701                {
1702                case TextureAttributes.COMBINE_OBJECT_COLOR:
1703                    return COMBINE_SOURCE_OBJECT_COLOR;
1704                case TextureAttributes.COMBINE_TEXTURE_COLOR:
1705                    return COMBINE_SOURCE_TEXTURE_COLOR;    
1706                case TextureAttributes.COMBINE_CONSTANT_COLOR:
1707                    return COMBINE_SOURCE_CONSTANT_COLOR;   
1708                case TextureAttributes.COMBINE_PREVIOUS_TEXTURE_UNIT_STATE:
1709                    return COMBINE_SOURCE_PREVIOUS_TEXTURE_UNIT_STATE;                  
1710                default :
1711                    return -1;
1712                }
1713        }
1714    
1715        /**
1716         * 
1717         * Convert a Texture Combine RGB/Alpha Color Source om Internal representation to TextureAttributes representation.
1718         * @param m a Texture Combine RGB/Alpha Color Source in Internal representation.
1719         * @return a Texture Combine RGB/Alpha Color Source in TextureAttributes representation.
1720         *
1721         */                 
1722        public static int convertExternTextureCombineSource (int m)
1723        {
1724            switch (m)
1725                {
1726                case COMBINE_SOURCE_OBJECT_COLOR:
1727                    return TextureAttributes.COMBINE_OBJECT_COLOR;
1728                case COMBINE_SOURCE_TEXTURE_COLOR:
1729                    return TextureAttributes.COMBINE_TEXTURE_COLOR; 
1730                case COMBINE_SOURCE_CONSTANT_COLOR:
1731                    return TextureAttributes.COMBINE_CONSTANT_COLOR;        
1732                case COMBINE_SOURCE_PREVIOUS_TEXTURE_UNIT_STATE:
1733                    return TextureAttributes.COMBINE_PREVIOUS_TEXTURE_UNIT_STATE;               
1734                default :
1735                    return -1;
1736                }
1737        }
1738    
1739        /**
1740         * 
1741         * Convert a Texture Combine RGB/Alpha Color Function om TextureAttributes representation to Internal representation.
1742         * @param m a Texture Combine RGB/Alpha Color Function in TextureAttributes representation.
1743         * @return a Texture Combine RGB/Alpha Color Function in Internal representation.
1744         *
1745         */                 
1746        public static int convertInternTextureCombineFunction (int m)
1747        {
1748            switch (m)
1749                {
1750                case TextureAttributes.COMBINE_SRC_COLOR:
1751                    return COMBINE_FUNCTION_SRC_COLOR;
1752                case TextureAttributes.COMBINE_ONE_MINUS_SRC_COLOR:
1753                    return COMBINE_FUNCTION_ONE_MINUS_SRC_COLOR;    
1754                case TextureAttributes.COMBINE_SRC_ALPHA:
1755                    return COMBINE_FUNCTION_SRC_ALPHA;      
1756                case TextureAttributes.COMBINE_ONE_MINUS_SRC_ALPHA:
1757                    return COMBINE_FUNCTION_ONE_MINUS_SRC_ALPHA;                
1758                default :
1759                    return -1;
1760                }
1761        }
1762    
1763        /**
1764         * 
1765         * Convert a Texture Combine RGB/Alpha Color Function om Internal representation to TextureAttributes representation.
1766         * @param m a Texture Combine RGB/Alpha Color Function in Internal representation.
1767         * @return a Texture Combine RGB/Alpha Color Function in TextureAttributes representation.
1768         *
1769         */                 
1770        public static int convertExternTextureCombineFunction (int m)
1771        {
1772            switch (m)
1773                {
1774                case COMBINE_FUNCTION_SRC_COLOR:
1775                    return TextureAttributes.COMBINE_SRC_COLOR;
1776                case COMBINE_FUNCTION_ONE_MINUS_SRC_COLOR:
1777                    return TextureAttributes.COMBINE_ONE_MINUS_SRC_COLOR;   
1778                case COMBINE_FUNCTION_SRC_ALPHA:
1779                    return TextureAttributes.COMBINE_SRC_ALPHA;     
1780                case COMBINE_FUNCTION_ONE_MINUS_SRC_ALPHA:
1781                    return TextureAttributes.COMBINE_ONE_MINUS_SRC_ALPHA;               
1782                default :
1783                    return -1;
1784                }
1785        }
1786    
1787        /**
1788         * 
1789         * Convert a Texture Combine Scale Factor om TextureAttributes representation to Internal representation.
1790         * @param m a Texture Combine Scale Factor in TextureAttributes representation.
1791         * @return a Texture Combine Scale Factor in Internal representation.
1792         *
1793         */                 
1794        public static int convertInternTextureCombineScale (int m)
1795        {
1796            switch (m)
1797                {
1798                case 1:
1799                    return 0;
1800                case 2:
1801                    return 1;       
1802                case 4:
1803                    return 2;       
1804                default :
1805                    return -1;
1806                }
1807        }
1808    
1809        /**
1810         * 
1811         * Convert a Texture Combine Scale Factor from Internal representation to TextureAttributes representation.
1812         * @param m a Texture Combine Scale Factor in Internal representation.
1813         * @return a Texture Combine Scale Factor in TextureAttributes representation.
1814         *
1815         */                 
1816        public static int convertExternTextureCombineScale (int m)
1817        {
1818            switch (m)
1819                {
1820                case 0:
1821                    return 1;
1822                case 1:
1823                    return 2;       
1824                case 2:
1825                    return 4;       
1826                default :
1827                    return -1;
1828                }
1829        }
1830    
1831    
1832    }