Example usage for javax.swing JTextField setMinimumSize

List of usage examples for javax.swing JTextField setMinimumSize

Introduction

In this page you can find the example usage for javax.swing JTextField setMinimumSize.

Prototype

@BeanProperty(description = "The minimum size of the component.")
public void setMinimumSize(Dimension minimumSize) 

Source Link

Document

Sets the minimum size of this component to a constant value.

Usage

From source file:Applet.EmbeddedChart.java

public synchronized void updateInfo(String[] legends, List<double[][]> yVals, boolean gofr) {
    removeAll();//from w w w  .  ja va2s .c om
    GridBagLayout gbl = new GridBagLayout();
    gbl.columnWidths = new int[] { 10, 0, 0 };
    gbl.rowHeights = new int[] { 0, 0, 0 };
    gbl.columnWeights = new double[] { 0.0, 1.0, 1.0 };
    gbl.rowWeights = new double[] { 1.0, 1.0, 0.0 };
    setLayout(gbl);

    this.legends = legends;
    this.yvals = yVals;
    this.gofr = gofr;

    XYDataset dataset = createDataset(gofr, legends, yVals);
    JFreeChart chart = createChart(dataset, title, gofr);
    chartPanel = new ChartPanel(chart);
    chartPanel.setMinimumDrawWidth(0);
    chartPanel.setMinimumDrawHeight(0);
    chartPanel.setMaximumDrawWidth(2000);
    chartPanel.setMaximumDrawHeight(2000);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    chartPanel.getChart().setBackgroundPaint(null);
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.gridwidth = 2;
    gbc.gridheight = 2;
    gbc.fill = GridBagConstraints.BOTH;
    add(chartPanel, gbc);

    GridBagConstraints gbcX1 = new GridBagConstraints();
    GridBagConstraints gbcX2 = new GridBagConstraints();
    GridBagConstraints gbcY1 = new GridBagConstraints();
    GridBagConstraints gbcY2 = new GridBagConstraints();
    GridBagConstraints gbcButton = new GridBagConstraints();
    final NumberAxis domain = (NumberAxis) ((XYPlot) chartPanel.getChart().getPlot()).getDomainAxis();
    final NumberAxis range = (NumberAxis) ((XYPlot) chartPanel.getChart().getPlot()).getRangeAxis();

    if (gofr) {
        domain.setLowerBound(over.gr_xMin);
        domain.setUpperBound(over.gr_xMax);
        range.setLowerBound(over.gr_yMin);
        range.setUpperBound(over.gr_yMax);
    } else {
        domain.setLowerBound(over.pot_xMin);
        domain.setUpperBound(over.pot_xMax);
        range.setLowerBound(over.pot_yMin);
        range.setUpperBound(over.pot_yMax);
    }

    gbcX2.gridx = 2;
    gbcX2.gridy = 2;
    gbcX2.anchor = GridBagConstraints.EAST;
    gbcX2.insets = new Insets(0, 0, 0, 12);
    final JTextField xMax = new JTextField(5);
    xMax.setMinimumSize(new Dimension(50, 20));
    xMax.setText("" + domain.getUpperBound());
    // gbcX2.fill = GridBagConstraints.VERTICAL;
    add(xMax, gbcX2);
    final boolean gr = gofr;
    xMax.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            if (gr) {
                over.gr_xMax = Double.parseDouble(xMax.getText());
                domain.setRange(over.gr_xMin, over.gr_xMax);
            } else {
                over.pot_xMax = Double.parseDouble(xMax.getText());
                domain.setRange(over.pot_xMin, over.pot_xMax);
            }
        }

        @Override
        public void focusGained(FocusEvent e) {
        }
    });

    gbcX1.gridx = 1;
    gbcX1.gridy = 2;
    gbcX1.anchor = GridBagConstraints.WEST;
    gbcX1.insets = new Insets(0, 70, 0, 0);
    final JTextField xMin = new JTextField(5);
    xMin.setMinimumSize(new Dimension(50, 20));
    xMin.setText("" + domain.getLowerBound());
    // gbcX1.fill = GridBagConstraints.VERTICAL;
    add(xMin, gbcX1);
    xMin.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            x1 = Double.parseDouble(xMin.getText());
            domain.setRange(x1, x2);
            if (gr) {
                over.gr_xMin = Double.parseDouble(xMin.getText());
                domain.setRange(over.gr_xMin, over.gr_xMax);
            } else {
                over.pot_xMin = Double.parseDouble(xMin.getText());
                domain.setRange(over.pot_xMin, over.pot_xMax);
            }
        }

        @Override
        public void focusGained(FocusEvent e) {
        }
    });

    gbcY1.gridx = 0;
    gbcY1.gridy = 1;
    gbcY1.anchor = GridBagConstraints.SOUTH;
    gbcY1.insets = new Insets(0, 0, 45, 0);
    final JTextField yMin = new JTextField(5);
    yMin.setMinimumSize(new Dimension(50, 20));
    yMin.setText("" + range.getLowerBound());
    // gbcY1.fill = GridBagConstraints.BOTH;
    add(yMin, gbcY1);
    yMin.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            if (gr) {
                over.gr_yMin = Double.parseDouble(yMin.getText());
                range.setRange(over.gr_yMin, over.gr_yMax);
            } else {
                over.pot_yMin = Double.parseDouble(yMin.getText());
                range.setRange(over.pot_yMin, over.pot_yMax);
            }

        }

        @Override
        public void focusGained(FocusEvent e) {
        }
    });

    gbcY2.gridx = 0;
    gbcY2.gridy = 0;
    gbcY2.anchor = GridBagConstraints.NORTH;
    gbcY2.insets = new Insets(10, 0, 0, 0);
    final JTextField yMax = new JTextField(5);
    yMax.setMinimumSize(new Dimension(50, 20));
    yMax.setText("" + range.getUpperBound());
    // gbcY2.fill = GridBagConstraints.BOTH;
    add(yMax, gbcY2);
    yMax.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            if (gr) {
                over.gr_yMax = Double.parseDouble(yMax.getText());
                range.setRange(over.gr_yMin, over.gr_yMax);
            } else {
                over.pot_yMax = Double.parseDouble(yMax.getText());
                range.setRange(over.pot_yMin, over.pot_yMax);
            }
        }

        @Override
        public void focusGained(FocusEvent e) {
        }
    });

}

From source file:org.languagetool.gui.ConfigurationDialog.java

private void createOfficeElements(GridBagConstraints cons, JPanel portPanel) {
    int numParaCheck = config.getNumParasToCheck();
    JRadioButton[] radioButtons = new JRadioButton[3];
    ButtonGroup numParaGroup = new ButtonGroup();
    radioButtons[0] = new JRadioButton(Tools.getLabel(messages.getString("guiCheckOnlyParagraph")));
    radioButtons[0].setActionCommand("ParagraphCheck");

    radioButtons[1] = new JRadioButton(Tools.getLabel(messages.getString("guiCheckFullText")));
    radioButtons[1].setActionCommand("FullTextCheck");

    radioButtons[2] = new JRadioButton(Tools.getLabel(messages.getString("guiCheckNumParagraphs")));
    radioButtons[2].setActionCommand("NParagraphCheck");
    radioButtons[2].setSelected(true);//from  w  w w.ja  va 2  s .c  o  m

    JTextField numParaField = new JTextField(Integer.toString(5), 2);
    numParaField.setEnabled(radioButtons[2].isSelected());
    numParaField.setMinimumSize(new Dimension(30, 25));

    for (int i = 0; i < 3; i++) {
        numParaGroup.add(radioButtons[i]);
    }

    if (numParaCheck == 0) {
        radioButtons[0].setSelected(true);
        numParaField.setEnabled(false);
    } else if (numParaCheck < 0) {
        radioButtons[1].setSelected(true);
        numParaField.setEnabled(false);
    } else {
        radioButtons[2].setSelected(true);
        numParaField.setText(Integer.toString(numParaCheck));
        numParaField.setEnabled(true);
    }

    radioButtons[0].addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            numParaField.setEnabled(false);
            config.setNumParasToCheck(0);
        }
    });

    radioButtons[1].addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            numParaField.setEnabled(false);
            config.setNumParasToCheck(-1);
        }
    });

    radioButtons[2].addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int numParaCheck = Integer.parseInt(numParaField.getText());
            if (numParaCheck < 1)
                numParaCheck = 1;
            else if (numParaCheck > 99)
                numParaCheck = 99;
            config.setNumParasToCheck(numParaCheck);
            numParaField.setForeground(Color.BLACK);
            numParaField.setText(Integer.toString(numParaCheck));
            numParaField.setEnabled(true);
        }
    });

    numParaField.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            try {
                int numParaCheck = Integer.parseInt(numParaField.getText());
                if (numParaCheck > 0 && numParaCheck < 99) {
                    numParaField.setForeground(Color.BLACK);
                    config.setNumParasToCheck(numParaCheck);
                } else {
                    numParaField.setForeground(Color.RED);
                }
            } catch (NumberFormatException ex) {
                numParaField.setForeground(Color.RED);
            }
        }
    });

    JLabel textChangedLabel = new JLabel(Tools.getLabel(messages.getString("guiTextChangeLabel")));
    cons.gridy++;
    portPanel.add(textChangedLabel, cons);

    cons.gridy++;
    cons.insets = new Insets(0, 30, 0, 0);
    for (int i = 0; i < 3; i++) {
        portPanel.add(radioButtons[i], cons);
        if (i < 2)
            cons.gridy++;
    }
    cons.gridx = 1;
    portPanel.add(numParaField, cons);

    JCheckBox noMultiResetbox = new JCheckBox(Tools.getLabel(messages.getString("guiNoMultiReset")));
    noMultiResetbox.setSelected(config.isNoMultiReset());
    noMultiResetbox.setEnabled(config.isResetCheck());
    noMultiResetbox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            config.setNoMultiReset(noMultiResetbox.isSelected());
        }
    });

    JCheckBox resetCheckbox = new JCheckBox(Tools.getLabel(messages.getString("guiDoResetCheck")));
    resetCheckbox.setSelected(config.isResetCheck());
    resetCheckbox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            config.setDoResetCheck(resetCheckbox.isSelected());
            noMultiResetbox.setEnabled(resetCheckbox.isSelected());
        }
    });
    cons.insets = new Insets(0, 4, 0, 0);
    cons.gridx = 0;
    //    JLabel dummyLabel = new JLabel(" ");
    //    cons.gridy++;
    //    portPanel.add(dummyLabel, cons);
    cons.gridy++;
    portPanel.add(resetCheckbox, cons);

    cons.insets = new Insets(0, 30, 0, 0);
    cons.gridx = 0;
    cons.gridy++;
    portPanel.add(noMultiResetbox, cons);

    JCheckBox fullTextCheckAtFirstBox = new JCheckBox(
            Tools.getLabel(messages.getString("guiCheckFullTextAtFirst")));
    fullTextCheckAtFirstBox.setSelected(config.doFullCheckAtFirst());
    fullTextCheckAtFirstBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            config.setFullCheckAtFirst(fullTextCheckAtFirstBox.isSelected());
        }
    });
    cons.insets = new Insets(0, 4, 0, 0);
    cons.gridx = 0;
    //    cons.gridy++;
    //    JLabel dummyLabel2 = new JLabel(" ");
    //    portPanel.add(dummyLabel2, cons);
    cons.gridy++;
    portPanel.add(fullTextCheckAtFirstBox, cons);

    JCheckBox isMultiThreadBox = new JCheckBox(Tools.getLabel(messages.getString("guiIsMultiThread")));
    isMultiThreadBox.setSelected(config.isMultiThread());
    isMultiThreadBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            config.setMultiThreadLO(isMultiThreadBox.isSelected());
        }
    });
    cons.gridy++;
    JLabel dummyLabel3 = new JLabel(" ");
    portPanel.add(dummyLabel3, cons);
    cons.gridy++;
    portPanel.add(isMultiThreadBox, cons);

}

From source file:org.languagetool.gui.ConfigurationDialog.java

private JPanel getSpecialRuleValuePanel() {
    JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    GridBagConstraints cons = new GridBagConstraints();
    cons.gridx = 0;//from  w w w. j  av a2s  .  c o  m
    cons.gridy = 0;
    cons.weightx = 0.0f;
    cons.anchor = GridBagConstraints.WEST;

    List<JCheckBox> ruleCheckboxes = new ArrayList<JCheckBox>();
    List<JLabel> ruleLabels = new ArrayList<JLabel>();
    List<JTextField> ruleValueFields = new ArrayList<JTextField>();

    for (int i = 0; i < configurableRules.size(); i++) {
        Rule rule = configurableRules.get(i);
        JCheckBox ruleCheckbox = new JCheckBox(rule.getDescription());
        ruleCheckboxes.add(ruleCheckbox);
        ruleCheckbox.setSelected(getEnabledState(rule));
        cons.insets = new Insets(3, 0, 0, 0);
        panel.add(ruleCheckbox, cons);

        cons.insets = new Insets(0, 24, 0, 0);
        cons.gridy++;
        JLabel ruleLabel = new JLabel(rule.getConfigureText());
        ruleLabels.add(ruleLabel);
        ruleLabel.setEnabled(ruleCheckbox.isSelected());
        panel.add(ruleLabel, cons);

        cons.gridx++;
        int value = config.getConfigurableValue(rule.getId());
        if (config.getConfigurableValue(rule.getId()) < 0) {
            value = rule.getDefaultValue();
        }
        JTextField ruleValueField = new JTextField(Integer.toString(value), 2);
        ruleValueFields.add(ruleValueField);
        ruleValueField.setEnabled(ruleCheckbox.isSelected());
        ruleValueField.setMinimumSize(new Dimension(35, 25)); // without this the box is just a few pixels small, but why?
        panel.add(ruleValueField, cons);

        ruleCheckbox.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(@SuppressWarnings("unused") ActionEvent e) {
                ruleValueField.setEnabled(ruleCheckbox.isSelected());
                ruleLabel.setEnabled(ruleCheckbox.isSelected());
                if (ruleCheckbox.isSelected()) {
                    config.getEnabledRuleIds().add(rule.getId());
                    config.getDisabledRuleIds().remove(rule.getId());
                } else {
                    config.getEnabledRuleIds().remove(rule.getId());
                    config.getDisabledRuleIds().add(rule.getId());
                }
            }
        });

        ruleValueField.getDocument().addDocumentListener(new DocumentListener() {
            @Override
            public void insertUpdate(DocumentEvent e) {
                changedUpdate(e);
            }

            @Override
            public void removeUpdate(DocumentEvent e) {
                changedUpdate(e);
            }

            @Override
            public void changedUpdate(DocumentEvent e) {
                try {
                    int num = Integer.parseInt(ruleValueField.getText());
                    if (num < rule.getMinConfigurableValue()) {
                        num = rule.getMinConfigurableValue();
                        ruleValueField.setForeground(Color.RED);
                    } else if (num > rule.getMaxConfigurableValue()) {
                        num = rule.getMaxConfigurableValue();
                        ruleValueField.setForeground(Color.RED);
                    } else {
                        ruleValueField.setForeground(null);
                    }
                    config.setConfigurableValue(rule.getId(), num);
                } catch (Exception ex) {
                    ruleValueField.setForeground(Color.RED);
                }
            }
        });

        cons.gridx = 0;
        cons.gridy++;

    }
    return panel;
}

From source file:org.ut.biolab.medsavant.client.query.view.NumberSearchConditionEditorView.java

@Override
public void loadViewFromSearchConditionParameters(String encoding) throws ConditionRestorationException {

    double[] selectedValues;
    if (encoding == null) {
        selectedValues = null;//from  ww w.j  a  v a  2  s.  c o  m
    } else {
        selectedValues = NumericConditionEncoder.unencodeConditions(encoding);
    }

    final double[] extremeValues = generator.getExtremeNumericValues();
    this.removeAll();

    if (extremeValues == null || (extremeValues[0] == 0 && extremeValues[1] == 0)) {
        JPanel p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
        p.add(Box.createHorizontalGlue());
        p.add(new JLabel("<html>All values are blank for this condition.</html>"));
        p.add(Box.createHorizontalGlue());
        this.add(p);
        return;
    }

    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    JPanel p = ViewUtil.getClearPanel();
    ViewUtil.applyVerticalBoxLayout(p);

    JPanel labelPanel = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(labelPanel);
    labelPanel.add(Box.createHorizontalGlue());
    labelPanel.add(new JLabel("Filtering variants where " + item.getName() + ": "));
    labelPanel.add(Box.createHorizontalGlue());
    ButtonGroup group = new ButtonGroup();
    //JRadioButton isButton = new JRadioButton("is within the following range:");
    //JRadioButton nullButton = new JRadioButton("is missing");
    //group.add(isButton);
    //group.add(nullButton);

    final JCheckBox nullButton = new JCheckBox("include missing values");

    JPanel bp = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(bp);
    p.add(labelPanel);
    p.add(bp);
    add(p);
    final DecimalRangeSlider slider = new DecimalRangeSlider();

    slider.setMajorTickSpacing(5);
    slider.setMinorTickSpacing(1);

    final JTextField fromBox = new JTextField();
    final JTextField toBox = new JTextField();

    nullButton.setSelected(NumericConditionEncoder.encodesNull(encoding));

    nullButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            encodeValue(ViewUtil.parseDoubleFromFormattedString(fromBox.getText()),
                    ViewUtil.parseDoubleFromFormattedString(toBox.getText()), extremeValues[0],
                    extremeValues[1], nullButton.isSelected());
        }
    });

    fromBox.setMaximumSize(new Dimension(10000, 24));
    toBox.setMaximumSize(new Dimension(10000, 24));
    fromBox.setPreferredSize(new Dimension(FROM_TO_WIDTH, 24));
    toBox.setPreferredSize(new Dimension(FROM_TO_WIDTH, 24));
    fromBox.setMinimumSize(new Dimension(FROM_TO_WIDTH, 24));
    toBox.setMinimumSize(new Dimension(FROM_TO_WIDTH, 24));
    fromBox.setHorizontalAlignment(JTextField.RIGHT);
    toBox.setHorizontalAlignment(JTextField.RIGHT);

    final JLabel fromLabel = new JLabel();
    final JLabel toLabel = new JLabel();

    ViewUtil.makeMini(fromLabel);
    ViewUtil.makeMini(toLabel);

    JPanel fromToContainer = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(fromToContainer);
    fromToContainer.add(Box.createHorizontalGlue());
    fromToContainer.add(fromBox);
    fromToContainer.add(new JLabel(" - "));
    fromToContainer.add(toBox);
    fromToContainer.add(Box.createHorizontalGlue());

    JPanel minMaxContainer = ViewUtil.getClearPanel();
    minMaxContainer.setLayout(new BoxLayout(minMaxContainer, BoxLayout.X_AXIS));

    JPanel sliderContainer = ViewUtil.getClearPanel();
    sliderContainer.setLayout(new BoxLayout(sliderContainer, BoxLayout.Y_AXIS));
    sliderContainer.add(slider);

    JPanel nullValueContainer = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(nullValueContainer);
    nullValueContainer.add(Box.createHorizontalGlue());
    nullValueContainer.add(nullButton);
    nullButton.setBackground(nullValueContainer.getBackground()); //fixes a windows issue.
    nullValueContainer.add(Box.createHorizontalGlue());

    JPanel labelContainer = ViewUtil.getClearPanel();
    labelContainer.setLayout(new BoxLayout(labelContainer, BoxLayout.X_AXIS));
    labelContainer.add(fromLabel);
    labelContainer.add(Box.createHorizontalGlue());
    labelContainer.add(toLabel);
    sliderContainer.add(labelContainer);
    minMaxContainer.add(Box.createHorizontalGlue());
    minMaxContainer.add(sliderContainer);
    minMaxContainer.add(Box.createHorizontalGlue());

    add(fromToContainer);
    add(minMaxContainer);
    add(nullValueContainer);
    add(Box.createVerticalBox());

    slider.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (slider.isEnabled()) {
                fromBox.setText(ViewUtil.numToString(slider.getLow()));
                toBox.setText(ViewUtil.numToString(slider.getHigh()));
                encodeValue(ViewUtil.parseDoubleFromFormattedString(fromBox.getText()),
                        ViewUtil.parseDoubleFromFormattedString(toBox.getText()), extremeValues[0],
                        extremeValues[1], nullButton.isSelected());
            }
        }
    });

    final KeyListener keyListener = new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            int key = e.getKeyCode();
            if (key == KeyEvent.VK_ENTER) {
                Range selectedRage = new Range(getNumber(fromBox.getText()), getNumber(toBox.getText()));
                setSelectedValues(slider, fromBox, toBox, selectedRage);
            }
        }

        private double getNumber(String s) {
            try {
                return Double.parseDouble(s.replaceAll(",", ""));
            } catch (NumberFormatException ignored) {
                return 0;
            }
        }
    };

    CaretListener caretListener = new CaretListener() {
        @Override
        public void caretUpdate(CaretEvent ce) {
            if (!isAdjustingSlider) {
                try {
                    encodeValue(ViewUtil.parseDoubleFromFormattedString(fromBox.getText()),
                            ViewUtil.parseDoubleFromFormattedString(toBox.getText()), extremeValues[0],
                            extremeValues[1], nullButton.isSelected());
                } catch (Exception e) {
                }
            }
        }
    };

    fromBox.addKeyListener(keyListener);

    toBox.addKeyListener(keyListener);

    fromBox.addCaretListener(caretListener);

    toBox.addCaretListener(caretListener);

    slider.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            isAdjustingSlider = true;
            fromBox.setText(ViewUtil.numToString(slider.getLow()));
            toBox.setText(ViewUtil.numToString(slider.getHigh()));
            isAdjustingSlider = false;
        }
    });

    JPanel bottomContainer = new JPanel();

    bottomContainer.setLayout(new BoxLayout(bottomContainer, BoxLayout.X_AXIS));

    bottomContainer.add(Box.createHorizontalGlue());

    add(bottomContainer);

    setExtremeValues(slider, fromLabel, toLabel, fromBox, toBox, 0,
            new Range(extremeValues[0], extremeValues[1]));

    if (encoding != null) {
        double[] d = NumericConditionEncoder.unencodeConditions(encoding);
        setSelectedValues(slider, fromBox, toBox, new Range(d[0], d[1]));
    }
}

From source file:org.ut.biolab.medsavant.client.variant.ImportVariantsWizard.java

private AbstractWizardPage getAddTagsPage() {
    //setup page/*from  www . j av  a  2 s.  co m*/
    final DefaultWizardPage page = new DefaultWizardPage("Add Tags") {
        @Override
        public void setupWizardButtons() {
            fireButtonEvent(ButtonEvent.HIDE_BUTTON, ButtonNames.FINISH);
            fireButtonEvent(ButtonEvent.SHOW_BUTTON, ButtonNames.BACK);
            fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.NEXT);
        }
    };

    page.addText("Variants can be filtered by tag value in the Filter section.");
    page.addText("Add tags for this set of variants:");

    final String[] patternExamples = { "<Tag Name>", "Sequencer", "Sequencer Version", "Variant Caller",
            "Variant Caller Version", "Technician" };

    locationField = new JComboBox(patternExamples);
    locationField.setEditable(true);

    final JPanel tagContainer = new JPanel();
    ViewUtil.applyVerticalBoxLayout(tagContainer);

    final JTextField valueField = new JTextField();

    final String startingValue = "<Value>";
    valueField.setText(startingValue);

    final JTextArea ta = new JTextArea();
    ta.setRows(10);
    ta.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    ta.setEditable(false);

    JLabel button = ViewUtil.createIconButton(IconFactory.getInstance().getIcon(IconFactory.StandardIcon.ADD));
    button.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {

            if (locationField.getSelectedItem().toString().isEmpty()) {
                DialogUtils.displayError("Tag cannot be empty");
                locationField.requestFocus();
                return;
            } else if (locationField.getSelectedItem().toString().equals(patternExamples[0])) {
                DialogUtils.displayError("Enter a valid tag name");
                locationField.requestFocus();
                return;
            }

            if (valueField.getText().toString().isEmpty()) {
                DialogUtils.displayError("Value cannot be empty");
                valueField.requestFocus();
                return;
            } else if (valueField.getText().equals(startingValue)) {
                DialogUtils.displayError("Enter a valid value");
                valueField.requestFocus();
                return;
            }

            VariantTag tag = new VariantTag((String) locationField.getSelectedItem(), valueField.getText());

            variantTags.add(tag);
            ta.append(tag.toString() + "\n");
            valueField.setText("");
        }
    });

    JPanel container2 = new JPanel();
    ViewUtil.clear(container2);
    ViewUtil.applyHorizontalBoxLayout(container2);
    container2.add(locationField);
    container2.add(ViewUtil.clear(new JLabel(" = ")));
    container2.add(valueField);
    container2.add(button);

    page.addComponent(container2);
    locationField.setToolTipText("Current display range");

    locationField.setPreferredSize(LOCATION_SIZE);
    locationField.setMinimumSize(LOCATION_SIZE);

    valueField.setPreferredSize(LOCATION_SIZE);
    valueField.setMinimumSize(LOCATION_SIZE);

    page.addComponent(tagContainer);

    page.addComponent(new JScrollPane(ta));

    JButton clear = new JButton("Clear");
    clear.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            variantTags.clear();
            ta.setText("");
            addDefaultTags(variantTags, ta);
        }
    });

    addDefaultTags(variantTags, ta);

    page.addComponent(ViewUtil.alignRight(clear));

    return page;

}

From source file:savant.plugin.ToolSettingsPanel.java

private void addField(ToolArgument arg, JTextField field, GridBagConstraints gbc) {
    field.addActionListener(executeListener);
    field.getDocument().addDocumentListener(new EditListener(arg));
    field.setMinimumSize(field.getPreferredSize());
    addWidget(arg, field, gbc);//from  w  ww.j a  va 2  s.c  o  m
}

From source file:savant.snp.SNPFinderPlugin.java

private void setupGUI(JPanel panel) {

    // add a toolbar
    JToolBar tb = new JToolBar();
    tb.setName("SNP Finder Toolbar");

    // add an ON/OFF checkbox
    JLabel lab_on = new JLabel("On/Off: ");
    JCheckBox cb_on = new JCheckBox();
    cb_on.setSelected(isSNPFinderOn);//from w w  w.j a v a  2 s .  c  o m

    // what to do when a user clicks the checkbox
    cb_on.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // switch the SNP finder on/off
            setIsOn(!isSNPFinderOn);
            addMessage("Turning SNP finder " + (isSNPFinderOn ? "on" : "off"));
        }
    });
    // add a  Bookmarking ON/OFF checkbox
    JLabel lab_bm = new JLabel("Add Bookmarks: ");
    JCheckBox cb_bm = new JCheckBox();
    cb_bm.setSelected(addBookmarks);

    // what to do when a user clicks the checkbox
    cb_bm.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // switch the SNP finder on/off
            setBookmarking(!addBookmarks);
            addMessage("Turning Bookmarking " + (addBookmarks ? "on" : "off"));
        }
    });

    JLabel lab_sp = new JLabel("Heterozygosity: ");
    //add snp prior textfield
    final JTextField snpPriorField = new JTextField(String.valueOf(snpPrior), 4);
    snpPriorField.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                setSNPPrior(Double.valueOf(snpPriorField.getText()));
            } catch (NumberFormatException ex) {
                snpPriorField.setText(String.valueOf(snpPrior));
            }
        }
    });
    int tfwidth = 35;
    int tfheight = 22;
    snpPriorField.setPreferredSize(new Dimension(tfwidth, tfheight));
    snpPriorField.setMaximumSize(new Dimension(tfwidth, tfheight));
    snpPriorField.setMinimumSize(new Dimension(tfwidth, tfheight));

    // add a sensitivity slider
    JLabel lab_confidence = new JLabel("Confidence: ");
    final JSlider sens_slider = new JSlider(0, 50);
    sens_slider.setValue(confidence);
    final JLabel lab_confidence_status = new JLabel("" + sens_slider.getValue());

    // what to do when a user slides the slider
    sens_slider.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            // set the snp finder's sensitivity
            lab_confidence_status.setText("" + sens_slider.getValue());
            setSensitivity(sens_slider.getValue());
        }
    });
    // don't report the new setting until the user stops sliding
    sens_slider.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            addMessage("Changed confidence to " + confidence);
        }
    });

    // add a transparency slider
    JLabel lab_trans = new JLabel("Transparency: ");
    final JSlider trans_slider = new JSlider(0, 100);
    trans_slider.setValue(transparency);
    final JLabel lab_transparency_status = new JLabel("" + trans_slider.getValue());

    // what to do when a user slides the slider
    trans_slider.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            // set the snp finder's transparency
            lab_transparency_status.setText("" + trans_slider.getValue());
            setTransparency(trans_slider.getValue());
        }
    });

    // don't report the new setting until the user stops sliding
    trans_slider.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            addMessage("Changed transparency to " + transparency);
        }
    });

    // add the components to the GUI
    panel.setLayout(new BorderLayout());
    tb.add(lab_on);
    tb.add(cb_on);
    tb.add(lab_bm);
    tb.add(cb_bm);
    tb.add(new JToolBar.Separator());
    tb.add(lab_sp);
    tb.add(snpPriorField);
    tb.add(new JToolBar.Separator());
    tb.add(lab_confidence);
    tb.add(sens_slider);
    tb.add(lab_confidence_status);

    tb.add(new JToolBar.Separator());

    tb.add(lab_trans);
    tb.add(trans_slider);
    tb.add(lab_transparency_status);

    panel.add(tb, BorderLayout.NORTH);

    // add a text area to the GUI
    info = new JTextArea();
    JScrollPane scrollPane = new JScrollPane(info);
    panel.add(scrollPane, BorderLayout.CENTER);

}