Search in sources :

Example 1 with OptionPanel

use of maspack.widgets.OptionPanel in project artisynth_core by artisynth.

the class ControlPanel method scanItem.

public boolean scanItem(ReaderTokenizer rtok, Deque<ScanToken> tokens) throws IOException {
    if (super.scanItem(rtok, tokens)) {
        return true;
    }
    rtok.nextToken();
    if (scanAttributeName(rtok, "options")) {
        String options = rtok.scanQuotedString('"');
        if (options != null) {
            if (myFrame != null) {
                OptionPanel optpanel = myFrame.addOptionPanel(options);
                optpanel.addMouseListener(new MouseHandler());
                myFrame.pack();
            } else {
                myOptionsString = options;
            }
        }
        return true;
    } else if (rtok.tokenIsWord()) {
        scanWidget(rtok.sval, rtok, tokens);
        return true;
    }
    rtok.pushBack();
    return false;
}
Also used : OptionPanel(maspack.widgets.OptionPanel)

Example 2 with OptionPanel

use of maspack.widgets.OptionPanel in project artisynth_core by artisynth.

the class ControlPanel method write.

public void write(PrintWriter pw, NumberFormat fmt, Object ref) throws IOException {
    CompositeComponent ancestor = ComponentUtils.castRefToAncestor(ref);
    pw.print("[ ");
    IndentingPrintWriter.addIndentation(pw, 2);
    getAllPropertyInfo().writeNonDefaultProps(this, pw, fmt);
    String optionsStr = null;
    if (myFrame != null) {
        OptionPanel optpanel = myFrame.getOptionPanel();
        if (optpanel != null) {
            optionsStr = optpanel.getButtonString();
        }
    } else {
        optionsStr = myOptionsString;
    }
    if (optionsStr != null) {
        pw.println("options=\"" + optionsStr + "\"");
    } else {
        pw.println("options=null");
    }
    for (Component comp : myPanel.getWidgets()) {
        writeWidget(pw, comp, fmt, ancestor);
    }
    IndentingPrintWriter.addIndentation(pw, -2);
    pw.println("]");
}
Also used : MutableCompositeComponent(artisynth.core.modelbase.MutableCompositeComponent) CompositeComponent(artisynth.core.modelbase.CompositeComponent) MutableCompositeComponent(artisynth.core.modelbase.MutableCompositeComponent) Component(java.awt.Component) ModelComponent(artisynth.core.modelbase.ModelComponent) CompositeComponent(artisynth.core.modelbase.CompositeComponent) JComponent(javax.swing.JComponent) OptionPanel(maspack.widgets.OptionPanel)

Example 3 with OptionPanel

use of maspack.widgets.OptionPanel in project artisynth_core by artisynth.

the class FrameBasedEditingAgent method createOptionPanel.

/**
 * Called by subclasses inside {@link #createDisplay createDisplay} to create
 * a button panel. The names of the buttons are placed inside the string
 * <code>buttonNames</code>, separated by white-space. An array of all
 * created buttons is returned. Buttons with certain known names (e.g.,
 * "Done", "Add") are also assigned to predefined variables.
 */
protected JButton[] createOptionPanel(String buttonNames) {
    myOptionPanel = new OptionPanel(buttonNames, this);
    myAddButton = myOptionPanel.getButton("Add");
    myDoneButton = myOptionPanel.getButton("Done");
    myStopButton = myOptionPanel.getButton("Stop");
    addToContentPane(myOptionPanel);
    return myOptionPanel.getButtons();
}
Also used : OptionPanel(maspack.widgets.OptionPanel)

Example 4 with OptionPanel

use of maspack.widgets.OptionPanel 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();
}
Also used : BoxLayout(javax.swing.BoxLayout) JSeparator(javax.swing.JSeparator) Container(java.awt.Container) PropertyField(artisynth.core.gui.widgets.PropertyField) ValueCheckListener(maspack.widgets.ValueCheckListener) ValueChangeEvent(maspack.widgets.ValueChangeEvent) StringHolder(maspack.util.StringHolder) BooleanSelector(maspack.widgets.BooleanSelector) DoubleIntervalField(maspack.widgets.DoubleIntervalField) StringField(maspack.widgets.StringField) DoubleInterval(maspack.util.DoubleInterval) LabeledComponentPanel(maspack.widgets.LabeledComponentPanel) ColorSelector(maspack.widgets.ColorSelector) OptionPanel(maspack.widgets.OptionPanel)

Example 5 with OptionPanel

use of maspack.widgets.OptionPanel 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

OptionPanel (maspack.widgets.OptionPanel)8 BooleanSelector (maspack.widgets.BooleanSelector)3 LabeledComponentPanel (maspack.widgets.LabeledComponentPanel)3 BoxLayout (javax.swing.BoxLayout)2 JSeparator (javax.swing.JSeparator)2 DoubleField (maspack.widgets.DoubleField)2 StringField (maspack.widgets.StringField)2 Main (artisynth.core.driver.Main)1 PropertyField (artisynth.core.gui.widgets.PropertyField)1 CompositeComponent (artisynth.core.modelbase.CompositeComponent)1 ModelComponent (artisynth.core.modelbase.ModelComponent)1 MutableCompositeComponent (artisynth.core.modelbase.MutableCompositeComponent)1 Component (java.awt.Component)1 Container (java.awt.Container)1 Dimension (java.awt.Dimension)1 Insets (java.awt.Insets)1 Point (java.awt.Point)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 JComponent (javax.swing.JComponent)1