/* * File : Options.java * Created : 02-jul-2002 00:20 * By : fbusquets * * JClic - Authoring and playing system for educational activities * * Copyright (C) 2000 - 2005 Francesc Busquets & Departament * d'Educacio de la Generalitat de Catalunya * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details (see the LICENSE file). */ package edu.xtec.util; import java.util.HashMap; import java.util.Map; import java.awt.Component; import java.applet.Applet; import java.util.Iterator; import java.util.Properties; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.Mixer; /** * * @author Francesc Busquets (fbusquets@xtec.net) * @version 1.0 */ public class Options extends HashMap { public static Boolean CLOSE_STREAMS=null; public static String CLOSESTREAMS="closestreams"; public static final String TRUE="true", FALSE="false"; public static final Boolean BTRUE=new Boolean(true), BFALSE=new Boolean(false); public static final String MAC="Mac", WIN="Windows", JAVA131="java131", JAVA14="java14", JAVA141="java141", ARCH64BIT="arch64bit"; public static final String MAIN_PARENT_COMPONENT="mainParentComponent", APPLET="applet"; public static final String LANGUAGE_BY_PARAM="languageByParam"; protected static final String[] TRANSIENT_KEYS={MAIN_PARENT_COMPONENT, APPLET, LANGUAGE_BY_PARAM, MAC, WIN, JAVA14, JAVA131, JAVA141, ARCH64BIT, Messages.MESSAGES}; public Options(){ init(); } public Options(Map t){ super(t); init(); } public Options(Component cmp){ init(); if(cmp!=null) setMainComponent(cmp); } protected void init(){ String ver=System.getProperty("java.version"); if(ver!=null && ver.compareTo("1.3.1")>=0) put(JAVA131, new Boolean(true)); if(ver!=null && ver.compareTo("1.4.0")>=0) put(JAVA14, new Boolean(true)); if(ver!=null && ver.compareTo("1.4.1")>=0) put(JAVA141, new Boolean(true)); String s=System.getProperty("os.name").toLowerCase(); //String s=System.getProperty("java.vendor"); if(s!=null){ if(s.indexOf("mac")>=0){ put(MAC, new Boolean(true)); put(LFUtil.LOOK_AND_FEEL, LFUtil.SYSTEM); } else if(s.toLowerCase().indexOf("win")>=0) put(WIN, new Boolean(true)); } s=System.getProperty("sun.arch.data.model"); if("64".equals(s)) put(ARCH64BIT, new Boolean(true)); } public void needViaHack(){ if (CLOSE_STREAMS == null) { if (containsKey(CLOSESTREAMS)) CLOSE_STREAMS=new Boolean(getBoolean(CLOSESTREAMS)); else { put(CLOSESTREAMS, "false"); Mixer.Info[] mixers = AudioSystem.getMixerInfo(); for(int i = 0; i < mixers.length; ++i) { //System.out.println(mixers[i].getDescription()); if (mixers[i].getDescription().indexOf("8237") > 0 || mixers[i].getDescription().indexOf("8235") > 0 || mixers[i].getDescription().indexOf("VT1708") > 0 || mixers[i].getDescription().indexOf("8233") > 0) { put(CLOSESTREAMS, "true"); break; } } CLOSE_STREAMS=new Boolean(getBoolean(CLOSESTREAMS)); } } //if (CLOSE_STREAMS.booleanValue()) System.out.println("Options: CLOSESTREAMS="+ CLOSE_STREAMS); } public Properties toProperties(){ Properties prop=new Properties(); Iterator it=keySet().iterator(); while(it.hasNext()){ Object k=it.next(); if(k!=null && k instanceof String){ int i=0; for(i=0; i=0){ java.util.StringTokenizer st=new java.util.StringTokenizer(values, delim); while(st.hasMoreTokens()){ String e=st.nextToken(); int i=e.indexOf(equals); if(i>0){ String key=e.substring(0, i); String value=e.substring(i+1); if(key!=null && key.length()>0 && (nullsAllowed || values.length()>0)) map.put(key, value); } } } return map; } public static String getString(Map map, String key, String defaultValue){ String result=(String)map.get(key); return result==null ? defaultValue : result; } public static java.awt.Window getWindowForComponent(Component parentComponent){ if(parentComponent == null) return null; if(parentComponent instanceof java.awt.Window) return (java.awt.Window)parentComponent; return getWindowForComponent(parentComponent.getParent()); } }