Example usage for javax.swing JTextField getText

List of usage examples for javax.swing JTextField getText

Introduction

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

Prototype

public String getText() 

Source Link

Document

Returns the text contained in this TextComponent.

Usage

From source file:op.tools.SYSTools.java

public static void markAllTxt(JTextField jtf) {
    jtf.setSelectionStart(0);
    jtf.setSelectionEnd(jtf.getText().length());
}

From source file:org.accada.hal.impl.sim.GraphicSimulator.java

/**
 * shows the dialog menu to add a new antenna
 *//*ww w. ja  va2  s .  com*/
private void showAddAntennaDialog() {
    Point pos = new Point();
    pos.x = jLayeredPane.getLocationOnScreen().x
            + (jLayeredPane.getWidth() - getProperty("DialogWindowWidth")) / 2;
    pos.y = jLayeredPane.getLocationOnScreen().y
            + (jLayeredPane.getHeight() - getProperty("DialogWindowHeight")) / 2;

    if (newAntennaDialog == null) {
        newAntennaDialog = new JDialog(this, guiTextConfig.getString("AddNewAntennaDialogTitle"), true);
        newAntennaDialog.setSize(getProperty("DialogWindowWidth"), getProperty("DialogWindowHeight"));
        newAntennaDialog.setLayout(new BorderLayout());

        // input fields
        JLabel idLabel = new JLabel(guiTextConfig.getString("AntennaIdLabel") + ": ");
        final JTextField idField = new JTextField();
        JPanel inputFields = new JPanel();
        inputFields.setLayout(new GridLayout(2, 2));
        inputFields.add(idLabel);
        inputFields.add(idField);

        // cancel button
        JButton cancelButton = new JButton(guiTextConfig.getString("CancelButton"));
        cancelButton.addMouseListener(new MouseAdapter() {
            public void mouseReleased(MouseEvent e) {
                newAntennaDialog.setVisible(false);
                idField.setText("");
            }
        });

        // add button
        JButton addButton = new JButton(guiTextConfig.getString("AddButton"));
        addButton.addMouseListener(new MouseAdapter() {
            public void mouseReleased(MouseEvent e) {
                newAntennaDialog.setVisible(false);
                createNewAntenna(idField.getText());
                idField.setText("");
            }
        });

        // buttons panel
        JPanel buttons = new JPanel();
        buttons.add(addButton);
        buttons.add(cancelButton);

        newAntennaDialog.add(inputFields, BorderLayout.CENTER);
        newAntennaDialog.add(buttons, BorderLayout.SOUTH);
        newAntennaDialog.getRootPane().setDefaultButton(addButton);
    }
    newAntennaDialog.setLocation(pos);
    newAntennaDialog.setVisible(true);
}

From source file:org.accada.reader.hal.impl.sim.GraphicSimulator.java

/**
 * shows the dialog menu to add a new antenna
 *///from w  w  w  .  j ava  2  s.c  om
private void showAddAntennaDialog() {
    Point pos = new Point();
    pos.x = jLayeredPane.getLocationOnScreen().x
            + (jLayeredPane.getWidth() - getProperty("DialogWindowWidth")) / 2;
    pos.y = jLayeredPane.getLocationOnScreen().y
            + (jLayeredPane.getHeight() - getProperty("DialogWindowHeight")) / 2;

    if (newAntennaDialog == null) {
        newAntennaDialog = new JDialog(this, guiText.getString("AddNewAntennaDialogTitle"), true);
        newAntennaDialog.setSize(getProperty("DialogWindowWidth"), getProperty("DialogWindowHeight"));
        newAntennaDialog.setLayout(new BorderLayout());

        // input fields
        JLabel idLabel = new JLabel(guiText.getString("AntennaIdLabel") + ": ");
        final JTextField idField = new JTextField();
        JPanel inputFields = new JPanel();
        inputFields.setLayout(new GridLayout(2, 2));
        inputFields.add(idLabel);
        inputFields.add(idField);

        // cancel button
        JButton cancelButton = new JButton(guiText.getString("CancelButton"));
        cancelButton.addMouseListener(new MouseAdapter() {
            public void mouseReleased(MouseEvent e) {
                newAntennaDialog.setVisible(false);
                idField.setText("");
            }
        });

        // add button
        JButton addButton = new JButton(guiText.getString("AddButton"));
        addButton.addMouseListener(new MouseAdapter() {
            public void mouseReleased(MouseEvent e) {
                newAntennaDialog.setVisible(false);
                createNewAntenna(idField.getText());
                idField.setText("");
            }
        });

        // buttons panel
        JPanel buttons = new JPanel();
        buttons.add(addButton);
        buttons.add(cancelButton);

        newAntennaDialog.add(inputFields, BorderLayout.CENTER);
        newAntennaDialog.add(buttons, BorderLayout.SOUTH);
        newAntennaDialog.getRootPane().setDefaultButton(addButton);
    }
    newAntennaDialog.setLocation(pos);
    newAntennaDialog.setVisible(true);
}

From source file:org.apache.cayenne.modeler.dialog.codegen.GeneratorController.java

/**
 * An action method that pops up a file chooser dialog to pick the
 * generation directory.//from   ww  w.  j  a v  a2 s.co  m
 */
public void selectOutputFolderAction() {

    JTextField outputFolder = ((GeneratorControllerPanel) getView()).getOutputFolder();

    String currentDir = outputFolder.getText();

    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setDialogType(JFileChooser.OPEN_DIALOG);

    // guess start directory
    if (!Util.isEmptyString(currentDir)) {
        chooser.setCurrentDirectory(new File(currentDir));
    } else {
        FSPath lastDir = Application.getInstance().getFrameController().getLastDirectory();
        lastDir.updateChooser(chooser);
    }

    int result = chooser.showOpenDialog(getView());
    if (result == JFileChooser.APPROVE_OPTION) {
        File selected = chooser.getSelectedFile();

        // update model
        String path = selected.getAbsolutePath();
        outputFolder.setText(path);
        setOutputPath(path);
    }
}

From source file:org.apache.syncope.ide.netbeans.view.ServerDetailsView.java

private List<String> validate(final JTextField schemeTxt, final JTextField hostTxt, final JTextField portTxt,
        final JTextField userNameTxt) {

    List<String> res = new ArrayList<>();

    if (StringUtils.isBlank(schemeTxt.getText()) || (!StringUtils.equals(schemeTxt.getText(), "http")
            && !StringUtils.equals(schemeTxt.getText(), "https"))) {
        res.add("scheme");
    }//from   ww w .j  ava  2  s .  c om
    if (StringUtils.isBlank(hostTxt.getText())) {
        res.add("host");
    }
    if (StringUtils.isBlank(portTxt.getText()) || !StringUtils.isNumeric(portTxt.getText())) {
        res.add("port");
    }
    if (StringUtils.isBlank(userNameTxt.getText())) {
        res.add("username");
    }
    return res;
}

From source file:org.broad.igv.ui.action.SetTrackHeightMenuAction.java

/**
 * Method description/*from  ww w.j a v a 2 s . com*/
 */
final public void doSetTrackHeight() {

    boolean doRefresh = false;
    try {
        JPanel container = new JPanel();
        JLabel trackHeightLabel = new JLabel("Track Height (pixels)");
        JTextField trackHeightField = new JTextField();
        Dimension preferredSize = trackHeightField.getPreferredSize();
        trackHeightField.setPreferredSize(new Dimension(50, (int) preferredSize.getHeight()));
        container.add(trackHeightLabel);
        container.add(trackHeightField);

        int repTrackHeight = getRepresentativeTrackHeight();
        trackHeightField.setText(String.valueOf(repTrackHeight));

        int status = JOptionPane.showConfirmDialog(mainFrame.getMainFrame(), container, "Set Track Height",
                JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null);

        if ((status == JOptionPane.CANCEL_OPTION) || (status == JOptionPane.CLOSED_OPTION)) {
            return;
        }

        try {
            int newTrackHeight = Integer.parseInt(trackHeightField.getText().trim());
            IGV.getInstance().setAllTrackHeights(newTrackHeight);
            lastTrackHeight = newTrackHeight;
            doRefresh = true;
        } catch (NumberFormatException numberFormatException) {
            JOptionPane.showMessageDialog(mainFrame.getMainFrame(), "Track height must be an integer number.");
        }

    } finally {

        // Refresh view
        if (doRefresh) {

            // Update the state of the current tracks for drawing purposes

            mainFrame.doRefresh();
        }
        mainFrame.resetStatusMessage();
    }

}

From source file:org.codinjutsu.tools.jenkins.view.BuildParamDialog.java

private Map<String, String> getParamValueMap() {//TODO transformer en visiteur
    HashMap<String, String> valueByNameMap = new HashMap<String, String>();
    for (Map.Entry<JobParameter, JComponent> inputFieldByParameter : inputFieldByParameterMap.entrySet()) {
        JobParameter jobParameter = inputFieldByParameter.getKey();
        String name = jobParameter.getName();
        JobParameter.JobParameterType jobParameterType = jobParameter.getJobParameterType();

        JComponent inputField = inputFieldByParameter.getValue();

        if (JobParameter.JobParameterType.ChoiceParameterDefinition.equals(jobParameterType)) {
            JComboBox comboBox = (JComboBox) inputField;
            valueByNameMap.put(name, String.valueOf(comboBox.getSelectedItem()));
        } else if (JobParameter.JobParameterType.BooleanParameterDefinition.equals(jobParameterType)) {
            JCheckBox checkBox = (JCheckBox) inputField;
            valueByNameMap.put(name, Boolean.toString(checkBox.isSelected()));
        } else if (JobParameter.JobParameterType.StringParameterDefinition.equals(jobParameterType)) {
            JTextField textField = (JTextField) inputField;
            valueByNameMap.put(name, textField.getText());
        }/* w w  w.j  a v  a2s . com*/
    }
    return valueByNameMap;
}

From source file:org.codinjutsu.tools.jenkins.view.ConfigurationPanel.java

public ConfigurationPanel(final Project project) {

    serverUrl.setName("serverUrl");
    buildDelay.setName("buildDelay");
    jobRefreshPeriod.setName("jobRefreshPeriod");
    rssRefreshPeriod.setName("rssRefreshPeriod");
    username.setName("_username_");

    passwordField.setName("passwordFile");
    crumbDataField.setName("crumbDataFile");

    testConnexionButton.setName("testConnexionButton");
    connectionStatusLabel.setName("connectionStatusLabel");

    successOrStableCheckBox.setName("successOrStableCheckBox");
    unstableOrFailCheckBox.setName("unstableOrFailCheckBox");
    abortedCheckBox.setName("abortedCheckBox");

    rssStatusFilterPanel.setBorder(IdeBorderFactory.createTitledBorder("Event Log Settings", true));

    debugPanel.setVisible(false);//from   w w  w .  j  a  v a2  s.co m

    initDebugTextPane();

    buildDelay.setDocument(new NumberDocument());
    jobRefreshPeriod.setDocument(new NumberDocument());
    rssRefreshPeriod.setDocument(new NumberDocument());

    uploadPatchSettingsPanel.setBorder(IdeBorderFactory.createTitledBorder("Upload a Patch Settings", true));

    passwordField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void insertUpdate(DocumentEvent e) {
            myPasswordModified = true;
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            myPasswordModified = true;
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            myPasswordModified = true;
        }
    });

    testConnexionButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                debugPanel.setVisible(false);

                new NotNullValidator().validate(serverUrl);
                new UrlValidator().validate(serverUrl);

                JenkinsSettings jenkinsSettings = JenkinsSettings.getSafeInstance(project);

                String password = isPasswordModified() ? getPassword() : jenkinsSettings.getPassword();

                RequestManager.getInstance(project).authenticate(serverUrl.getText(), username.getText(),
                        password, crumbDataField.getText());
                setConnectionFeedbackLabel(CONNECTION_TEST_SUCCESSFUL_COLOR, "Successful");
                setPassword(password);
            } catch (Exception ex) {
                setConnectionFeedbackLabel(CONNECTION_TEST_FAILED_COLOR, "[Fail] " + ex.getMessage());
                if (ex instanceof AuthenticationException) {
                    AuthenticationException authenticationException = (AuthenticationException) ex;
                    String responseBody = authenticationException.getResponseBody();
                    if (StringUtils.isNotBlank(responseBody)) {
                        debugPanel.setVisible(true);
                        debugTextPane.setText(responseBody);
                    }
                }
            }
        }
    });

    formValidator = FormValidator.init(this).addValidator(username, new UIValidator<JTextField>() {
        public void validate(JTextField component) throws ConfigurationException {
            if (StringUtils.isNotBlank(component.getText())) {
                String password = getPassword();
                if (StringUtils.isBlank(password)) {
                    throw new ConfigurationException(
                            String.format("'%s' must be set", passwordField.getName()));
                }
            }
        }
    });

}

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()));
        }/*  w ww . j a  v a  2  s.  c o  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 {//from w ww .j a  v  a  2s  . c o m
            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));
        }
    }
}