use of maspack.widgets.ValueCheckListener in project artisynth_core by artisynth.
the class MenuBarHandler method createStepDisplay.
private DoubleField createStepDisplay() {
DoubleField display = new DoubleField("step:", 0, "%7.5f");
display.setToolTipText("maximum step size");
display.getTextField().setToolTipText("maximum step size");
// display.setEnabledAll (false);
display.setColumns(5);
display.addValueChangeListener(this);
display.addValueCheckListener(new ValueCheckListener() {
public Object validateValue(ValueChangeEvent e, StringHolder errMsg) {
double dval = ((Double) e.getValue()).doubleValue();
if (dval <= 0) {
return PropertyUtils.illegalValue("value must be positive", errMsg);
} else {
return PropertyUtils.validValue(e.getValue(), errMsg);
}
}
});
return display;
}
use of maspack.widgets.ValueCheckListener in project artisynth_core by artisynth.
the class ControlPanel method actionPerformed.
public void actionPerformed(ActionEvent e) {
String actionCmd = e.getActionCommand();
if (actionCmd.equals("add widget")) {
myPanel.actionPerformed(e);
} else if (actionCmd.equals("set name")) {
WidgetDialog dialog = WidgetDialog.createDialog(myFrame, "set name", "Set");
StringField widget = new StringField("name:", getName(), 20);
widget.addValueCheckListener(new ValueCheckListener() {
public Object validateValue(ValueChangeEvent e, StringHolder errMsg) {
String name = (String) e.getValue();
if (name != null && name.length() == 0) {
return null;
}
errMsg.value = ModelComponentBase.checkName(name, null);
if (errMsg.value != null) {
return Property.IllegalValue;
} else {
return name;
}
}
});
dialog.addWidget(widget);
GuiUtils.locateVertically(dialog, myFrame, GuiUtils.BELOW);
GuiUtils.locateHorizontally(dialog, myFrame, GuiUtils.CENTER);
dialog.setVisible(true);
if (dialog.getReturnValue() == OptionPanel.OK_OPTION) {
String name = (String) widget.getValue();
setName(name);
}
} else if (actionCmd.equals("save as ...")) {
Main main = Main.getMain();
RootModel root = main.getRootModel();
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(main.getModelDirectory());
int retVal = chooser.showSaveDialog(myFrame);
if (retVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
try {
ComponentUtils.saveComponent(file, this, new NumberFormat("%.6g"), root);
} catch (Exception ex) {
JOptionPane.showMessageDialog(myFrame, "Error saving file: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
main.setModelDirectory(chooser.getCurrentDirectory());
}
} else if (actionCmd.equals("merge panel")) {
Main main = Main.getMain();
main.getRootModel().mergeControlPanel(true, this);
} else if (actionCmd.equals("separate panel")) {
Main main = Main.getMain();
main.getRootModel().mergeControlPanel(false, this);
} else {
throw new InternalErrorException("Unknown action: " + actionCmd);
}
}
use of maspack.widgets.ValueCheckListener in project artisynth_core by artisynth.
the class PropertyWidgetDialog method initialize.
private void initialize() {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
Container pane = getContentPane();
pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
LabeledComponentPanel propPanel = new LabeledComponentPanel();
propPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
// myChooser = new PropertyChooser ("component/property", 30, myMain);
// myChooser.setAlignmentX (Component.CENTER_ALIGNMENT);
// myChooser.addValueChangeListener (this);
// pane.add (Box.createRigidArea (new Dimension (0, 4)));
// propPanel.addWidget (myChooser);
myPropField = new PropertyField("component/property", 30, myMain);
myPropField.setAlignmentX(Component.CENTER_ALIGNMENT);
myPropField.addValueChangeListener(this);
propPanel.addWidget(myPropField);
propPanel.addWidget(new JSeparator());
mySliderSelector = new BooleanSelector("slider");
mySliderSelector.addValueChangeListener(this);
propPanel.addWidget(mySliderSelector);
myRangeField = new DoubleIntervalField("range", new DoubleInterval(0, 1), "%.6g");
// new VectorMultiField (
// "range", new String[] { "min:", "max:" }, new Vector2d (0, 1),
// "%.6f");
// myRangeField.setAlignmentX (Component.CENTER_ALIGNMENT);
propPanel.addWidget(myRangeField);
myLabelTextField = new StringField("labelText", 20);
myLabelTextField.setEnabledAll(false);
myLabelTextField.addValueCheckListener(new ValueCheckListener() {
public Object validateValue(ValueChangeEvent e, StringHolder errMsg) {
String newName = (String) e.getValue();
String err = ModelComponentBase.checkName(newName, null);
if (err != null) {
err = "Invalid name '" + newName + "': " + err;
newName = null;
}
if (errMsg != null) {
errMsg.value = err;
}
return newName;
}
});
propPanel.addWidget(myLabelTextField);
myLabelFontColorSelector = new ColorSelector("labelFontColor");
myLabelFontColorSelector.enableNullColors();
myLabelFontColorSelector.setValue(null);
propPanel.addWidget(myLabelFontColorSelector);
myBackgroundColorSelector = new ColorSelector("backgroundColor");
myBackgroundColorSelector.enableNullColors();
myBackgroundColorSelector.setValue(null);
propPanel.addWidget(myBackgroundColorSelector);
// sliderPanel.add (myRangeField);
// pane.add (Box.createRigidArea (new Dimension (0, 4)));
// pane.add (sliderPanel);
pane.add(propPanel);
pane.add(new JSeparator());
// set slider value here because valueChanged needs some
// other widgets instantiated.
mySliderSelector.setValue(false);
mySliderSelector.setEnabledAll(false);
OptionPanel options = new OptionPanel("OK Cancel", this);
myOKButton = options.getButton("OK");
myOKButton.setEnabled(false);
options.setAlignmentX(Component.CENTER_ALIGNMENT);
pane.add(options);
pack();
}
use of maspack.widgets.ValueCheckListener in project artisynth_core by artisynth.
the class TimelineController method getWayPointFromUser.
/**
* Gets waypoint information from the user and adds the waypoint to
* the waypoint probe.
*/
public void getWayPointFromUser() {
DoubleField myTimeField = new DoubleField("Time");
myTimeField.addValueCheckListener(new ValueCheckListener() {
public Object validateValue(ValueChangeEvent e, StringHolder errMsg) {
Object val = e.getValue();
if (val instanceof Double && ((Double) val).doubleValue() <= 0) {
if (errMsg != null) {
errMsg.value = "Time value must be positive";
}
return Property.IllegalValue;
} else {
if (errMsg != null) {
errMsg.value = null;
}
return val;
}
}
});
myTimeField.setVoidValueEnabled(true);
myTimeField.setValue(Property.VoidValue);
IntegerField myRepeatField = new IntegerField("Repeat", 1);
myRepeatField.setRange(1, Integer.MAX_VALUE);
BooleanSelector myBreakpointSelector = new BooleanSelector("Breakpoint", false);
PropertyPanel addPanel = new PropertyPanel();
addPanel.addWidget(myTimeField);
addPanel.addWidget(myRepeatField);
addPanel.addWidget(myBreakpointSelector);
PropertyDialog addDialog = new PropertyDialog(this, "Add Waypoints", addPanel, "OK Cancel");
addDialog.setModal(true);
GuiUtils.locateCenter(addDialog, this);
addDialog.setVisible(true);
if (addDialog.getReturnValue() == OptionPanel.OK_OPTION && !myTimeField.valueIsVoid()) {
double t = myTimeField.getDoubleValue();
for (int i = 1; i <= myRepeatField.getIntValue(); i++) {
addWayPoint(t * i, myBreakpointSelector.getBooleanValue());
}
myToolBar.validateFastForward(myMain.getRootModel());
}
}
Aggregations