Search in sources :

Example 46 with TextField

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

the class NewGameOptionsFrame method initInterface_Opt1.

/**
 * Add one GridBagLayout row with this game option (component and label(s)).
 * The option's descriptive text may have "#" as a placeholder for where
 * int/enum value is specified (IntTextField or Choice-dropdown).
 * @param op  Option data
 * @param oc  Component with option choices (popup menu, textfield, etc).
 *            If oc is a {@link TextField} or {@link Choice}, and hasCB,
 *            changing the component's value will set the checkbox.
 *            <tt>oc</tt> will be added to {@link #optsControls} and {@link #controlsOpts}.
 * @param hasCB  Add a checkbox?  If oc is {@link Checkbox}, set this true;
 *            it won't add a second checkbox.
 *            The checkbox will be added to {@link #boolOptCheckboxes} and {@link #controlsOpts}.
 * @param allowPH  Allow the "#" placeholder within option desc?
 * @param bp  Add to this panel
 * @param gbl Use this layout
 * @param gbc Use these constraints; gridwidth will be set to 1 and then REMAINDER
 */
private void initInterface_Opt1(SOCGameOption op, Component oc, boolean hasCB, boolean allowPH, JPanel bp, GridBagLayout gbl, GridBagConstraints gbc) {
    Label L;
    // reminder: same gbc widths/weights are used in initInterface_UserPrefs/initInterface_Pref1
    gbc.gridwidth = 1;
    gbc.weightx = 0;
    if (hasCB) {
        Checkbox cb;
        if (oc instanceof Checkbox)
            cb = (Checkbox) oc;
        else
            cb = new Checkbox();
        controlsOpts.put(cb, op);
        cb.setState(op.getBoolValue());
        cb.setEnabled(!readOnly);
        gbl.setConstraints(cb, gbc);
        bp.add(cb);
        if (!readOnly) {
            boolOptCheckboxes.put(op.key, cb);
            // for op's ChangeListener and userChanged
            cb.addItemListener(this);
        }
    } else {
        // to fill checkbox's column
        L = new Label();
        gbl.setConstraints(L, gbc);
        bp.add(L);
    }
    final String opDesc = op.getDesc();
    final int placeholderIdx = allowPH ? opDesc.indexOf('#') : -1;
    // with FlowLayout
    Panel optp = new Panel();
    try {
        FlowLayout fl = (FlowLayout) (optp.getLayout());
        fl.setAlignment(FlowLayout.LEFT);
        fl.setVgap(0);
        fl.setHgap(0);
    } catch (Throwable fle) {
    }
    // Any text to the left of placeholder in op.desc?
    if (placeholderIdx > 0) {
        L = new Label(opDesc.substring(0, placeholderIdx));
        L.setForeground(LABEL_TXT_COLOR);
        optp.add(L);
        if (hasCB && !readOnly) {
            controlsOpts.put(L, op);
            // Click label to toggle checkbox
            L.addMouseListener(this);
        }
    }
    // TextField or Choice or JComboBox at placeholder position
    if (!(oc instanceof Checkbox)) {
        controlsOpts.put(oc, op);
        oc.setEnabled(!readOnly);
        optp.add(oc);
        if (hasCB && !readOnly) {
            if (oc instanceof TextField) {
                // for enable/disable
                ((TextField) oc).addTextListener(this);
                // for ESC/ENTER
                ((TextField) oc).addKeyListener(this);
            } else if (oc instanceof Choice) {
                // for related cb, and op.ChangeListener and userChanged
                ((Choice) oc).addItemListener(this);
            } else if (oc instanceof JComboBox) {
                // for related cb, and op.ChangeListener and userChanged
                ((JComboBox) oc).addActionListener(this);
            }
        }
    }
    if (!readOnly)
        optsControls.put(op.key, oc);
    // the text label if there is no placeholder (placeholderIdx == -1).
    if (placeholderIdx + 1 < opDesc.length()) {
        L = new Label(opDesc.substring(placeholderIdx + 1));
        L.setForeground(LABEL_TXT_COLOR);
        optp.add(L);
        if (hasCB && !readOnly) {
            controlsOpts.put(L, op);
            // Click label to toggle checkbox
            L.addMouseListener(this);
        }
    }
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.weightx = 1;
    gbl.setConstraints(optp, gbc);
    bp.add(optp);
}
Also used : Panel(java.awt.Panel) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) Choice(java.awt.Choice) JComboBox(javax.swing.JComboBox) Checkbox(java.awt.Checkbox) Label(java.awt.Label) TextField(java.awt.TextField)

Example 47 with TextField

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

the class NewGameOptionsFrame method textValueChanged.

/**
 * When gamename contents change, enable/disable buttons as appropriate. (TextListener)
 * Also handles {@link SOCGameOption#OTYPE_INTBOOL} textfield/checkbox combos.
 * Also sets {@link SOCGameOption#userChanged}.
 * @param e textevent from {@link #gameName}, or from a TextField in {@link #controlsOpts}
 */
public void textValueChanged(TextEvent e) {
    if (readOnly)
        return;
    Object srcObj = e.getSource();
    if (!(srcObj instanceof TextField))
        return;
    final String newText = ((TextField) srcObj).getText().trim();
    final boolean notEmpty = (newText.length() > 0);
    if (srcObj == gameName) {
        if (notEmpty != create.isEnabled())
            // enable "create" btn only if game name filled in
            create.setEnabled(notEmpty);
    } else {
        // Check for a ChangeListener for OTYPE_STR and OTYPE_STRHIDE,
        // OTYPE_INT and OTYPE_INTBOOL.
        // if source is OTYPE_INTBOOL, check its checkbox vs notEmpty.
        SOCGameOption opt = controlsOpts.get(srcObj);
        if (opt == null)
            return;
        final String oldText = opt.getStringValue();
        boolean validChange = false;
        boolean otypeIsInt;
        int oldIntValue = 0;
        if ((opt.optType == SOCGameOption.OTYPE_STR) || (opt.optType == SOCGameOption.OTYPE_STRHIDE)) {
            otypeIsInt = false;
            try {
                opt.setStringValue(newText);
                validChange = true;
            } catch (IllegalArgumentException ex) {
            }
        } else {
            otypeIsInt = true;
            try // OTYPE_INT, OTYPE_INTBOOL
            {
                final int iv = Integer.parseInt(newText);
                oldIntValue = opt.getIntValue();
                // ignored if outside min,max range
                opt.setIntValue(iv);
                if (iv == opt.getIntValue())
                    validChange = true;
            } catch (NumberFormatException ex) {
            }
        }
        if (validChange && !opt.userChanged)
            opt.userChanged = true;
        // If this string or int option also has a bool checkbox,
        // set or clear that based on string/int not empty.
        boolean cbSet = false;
        Checkbox cb = boolOptCheckboxes.get(opt.key);
        if ((cb != null) && (notEmpty != cb.getState())) {
            cb.setState(notEmpty);
            opt.setBoolValue(notEmpty);
            cbSet = true;
        }
        SOCGameOption.ChangeListener cl = opt.getChangeListener();
        if (cl == null)
            return;
        // calling fireOptionChangeListener.  Boolean is called before int.
        if (cbSet) {
            // ChangeListener for checkbox
            final Boolean newValue = (notEmpty) ? Boolean.TRUE : Boolean.FALSE;
            final Boolean oldValue = (notEmpty) ? Boolean.FALSE : Boolean.TRUE;
            fireOptionChangeListener(cl, opt, oldValue, newValue);
        }
        // ChangeListener for text field
        if (validChange) {
            if (otypeIsInt)
                fireOptionChangeListener(cl, opt, new Integer(oldIntValue), new Integer(opt.getIntValue()));
            else
                fireOptionChangeListener(cl, opt, oldText, newText);
        }
    }
}
Also used : Checkbox(java.awt.Checkbox) SOCGameOption(soc.game.SOCGameOption) TextField(java.awt.TextField)

Example 48 with TextField

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

the class SOCConnectOrPracticePanel method initInterface_conn.

/**
 * panel_conn setup
 */
private Panel initInterface_conn() {
    Panel pconn = new Panel();
    Label L;
    GridBagLayout gbl = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    pconn.setLayout(gbl);
    gbc.fill = GridBagConstraints.BOTH;
    // heading row
    // "Connect to Server"
    L = new Label(strings.get("pcli.cpp.connecttoserv"));
    L.setAlignment(Label.CENTER);
    L.setBackground(HEADER_LABEL_BG);
    L.setForeground(HEADER_LABEL_FG);
    gbc.gridwidth = 4;
    gbl.setConstraints(L, gbc);
    pconn.add(L);
    // Spacing for rest of form's rows
    L = new Label(" ");
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbl.setConstraints(L, gbc);
    pconn.add(L);
    // blank row
    L = new Label();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbl.setConstraints(L, gbc);
    pconn.add(L);
    L = new Label(strings.get("pcli.cpp.server"));
    gbc.gridwidth = 1;
    gbl.setConstraints(L, gbc);
    pconn.add(L);
    conn_servhost = new TextField(20);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbl.setConstraints(conn_servhost, gbc);
    // for ESC/ENTER
    conn_servhost.addKeyListener(this);
    pconn.add(conn_servhost);
    L = new Label(strings.get("pcli.cpp.port"));
    gbc.gridwidth = 1;
    gbl.setConstraints(L, gbc);
    pconn.add(L);
    conn_servport = new TextField(20);
    {
        String svp = Integer.toString(clientNetwork.getPort());
        conn_servport.setText(svp);
        conn_servport.setSelectionStart(0);
        conn_servport.setSelectionEnd(svp.length());
    }
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbl.setConstraints(conn_servport, gbc);
    // for ESC/ENTER
    conn_servport.addKeyListener(this);
    pconn.add(conn_servport);
    L = new Label(strings.get("pcli.cpp.nickname"));
    gbc.gridwidth = 1;
    gbl.setConstraints(L, gbc);
    pconn.add(L);
    conn_user = new TextField(20);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbl.setConstraints(conn_user, gbc);
    conn_user.addKeyListener(this);
    pconn.add(conn_user);
    L = new Label(strings.get("pcli.cpp.password"));
    gbc.gridwidth = 1;
    gbl.setConstraints(L, gbc);
    pconn.add(L);
    conn_pass = new TextField(20);
    if (SOCPlayerClient.isJavaOnOSX)
        // round bullet (option-8)
        conn_pass.setEchoChar('\u2022');
    else
        conn_pass.setEchoChar('*');
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbl.setConstraints(conn_pass, gbc);
    conn_pass.addKeyListener(this);
    pconn.add(conn_pass);
    L = new Label(" ");
    gbc.gridwidth = 1;
    gbl.setConstraints(L, gbc);
    pconn.add(L);
    conn_connect = new Button(strings.get("pcli.cpp.connect"));
    conn_connect.addActionListener(this);
    // for win32 keyboard-focus
    conn_connect.addKeyListener(this);
    gbl.setConstraints(conn_connect, gbc);
    pconn.add(conn_connect);
    conn_cancel = new Button(strings.get("base.cancel"));
    conn_cancel.addActionListener(this);
    conn_cancel.addKeyListener(this);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbl.setConstraints(conn_cancel, gbc);
    pconn.add(conn_cancel);
    return pconn;
}
Also used : Panel(java.awt.Panel) GridBagConstraints(java.awt.GridBagConstraints) GridBagLayout(java.awt.GridBagLayout) Button(java.awt.Button) Label(java.awt.Label) TextField(java.awt.TextField)

Example 49 with TextField

use of java.awt.TextField in project GDSC-SMLM by aherbert.

the class TraceMolecules method showDynamicTraceDialog.

private boolean showDynamicTraceDialog() {
    pluginTitle = outputName + " Molecules";
    final ExtendedGenericDialog gd = new ExtendedGenericDialog(pluginTitle);
    gd.addHelp(HelpUrls.getUrl("dynamic-trace-molecules"));
    readSettings();
    ResultsManager.addInput(gd, pluginSettings.inputOption, InputSource.MEMORY);
    // Dynamic Multiple Target Tracing
    final TextField tfD = gd.addAndGetNumericField("Diffusion_coefficient", settings.getDiffusionCoefficentMaximum(), 3, 6, "um^2/s");
    final TextField tfW = gd.addAndGetNumericField("Temporal_window", settings.getTemporalWindow(), 0, 6, "frames");
    final TextField tfLdw = gd.addAndGetNumericField("Local_diffusion_weight", settings.getLocalDiffusionWeight(), 2);
    final TextField tfOiw = gd.addAndGetNumericField("On_intensity_weight", settings.getOnIntensityWeight(), 2);
    final TextField tfDdf = gd.addAndGetNumericField("Disappearance_decay_factor", settings.getDisappearanceDecayFactor(), 0, 6, "frames");
    final TextField tfDt = gd.addAndGetNumericField("Disappearance_threshold", settings.getDisappearanceThreshold(), 0, 6, "frames");
    final Checkbox cbDld = gd.addAndGetCheckbox("Disable_local_diffusion_model", settings.getDisableLocalDiffusionModel());
    final Checkbox cbDim = gd.addAndGetCheckbox("Disable_intensity_model", settings.getDisableIntensityModel());
    // Allow reset to defaults
    gd.addAndGetButton("Defaults", e -> {
        final DmttConfiguration config = DmttConfiguration.newBuilder(1).build();
        tfD.setText(String.valueOf(settings.getDiffusionCoefficentMaximum()));
        tfW.setText(String.valueOf(config.getTemporalWindow()));
        tfLdw.setText(String.valueOf(config.getLocalDiffusionWeight()));
        tfOiw.setText(String.valueOf(config.getOnIntensityWeight()));
        tfDdf.setText(String.valueOf(config.getDisappearanceDecayFactor()));
        tfDt.setText(String.valueOf(config.getDisappearanceThreshold()));
        cbDld.setState(config.isDisableLocalDiffusionModel());
        cbDim.setState(config.isDisableIntensityModel());
    });
    gd.addCheckbox("Save_traces", settings.getSaveTraces());
    gd.addCheckbox("Show_histograms", settings.getShowHistograms());
    gd.addCheckbox("Save_trace_data", settings.getSaveTraceData());
    gd.showDialog();
    if (gd.wasCanceled() || !readDynamicTraceDialog(gd)) {
        return false;
    }
    // Load the results
    results = ResultsManager.loadInputResults(pluginSettings.inputOption, true, null, null);
    if (MemoryPeakResults.isEmpty(results)) {
        IJ.error(pluginTitle, "No results could be loaded");
        IJ.showStatus("");
        return false;
    }
    // Store exposure time in seconds
    exposureTime = results.getCalibrationReader().getExposureTime() / 1000;
    return true;
}
Also used : DmttConfiguration(uk.ac.sussex.gdsc.smlm.results.DynamicMultipleTargetTracing.DmttConfiguration) Checkbox(java.awt.Checkbox) TextField(java.awt.TextField) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)

Example 50 with TextField

use of java.awt.TextField in project GDSC-SMLM by aherbert.

the class SpotFinderPreview method showDialog.

@Override
public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) {
    settings = Settings.load();
    this.overlay = imp.getOverlay();
    this.imp = imp;
    // Saved by reference so do it once now
    settings.save();
    // The image is locked by the PlugInFilterRunner so unlock it to allow scroll.
    // This should be OK as the image data is not modified and only the overlay is
    // adjusted. If another plugin changes the image then the preview should update
    // the overlay and it will be obvious to the user to turn this plugin off.
    imp.unlock();
    config = SettingsManager.readFitEngineConfiguration(0);
    fitConfig = config.getFitConfiguration();
    gd = new NonBlockingExtendedGenericDialog(TITLE);
    gd.addHelp(HelpUrls.getUrl("spot-finder-preview"));
    gd.addMessage("Preview candidate maxima");
    final String[] templates = ConfigurationTemplate.getTemplateNames(true);
    gd.addChoice("Template", templates, templates[0]);
    final String[] models = CameraModelManager.listCameraModels(true);
    gd.addChoice("Camera_model_name", models, fitConfig.getCameraModelName());
    PeakFit.addPsfOptions(gd, (FitConfigurationProvider) () -> fitConfig);
    final PeakFit.SimpleFitEngineConfigurationProvider provider = new PeakFit.SimpleFitEngineConfigurationProvider(config);
    PeakFit.addDataFilterOptions(gd, provider);
    gd.addChoice("Spot_filter_2", SettingsManager.getDataFilterMethodNames(), config.getDataFilterMethod(1, settings.defaultDataFilterMethod).ordinal());
    PeakFit.addRelativeParameterOptions(gd, new RelativeParameterProvider(2.5, 4.5, "Smoothing_2", provider) {

        @Override
        void setAbsolute(boolean absolute) {
            final FitEngineConfiguration c = fitEngineConfigurationProvider.getFitEngineConfiguration();
            final DataFilterMethod m = c.getDataFilterMethod(1, settings.defaultDataFilterMethod);
            final double smooth = c.getDataFilterParameterValue(1, settings.defaultSmooth);
            c.setDataFilter(m, smooth, absolute, 1);
        }

        @Override
        boolean isAbsolute() {
            return fitEngineConfigurationProvider.getFitEngineConfiguration().getDataFilterParameterAbsolute(1, false);
        }

        @Override
        double getValue() {
            return fitEngineConfigurationProvider.getFitEngineConfiguration().getDataFilterParameterValue(1, settings.defaultSmooth);
        }
    });
    PeakFit.addSearchOptions(gd, provider);
    PeakFit.addBorderOptions(gd, provider);
    // Find if this image was created with ground truth data
    if (imp.getID() == CreateData.getImageId()) {
        final MemoryPeakResults results = CreateData.getResults();
        if (results != null) {
            gd.addSlider("Match_distance", 0, 2.5, settings.distance);
            gd.addSlider("Lower_match_distance (%)", 0, 100, settings.lowerDistance);
            gd.addCheckbox("Multiple_matches", settings.multipleMatches);
            gd.addCheckbox("Show_TP", settings.showTP);
            gd.addCheckbox("Show_FP", settings.showFP);
            gd.addMessage("");
            label = (Label) gd.getMessage();
            final boolean integerCoords = false;
            actualCoordinates = ResultsMatchCalculator.getCoordinates(results, integerCoords);
        }
    }
    if (label == null) {
        // If no ground truth data add options to show the spots by their rank
        // and number of neighbours
        gd.addSlider("Top_N", 0, 100, settings.topN);
        topNScrollBar = gd.getLastScrollbar();
        gd.addSlider("Select", 0, 100, settings.select);
        selectScrollBar = gd.getLastScrollbar();
        gd.addSlider("Neigbour_radius", 0, 10, settings.neighbourRadius);
    }
    ImageListener imageListener = null;
    if (ImageJUtils.isShowGenericDialog()) {
        // Listen for changes in the dialog options
        gd.addOptionCollectedListener(event -> {
            // Just run on the current processor
            if (preview) {
                run(imp.getProcessor());
            }
        });
        // Listen for changes to an image
        imageListener = new ImageAdapter() {

            @Override
            public void imageUpdated(ImagePlus imp) {
                if (SpotFinderPreview.this.imp.getID() == imp.getID() && preview && imp.getCurrentSlice() != currentSlice && filter != null) {
                    run(imp.getProcessor(), filter);
                }
            }
        };
        ImagePlus.addImageListener(imageListener);
        // Support template settings
        final Vector<TextField> numerics = gd.getNumericFields();
        final Vector<Choice> choices = gd.getChoices();
        final Iterator<TextField> nu = numerics.iterator();
        final Iterator<Choice> ch = choices.iterator();
        final Choice textTemplate = ch.next();
        textTemplate.removeItemListener(gd);
        textTemplate.removeKeyListener(gd);
        textTemplate.addItemListener(this::itemStateChanged);
        textCameraModelName = ch.next();
        textPsf = ch.next();
        textDataFilterType = ch.next();
        textDataFilterMethod = ch.next();
        textSmooth = nu.next();
        textDataFilterMethod2 = ch.next();
        textSmooth2 = nu.next();
        textSearch = nu.next();
        textBorder = nu.next();
    }
    gd.addPreviewCheckbox(pfr);
    gd.addDialogListener(this::dialogItemChanged);
    gd.setOKLabel("Save");
    gd.setCancelLabel("Close");
    gd.showDialog();
    if (imageListener != null) {
        ImagePlus.removeImageListener(imageListener);
    }
    if (!gd.wasCanceled() && !SettingsManager.writeSettings(config, SettingsManager.FLAG_SILENT)) {
        IJ.error(TITLE, "Failed to save settings");
    }
    // Reset
    imp.setOverlay(overlay);
    return DONE;
}
Also used : Choice(java.awt.Choice) ImageListener(ij.ImageListener) FitEngineConfiguration(uk.ac.sussex.gdsc.smlm.engine.FitEngineConfiguration) NonBlockingExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog) ImagePlus(ij.ImagePlus) DataFilterMethod(uk.ac.sussex.gdsc.smlm.data.config.FitProtos.DataFilterMethod) RelativeParameterProvider(uk.ac.sussex.gdsc.smlm.ij.plugins.PeakFit.RelativeParameterProvider) ImageAdapter(uk.ac.sussex.gdsc.core.ij.ImageAdapter) TextField(java.awt.TextField) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)

Aggregations

TextField (java.awt.TextField)55 Checkbox (java.awt.Checkbox)21 Choice (java.awt.Choice)21 Label (java.awt.Label)18 Panel (java.awt.Panel)17 Button (java.awt.Button)13 GenericDialog (ij.gui.GenericDialog)11 GridBagConstraints (java.awt.GridBagConstraints)11 GridBagLayout (java.awt.GridBagLayout)11 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)10 Color (java.awt.Color)9 Component (java.awt.Component)8 Vector (java.util.Vector)8 BorderLayout (java.awt.BorderLayout)6 FlowLayout (java.awt.FlowLayout)6 Dimension (java.awt.Dimension)5 Frame (java.awt.Frame)5 Insets (java.awt.Insets)5 Point (java.awt.Point)5 JPanel (javax.swing.JPanel)5