Search in sources :

Example 1 with StringField

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

the class NumericProbeEditor method fillPanes.

private void fillPanes() {
    vectorPane.removeAll();
    propPane.removeAll();
    addVectorButton = new JButton(GuiStorage.getAddIcon());
    GuiUtils.setFixedSize(addVectorButton, 25, 25);
    addVectorButton.addActionListener(this);
    addVectorButton.setActionCommand("Add");
    addVectorButton.setAlignmentX(LEFT_ALIGNMENT);
    addVectorButton.setOpaque(true);
    addPropertyButton = new JButton(GuiStorage.getAddIcon());
    GuiUtils.setFixedSize(addPropertyButton, 25, 25);
    addPropertyButton.setActionCommand("Add Property");
    addPropertyButton.addActionListener(this);
    addPropertyButton.setAlignmentX(LEFT_ALIGNMENT);
    addPropertyButton.setOpaque(true);
    infoPaneA = new JPanel();
    infoPaneA.setLayout(new BoxLayout(infoPaneA, BoxLayout.X_AXIS));
    infoPaneA.setOpaque(false);
    infoPaneB = new JPanel();
    infoPaneB.setLayout(new BoxLayout(infoPaneB, BoxLayout.X_AXIS));
    infoPaneB.setOpaque(false);
    nameLabel = new JLabel("Name");
    infoPaneA.setAlignmentX(LEFT_ALIGNMENT);
    infoPaneA.add(nameLabel);
    infoPaneA.add(Box.createRigidArea(new Dimension(15, 0)));
    infoPaneA.add(Box.createHorizontalGlue());
    infoPaneA.add(new JLabel("Dim"));
    infoPaneC = new JPanel();
    infoPaneC.setLayout(new BoxLayout(infoPaneC, BoxLayout.X_AXIS));
    infoPaneC.add(Box.createHorizontalGlue());
    infoPaneC.add(new JLabel("Formula"));
    infoPaneC.add(Box.createHorizontalGlue());
    infoPaneC.setOpaque(false);
    infoPaneC.setAlignmentX(LEFT_ALIGNMENT);
    infoPaneB.add(Box.createRigidArea(new Dimension(50, 0)));
    infoPaneB.add(Box.createHorizontalGlue());
    infoPaneB.add(new JLabel("Component"));
    infoPaneB.add(Box.createHorizontalGlue());
    infoPaneB.add(new JLabel("Property"));
    infoPaneB.setAlignmentX(LEFT_ALIGNMENT);
    infoPaneB.add(Box.createRigidArea(new Dimension(100, 0)));
    vectorPane.add(infoPaneA);
    propPane.add(infoPaneB);
    equationPane.add(infoPaneC);
    // filePane.add(new JLabel("File:"));
    // filePane.add(horizontalSpacer(10));
    attachedFileField = new StringField("attached file", 24);
    // filePane.add(attachedFileField);
    // filePane.add(horizontalSpacer(10));
    browseButton = new JButton("Browse");
    browseButton.addActionListener(this);
    attachedFileField.addMajorComponent(browseButton);
    // filePane.add(browseButton);
    // todo: retreive default values from Probe class
    startTimeField = new DoubleField("start time", Probe.getDefaultStartTime());
    startTimeField.setColumns(8);
    startTimeField.setFormat("%8.4f");
    endTimeField = new DoubleField("end time", Probe.getDefaultStopTime());
    endTimeField.setColumns(8);
    endTimeField.setFormat("%8.4f");
    scaleField = new DoubleField("scale", Probe.getDefaultScale());
    scaleField.setColumns(8);
    intervalField = new DoubleField("update interval", 0.01, "%8.4f");
    intervalField.setColumns(8);
    // intervalField.setFormat ("%8.4f");
    probeNameField = new StringField("name", 8);
    probeNameField.setValue("");
    probeNameField.setStretchable(true);
    dispUpperField = new DoubleField("upper", 50);
    dispUpperField.setColumns(4);
    dispLowerField = new DoubleField("lower", -50);
    dispLowerField.setColumns(4);
    rangeField = new DoubleIntervalField("display range");
    rangeField.setGUIVoidEnabled(true);
    rangeField.setVoidValueEnabled(true);
    // optionsPane.add(probeNameField);
    // optionsPane.add(horizontalSpacer(5));
    // optionsPane.add(startTimeField);
    // optionsPane.add(horizontalSpacer(5));
    // optionsPane.add(endTimeField);
    // optionsPane.add(horizontalSpacer(5));
    leftPropertyPanel.addWidget(probeNameField);
    leftPropertyPanel.addWidget(startTimeField);
    leftPropertyPanel.addWidget(endTimeField);
    // optionsPane.add(scaleField);
    // optionsPane.add(Box.createRigidArea(new Dimension(5, 0)));
    addProbeButton = new JButton("Done");
    addProbeButton.addActionListener(this);
    closeButton = new JButton("Cancel");
    closeButton.addActionListener(this);
    bottomPane.add(addProbeButton);
    bottomPane.add(Box.createRigidArea(new Dimension(10, 0)));
    bottomPane.add(closeButton);
}
Also used : JPanel(javax.swing.JPanel) DoubleIntervalField(maspack.widgets.DoubleIntervalField) BoxLayout(javax.swing.BoxLayout) StringField(maspack.widgets.StringField) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) DoubleField(maspack.widgets.DoubleField)

Example 2 with StringField

use of maspack.widgets.StringField 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);
    }
}
Also used : WidgetDialog(maspack.widgets.WidgetDialog) RootModel(artisynth.core.workspace.RootModel) Point(java.awt.Point) IOException(java.io.IOException) ValueCheckListener(maspack.widgets.ValueCheckListener) ValueChangeEvent(maspack.widgets.ValueChangeEvent) JFileChooser(javax.swing.JFileChooser) StringField(maspack.widgets.StringField) Main(artisynth.core.driver.Main) File(java.io.File)

Example 3 with StringField

use of maspack.widgets.StringField 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 4 with StringField

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

the class AddComponentAgent method createNameField.

protected void createNameField() {
    myNameField = new StringField("name", 20);
    addWidget(myNameField);
}
Also used : StringField(maspack.widgets.StringField)

Example 5 with StringField

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

the class DicomLoader method createControlPanel.

void createControlPanel() {
    panel = new ControlPanel("DICOM controls");
    fnf = new FileNameField("File or folder:", 30);
    fnf.getFileChooser().setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    fnf.getFileChooser().setCurrentDirectory(ArtisynthPath.getSrcRelativeFile(this, "data/"));
    fnf.setName("dicom_path");
    panel.addWidget(fnf);
    fnp = new StringField("File regex:", 30);
    fnp.setValue(".*");
    panel.addWidget(fnp);
    fns = new BooleanSelector("Subdirectories", true);
    panel.addWidget(fns);
    // panel for full-width button
    JPanel jpanel = new JPanel();
    jpanel.setLayout(new GridLayout());
    panel.addWidget(jpanel);
    JButton button = new JButton("Load");
    button.setActionCommand("load");
    button.addActionListener(this);
    jpanel.add(button);
    button = new JButton("Add Plane");
    button.setActionCommand("plane");
    button.addActionListener(this);
    jpanel.add(button);
    addControlPanel(panel);
}
Also used : JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) BooleanSelector(maspack.widgets.BooleanSelector) ControlPanel(artisynth.core.gui.ControlPanel) StringField(maspack.widgets.StringField) JButton(javax.swing.JButton) FileNameField(maspack.widgets.FileNameField)

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