001/** 002 * Test4Java3D -- A class used to test for the existence of Java3D. 003 * 004 * Copyright (C) 2009-2025, by Joseph A. Huwaldt 005 * All rights reserved. 006 * 007 * This library is free software; you can redistribute it and/or modify it under the terms 008 * of the GNU Lesser General Public License as published by the Free Software Foundation; 009 * either version 2.1 of the License, or (at your option) any later version. 010 * 011 * This library is distributed in the hope that it will be useful, but WITHOUT ANY 012 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 013 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public License along with 016 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - 017 * Suite 330, Boston, MA 02111-1307, USA. Or visit: http://www.gnu.org/licenses/lgpl.html 018 */ 019package geomss.app; 020 021import java.util.Map; 022import org.jogamp.java3d.VirtualUniverse; 023 024/** 025 * A class used to test for the existence of Java3D. If this class fails to load or throws 026 * an Exception of any kind, then the correct version of Java3D was not found. 027 * 028 * <p> Modified by: Joseph A. Huwaldt</p> 029 * 030 * @author Joseph A. Huwaldt, Date: June 19, 2010 031 * @version February 17, 2025 032 */ 033public class Test4Java3D { 034 035 /** 036 * Call this method to test for Java3D. If it throws an exception, then the correct 037 * version of Java3D was not found (and the Exception will have the Java3D version 038 * number as it's message or <code>null</code> if Java3D could not be found at all. If 039 * it returns normally, then it this method will return the version of Java3D found. 040 * 041 * @param primary The primary version number to look for (1 if the desired version 042 * is > 1). 043 * @param secondary The secondary version number to look for (5 if the desired version 044 * is > 5). 045 * @return The version of Java3D found. 046 * @throws java.lang.Exception if the correct version of Java 3D could not be found. 047 */ 048 public static String test(int primary, int secondary) throws Exception { 049 String j3dVersion = null; 050 051 try { 052 VirtualUniverse vu = new VirtualUniverse(); 053 Map vuMap = VirtualUniverse.getProperties(); 054 //System.out.println(" Java3D version : " + vuMap.get("j3d.version")); 055 //System.out.println(" Java3D vendor : " + vuMap.get("j3d.vendor")); 056 //System.out.println(" Java3D renderer: " + vuMap.get("j3d.renderer")); 057 058 j3dVersion = (String)vuMap.get("j3d.version"); 059 int idx = j3dVersion.indexOf('.'); 060 String sub = j3dVersion.substring(0, idx); 061 int v = Integer.parseInt(sub); 062 if (v < primary) 063 throw new Exception(); 064 065 sub = j3dVersion.substring(idx + 1, j3dVersion.indexOf('.', idx + 1)); 066 v = Integer.parseInt(sub); 067 if (v < secondary) 068 throw new Exception(); 069 070 } catch (Throwable e) { 071 e.printStackTrace(); 072 073 // Throw an exception with the Java3D version number in it. 074 throw new Exception(j3dVersion); 075 } 076 077 return j3dVersion; 078 } 079 080}