001 /** 002 ############################################################################## 003 ## ## 004 ## Appearance3DChooser ## 005 ## ## 006 ## Copyright (C) 2009 Frederic Roudaut <frederic.roudaut@free.fr> ## 007 ## ## 008 ## ## 009 ## This program is free software: you can redistribute it and/or modify ## 010 ## it under the terms of the GNU General Public License as published by ## 011 ## the Free 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.io.*; 032 import javax.swing.JApplet; 033 034 035 /** 036 * Applet Exemple for Appearence3DChooserPanel. 037 * 038 */ 039 public class Appearance3DChooserPanelApplet extends JApplet 040 { 041 private static final long serialVersionUID = 1L; 042 043 /* 044 public static void main(final String[] args) 045 { 046 final Appearance3DChooserApplet demo = new Appearance3DChooserApplet(); 047 demo.setVisible(true); 048 } 049 */ 050 051 052 /** 053 * Called when the applet is first loaded. 054 * 055 */ 056 057 public void init () 058 { 059 060 // if loadDLL is set to true, then it means that the dynamic library has to be loaded 061 // into the client JRE Path. In this case the associated jar has to be signed first. 062 // Use to Automaticaly copy the DLL in the java path . Nevertheless they have to be in a root 063 // dll directory 064 if (getParameter("loadDLL") != null && getParameter("loadDLL").compareTo("true") == 0) 065 { 066 // load Windows DLL for Java3D 067 if(System.getProperty("os.name").indexOf("Win") != -1) 068 { 069 copyResourceFromJarToBinDir("j3dcore-d3d.dll"); 070 copyResourceFromJarToBinDir("j3dcore-ogl.dll"); 071 copyResourceFromJarToBinDir("j3dcore-ogl-cg.dll"); 072 copyResourceFromJarToBinDir("j3dcore-ogl-chk.dll"); 073 } 074 else // Consider it is Linux 075 { 076 copyResourceFromJarToBinDir("libj3dcore-ogl.so"); 077 copyResourceFromJarToBinDir("libj3dcore-ogl-cg.so"); 078 } 079 } 080 081 082 final Appearance3DChooserPanel m = new Appearance3DChooserPanel(true, true, true, true); 083 setContentPane(m); 084 m.addPropertyChangeListener(new PropertyChangeListener() { 085 public void propertyChange(PropertyChangeEvent evt) 086 { 087 if (evt.getPropertyName().compareTo(Appearance3DChooser.SPECULAR) == 0) 088 { 089 System.out.println("SPECULAR : (" + m.getSpecularColor()[0]+ "," 090 + m.getSpecularColor()[1]+ "," 091 + m.getSpecularColor()[2]+")"); 092 } 093 else if (evt.getPropertyName().compareTo(Appearance3DChooser.AMBIENT) == 0) 094 { 095 System.out.println("AMBIENT : (" + m.getAmbientColor()[0]+ "," 096 + m.getAmbientColor()[1] + "," 097 + m.getAmbientColor()[2]+")"); 098 } 099 else if (evt.getPropertyName().compareTo(Appearance3DChooser.EMISSIVE) == 0) 100 { 101 System.out.println("EMISSIVE : (" + m.getEmissiveColor()[0]+ "," 102 + m.getEmissiveColor()[1] + "," 103 + m.getEmissiveColor()[2]+")"); 104 } 105 else if (evt.getPropertyName().compareTo(Appearance3DChooser.DIFFUSE) == 0) 106 { 107 System.out.println("DIFFUSE : (" + m.getDiffuseColor()[0] + "," 108 + m.getDiffuseColor()[1] + "," 109 + m.getDiffuseColor()[2]+")"); 110 } 111 else if (evt.getPropertyName().compareTo(Appearance3DChooser.COLORTARGET) == 0) 112 { 113 System.out.println("COLORTARGET : (" + m.getColorTarget() +")"); 114 } 115 else if (evt.getPropertyName().compareTo(Appearance3DChooser.SHININESS) == 0) 116 { 117 System.out.println("SHININESS : (" + m.getShininess() + ")"); 118 } 119 else if (evt.getPropertyName().compareTo(Appearance3DChooser.LIGHTING) == 0) 120 { 121 System.out.println("LIGHTING : (" + m.getLighting() +")"); 122 } 123 else if (evt.getPropertyName().compareTo(Appearance3DChooser.TRANSPARENCY) == 0) 124 { 125 System.out.println("TRANSPARENCY : (" + m.getTransparency() +")"); 126 } 127 else if (evt.getPropertyName().compareTo(Appearance3DChooser.TRANSPARENCY_MODE) == 0) 128 { 129 System.out.println("TRANSPARENCY_MODE : (" + m.getTransparencyMode() +")"); 130 } 131 else if (evt.getPropertyName().compareTo(Appearance3DChooser.TRANSPARENCY_SRC_BLEND_FUNCTION) == 0) 132 { 133 System.out.println("TRANSPARENCY_SRC_BLEND_FUNCTION : (" + m.getTransparencySrcBlendFunction() +")"); 134 } 135 else if (evt.getPropertyName().compareTo(Appearance3DChooser.TRANSPARENCY_DST_BLEND_FUNCTION) == 0) 136 { 137 System.out.println("TRANSPARENCY_DST_BLEND_FUNCTION : (" + m.getTransparencyDstBlendFunction() +")"); 138 } 139 else if (evt.getPropertyName().compareTo(Appearance3DChooserPanel.TEXTURE_USE) == 0) 140 { 141 System.out.println("TEXTURE_USE : (" + m.isTextureSet() +")"); 142 } 143 else if (evt.getPropertyName().compareTo(Appearance3DChooser.TEXTURE_FILE) == 0) 144 { 145 System.out.println("TEXTURE_FILE : (" + m.getTextureFile() +")"); 146 } 147 else if (evt.getPropertyName().compareTo(Appearance3DChooser.TEXTURE_TRANSFORM) == 0) 148 { 149 System.out.println("TEXTURE_TRANSFORM : \n" + m.getTextureTransform() ); 150 System.out.println("Scale : x=" + m.getTextureTransformScaleX() + ", y=" +m.getTextureTransformScaleY()); 151 System.out.println("Translation : x=" + m.getTextureTransformTranslatX() + ", y=" +m.getTextureTransformTranslatY()); 152 System.out.println("Rotation : z=" + m.getTextureTransformRotZ()); 153 } 154 else if (evt.getPropertyName().compareTo(Appearance3DChooser.TEXTURE_PERSPECTIVE_CORRECTION_MODE) == 0) 155 { 156 System.out.println("TEXTURE_PERSPECTIVE_CORRECTION_MODE : (" + m.getTexturePerspectiveCorrectionMode() +")"); 157 } 158 else if (evt.getPropertyName().compareTo(Appearance3DChooser.TEXTURE_MODE) == 0) 159 { 160 System.out.println("TEXTURE_MODE : (" + m.getTextureMode() +")"); 161 } 162 else if (evt.getPropertyName().compareTo(Appearance3DChooser.TEXTURE_BLEND) == 0) 163 { 164 System.out.println("TEXTURE_BLEND : (" + 165 m.getTextureBlendColor()[0] + "," + 166 m.getTextureBlendColor()[1] + "," + 167 m.getTextureBlendColor()[2] + "," + 168 m.getTextureBlendColor()[3] 169 + ")"); 170 } 171 else if (evt.getPropertyName().compareTo(Appearance3DChooserPanel.TEXTURE_COMBINE_RGB_MODE) == 0) 172 { 173 System.out.println("TEXTURE_COMBINE_RGB_MODE : (" + m.getTextureCombineRGBMode() +")"); 174 } 175 else if (evt.getPropertyName().compareTo(Appearance3DChooserPanel.TEXTURE_COMBINE_RGB_SOURCE) == 0) 176 { 177 System.out.println("TEXTURE_COMBINE_RGB_SOURCE : (" + 178 m.getTextureCombineRGBSource()[0] + "," + 179 m.getTextureCombineRGBSource()[1] + "," + 180 m.getTextureCombineRGBSource()[2] 181 + ")"); 182 } 183 else if (evt.getPropertyName().compareTo(Appearance3DChooserPanel.TEXTURE_COMBINE_RGB_FUNCTION) == 0) 184 { 185 System.out.println("TEXTURE_COMBINE_RGB_FUNCTION : (" + 186 m.getTextureCombineRGBFunction()[0] + "," + 187 m.getTextureCombineRGBFunction()[1] + "," + 188 m.getTextureCombineRGBFunction()[2] 189 + ")"); 190 } 191 else if (evt.getPropertyName().compareTo(Appearance3DChooserPanel.TEXTURE_COMBINE_RGB_SCALE) == 0) 192 { 193 System.out.println("TEXTURE_COMBINE_RGB_SCALE : (" + m.getTextureCombineRGBScale() +")"); 194 } 195 else if (evt.getPropertyName().compareTo(Appearance3DChooserPanel.TEXTURE_COMBINE_ALPHA_MODE) == 0) 196 { 197 System.out.println("TEXTURE_COMBINE_ALPHA_MODE : (" + m.getTextureCombineAlphaMode() +")"); 198 } 199 else if (evt.getPropertyName().compareTo(Appearance3DChooserPanel.TEXTURE_COMBINE_ALPHA_SOURCE) == 0) 200 { 201 System.out.println("TEXTURE_COMBINE_ALPHA_SOURCE : (" + 202 m.getTextureCombineAlphaSource()[0] + "," + 203 m.getTextureCombineAlphaSource()[1] + "," + 204 m.getTextureCombineAlphaSource()[2] 205 + ")"); 206 } 207 else if (evt.getPropertyName().compareTo(Appearance3DChooserPanel.TEXTURE_COMBINE_ALPHA_FUNCTION) == 0) 208 { 209 System.out.println("TEXTURE_COMBINE_ALPHA_FUNCTION : (" + 210 m.getTextureCombineAlphaFunction()[0] + "," + 211 m.getTextureCombineAlphaFunction()[1] + "," + 212 m.getTextureCombineAlphaFunction()[2] 213 + ")"); 214 } 215 else if (evt.getPropertyName().compareTo(Appearance3DChooserPanel.TEXTURE_COMBINE_ALPHA_SCALE) == 0) 216 { 217 System.out.println("TEXTURE_COMBINE_ALPHA_SCALE : (" + m.getTextureCombineAlphaScale() +")"); 218 } 219 220 }}); 221 222 } 223 224 225 /** 226 * Used to automaticaly download a DLL on the client Host. 227 * @param tDll the DLL to download. It Must be in a Root dll directory. 228 * 229 */ 230 protected void copyResourceFromJarToBinDir(String tDll) // Name of the DLL 231 { 232 try 233 { 234 //InputStream dllInputStream = getClass().getResourceAsStream("/dll/"+tDll); 235 InputStream dllInputStream = new FileInputStream("dll\\"+tDll); 236 237 String javaHome = System.getProperty("java.home"); 238 String fileSeparator = "" + System.getProperty("file.separator").charAt(0); 239 File outFile = null; 240 241 BufferedInputStream binStream = new BufferedInputStream(dllInputStream); 242 outFile = new File(javaHome+fileSeparator+"bin"+fileSeparator+tDll); 243 244 BufferedOutputStream boutStream = new BufferedOutputStream(new FileOutputStream(outFile)); 245 int b = -1; 246 while((b = binStream.read()) != -1) 247 { 248 boutStream.write(b); 249 } 250 binStream.close(); 251 binStream.close(); 252 boutStream.flush(); 253 boutStream.close(); 254 255 System.out.println("Copy " + tDll + " into " + outFile.getPath()); 256 } 257 258 catch(Exception e) 259 { 260 System.err.println("Error : cannot download " + tDll); 261 e.printStackTrace(); 262 } 263 } 264 265 }