Search in sources :

Example 6 with StringField

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;
}
Also used : WidgetDialog(maspack.widgets.WidgetDialog) AutoCompleteStringField(maspack.widgets.AutoCompleteStringField) AutoCompleteStringField(maspack.widgets.AutoCompleteStringField) StringField(maspack.widgets.StringField) PropertyPanel(maspack.widgets.PropertyPanel)

Example 7 with StringField

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);
}
Also used : Insets(java.awt.Insets) ActionEvent(java.awt.event.ActionEvent) IntegerField(maspack.widgets.IntegerField) Dimension(java.awt.Dimension) ActionListener(java.awt.event.ActionListener) StringField(maspack.widgets.StringField) LabeledComponentPanel(maspack.widgets.LabeledComponentPanel) Main(artisynth.core.driver.Main) OptionPanel(maspack.widgets.OptionPanel)

Aggregations

StringField (maspack.widgets.StringField)7 Main (artisynth.core.driver.Main)2 Dimension (java.awt.Dimension)2 BoxLayout (javax.swing.BoxLayout)2 JButton (javax.swing.JButton)2 JPanel (javax.swing.JPanel)2 BooleanSelector (maspack.widgets.BooleanSelector)2 DoubleIntervalField (maspack.widgets.DoubleIntervalField)2 LabeledComponentPanel (maspack.widgets.LabeledComponentPanel)2 OptionPanel (maspack.widgets.OptionPanel)2 ValueChangeEvent (maspack.widgets.ValueChangeEvent)2 ValueCheckListener (maspack.widgets.ValueCheckListener)2 WidgetDialog (maspack.widgets.WidgetDialog)2 ControlPanel (artisynth.core.gui.ControlPanel)1 PropertyField (artisynth.core.gui.widgets.PropertyField)1 RootModel (artisynth.core.workspace.RootModel)1 Container (java.awt.Container)1 GridLayout (java.awt.GridLayout)1 Insets (java.awt.Insets)1 Point (java.awt.Point)1