use of artisynth.core.gui.Timeline 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 artisynth.core.gui.Timeline in project artisynth_core by artisynth.
the class OutputNumericProbeEditor method actionPerformed.
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand() == "Add") {
addBlankOutputProbeVector();
increaseFrameSize();
} else if (e.getActionCommand() == "Add Property") {
addBlankOutputProperty();
increaseFrameSize();
} else // }
if (e.getActionCommand() == "PropSelected") {
// same as input?
AddPropertyPane propPane = (AddPropertyPane) e.getSource();
propPane.setPropNameEnabled(true);
int index = propList.indexOf(propPane);
System.out.println("prop selected from prop pane #: " + index);
String propPath = propPane.getPropPath();
Property prop = getProp(propPath);
if (updateProperty(index, prop)) {
increaseFrameSize();
}
updateVariable(propPane.getPropNameFieldText(), prop);
} else if (e.getActionCommand() == "blank") {
// happens when we receive a non-selection from the prop select box
// todo: decide if this method is better (leave prop in list as is)
// or the one in input editor (where we null the property).
AddPropertyPane propPane = (AddPropertyPane) e.getSource();
int index = propList.indexOf(propPane);
if (index < 0)
return;
for (NumericProbeDriver driver : myDrivers) {
if (driver.usesVariable(propPane.getPropNameFieldText())) {
int driverIndex = myDrivers.indexOf(driver);
driver.setInvalid();
AddEquationPane eqPane = eqList.get(driverIndex);
eqPane.setEqText("");
eqPane.clearDimensionLabel();
// AddVectorPane vecPane = probeChannels.get(driverIndex);
// vecPane.clearDimBox();
System.out.println("invalidated driver with expr [" + driver.getExpression() + "]");
}
}
myVariables.remove(propPane.getPropNameFieldText());
myProperties.set(index, null);
propPane.setPropNameEnabled(false);
// 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 (// delete output
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));
eqPane.clearDimensionLabel();
}
} else if (// delete output
e.getActionCommand() == "Delete Channel") {
System.out.println("Deleting channel and equation GUI...");
AddEquationPane pane = (AddEquationPane) e.getSource();
int index = eqList.indexOf(pane);
removeEquationGUI(index);
deleteOutput(index);
} else if (// delete a property
e.getActionCommand() == "Delete Property") {
AddPropertyPane pane = (AddPropertyPane) e.getSource();
int index = propList.indexOf(pane);
String propname = pane.getPropNameFieldText();
System.out.println("Deleting Property ID" + index);
removePropertyGUI(index);
deleteProperty(index);
myVariables.remove(propname);
revalidateDrivers(propname);
} else if (// rename property
e.getActionCommand() == "Property Renamed") {
AddPropertyPane propPane = (AddPropertyPane) e.getSource();
String newName = propPane.getPropNameFieldText();
String oldName = propPane.getOldPropName();
for (AddPropertyPane pane : propList) {
if (!propPane.equals(pane)) {
if (newName.compareTo(pane.getPropNameFieldText()) == 0) {
// check to make sure there are no duplicates
showErrorWindow("Name already exists!");
newName = oldName;
// 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
}
}
}
// System.out.println("trying to set name");
propPane.setPropNameField(newName);
renameProperty(oldName, newName);
} else if (e.getActionCommand() == "MouseEnteredEq") {
// int index = eqList.indexOf(e.getSource());
// AddVectorPane vec = probeChannels.get(index);
// vec.setHighlight(true);
} else if (e.getActionCommand() == "MouseExitedEq") {
// int index = eqList.indexOf(e.getSource());
// AddVectorPane vec = probeChannels.get(index);
// vec.setHighlight(false);
} else if (e.getActionCommand() == "MouseEnteredVec") {
// int index = probeChannels.indexOf(e.getSource());
// AddEquationPane eq = eqList.get(index);
// eq.setHighlight(true);
} else if (e.getActionCommand() == "MouseExitedVec") {
// int index = probeChannels.indexOf(e.getSource());
// AddEquationPane eq = eqList.get(index);
// eq.setHighlight(false);
} else if (// done. add the probe!
e.getActionCommand() == "Done") {
setOutputProbe();
// if (myParent != null) {
// myParent.actionPerformed (new ActionEvent (this, 0, "ProbeEdited"));
// }
Timeline timeline = myMain.getTimeline();
if (timeline != null) {
timeline.updateProbes(myMain.getRootModel());
}
dispose();
} else {
super.actionPerformed(e);
}
refreshAddBtn();
}
Aggregations