Search in sources :

Example 36 with Checkbox

use of java.awt.Checkbox in project jdk8u_jdk by JetBrains.

the class SetStateExcessEvent method main.

public static void main(final String[] args) throws Exception {
    final Robot robot = new Robot();
    final CheckboxGroup group = new CheckboxGroup();
    final Checkbox[] cbs = { new Checkbox("checkbox1", true, group), new Checkbox("checkbox2", false, group), new Checkbox("checkbox3", true, group), new Checkbox("checkbox4", true), new Checkbox("checkbox5", false), new Checkbox("checkbox6", true) };
    final Frame frame = new Frame();
    frame.setLayout(new GridBagLayout());
    try {
        for (final Checkbox cb : cbs) {
            cb.addItemListener(e -> {
                failed = true;
            });
        }
        for (final Checkbox cb : cbs) {
            frame.add(cb);
        }
        frame.pack();
        for (final Checkbox cb : cbs) {
            cb.setState(!cb.getState());
        }
        for (final Checkbox cb : cbs) {
            group.setSelectedCheckbox(cb);
        }
        robot.waitForIdle();
    } finally {
        frame.dispose();
    }
    if (failed) {
        throw new RuntimeException("Listener should not be called");
    }
    System.out.println("Test passed");
}
Also used : Frame(java.awt.Frame) GridBagLayout(java.awt.GridBagLayout) Checkbox(java.awt.Checkbox) CheckboxGroup(java.awt.CheckboxGroup) Robot(java.awt.Robot)

Example 37 with Checkbox

use of java.awt.Checkbox in project bioformats by openmicroscopy.

the class FilePatternDialog method constructDialog.

@Override
protected GenericDialog constructDialog() {
    // CTR - CHECK
    Location idLoc = new Location(options.getId());
    String id = FilePattern.findPattern(idLoc);
    if (id == null) {
        if (!options.isQuiet()) {
            IJ.showMessage("Bio-Formats", "Warning: Bio-Formats was unable to determine a grouping that\n" + "includes the file you chose. The most common reason for this\n" + "situation is that the folder contains extraneous files with\n" + "similar names and numbers that confuse the detection algorithm.\n" + " \n" + "For example, if you have multiple datasets in the same folder\n" + "named series1_z*_c*.tif, series2_z*_c*.tif, etc., Bio-Formats\n" + "may try to group all such files into a single series.\n" + " \n" + "For best results, put each image series's files in their own\n" + "folder, or type in a file pattern manually.\n");
        }
        id = idLoc.getAbsolutePath();
    }
    // construct dialog
    GenericDialog gd = new GenericDialog("Bio-Formats File Stitching") {

        @Override
        public void itemStateChanged(ItemEvent e) {
            super.itemStateChanged(e);
            Object source = e.getSource();
            if (!(source instanceof Checkbox)) {
                return;
            }
            boolean selected = e.getStateChange() == ItemEvent.SELECTED;
            Vector checkboxes = getCheckboxes();
            for (Object checkbox : checkboxes) {
                if (!checkbox.equals(source)) {
                    if (selected) {
                        ((Checkbox) checkbox).setState(false);
                    }
                } else if (!selected && checkbox.equals(source)) {
                    ((Checkbox) checkbox).setState(true);
                }
            }
        }
    };
    gd.addMessage("The list of files to be grouped can be specified in one of the following ways:");
    // option one
    int len = id.length() + 1;
    if (len > 80)
        len = 80;
    originalID = id;
    fp = new FilePattern(id);
    String[] prefixes = fp.getPrefixes();
    if (prefixes.length > 0) {
        gd.addCheckbox("Dimensions", true);
        int[] counts = fp.getCount();
        paddingZeros = new int[counts.length];
        String[][] elements = fp.getElements();
        BigInteger[] first = fp.getFirst();
        BigInteger[] step = fp.getStep();
        for (int i = 0; i < prefixes.length; i++) {
            String prefix = "Axis_" + (i + 1);
            gd.addStringField(prefix + "_number_of_images", "" + counts[i]);
            gd.addStringField(prefix + "_axis_first_image", first[i].toString());
            gd.addStringField(prefix + "_axis_increment", step[i].toString());
            try {
                paddingZeros[i] = elements[i][0].length() - String.valueOf(Integer.parseInt(elements[i][0])).length();
            } catch (NumberFormatException e) {
            }
        }
    }
    // option two
    gd.addCheckbox("File_name", false);
    gd.addStringField("contains", "");
    // option three
    gd.addCheckbox("Pattern", false);
    gd.addStringField("name", id, len);
    rebuild(gd);
    return gd;
}
Also used : ItemEvent(java.awt.event.ItemEvent) Checkbox(java.awt.Checkbox) GenericDialog(ij.gui.GenericDialog) BigInteger(java.math.BigInteger) FilePattern(loci.formats.FilePattern) Vector(java.util.Vector) Location(loci.common.Location)

Example 38 with Checkbox

use of java.awt.Checkbox in project bioformats by openmicroscopy.

the class MainDialog method rebuildDialog.

// -- Helper methods --
/**
 * Fancies up the importer dialog to look much nicer.
 */
private void rebuildDialog(GenericDialog gd) {
    // extract GUI components from dialog and add listeners
    List<Checkbox> boxes = null;
    List<Choice> choices = null;
    List<Label> labels = null;
    Label colorModeLabel = null;
    Label roisModeLabel = null;
    Label stackFormatLabel = null;
    Label stackOrderLabel = null;
    Component[] c = gd.getComponents();
    if (c != null) {
        boxes = new ArrayList<Checkbox>();
        choices = new ArrayList<Choice>();
        labels = new ArrayList<Label>();
        for (int i = 0; i < c.length; i++) {
            if (c[i] instanceof Checkbox) {
                Checkbox item = (Checkbox) c[i];
                item.addFocusListener(this);
                item.addItemListener(this);
                item.addMouseListener(this);
                boxes.add(item);
            } else if (c[i] instanceof Choice) {
                Choice item = (Choice) c[i];
                item.addFocusListener(this);
                item.addItemListener(this);
                item.addMouseListener(this);
                choices.add(item);
            } else if (c[i] instanceof Label)
                labels.add((Label) c[i]);
        }
        int boxIndex = 0, choiceIndex = 0, labelIndex = 0;
        autoscaleBox = boxes.get(boxIndex++);
        colorModeChoice = choices.get(choiceIndex++);
        colorModeLabel = labels.get(labelIndex++);
        concatenateBox = boxes.get(boxIndex++);
        cropBox = boxes.get(boxIndex++);
        groupFilesBox = boxes.get(boxIndex++);
        ungroupFilesBox = boxes.get(boxIndex++);
        openAllSeriesBox = boxes.get(boxIndex++);
        // quiet
        boxIndex++;
        // recordBox         = boxes.get(boxIndex++);
        showMetadataBox = boxes.get(boxIndex++);
        showOMEXMLBox = boxes.get(boxIndex++);
        showROIsBox = boxes.get(boxIndex++);
        roisModeChoice = choices.get(choiceIndex++);
        roisModeLabel = labels.get(labelIndex++);
        specifyRangesBox = boxes.get(boxIndex++);
        splitZBox = boxes.get(boxIndex++);
        splitTBox = boxes.get(boxIndex++);
        splitCBox = boxes.get(boxIndex++);
        stackFormatChoice = choices.get(choiceIndex++);
        stackFormatLabel = labels.get(labelIndex++);
        stackOrderChoice = choices.get(choiceIndex++);
        stackOrderLabel = labels.get(labelIndex++);
        swapDimsBox = boxes.get(boxIndex++);
        virtualBox = boxes.get(boxIndex++);
        stitchTilesBox = boxes.get(boxIndex++);
    }
    verifyOptions(null);
    // TODO: The info table and focus logic could be split into
    // its own class, rather than being specific to this dialog.
    // associate information for each option
    infoTable = new HashMap<Component, String>();
    infoTable.put(autoscaleBox, options.getAutoscaleInfo());
    infoTable.put(colorModeChoice, options.getColorModeInfo());
    infoTable.put(colorModeLabel, options.getColorModeInfo());
    infoTable.put(concatenateBox, options.getConcatenateInfo());
    infoTable.put(cropBox, options.getCropInfo());
    infoTable.put(groupFilesBox, options.getGroupFilesInfo());
    infoTable.put(ungroupFilesBox, options.getUngroupFilesInfo());
    infoTable.put(openAllSeriesBox, options.getOpenAllSeriesInfo());
    // infoTable.put(recordBox, options.getRecordInfo());
    infoTable.put(showMetadataBox, options.getShowMetadataInfo());
    infoTable.put(showOMEXMLBox, options.getShowOMEXMLInfo());
    infoTable.put(showROIsBox, options.getShowROIsInfo());
    infoTable.put(roisModeChoice, options.getROIsModeInfo());
    infoTable.put(roisModeLabel, options.getROIsModeInfo());
    infoTable.put(specifyRangesBox, options.getSpecifyRangesInfo());
    infoTable.put(splitZBox, options.getSplitFocalPlanesInfo());
    infoTable.put(splitTBox, options.getSplitTimepointsInfo());
    infoTable.put(splitCBox, options.getSplitChannelsInfo());
    infoTable.put(stackFormatChoice, options.getStackFormatInfo());
    infoTable.put(stackFormatLabel, options.getStackFormatInfo());
    infoTable.put(stackOrderChoice, options.getStackOrderInfo());
    infoTable.put(stackOrderLabel, options.getStackOrderInfo());
    infoTable.put(swapDimsBox, options.getSwapDimensionsInfo());
    infoTable.put(virtualBox, options.getVirtualInfo());
    infoTable.put(stitchTilesBox, options.getStitchTilesInfo());
    // rebuild dialog using FormLayout to organize things more nicely
    String cols = // first column
    "pref, 3dlu, pref:grow, " + // second column
    "10dlu, pref, 3dlu, pref:grow, " + // third column
    "10dlu, fill:150dlu";
    String rows = // Stack viewing        | Metadata viewing
    "pref, 3dlu, pref, 3dlu, pref, 3dlu, pref, 3dlu, pref, " + // Dataset organization | Memory management
    "9dlu, pref, 3dlu, pref, 3dlu, pref, 3dlu, pref, 3dlu, pref, " + "3dlu, pref, " + // Color options        | Split into separate windows
    "9dlu, pref, 3dlu, pref, 3dlu, pref, 3dlu, pref, 3dlu, pref";
    // TODO: Change "Use virtual stack" and "Record modifications to virtual
    // stack" checkboxes to "Stack type" choice with options:
    // "Normal", "Virtual" or "Smart virtual"
    PanelBuilder builder = new PanelBuilder(new FormLayout(cols, rows));
    CellConstraints cc = new CellConstraints();
    // populate 1st column
    int row = 1;
    builder.addSeparator("Stack viewing", cc.xyw(1, row, 3));
    row += 2;
    builder.add(stackFormatLabel, cc.xy(1, row));
    builder.add(stackFormatChoice, cc.xy(3, row));
    row += 2;
    builder.add(stackOrderLabel, cc.xy(1, row));
    builder.add(stackOrderChoice, cc.xy(3, row));
    row += 6;
    builder.addSeparator("Dataset organization", cc.xyw(1, row, 3));
    row += 2;
    builder.add(groupFilesBox, xyw(cc, 1, row, 3));
    row += 2;
    builder.add(ungroupFilesBox, xyw(cc, 1, row, 3));
    row += 2;
    builder.add(swapDimsBox, xyw(cc, 1, row, 3));
    row += 2;
    builder.add(openAllSeriesBox, xyw(cc, 1, row, 3));
    row += 2;
    builder.add(concatenateBox, xyw(cc, 1, row, 3));
    row += 2;
    builder.add(stitchTilesBox, xyw(cc, 1, row, 3));
    row += 2;
    builder.addSeparator("Color options", cc.xyw(1, row, 3));
    row += 2;
    builder.add(colorModeLabel, cc.xy(1, row));
    builder.add(colorModeChoice, cc.xy(3, row));
    row += 2;
    builder.add(autoscaleBox, xyw(cc, 1, row, 3));
    row += 2;
    // populate 2nd column
    row = 1;
    builder.addSeparator("Metadata viewing", cc.xyw(5, row, 3));
    row += 2;
    builder.add(showMetadataBox, xyw(cc, 5, row, 3));
    row += 2;
    builder.add(showOMEXMLBox, xyw(cc, 5, row, 3));
    row += 2;
    builder.add(showROIsBox, xyw(cc, 5, row, 3));
    row += 2;
    builder.add(roisModeLabel, cc.xy(5, row));
    builder.add(roisModeChoice, cc.xy(7, row));
    row += 2;
    builder.addSeparator("Memory management", cc.xyw(5, row, 3));
    row += 2;
    builder.add(virtualBox, xyw(cc, 5, row, 3));
    row += 2;
    // builder.add(recordBox, xyw(cc, 5, row, 3));
    // row += 2;
    builder.add(specifyRangesBox, xyw(cc, 5, row, 3));
    row += 2;
    builder.add(cropBox, xyw(cc, 5, row, 3));
    row += 4;
    builder.addSeparator("Split into separate windows", cc.xyw(5, row, 3));
    row += 2;
    builder.add(splitCBox, xyw(cc, 5, row, 3));
    row += 2;
    builder.add(splitZBox, xyw(cc, 5, row, 3));
    row += 2;
    builder.add(splitTBox, xyw(cc, 5, row, 3));
    // row += 4;
    // information section
    builder.addSeparator("Information", cc.xy(9, 1));
    // row += 2;
    infoPane = new JEditorPane();
    infoPane.setContentType("text/html");
    infoPane.setEditable(false);
    infoPane.setText("<html>" + INFO_DEFAULT);
    builder.add(new JScrollPane(infoPane), cc.xywh(9, 3, 1, row));
    // row += 2;
    gd.removeAll();
    gd.add(builder.getPanel());
    WindowTools.addScrollBars(gd);
    // HACK: workaround for JPanel in a Dialog
    gd.setBackground(Color.white);
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) JScrollPane(javax.swing.JScrollPane) PanelBuilder(com.jgoodies.forms.builder.PanelBuilder) Choice(java.awt.Choice) Label(java.awt.Label) Checkbox(java.awt.Checkbox) JEditorPane(javax.swing.JEditorPane) Component(java.awt.Component) CellConstraints(com.jgoodies.forms.layout.CellConstraints)

Example 39 with Checkbox

use of java.awt.Checkbox in project JSettlers2 by jdmonin.

the class NewGameOptionsFrame method readOptsValuesFromControls.

/**
 * Read option values from controls, as prep to request the new game.
 * If there is a problem (out of range, bad character in integer field, etc),
 * set {@link #msgText} and set focus on the field.
 * @param checkOptionsMinVers Warn the user if the options will require a
 *           minimum client version?  Won't do so if {@link #forPractice} is set,
 *           because this isn't a problem for local practice games.
 *           The warning is skipped if that minimum is an old version
 *           &lt;= {@link Version#versionNumberMaximumNoWarn()}.
 * @return true if all were read OK, false if a problem (such as NumberFormatException)
 */
private boolean readOptsValuesFromControls(final boolean checkOptionsMinVers) {
    if (readOnly)
        // shouldn't be called in that case
        return false;
    boolean allOK = true;
    for (Component ctrl : controlsOpts.keySet()) {
        if (ctrl instanceof Label)
            continue;
        SOCGameOption op = controlsOpts.get(ctrl);
        if (op.key.equals("SC")) {
            // Special case: AWT event listeners have already set its value from controls
            if (!op.getBoolValue())
                op.setStringValue("");
            continue;
        }
        if (ctrl instanceof Checkbox) {
            op.setBoolValue(((Checkbox) ctrl).getState());
        } else if (ctrl instanceof TextField) {
            String txt = ((TextField) ctrl).getText().trim();
            if ((op.optType == SOCGameOption.OTYPE_STR) || (op.optType == SOCGameOption.OTYPE_STRHIDE)) {
                try {
                    op.setStringValue(txt);
                } catch (IllegalArgumentException ex) {
                    allOK = false;
                    // only a single line of text allowed
                    msgText.setText(strings.get("game.options.singleline"));
                    ctrl.requestFocusInWindow();
                }
            } else {
            // OTYPE_INT, OTYPE_INTBOOL; defer setting until after all checkboxes have been read
            }
        } else if (ctrl instanceof Choice) {
            // this works with OTYPE_INT, OTYPE_INTBOOL, OTYPE_ENUM, OTYPE_ENUMBOOL
            // 0 to n-1
            int chIdx = ((Choice) ctrl).getSelectedIndex();
            if (chIdx != -1)
                op.setIntValue(chIdx + op.minIntValue);
            else
                allOK = false;
        }
    }
    // Use 0 if blank (still checks if in range).
    for (Component ctrl : controlsOpts.keySet()) {
        if (!(ctrl instanceof TextField))
            continue;
        SOCGameOption op = controlsOpts.get(ctrl);
        if (op.optType == SOCGameOption.OTYPE_INTBOOL) {
            if (!op.getBoolValue())
                continue;
        } else if (op.optType != SOCGameOption.OTYPE_INT) {
            continue;
        }
        String txt = ((TextField) ctrl).getText().trim();
        try {
            int iv;
            if (txt.length() > 0)
                iv = Integer.parseInt(txt);
            else
                iv = 0;
            op.setIntValue(iv);
            if (iv != op.getIntValue()) {
                allOK = false;
                msgText.setText(// "out of range"
                strings.get("game.options.outofrange", op.minIntValue, op.maxIntValue));
                ctrl.requestFocusInWindow();
            }
        } catch (NumberFormatException ex) {
            allOK = false;
            // "please use only digits here"
            msgText.setText(strings.get("game.options.onlydigits"));
            ctrl.requestFocusInWindow();
        }
    }
    if (allOK && checkOptionsMinVers && !forPractice) {
        int optsVers = SOCVersionedItem.itemsMinimumVersion(controlsOpts);
        if ((optsVers > -1) && (optsVers > Version.versionNumberMaximumNoWarn())) {
            allOK = false;
            new VersionConfirmDialog(this, optsVers).setVisible(true);
        }
    }
    return allOK;
}
Also used : Choice(java.awt.Choice) Checkbox(java.awt.Checkbox) SOCGameOption(soc.game.SOCGameOption) Label(java.awt.Label) TextField(java.awt.TextField) Component(java.awt.Component)

Example 40 with Checkbox

use of java.awt.Checkbox in project JSettlers2 by jdmonin.

the class NewGameOptionsFrame method fireOptionChangeListener.

/**
 * Handle firing a game option's ChangeListener, and refreshing related
 * gameopts' values on-screen if needed.
 * If <tt>oldValue</tt>.equals(<tt>newValue</tt>), nothing happens and
 * the ChangeListener is not called.
 * @param cl  The ChangeListener; must not be null
 * @param opt  The game option
 * @param oldValue  Old value, string or boxed primitive
 * @param newValue  New value, string or boxed primitive
 * @since 1.1.13
 */
private void fireOptionChangeListener(SOCGameOption.ChangeListener cl, SOCGameOption opt, final Object oldValue, final Object newValue) {
    if (oldValue.equals(newValue))
        // <--- Early return: Value didn't change ---
        return;
    try {
        cl.valueChanged(opt, oldValue, newValue, opts);
    } catch (Throwable thr) {
        System.err.println("-- Error caught in ChangeListener: " + thr.toString() + " --");
        thr.printStackTrace();
        while (thr.getCause() != null) {
            thr = thr.getCause();
            System.err.println(" --> Cause: " + thr + " --");
            thr.printStackTrace();
        }
        System.err.println("-- Error stack trace end --");
        System.err.println();
    }
    List<SOCGameOption> refresh = SOCGameOption.getAndClearRefreshList();
    if (refresh == null)
        // <--- Early return: Nothing else changed ---
        return;
    // Refresh each one now, depending on type:
    if (optsControls == null)
        // should only be null if readOnly, and thus no changes to values anyway
        return;
    for (int i = refresh.size() - 1; i >= 0; --i) {
        final SOCGameOption op = refresh.get(i);
        final Component opComp = optsControls.get(op.key);
        switch(// OTYPE_*
        op.optType) {
            case SOCGameOption.OTYPE_BOOL:
                ((Checkbox) opComp).setState(op.getBoolValue());
                break;
            case SOCGameOption.OTYPE_INT:
            case SOCGameOption.OTYPE_INTBOOL:
                {
                    if (opComp instanceof TextField)
                        ((TextField) opComp).setText(Integer.toString(op.getIntValue()));
                    else
                        ((Choice) opComp).select(op.getIntValue() - op.minIntValue);
                    final boolean hasCheckbox = (op.optType == SOCGameOption.OTYPE_INTBOOL);
                    if (hasCheckbox) {
                        Checkbox cb = boolOptCheckboxes.get(op.key);
                        if (cb != null)
                            cb.setState(op.getBoolValue());
                    }
                }
                break;
            case SOCGameOption.OTYPE_ENUM:
            case SOCGameOption.OTYPE_ENUMBOOL:
                {
                    ((Choice) opComp).select(op.getIntValue() - op.minIntValue);
                    final boolean hasCheckbox = (op.optType == SOCGameOption.OTYPE_ENUMBOOL);
                    if (hasCheckbox) {
                        Checkbox cb = boolOptCheckboxes.get(op.key);
                        if (cb != null)
                            cb.setState(op.getBoolValue());
                    }
                }
                break;
            case SOCGameOption.OTYPE_STR:
            case SOCGameOption.OTYPE_STRHIDE:
                ((TextField) opComp).setText(op.getStringValue());
                break;
        }
    }
}
Also used : Choice(java.awt.Choice) Checkbox(java.awt.Checkbox) SOCGameOption(soc.game.SOCGameOption) TextField(java.awt.TextField) Component(java.awt.Component)

Aggregations

Checkbox (java.awt.Checkbox)54 TextField (java.awt.TextField)21 Choice (java.awt.Choice)18 GenericDialog (ij.gui.GenericDialog)13 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)11 Vector (java.util.Vector)9 Component (java.awt.Component)8 Label (java.awt.Label)8 GlobalSettings (gdsc.smlm.ij.settings.GlobalSettings)7 Panel (java.awt.Panel)7 GridBagLayout (java.awt.GridBagLayout)5 SOCGameOption (soc.game.SOCGameOption)5 BasePoint (gdsc.core.match.BasePoint)4 PeakResultPoint (gdsc.smlm.ij.plugins.ResultsMatchCalculator.PeakResultPoint)4 Color (java.awt.Color)4 GridBagConstraints (java.awt.GridBagConstraints)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 CalibrationWriter (uk.ac.sussex.gdsc.smlm.data.config.CalibrationWriter)4 FitConfiguration (uk.ac.sussex.gdsc.smlm.engine.FitConfiguration)4