use of maspack.widgets.StringField 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;
}
use of maspack.widgets.StringField in project artisynth_core by artisynth.
the class EditorUtils method saveMeshAsAnsysFile.
public static void saveMeshAsAnsysFile(final FemModel3d model) {
final Main main = Main.getMain();
JFrame frame = main.getMainFrame();
final JDialog saveOptions = new JDialog(frame, "Save As Ansys File");
LabeledComponentPanel savePanel = new LabeledComponentPanel();
savePanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 8));
final StringField dirField = new StringField("Output folder", main.getModelDirectory().getAbsolutePath(), 20);
dirField.setStretchable(true);
dirField.getTextField().setEditable(false);
final JButton browseButton = new JButton("Change");
browseButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent a_evt) {
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(main.getModelDirectory());
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if (chooser.showSaveDialog(browseButton) == JFileChooser.APPROVE_OPTION) {
dirField.setValue(chooser.getSelectedFile().getAbsolutePath());
}
}
});
browseButton.setMargin(new Insets(3, 3, 3, 3));
GuiUtils.setFixedSize(browseButton, new Dimension(80, 25));
dirField.add(browseButton);
savePanel.addWidget(dirField);
final StringField nodeField = new StringField("Node file name", "mesh.node", 10);
nodeField.setStretchable(true);
savePanel.addWidget(nodeField);
final StringField elemField = new StringField("Element file name", "mesh.elem", 10);
elemField.setStretchable(true);
savePanel.addWidget(elemField);
final JCheckBox elemType = new JCheckBox("Use custom type values for different elements");
savePanel.addWidget(elemType);
LabeledComponentPanel elemTypePanel = new LabeledComponentPanel();
elemTypePanel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0));
final IntegerField tetField = new IntegerField("Tets (4 node)", 1);
tetField.getTextField().setEditable(false);
elemTypePanel.addWidget(tetField);
final IntegerField quadtetField = new IntegerField("Quadtets (10 node)", 1);
quadtetField.getTextField().setEditable(false);
elemTypePanel.addWidget(quadtetField);
final IntegerField wedgeField = new IntegerField("Wedges", 1);
wedgeField.getTextField().setEditable(false);
elemTypePanel.addWidget(wedgeField);
final IntegerField hexField = new IntegerField("Hexs (8 node)", 1);
hexField.getTextField().setEditable(false);
elemTypePanel.addWidget(hexField);
final IntegerField quadhexField = new IntegerField("Quadhexs (20 node)", 1);
quadhexField.getTextField().setEditable(false);
elemTypePanel.addWidget(quadhexField);
savePanel.addWidget(elemTypePanel);
elemType.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent a_evt) {
if (elemType.isSelected()) {
tetField.getTextField().setEditable(true);
quadtetField.getTextField().setEditable(true);
wedgeField.getTextField().setEditable(true);
hexField.getTextField().setEditable(true);
quadhexField.getTextField().setEditable(true);
} else {
tetField.getTextField().setEditable(false);
quadtetField.getTextField().setEditable(false);
wedgeField.getTextField().setEditable(false);
hexField.getTextField().setEditable(false);
quadhexField.getTextField().setEditable(false);
}
}
});
OptionPanel dialogOptions = new OptionPanel("Save Cancel", new ActionListener() {
public void actionPerformed(ActionEvent a_evt) {
if (a_evt.getActionCommand().equals("Save")) {
File directory = new File(dirField.getStringValue());
File nodeFile = new File(directory, nodeField.getStringValue());
File elemFile = new File(directory, elemField.getStringValue());
AnsysWriter.writeNodeFile(model, nodeFile.getAbsolutePath());
AnsysWriter.writeElemFile(model, elemFile.getAbsolutePath());
}
saveOptions.dispose();
}
});
GuiUtils.setFixedSize(dialogOptions.getButton("Save"), new Dimension(80, 25));
GuiUtils.setFixedSize(dialogOptions.getButton("Cancel"), new Dimension(80, 25));
dialogOptions.setBorder(BorderFactory.createEmptyBorder(0, 0, 8, 0));
savePanel.addWidget(dialogOptions);
saveOptions.getContentPane().add(savePanel);
saveOptions.pack();
saveOptions.setMinimumSize(saveOptions.getPreferredSize());
saveOptions.setVisible(true);
}
Aggregations