/** * A color is a set of 3 values separated by spaces * * @param property the property key associated to the color * @param defaultValue the color to return if the property key is not associated to a color * @return the color associated to the property key, or <code>defaultValue</code> if there is no * color associated to the property */ public Color getColor(String property, Color defaultValue) { // TODO enhance error handling Color color = defaultValue; String colorValue = getProperty(property); if (colorValue == null) { displayError("Property " + property + " not found"); // $NON-NLS-1$ //$NON-NLS-2$ } else { color = null; try { color = TColor.translateColor(colorValue, null); } catch (Exception e) { } if (color == null) { try { StringTokenizer tokenizer = new StringTokenizer(colorValue); int red = Integer.parseInt(tokenizer.nextToken()); int green = Integer.parseInt(tokenizer.nextToken()); int blue = Integer.parseInt(tokenizer.nextToken()); color = new Color(red, green, blue); } catch (Exception ex) { displayError("Failed loading color " + property); // $NON-NLS-1$ } } } return color; }
/** * Gets the urlClassLoader that enables to access to the objects jar files. * * @return an URLClassLoader */ public URLClassLoader getObjectsClassLoader() { if (objectsClassLoader == null) { try { if (isExecutionMode()) { URL[] listUrl = new URL[1]; listUrl[0] = instance.getTangaraPath().toURI().toURL(); objectsClassLoader = new URLClassLoader(listUrl); } else { File f = new File(instance.getTangaraPath().getParentFile(), "objects"); File[] list = f.listFiles(); Vector<URL> vector = new Vector<URL>(); for (int i = 0; i < list.length; i++) { if (list[i].getName().endsWith(".jar")) vector.add(list[i].toURI().toURL()); } File flib = new File( instance.getTangaraPath().getParentFile().getAbsolutePath().replace("\\", "/") + "/objects/lib"); File[] listflib = flib.listFiles(); for (int j = 0; j < listflib.length; j++) { if (listflib[j].getName().endsWith(".jar")) vector.add(listflib[j].toURI().toURL()); } URL[] listUrl = new URL[vector.size()]; for (int j = 0; j < vector.size(); j++) listUrl[j] = vector.get(j); objectsClassLoader = new URLClassLoader(listUrl); } } catch (Exception e1) { displayError("URL MAL FORMED " + e1); return null; } } return objectsClassLoader; }
/** * Gets the value of a property in a double format * * @param property name of the property * @param defaultValue the value to return if the property cannot be found * @return the value of the property, or <code>defaultValue</code> if the property is not found. */ public double getDouble(String property, double defaultValue) { double doubleValue = defaultValue; try { String value = getProperty(property); return Double.parseDouble(value); } catch (Exception ex) { displayError("Failed to load double property " + property); } return doubleValue; }
/** * Gets the value of a property in a float format * * @param property name of the property * @param defaultValue the value to return if the property cannot be found * @return the value of the property, or <code>defaultValue</code> if the property is not found. */ public float getFloat(String property, float defaultValue) { float floatValue = defaultValue; try { String strValue = getProperty(property); floatValue = Float.parseFloat(strValue); } catch (Exception ex) { displayError("Failed to load float property " + property); } return floatValue; }
/** * Gets the value of a property in a long format * * @param defaultValue the value to return if the property cannot be found * @return the value of the property, or <code>defaultValue</code> if the property is not found. */ public long getLong(String property, long defaultValue) { long longValue = defaultValue; try { String strValue = getProperty(property); longValue = Long.parseLong(strValue); } catch (Exception ex) { displayError("Failed to load long property " + property); } return longValue; }
/** * Gets the value of a property in an integer format * * @param defaultValue the value to return if the property cannot be found * @return the value of the property, or <code>defaultValue</code> if the property is not found. */ public int getInteger(String property, int defaultValue) { int intValue = defaultValue; try { String strValue = getProperty(property); intValue = Integer.parseInt(strValue); } catch (Exception ex) { displayError("Failed to load integer property " + property); } return intValue; }
/** * Gets the value of a property * * @param name name of the property * @return the property value or <code>null</code> if the property does not exist */ public String getProperty(String name) { if (properties.containsKey(name)) return properties.getProperty(name); else if (fixedProperties.containsKey(name)) return fixedProperties.getProperty(name); displayError("Could not find property " + name); return null; }