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:edu.ku.brc.specify.conversion.ConvertVerifier.java

/**
 * Loads the dialog/*from  w w  w . j av  a 2s  .c  o  m*/
 * @param hashNames every other one is the new name
 * @return the list of selected DBs
 */
private boolean selectedDBsToConvert() {
    final JTextField itUserNameTF = UIHelper.createTextField("root", 15);
    final JPasswordField itPasswordTF = UIHelper.createPasswordField("", 15);

    final JTextField hostNameTF = UIHelper.createTextField("localhost", 15);

    CellConstraints cc = new CellConstraints();
    PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,p,f:p:g", "p,2px,p,2px,p,8px,p"));

    int y = 1;
    pb.addSeparator("IT User", cc.xyw(1, y, 4));
    y += 2;
    pb.add(UIHelper.createLabel("Username:", SwingConstants.RIGHT), cc.xy(1, y));
    pb.add(itUserNameTF, cc.xy(3, y));
    y += 2;

    pb.add(UIHelper.createLabel("Password:", SwingConstants.RIGHT), cc.xy(1, y));
    pb.add(itPasswordTF, cc.xy(3, y));
    y += 2;

    pb.add(UIHelper.createLabel("Host Name:", SwingConstants.RIGHT), cc.xy(1, y));
    pb.add(hostNameTF, cc.xy(3, y));
    y += 2;

    PanelBuilder panel = new PanelBuilder(new FormLayout("f:p:g,10px,f:p:g", "f:p:g"));
    panel.add(new JLabel(IconManager.getIcon("SpecifyLargeIcon")), cc.xy(1, 1));
    panel.add(pb.getPanel(), cc.xy(3, 1));

    CustomDialog dlg = new CustomDialog(null, "Database Info", true, panel.getPanel());
    ((JPanel) dlg.getContentPanel()).setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    UIHelper.centerAndShow(dlg);

    dlg.dispose();
    if (dlg.isCancelled()) {
        return false;
    }

    hostName = hostNameTF.getText();
    itUsrPwd.first = itUserNameTF.getText();
    itUsrPwd.second = ((JTextField) itPasswordTF).getText();

    return true;
}

From source file:com.nikonhacker.gui.EmulatorUI.java

private void openEncodeDialog() {
    JTextField destinationFile = new JTextField();
    JTextField sourceFile1 = new JTextField();
    JTextField sourceFile2 = new JTextField();
    FileSelectionPanel destinationFileSelectionPanel = new FileSelectionPanel("Destination file",
            destinationFile, false);/*w  w w. j av  a2  s.  co m*/
    destinationFileSelectionPanel.setFileFilter(".bin", "Encoded firmware file (*.bin)");
    FileSelectionPanel sourceFile1SelectionPanel = new FileSelectionPanel("Source file 1", sourceFile1, false);
    destinationFileSelectionPanel.setFileFilter("a*.bin", "Decoded A firmware file (a*.bin)");
    FileSelectionPanel sourceFile2SelectionPanel = new FileSelectionPanel("Source file 2", sourceFile2, false);
    destinationFileSelectionPanel.setFileFilter("b*.bin", "Decoded B firmware file (b*.bin)");
    final JComponent[] inputs = new JComponent[] { destinationFileSelectionPanel, sourceFile1SelectionPanel,
            sourceFile2SelectionPanel };
    if (JOptionPane.OK_OPTION == JOptionPane.showOptionDialog(this, inputs,
            "Choose target encoded file and source files", JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.PLAIN_MESSAGE, null, null, JOptionPane.DEFAULT_OPTION)) {
        try {
            ArrayList<String> inputFilenames = new ArrayList<String>();
            inputFilenames.add(sourceFile1.getText());
            inputFilenames.add(sourceFile2.getText());
            new FirmwareEncoder().encode(inputFilenames, destinationFile.getText());
            JOptionPane.showMessageDialog(this, "Encoding complete", "Done", JOptionPane.INFORMATION_MESSAGE);
        } catch (FirmwareFormatException e) {
            JOptionPane.showMessageDialog(this, e.getMessage() + "\nPlease see console for full stack trace",
                    "Error encoding files", JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        }
    }
}

From source file:edu.ku.brc.specify.conversion.SpecifyDBConverter.java

/**
 * Loads the dialog//from   w  w  w.  j av a  2  s .  co  m
 * @param hashNames every other one is the new name
 * @return the list of selected DBs
 */
public boolean selectedDBsToConvert(final boolean useITOnly) {
    final JTextField itUserNameTF = UIHelper.createTextField("root", 15);
    final JPasswordField itPasswordTF = UIHelper.createPasswordField("", 15);

    final JTextField masterUserNameTF = UIHelper.createTextField("Master", 15);
    final JPasswordField masterPasswordTF = UIHelper.createPasswordField("Master", 15);

    final JTextField hostNameTF = UIHelper.createTextField("localhost", 15);

    CellConstraints cc = new CellConstraints();
    PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,p,f:p:g",
            "p,2px,p,2px,p,4px," + (useITOnly ? "" : "p,2px,p,2px,") + "p,8px,p,4px"));

    int y = 1;
    pb.addSeparator("IT User", cc.xyw(1, y, 4));
    y += 2;
    pb.add(UIHelper.createLabel("Username:", SwingConstants.RIGHT), cc.xy(1, y));
    pb.add(itUserNameTF, cc.xy(3, y));
    y += 2;

    pb.add(UIHelper.createLabel("Password:", SwingConstants.RIGHT), cc.xy(1, y));
    pb.add(itPasswordTF, cc.xy(3, y));
    y += 2;

    if (!useITOnly) {
        pb.addSeparator("Master User", cc.xyw(1, y, 4));
        y += 2;
        pb.add(UIHelper.createLabel("Username:", SwingConstants.RIGHT), cc.xy(1, y));
        pb.add(masterUserNameTF, cc.xy(3, y));
        y += 2;

        pb.add(UIHelper.createLabel("Password:", SwingConstants.RIGHT), cc.xy(1, y));
        pb.add(masterPasswordTF, cc.xy(3, y));
        y += 2;
    }

    pb.add(UIHelper.createLabel("Host Name:", SwingConstants.RIGHT), cc.xy(1, y));
    pb.add(hostNameTF, cc.xy(3, y));
    y += 2;

    if (System.getProperty("user.name").equals("rods")) {
        itPasswordTF.setText("root"); // password for converter database
    } else {
        itPasswordTF.requestFocus();
    }

    PanelBuilder panel = new PanelBuilder(new FormLayout("f:p:g,10px,f:p:g", "f:p:g"));
    panel.add(new JLabel(IconManager.getIcon("SpecifyConv")), cc.xy(1, 1));
    panel.add(pb.getPanel(), cc.xy(3, 1));
    panel.setDefaultDialogBorder();

    CustomDialog dlg = new CustomDialog(null, "Specify Converter", true, panel.getPanel());
    UIHelper.centerAndShow(dlg);

    dlg.dispose();
    if (dlg.isCancelled()) {
        return false;
    }

    hostName = hostNameTF.getText();
    itUsrPwd.first = itUserNameTF.getText();
    itUsrPwd.second = ((JTextField) itPasswordTF).getText();

    masterUsrPwd.first = masterUserNameTF.getText();
    masterUsrPwd.second = ((JTextField) masterPasswordTF).getText();

    return true;
}

From source file:com.osparking.osparking.Settings_System.java

private void setButtonEnabled_If_GateNameChanged(int gateNo) {
    JTextField gateNameField = (JTextField) componentMap.get("TextFieldGateName" + gateNo);

    if (gateNameField.getText().trim().equals(gateNames[gateNo])) {
        changedControls.remove(gateNameField);
    } else {/*from  w  ww  .j a va2 s .  c  o m*/
        changedControls.add(gateNameField);
    }
}

From source file:com.osparking.osparking.Settings_System.java

private void setButtonEnabled_If_IP_addrChanged(int gateNo, DeviceType devType) {
    JTextField ipAddrField = (JTextField) componentMap.get(devType.toString() + gateNo + "_IP_TextField");

    if (ipAddrField.getText().trim().equals(deviceIP[devType.ordinal()][gateNo])) {
        changedControls.remove(ipAddrField);
    } else {// w  w  w. j av a2  s.c  o  m
        changedControls.add(ipAddrField);
    }
}

From source file:com.osparking.osparking.Settings_System.java

private void setButtonEnabled_If_PortChanged(int gateNo, DeviceType devType) {
    JTextField portField = (JTextField) componentMap.get(devType.toString() + gateNo + "_Port_TextField");

    if (portField.getText().trim().equals(devicePort[devType.ordinal()][gateNo])) {
        changedControls.remove(portField);
    } else {//from w ww . j  ava  2s  . com
        changedControls.add(portField);
    }
}

From source file:com.osparking.osparking.Settings_System.java

private void rejectLongPortNumber(KeyEvent evt, DeviceType devType, int gateNo) {
    JTextField portField = (JTextField) componentMap.get(devType.toString() + gateNo + "_Port_TextField");

    if (portField.getText().trim().length() >= PORT_NUMBER_LENGTH_MAX) {
        getToolkit().beep();//from   w w  w.  ja v  a2s  . c o  m
        JOptionPane.showConfirmDialog(this,
                PORT_LABEL.getContent() + " " + NUMBER_LIMIT_DESCRIPTION.getContent() + " : "
                        + PORT_NUMBER_LENGTH_MAX,
                ERROR_DIALOGTITLE.getContent(), JOptionPane.PLAIN_MESSAGE, WARNING_MESSAGE);
        evt.consume();
    } else {
        // check if portField input is in the available range of port number.
    }
}

From source file:com.osparking.osparking.Settings_System.java

private void checkGateNameLength(int gateNo, KeyEvent evt) {
    JTextField gateNameField = (JTextField) getComponentByName("TextFieldGateName" + gateNo);
    String gateName = gateNameField.getText().trim();

    if (gateName.length() > GATE_NAME_LENGTH_MAX) {
        gateNameField.setText(gateNames[gateNo]);
        getToolkit().beep();//from   w w w . ja v  a  2 s  .  c  o  m
        JOptionPane.showConfirmDialog(this,
                GATE_NAME_LABEL2.getContent() + " " + System.lineSeparator() + System.lineSeparator()
                        + LIMIT_LABEL.getContent() + GATE_NAME_LENGTH_MAX,
                ERROR_DIALOGTITLE.getContent(), JOptionPane.PLAIN_MESSAGE, WARNING_MESSAGE);
        evt.consume();
    }
}

From source file:com.osparking.osparking.Settings_System.java

/**
 * Checks if natural number is entered and give warning when non-numeric entered.
 * @param textField field whose text is supposed to contain a number
 * @param dialogTitle title of the dialog box that will be shown when non-natural number string is entered
 * @return <b>true</b> when a natural number is in the <code>textField</code>, 
 * <b>false</b> otherwise/*from ww  w  .  j a va  2  s.c o m*/
 */
private boolean TextFieldNumericValueOK(JTextField textField, String dialogTitle) {
    // Check if empty string or numeric 0 were entered. 
    String input = textField.getText().trim();

    input = removeNonNumeric(input);

    if (input.length() == 0 || Integer.parseInt(input) == 0) {
        JOptionPane.showConfirmDialog(this, "Enter a value of 1 or more ..", dialogTitle,
                JOptionPane.PLAIN_MESSAGE, WARNING_MESSAGE);
        textField.requestFocusInWindow();
        textField.select(0, input.length());
        return false;
    } else {
        return true;
    }
}

From source file:be.agiv.security.demo.Main.java

private void invokeClaimsAwareService() {
    GridBagLayout gridBagLayout = new GridBagLayout();
    GridBagConstraints gridBagConstraints = new GridBagConstraints();
    JPanel contentPanel = new JPanel(gridBagLayout);

    final JLabel ipStsLabel = new JLabel("IP-STS:");
    gridBagConstraints.gridx = 0;/*ww w. ja  v  a 2  s . c o  m*/
    gridBagConstraints.gridy = 0;
    gridBagConstraints.anchor = GridBagConstraints.WEST;
    gridBagConstraints.ipadx = 5;
    gridBagLayout.setConstraints(ipStsLabel, gridBagConstraints);
    contentPanel.add(ipStsLabel);

    final JTextField ipStsTextField = new JTextField(
            "https://auth.beta.agiv.be/ipsts/Services/DaliSecurityTokenServiceConfiguration.svc/IWSTrust13",
            60);
    gridBagConstraints.gridx++;
    gridBagLayout.setConstraints(ipStsTextField, gridBagConstraints);
    contentPanel.add(ipStsTextField);

    JLabel realmLabel = new JLabel("Realm:");
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagLayout.setConstraints(realmLabel, gridBagConstraints);
    contentPanel.add(realmLabel);

    JTextField realmTextField = new JTextField(AGIVSecurity.BETA_REALM, 30);
    gridBagConstraints.gridx++;
    gridBagLayout.setConstraints(realmTextField, gridBagConstraints);
    contentPanel.add(realmTextField);

    final CredentialPanel credentialPanel = new CredentialPanel();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(credentialPanel, gridBagConstraints);
    contentPanel.add(credentialPanel);

    final JLabel rStsLabel = new JLabel("R-STS:");
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagConstraints.gridwidth = 1;
    gridBagLayout.setConstraints(rStsLabel, gridBagConstraints);
    contentPanel.add(rStsLabel);

    final JTextField rStsTextField = new JTextField(
            "https://auth.beta.agiv.be/sts/Services/SalvadorSecurityTokenServiceConfiguration.svc/IWSTrust13",
            60);
    gridBagConstraints.gridx++;
    gridBagLayout.setConstraints(rStsTextField, gridBagConstraints);
    contentPanel.add(rStsTextField);

    JLabel serviceRealmLabel = new JLabel("Service realm:");
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagLayout.setConstraints(serviceRealmLabel, gridBagConstraints);
    contentPanel.add(serviceRealmLabel);

    JTextField serviceRealmTextField = new JTextField(ClaimsAwareServiceFactory.SERVICE_REALM, 60);
    gridBagConstraints.gridx++;
    gridBagLayout.setConstraints(serviceRealmTextField, gridBagConstraints);
    contentPanel.add(serviceRealmTextField);

    JLabel urlLabel = new JLabel("Service URL:");
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagLayout.setConstraints(urlLabel, gridBagConstraints);
    contentPanel.add(urlLabel);

    JTextField urlTextField = new JTextField(ClaimsAwareServiceFactory.SERVICE_LOCATION, 60);
    gridBagConstraints.gridx++;
    gridBagLayout.setConstraints(urlTextField, gridBagConstraints);
    contentPanel.add(urlTextField);

    final JCheckBox noWsPolicyCheckBox = new JCheckBox("WSDL without WS-Policy");
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(noWsPolicyCheckBox, gridBagConstraints);
    contentPanel.add(noWsPolicyCheckBox);

    final JCheckBox useWsSecureConversationCheckBox = new JCheckBox("Use WS-SecureConversation");
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(useWsSecureConversationCheckBox, gridBagConstraints);
    contentPanel.add(useWsSecureConversationCheckBox);

    final JCheckBox usePreviousSecurityCheckBox = new JCheckBox("Use previous AGIV Security");
    final JCheckBox cancelPreviousSecureConversationToken = new JCheckBox("Cancel previous conversation token");
    usePreviousSecurityCheckBox.setEnabled(null != this.agivSecurity);
    cancelPreviousSecureConversationToken.setEnabled(false);
    usePreviousSecurityCheckBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            LOG.debug("use previous security: " + usePreviousSecurityCheckBox.isSelected());
            boolean newSecurity = !usePreviousSecurityCheckBox.isSelected();
            ipStsLabel.setEnabled(newSecurity);
            ipStsTextField.setEditable(newSecurity);
            credentialPanel.setEnabled(newSecurity);
            rStsLabel.setEnabled(newSecurity);
            rStsTextField.setEnabled(newSecurity);
            cancelPreviousSecureConversationToken.setEnabled(!newSecurity);
        }
    });
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(usePreviousSecurityCheckBox, gridBagConstraints);
    contentPanel.add(usePreviousSecurityCheckBox);

    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(cancelPreviousSecureConversationToken, gridBagConstraints);
    contentPanel.add(cancelPreviousSecureConversationToken);

    JPanel expiresPanel = new JPanel();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagConstraints.gridwidth = 2;
    gridBagLayout.setConstraints(expiresPanel, gridBagConstraints);
    contentPanel.add(expiresPanel);

    JLabel expiresLabelLabel = new JLabel("Secure conversation token expires:");
    expiresLabelLabel.setEnabled(null != this.agivSecurity);
    expiresPanel.add(expiresLabelLabel);

    JLabel expiresLabel = new JLabel();
    expiresLabel.setEnabled(null != this.agivSecurity);
    expiresPanel.add(expiresLabel);
    if (null != this.agivSecurity) {
        if (false == this.agivSecurity.getSecureConversationTokens().isEmpty()) {
            SecurityToken secureConversationToken = this.agivSecurity.getSecureConversationTokens().values()
                    .iterator().next();
            expiresLabel.setText(secureConversationToken.getExpires().toString());
        }
    }

    int dialogResult = JOptionPane.showConfirmDialog(this, contentPanel, "Claims Aware Service",
            JOptionPane.OK_CANCEL_OPTION);
    if (dialogResult == JOptionPane.CANCEL_OPTION) {
        return;
    }

    final String location = urlTextField.getText();
    final String serviceRealm = serviceRealmTextField.getText();
    final String ipStsLocation = ipStsTextField.getText();
    final String rStsLocation = rStsTextField.getText();
    final String username = credentialPanel.getUsername();
    final String password = credentialPanel.getPassword();
    final File pkcs12File = credentialPanel.getPKCS12File();
    final String realm = realmTextField.getText();

    ExecutorService executor = Executors.newFixedThreadPool(1);
    FutureTask<ArrayOfClaimInfo> futureTask = new FutureTask<ArrayOfClaimInfo>(
            new Callable<ArrayOfClaimInfo>() {

                public ArrayOfClaimInfo call() throws Exception {
                    Service service;
                    if (noWsPolicyCheckBox.isSelected()) {
                        service = ClaimsAwareServiceFactory.getInstanceNoWSPolicy();
                    } else {
                        service = ClaimsAwareServiceFactory.getInstance();
                    }
                    IService iservice = service.getWS2007FederationHttpBindingIService(new AddressingFeature());
                    BindingProvider bindingProvider = (BindingProvider) iservice;

                    if (false == usePreviousSecurityCheckBox.isSelected()) {
                        if (null != username) {
                            Main.this.agivSecurity = new AGIVSecurity(ipStsLocation, rStsLocation, realm,
                                    username, password);
                        } else {
                            Main.this.agivSecurity = new AGIVSecurity(ipStsLocation, rStsLocation, realm,
                                    pkcs12File, password);
                        }
                        Main.this.agivSecurity.addSTSListener(Main.this);
                        if (Main.this.proxyEnable) {
                            agivSecurity.setProxy(Main.this.proxyHost, Main.this.proxyPort,
                                    Main.this.proxyType);
                        }
                    }
                    if (cancelPreviousSecureConversationToken.isSelected()) {
                        Main.this.agivSecurity.cancelSecureConversationTokens();
                    }
                    Main.this.agivSecurity.enable(bindingProvider, location,
                            useWsSecureConversationCheckBox.isSelected(), serviceRealm);

                    ArrayOfClaimInfo result = iservice.getData(0);
                    return result;
                }
            }) {

        @Override
        protected void done() {
            try {
                ArrayOfClaimInfo result = get();
                List<ClaimInfo> claims = result.getClaimInfo();
                StringBuffer message = new StringBuffer();
                for (ClaimInfo claim : claims) {
                    message.append(claim.getName());
                    message.append(" = ");
                    message.append(claim.getValue());
                    message.append("\n");
                }

                JOptionPane.showMessageDialog(Main.this, message.toString(), "Claims Aware Service Result",
                        JOptionPane.INFORMATION_MESSAGE);
            } catch (final Exception e) {
                try {
                    SwingUtilities.invokeAndWait(new Runnable() {

                        public void run() {
                            Main.this.statusBar.setErrorStatus(e.getMessage());
                        }
                    });
                } catch (Exception e1) {
                }
                showException(e);
            }
        }
    };
    executor.execute(futureTask);
}