use of maspack.widgets.WidgetDialog 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.WidgetDialog in project artisynth_core by artisynth.
the class MuscleBundleEditor method addElementsNearFibres.
private void addElementsNearFibres(MuscleBundle bundle) {
WidgetDialog dialog = WidgetDialog.createDialog(myMain.getFrame(), "Specify fibre distance", "Set");
DoubleField widget = new DoubleField("distance:", myLastElementFibreDist);
widget.setRange(0, Double.POSITIVE_INFINITY);
dialog.addWidget(widget);
GuiUtils.locateCenter(dialog, myMain.getFrame());
dialog.setVisible(true);
if (dialog.getReturnValue() == OptionPanel.OK_OPTION) {
double dist = widget.getDoubleValue();
LinkedList<MuscleElementDesc> list = bundle.getNewElementsNearFibres(dist);
AddComponentsCommand cmd = new AddComponentsCommand("Add near elements", list, bundle.getElements());
myMain.getUndoManager().saveStateAndExecute(cmd);
myLastElementFibreDist = dist;
}
}
use of maspack.widgets.WidgetDialog in project artisynth_core by artisynth.
the class MenuBarHandler method selectClass.
private Class<?> selectClass(String existingClassName) {
// ClassDialog dialog =
// ClassDialog.createDialog (
// myFrame, "Choose model class", "Load", "class", existingClassName);
WidgetDialog dialog = WidgetDialog.createDialog(myFrame, "Choose model class", "Load");
// find all instances of 'RootModel' and create an AutoComplete test field
ArrayList<String> demoClassNames = ClassFinder.findClassNames("artisynth.models", RootModel.class);
AutoCompleteStringField widget = new AutoCompleteStringField("class:", lastSelectedClassName, 30, demoClassNames);
// widget.addValueCheckListener (
// new ValueCheckListener() {
// public Object validateValue(ValueChangeEvent e, StringHolder errMsg) {
// String className = (String)e.getValue();
// if (className != null || !className.equals("")) {
// Class type = getClassFromName (className);
// if (type == null) {
// return PropertyUtils.illegalValue (
// "class not found", errMsg);
// }
// if (!RootModel.class.isAssignableFrom (type)) {
// return PropertyUtils.illegalValue (
// "class not an instance of RootModel", errMsg);
// }
// }
// return PropertyUtils.validValue (className, errMsg);
// }
// });
dialog.setValidator(new WidgetDialog.Validator() {
public String validateSettings(PropertyPanel panel) {
StringField widget = (StringField) panel.getWidgets()[0];
String className = widget.getStringValue();
if (className != null) {
Class<?> type = getClassFromName(className);
if (type == null) {
return "class not found";
}
if (!RootModel.class.isAssignableFrom(type)) {
return "class not an instance of RootModel";
}
}
return null;
}
});
dialog.addWidget(widget);
GuiUtils.locateCenter(dialog, myFrame);
dialog.setVisible(true);
if (dialog.getReturnValue() == OptionPanel.OK_OPTION) {
String className = widget.getStringValue();
if (className != null && !className.equals("")) {
lastSelectedClassName = className;
return getClassFromName(className);
}
}
return null;
}
Aggregations