/** * Set the interpolator being configured * * @param value The value to be configured */ public void setInterpolator(LinearInterpolator value) { if (value == null) { this.value = null; this.curve = null; } else { this.value = value; curve = convertToCurvePointCurve(value.getCurve()); minSpinner.setValue(new Integer(value.getMin())); maxSpinner.setValue(new Integer(value.getMax())); worldMinY = value.getMin(); worldMaxY = value.getMax(); repaint(); } }
/** * Create an XML element based on a configured value * * @param document * The document the element will be part of * @param name * The name to give the new element * @param value * The configured value * @return A configure XML element based on the value */ private static Element createValueElement(Document document, String name, ConfigurableEmitter.Value value) { Element element = document.createElement(name); // void: now writes the value type if (value instanceof SimpleValue) { element.setAttribute("type", "simple"); element.setAttribute("value", "" + value.getValue(0)); } else if (value instanceof RandomValue) { element.setAttribute("type", "random"); element .setAttribute("value", "" + ((RandomValue) value).getValue()); } else if (value instanceof LinearInterpolator) { element.setAttribute("type", "linear"); element.setAttribute("min", "" + ((LinearInterpolator) value).getMin()); element.setAttribute("max", "" + ((LinearInterpolator) value).getMax()); element.setAttribute("active", "" + ((LinearInterpolator) value).isActive()); ArrayList curve = ((LinearInterpolator) value).getCurve(); for (int i = 0; i < curve.size(); i++) { Vector2f point = (Vector2f) curve.get(i); Element pointElement = document.createElement("point"); pointElement.setAttribute("x", "" + point.x); pointElement.setAttribute("y", "" + point.y); element.appendChild(pointElement); } } else { Log.warn("unkown value type ignored: " + value.getClass()); } return element; }
/** * Notificaiton that one of the configuration option has changed state * * @param e The event describing the change of state */ public void itemStateChangedHandler(ItemEvent e) { String valueName = (String) controlToValueName.get(e.getSource()); LinearInterpolator value = (LinearInterpolator) valueMap.get(valueName); if (e.getStateChange() == ItemEvent.SELECTED) { value.setActive(true); editor.registerValue(value, valueName); } else { value.setActive(false); editor.removeValue(valueName); } }
/** * Link this set of controls to a linear interpolater within the particle emitter * * @param name The name of the article emitter being linked * @param interpol The interpolator being configured */ private void linkToEmitter(String name, LinearInterpolator interpol) { // put to value map valueMap.put(name, interpol); // now update the checkbox to represent the state of the given // interpolator boolean checked = interpol.isActive(); JCheckBox enableControl = (JCheckBox) valueNameToControl.get(name); enableControl.setSelected(false); if (checked) enableControl.setSelected(checked); }
/** * Register a configurable value with the graph panel * * @param value The value to be registered * @param name The name to display for this value */ public void registerValue(LinearInterpolator value, String name) { // add to properties combobox properties.addItem(name); // add to value map values.put(name, value); // set as current interpolator panel.setInterpolator(value); // enable all input fields enableControls(); }
/** * Indicate that the first property should be displayed */ public void setFirstProperty() { if (properties.getItemCount() > 0) { properties.setSelectedIndex(0); LinearInterpolator currentValue = (LinearInterpolator) values .get(properties.getSelectedItem()); panel.setInterpolator(currentValue); } }
/** * Parse an XML element into a configured value * * @param element * The XML element to parse * @param value * The value to configure based on the XML */ private static void parseValueElement(Element element, ConfigurableEmitter.Value value) { if (element == null) { return; } String type = element.getAttribute("type"); String v = element.getAttribute("value"); if (type == null || type.length() == 0) { // support for old style which did not write the type if (value instanceof SimpleValue) { ((SimpleValue) value).setValue(Float.parseFloat(v)); } else if (value instanceof RandomValue) { ((RandomValue) value).setValue(Float.parseFloat(v)); } else { Log.warn("problems reading element, skipping: " + element); } } else { // type given: this is the new style if (type.equals("simple")) { ((SimpleValue) value).setValue(Float.parseFloat(v)); } else if (type.equals("random")) { ((RandomValue) value).setValue(Float.parseFloat(v)); } else if (type.equals("linear")) { String min = element.getAttribute("min"); String max = element.getAttribute("max"); String active = element.getAttribute("active"); NodeList points = element.getElementsByTagName("point"); ArrayList curve = new ArrayList(); for (int i = 0; i < points.getLength(); i++) { Element point = (Element) points.item(i); float x = Float.parseFloat(point.getAttribute("x")); float y = Float.parseFloat(point.getAttribute("y")); curve.add(new Vector2f(x, y)); } ((LinearInterpolator) value).setCurve(curve); ((LinearInterpolator) value).setMin(Integer.parseInt(min)); ((LinearInterpolator) value).setMax(Integer.parseInt(max)); ((LinearInterpolator) value).setActive("true".equals(active)); } else { Log.warn("unkown type detected: " + type); } } }