use of maspack.properties.Property in project artisynth_core by artisynth.
the class ExpandablePropertyPanel method addExtraWidgets.
public void addExtraWidgets(Iterable<?> items) {
for (Object item : items) {
// ignore inactive properties
if (item instanceof Property) {
Property prop = (Property) item;
if (isInheritableProperty(prop) && ((InheritableProperty) prop).getMode() == PropertyMode.Inactive) {
continue;
}
addExtraWidget(prop);
} else if (item instanceof Component) {
addExtraWidget((Component) item);
}
}
}
use of maspack.properties.Property in project artisynth_core by artisynth.
the class AddPropertyPane method actionPerformed.
public void actionPerformed(ActionEvent e) {
clearDimensionLabel();
// System.out.println("AddPropPane event: " + e.getActionCommand());
if (e.getActionCommand() == "Edit") {
JCheckBox chk = (JCheckBox) e.getSource();
if (chk != null) {
// TODO: delete this section
// compNameField.attachSelectionListener(chk.isSelected());
// compNameField.setEnabled(chk.isSelected());
// propSelectBox.setEnabled(chk.isSelected());
// setEditable(chk.isSelected());
}
} else if (e.getActionCommand() == "Delete Property") {
myParent.actionPerformed(new ActionEvent(this, 0, "Delete Property"));
} else if (e.getActionCommand() == "PropSelected") {
System.out.println("PropSelected event; prop path is " + propertyPath);
Property prop = getPropFromString(propertyPath);
if (prop != null) {
if (HasProperties.class.isAssignableFrom(prop.get().getClass()) == false) {
isComplete = true;
int dim = NumericProbeEditor.GetPropDim(propertyPath);
setDimensionLabel(dim);
myParent.actionPerformed(new ActionEvent(this, 0, // the parent can call
"PropSelected"));
// getPropertyPath to
// find the path
// setEditable(false);
normalColor = NumericProbeEditor.completedColor;
updateAppearance();
// System.out.println("SET TRUE");
}
} else {
// shouldn't really reach here, EVER.
normalColor = NumericProbeEditor.inactiveColor;
// generate error?
}
} else {
}
}
use of maspack.properties.Property in project artisynth_core by artisynth.
the class AddPropertyPane method RecursePropString.
private Property RecursePropString(String propPath, Object parent) {
// System.out.println("recurse path: " + propPath);
if (// if there is a . in the path, then we
propPath.indexOf(".") > 0) // need to go down further
{
String propName = propPath.substring(0, propPath.indexOf("."));
String rest = propPath.substring(propPath.indexOf(".") + 1, propPath.length());
Property prop = ((HasProperties) parent).getProperty(propName);
if (prop != null) {
Object obj = prop.get();
return RecursePropString(rest, obj);
} else {
return (Property) parent;
}
} else {
// if there are no more "."s in the name, then just
// simply get all the properties contained within this property
System.out.println("no more .'s... just list the properties at this level");
Property prop = ((HasProperties) parent).getProperty(propPath);
if (prop != null) {
// System.out.println("bottom prop found");
return prop;
} else {
// System.out.println("bottom prop NOT found");
return null;
}
}
}
use of maspack.properties.Property in project artisynth_core by artisynth.
the class InputNumericProbeEditor method actionPerformed.
/**
* Event handler. Goes through the input probe specific commands first, and
* if its not specifically for an input probe, send it up to the parent class
*/
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand() == "Add") {
String name = getUniqueVariableName(INPUT_PREFIX);
AddVectorPane newVec = new AddVectorPane(this, name);
addVectorGUI(newVec);
addInputVariable(name, 1);
increaseFrameSize();
} else if (e.getActionCommand() == "Delete Channel") {
AddVectorPane vecPane = (AddVectorPane) e.getSource();
System.out.println("Deleting Channel GUI ID" + e.getID());
String name = vecPane.getChannelName();
revalidateDrivers(name);
deleteInputVariable(name);
removeChannelGUI(vecPane);
} else if (e.getActionCommand() == "Add Property") {
addBlankInputProbeProperty();
increaseFrameSize();
} else if (e.getActionCommand() == "Delete Property") {
AddPropertyPane pane = (AddPropertyPane) e.getSource();
int index = propList.indexOf(pane);
System.out.println("Deleting Property ID" + index);
removePropertyGUI(index);
removeEquationGUI(index);
deleteProperty(index);
} else if (e.getActionCommand() == "PropSelected") {
AddPropertyPane propPane = (AddPropertyPane) e.getSource();
int index = propList.indexOf(propPane);
System.out.println("prop selected from prop pane #: " + index);
String propPath = propPane.getPropPath();
Property prop = getProp(propPath);
updateProperty(index, prop);
increaseFrameSize();
} else if (e.getActionCommand() == "blank") {
// happens when we make a non-selection
AddPropertyPane propPane = (AddPropertyPane) e.getSource();
int index = propList.indexOf(propPane);
if (index < 0)
return;
System.out.println("trying to get eq at index " + index);
AddEquationPane eqPane = getEqPane(index);
if (eqPane != null) {
try {
// myProperties.set(index, null);
myDrivers.get(index).setInvalid();
} catch (Exception exp) {
System.out.println(exp.getMessage());
}
eqPane.setEnabled(false);
eqPane.setEqText("");
}
} else if (e.getActionCommand() == "Resized") {
AddVectorPane vecPane = (AddVectorPane) e.getSource();
NumericProbeVariable var = myVariables.get(vecPane.getChannelName());
if (var != null) {
changeVariableDimension(vecPane.getChannelName(), vecPane.getDim());
// myVariables.get(vecPane.getChannelName()).getDimension());
System.out.println("new dim: " + vecPane.getDim());
}
} else if (e.getActionCommand() == "Renamed") {
AddVectorPane vecPane = (AddVectorPane) e.getSource();
String newName = vecPane.getChannelName();
String oldName = vecPane.getOldName();
for (AddVectorPane pane : probeChannels) {
if (!pane.equals(vecPane)) {
if (newName.compareTo(pane.getChannelName()) == 0) {
// check to make sure there are no duplicates
JOptionPane.showMessageDialog(this, "Name already exists!", "Error!", JOptionPane.ERROR_MESSAGE);
newName = vecPane.getOldName();
// so in this case, the 'new' name is the same as old, so
// effectively we don't make any changes
// and when calling setChannelName a few lines later we
// restore the old name into the GUI
}
}
}
vecPane.setOldName(newName);
vecPane.setChannelName(newName);
renameInputVariable(oldName, newName);
System.out.println(oldName + " changed to " + newName);
// if (newName.compareTo(oldName) != 0 )
// {
// revalidateDrivers(oldName); //any driver that uses this name should
// be invalidated
// }
} else if (e.getActionCommand() == "Expression Changed") {
AddEquationPane eqPane = (AddEquationPane) e.getSource();
System.out.println("new expression entered :" + eqPane.getEqText());
String newExpr = eqPane.getEqText();
if (// otherwise, do nothing and driver will
!newExpr.equals("")) // remain invalid
{
changeExpression(eqList.indexOf(eqPane), newExpr);
} else {
invalidateDriverAndGUI(eqList.indexOf(eqPane));
}
// check consistency of size:
} else // }
if (e.getActionCommand() == "MouseEnteredProp") {
int index = propList.indexOf(e.getSource());
AddEquationPane eqPane = eqList.get(index);
if (eqPane != null) {
eqPane.setHighlight(true);
}
} else if (e.getActionCommand() == "MouseExitedProp") {
int index = propList.indexOf(e.getSource());
AddEquationPane eqPane = eqList.get(index);
if (eqPane != null) {
eqPane.setHighlight(false);
}
} else if (e.getActionCommand() == "MouseEnteredEq") {
int index = eqList.indexOf(e.getSource());
AddPropertyPane propPane = propList.get(index);
if (propPane != null) {
propPane.setHighlight(true);
}
} else if (e.getActionCommand() == "MouseExitedEq") {
int index = eqList.indexOf(e.getSource());
AddPropertyPane propPane = propList.get(index);
if (propPane != null) {
propPane.setHighlight(false);
}
} else if (e.getActionCommand() == "Done") {
setInputProbe();
// if (myParent != null) {
// myParent.actionPerformed (new ActionEvent (this, 0, "ProbeEdited"));
// }
Timeline timeline = myMain.getTimeline();
if (timeline != null) {
timeline.updateProbes(myMain.getRootModel());
}
dispose();
} else {
// send it to the superclass
super.actionPerformed(e);
}
refreshAddBtn();
}
use of maspack.properties.Property in project artisynth_core by artisynth.
the class InputNumericProbeEditor method setInputProbe.
// //
// // Called when a user adds an input property
// //
// public void addInputProbeProperty (int index, Property prop)
// {
// myProperties.set (index, prop);
//
// NumericConverter conv = new NumericConverter(prop.get());
// String varname = getUniqueVariableName(INPUT_PREFIX);
// NumericProbeVariable var = new NumericProbeVariable(conv.getDimension());
// myVariables.put (varname, var);
// NumericProbeDriver driver = new NumericProbeDriver();
// driver.setExpression (varname, myVariables);
// myDrivers.set (index, driver);
//
// AddVectorPane newVec = new AddVectorPane(this, varname);
// newVec.setDim(var.getDimension());
// addVectorGUI(newVec);
// super.updateGUI();
// }
private void setInputProbe() {
ArrayList<String> variableNames = new ArrayList<String>();
ArrayList<Integer> variableDims = new ArrayList<Integer>();
for (Map.Entry<String, NumericProbeVariable> entry : myVariables.entrySet()) {
variableNames.add(entry.getKey());
variableDims.add(entry.getValue().getDimension());
System.out.println(entry.getKey() + " -- " + entry.getValue());
}
int[] varDimsInt = new int[variableDims.size()];
for (int i = 0; i < variableDims.size(); i++) {
varDimsInt[i] = variableDims.get(i);
// System.out.println("size of V="+variableDims.get(i));
}
NumericInputProbe probeToSet;
if (oldProbe == null) {
ModelComponent refComp = ComponentUtils.getPropertyComponent(myProperties.get(0));
probeToSet = new NumericInputProbe(refComp);
} else {
probeToSet = oldProbe;
}
probeToSet.set(myProperties.toArray(new Property[0]), getDriverExpressions(), variableNames.toArray(new String[0]), varDimsInt);
probeToSet.setStartTime(startTimeField.getDoubleValue());
probeToSet.setStopTime(endTimeField.getDoubleValue());
probeToSet.setScale(scaleField.getDoubleValue());
probeToSet.setName(probeNameField.getStringValue());
String attachedFilePath = attachedFileField.getStringValue();
if (attachedFilePath != null) {
if (attachedFilePath.equals("") || !attachedInputFileValid(attachedFilePath, null)) {
attachedFilePath = null;
}
}
if (attachedFilePath != null) {
probeToSet.setAttachedFileName(attachedFilePath);
try {
probeToSet.load();
((Displayable) probeToSet).updateDisplays();
} catch (IOException e) {
System.err.println("Couldn't load probe ");
e.printStackTrace();
probeToSet.setAttachedFileName(null);
}
} else {
probeToSet.setAttachedFileName(null);
if (probeToSet.getNumericList().isEmpty()) {
// add knots at beginning and end
if (probeToSet.isSettable()) {
probeToSet.setData(probeToSet.getStartTime());
probeToSet.setData(probeToSet.getStopTime());
} else {
probeToSet.loadEmpty();
}
}
}
if (oldProbe == null) {
AddComponentsCommand cmd = new AddComponentsCommand("add input probe", probeToSet, myMain.getRootModel().getInputProbes());
myMain.getUndoManager().saveStateAndExecute(cmd);
}
}
Aggregations