Example usage for javax.swing JTextField isEnabled

List of usage examples for javax.swing JTextField isEnabled

Introduction

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

Prototype

public boolean isEnabled() 

Source Link

Document

Determines whether this component is enabled.

Usage

From source file:ffx.ui.ModelingPanel.java

/**
 * Create a string representing the modeling command to execute.
 *
 * @return the modeling command string.//from   w w w  . j a va 2  s.  co m
 */
private String createCommandInput() {
    StringBuilder commandLineParams = new StringBuilder(activeCommand + " ");
    // Now append command line input to a TextArea, one option per line.
    // This TextArea gets dumped to an input file.
    commandTextArea.setText("");
    int numparams = optionsTabbedPane.getTabCount();
    for (int i = 0; i < numparams; i++) {
        // A few cases require that a newLine not be generated between
        // options.
        boolean newLine = true;
        // The optionString will collect the parameters for this Option,
        // then append them to the CommandTextArea.
        StringBuilder optionString = new StringBuilder();
        JPanel optionPanel = (JPanel) optionsTabbedPane.getComponentAt(i);
        int numOptions = optionPanel.getComponentCount();
        String title = optionsTabbedPane.getTitleAt(i);
        if (title.equalsIgnoreCase("Sequence")) {
            for (int k = 0; k < acidComboBox.getItemCount(); k++) {
                if (k != 0) {
                    optionString.append("\n");
                }
                String s = (String) acidComboBox.getItemAt(k);
                s = s.substring(s.indexOf(" "), s.length()).trim();
                optionString.append(s);
            }
            // Need an extra newline for Nucleic
            if (activeCommand.equalsIgnoreCase("NUCLEIC")) {
                optionString.append("\n");
            }
        } else {
            JPanel valuePanel = (JPanel) optionPanel.getComponent(numOptions - 1);
            int numValues = valuePanel.getComponentCount();
            for (int j = 0; j < numValues; j++) {
                Component value = valuePanel.getComponent(j);
                if (value instanceof JCheckBox) {
                    JCheckBox jcbox = (JCheckBox) value;
                    if (jcbox.isSelected()) {
                        optionString.append("-");
                        optionString.append(jcbox.getName());
                        optionString.append(" ");
                        optionString.append(jcbox.getText());
                    }
                } else if (value instanceof JTextField) {
                    JTextField jtfield = (JTextField) value;
                    optionString.append("-");
                    optionString.append(jtfield.getName());
                    optionString.append(" ");
                    optionString.append(jtfield.getText());
                } else if (value instanceof JComboBox) {
                    JComboBox jcb = (JComboBox) value;
                    Object object = jcb.getSelectedItem();
                    if (object instanceof FFXSystem) {
                        FFXSystem system = (FFXSystem) object;
                        File file = system.getFile();
                        if (file != null) {
                            String absolutePath = file.getAbsolutePath();
                            if (absolutePath.endsWith("xyz")) {
                                absolutePath = absolutePath + "_1";
                            }
                            optionString.append(absolutePath);
                        }
                    }
                } else if (value instanceof JRadioButton) {
                    JRadioButton jrbutton = (JRadioButton) value;
                    if (jrbutton.isSelected()) {
                        if (!jrbutton.getText().equalsIgnoreCase("NONE")) {
                            optionString.append("-");
                            optionString.append(jrbutton.getName());
                            optionString.append(" ");
                            optionString.append(jrbutton.getText());
                        }
                        if (title.equalsIgnoreCase("C-CAP")) {
                            optionString.append("\n");
                        }
                    }
                }
            }
            // Handle Conditional Options
            if (optionPanel.getComponentCount() == 3) {
                valuePanel = (JPanel) optionPanel.getComponent(1);
                // JLabel conditionalLabel = (JLabel)
                // valuePanel.getComponent(0);
                JTextField jtf = (JTextField) valuePanel.getComponent(1);
                if (jtf.isEnabled()) {
                    String conditionalInput = jtf.getText();
                    // Post-Process the Input into Atom Pairs
                    String postProcess = jtf.getName();
                    if (postProcess != null && postProcess.equalsIgnoreCase("ATOMPAIRS")) {
                        String tokens[] = conditionalInput.split(" +");
                        StringBuilder atomPairs = new StringBuilder();
                        int atomNumber = 0;
                        for (String token : tokens) {
                            atomPairs.append(token);
                            if (atomNumber++ % 2 == 0) {
                                atomPairs.append(" ");
                            } else {
                                atomPairs.append("\n");
                            }
                        }
                        conditionalInput = atomPairs.toString();
                    }
                    // Append a newline to "enter" the option string.
                    // Append "conditional" input.
                    optionString.append("\n").append(conditionalInput);
                }
            }
        }
        if (optionString.length() > 0) {
            commandTextArea.append(optionString.toString());
            if (newLine) {
                commandTextArea.append("\n");
            }
        }
    }
    String commandInput = commandTextArea.getText();
    if (commandInput != null && !commandInput.trim().equalsIgnoreCase("")) {
        commandLineParams.append(commandInput);
    }

    // The final token on the command line is the structure file name, except
    // for protein and nucleic.
    if (!activeCommand.equalsIgnoreCase("Protein") && !activeCommand.equalsIgnoreCase("Nucleic")) {
        File file = activeSystem.getFile();
        if (file != null) {
            String name = file.getName();
            commandLineParams.append(name);
            commandLineParams.append(" ");
        } else {
            return null;
        }
    }

    return commandLineParams.toString();
}

From source file:org.codinjutsu.tools.jenkins.view.validator.NotNullValidator.java

public void validate(JTextField component) throws ConfigurationException {
    if (component.isEnabled()) { //TODO a revoir
        String value = component.getText();
        if (StringUtils.isEmpty(value)) {
            throw new ConfigurationException(String.format("'%s' must be set", component.getName()));
        }/*from  w w  w  .j av  a2 s.  co  m*/
    }
}

From source file:org.codinjutsu.tools.jenkins.view.validator.PositiveIntegerValidator.java

public void validate(JTextField component) throws ConfigurationException {
    String value = component.getText();
    if (component.isEnabled() && StringUtils.isNotEmpty(value)) { //TODO A revoir
        try {// w ww. jav a  2s .  c om
            int intValue = Integer.parseInt(value);
            if (intValue < 0)
                throw new ConfigurationException(String.format("'%s' is not a positive integer", value));
        } catch (NumberFormatException ex) {
            throw new ConfigurationException(String.format("'%s' is not a positive integer", value));
        }
    }
}

From source file:org.codinjutsu.tools.jenkins.view.validator.StrictPositiveIntegerValidator.java

public void validate(JTextField component) throws ConfigurationException {
    String value = component.getText();
    if (component.isEnabled() && StringUtils.isNotEmpty(value)) { //TODO A revoir
        try {// w  ww .  ja  v a 2s .  c o  m
            int intValue = Integer.parseInt(value);
            if (intValue <= 0) {
                throw new NumberFormatException();
            }
        } catch (NumberFormatException ex) {
            throw new ConfigurationException(String.format("'%s' is not a positive integer", value));
        }
    }
}