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:configuration.Util.java

public static void buttonEventText(workflow_properties properties, javax.swing.JRadioButton b,
        javax.swing.JTextField t) {
    if (b == null) {
        properties.put(t.getName(), t.getText());
    } else {/*from   w  ww.jav a 2  s  .co  m*/
        if (b.isSelected() == true) {
            if (t == null) {
                properties.put(b.getName(), b.isSelected());
            } else {
                t.setEnabled(true);
                properties.put(t.getName(), t.getText());
                properties.put(b.getName(), t.getText());
            }
        }
    }
}

From source file:configuration.Util.java

public static void boxEventText(workflow_properties properties, javax.swing.JCheckBox b,
        javax.swing.JTextField t) {
    if (b == null) {
        properties.put(t.getName(), t.getText());
    } else {//from   w ww . jav  a 2s.  co  m
        if (b.isSelected() == true) {
            if (t == null) {
                properties.put(b.getName(), b.isSelected());
            } else {
                t.setEnabled(true);
                properties.put(t.getName(), t.getText());
                properties.put(b.getName(), t.getText());
            }
        } else {
            properties.remove(b.getName());
            if (t != null) {
                t.setEnabled(false);
            }
        }
    }
}

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

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

    JLabel urlLabel = new JLabel("URL:");
    gridBagConstraints.gridx = 0;/* www .  j  a  v  a  2  s  .  c  o m*/
    gridBagConstraints.gridy = 0;
    gridBagConstraints.anchor = GridBagConstraints.WEST;
    gridBagConstraints.ipadx = 5;
    gridBagLayout.setConstraints(urlLabel, gridBagConstraints);
    contentPanel.add(urlLabel);

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

    int result = JOptionPane.showConfirmDialog(this, contentPanel, "Secure Conversation Cancel Token",
            JOptionPane.OK_CANCEL_OPTION);
    if (result == JOptionPane.CANCEL_OPTION) {
        return;
    }

    String location = urlTextField.getText();

    SecureConversationClient secConvClient = new SecureConversationClient(location);
    try {
        secConvClient.cancelSecureConversationToken(this.secConvSecurityToken);
        this.secConvViewMenuItem.setEnabled(false);
        this.secConvCancelMenuItem.setEnabled(false);
        this.secConvSecurityToken = null;
        JOptionPane.showMessageDialog(this, "Secure conversation token cancelled.", "Secure Conversation",
                JOptionPane.INFORMATION_MESSAGE);
    } catch (Exception e) {
        showException(e);
    }
}

From source file:edu.ku.brc.af.ui.forms.formatters.UIFormatterEditorDlg.java

/**
 * @param txtFld//w  w  w  .java2  s . c  o m
 */
private void hookTextChangeListener(final JTextField txtFld, final String errMsgKey, final int maxLen) {
    txtFld.getDocument().addDocumentListener(new DocumentAdaptor() {
        @Override
        protected void changed(DocumentEvent e) {
            if (StringUtils.isEmpty(txtFld.getText())) {
                setError(getResourceString(errMsgKey), false);
                updateUIEnabled();

            } else if (selectedFormat == null) {
                setError(fmtErrMsg, true);

            } else {
                updateUIEnabled();

                if (checkFieldLen(txtFld.getDocument().getLength(), maxLen)) {
                    sampleLabel.setText("");
                    updateSample();
                }
            }
            hasChanged = true;
        }
    });
}

From source file:net.sf.jsignpdf.SignPdfForm.java

/**
 * Checks if file exists and it's possible write to it.
 * //  w w  w.  ja  v a 2  s.c  o  m
 * @param aTF
 *            text field with file name filled
 * @param aFileDescKey
 *            file description (used in error message)
 * @return result of the check
 */
private boolean checkFileExists(JTextField aTF, String aFileDescKey) {
    final String tmpFileName = aTF.getText();
    try {
        if (tmpFileName != null) {
            File tmpFile = new File(tmpFileName);
            if (tmpFile.canRead() && !tmpFile.isDirectory()) {
                return true;
            }
        }
    } catch (Exception e) {
    }

    final String tmpMsg = RES.get("gui.fileNotExists.error", new String[] { RES.get(aFileDescKey) });
    JOptionPane.showMessageDialog(this, tmpMsg, RES.get("gui.check.error.title"), JOptionPane.ERROR_MESSAGE);
    return false;
}

From source file:de.fhg.iais.asc.ui.parts.HarvesterPanel.java

private JTextField createSetsTextField() {
    final JTextField textField = new JTextField(30);

    textField.addFocusListener(new FocusAdapter() {
        @Override// w  w  w  . j a  v  a2s.  co  m
        public void focusGained(FocusEvent e) {
            e.getOppositeComponent().requestFocus();

            // get the frame the panel is embedded in
            Component currentComponent = HarvesterPanel.this;
            while (currentComponent.getParent() != null && !(currentComponent instanceof JFrame)) {
                currentComponent = currentComponent.getParent();
            }
            final JFrame parentFrame = currentComponent instanceof JFrame ? (JFrame) currentComponent : null;

            if (HarvesterPanel.this.availableSets == null) {
                LocalizedOptionPane.showMessageDialog(parentFrame, "No_setnames_retrieved",
                        JOptionPane.ERROR_MESSAGE);
                return;
            }

            String[] selectedSets = textField.getText().split(","); //$NON-NLS-1$

            for (int i = 0; i < selectedSets.length; i++) {
                selectedSets[i] = selectedSets[i].trim();
            }

            SetSelectionWindow ssw = new SetSelectionWindow(parentFrame, HarvesterPanel.this.availableSets,
                    selectedSets);
            ssw.setVisible(true);

            textField.setText(StringUtils.join(ssw.getSelectedSets(), ", "));
        }
    });

    return textField;
}

From source file:com.sec.ose.osi.ui.frm.main.manage.dialog.JDlgProjectCreate.java

/**
 * This method initializes jComboBoxClonedFrom   
 *    /*from   w w w.  j a  v  a 2 s .  c  o  m*/
 * @return javax.swing.JComboBox   
 */
private JComboBox<String> getJComboBoxClonedFrom() {
    if (jComboBoxClonedFrom == null) {
        jComboBoxClonedFrom = new JComboBox<String>();
        jComboBoxClonedFrom.setRenderer(new ComboToopTip());
        jComboBoxClonedFrom.setEditable(true);
        jComboBoxClonedFrom.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent e) {
                log.debug("jComboBoxClonedFrom.actionPerformed()");
                eventHandler.handleEvent(EventHandler.COMBO_CLONED_FROM);
            }
        });
        refresh(jComboBoxClonedFrom);

        final JTextField editor;
        editor = (JTextField) jComboBoxClonedFrom.getEditor().getEditorComponent();
        editor.addKeyListener(new KeyAdapter() {
            public void keyReleased(KeyEvent e) {
                char ch = e.getKeyChar();

                if (ch != KeyEvent.VK_ENTER && ch != KeyEvent.VK_BACK_SPACE
                        && (ch == KeyEvent.CHAR_UNDEFINED || Character.isISOControl(ch)))
                    return;
                if (ch == KeyEvent.VK_ENTER) {
                    jComboBoxClonedFrom.hidePopup();
                    return;
                }

                String str = editor.getText();

                if (jComboBoxClonedFrom.getComponentCount() > 0) {
                    jComboBoxClonedFrom.removeAllItems();
                }

                jComboBoxClonedFrom.addItem(str);
                try {
                    String tmpProjectName = null;
                    if (str.length() > 0) {
                        for (int i = 0; i < names.size(); i++) {
                            tmpProjectName = names.get(i);
                            if (tmpProjectName.toLowerCase().startsWith(str.toLowerCase()))
                                jComboBoxClonedFrom.addItem(tmpProjectName);
                        }
                    } else {
                        for (int i = 0; i < names.size(); i++) {
                            jComboBoxClonedFrom.addItem(names.get(i));
                        }
                    }
                } catch (Exception e1) {
                    log.warn(e1.getMessage());
                }

                jComboBoxClonedFrom.hidePopup();
                if (str.length() > 0)
                    jComboBoxClonedFrom.showPopup();
            }
        });

        editor.addFocusListener(new FocusAdapter() {
            public void focusGained(FocusEvent e) {
                if (editor.getText().length() > 0)
                    jComboBoxClonedFrom.showPopup();
            }

            public void focusLost(FocusEvent e) {
                jComboBoxClonedFrom.hidePopup();
            }
        });
    }
    return jComboBoxClonedFrom;
}

From source file:ca.osmcanada.osvuploadr.JPMain.java

private void jbUploadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbUploadActionPerformed
    String path = ca.osmcanada.osvuploadr.JFMain.class.getProtectionDomain().getCodeSource().getLocation()
            .getPath();/*from   w  w  w.j  a  v  a 2s . c  o m*/
    String decodedPath = "";
    try {
        decodedPath = new File(URLDecoder.decode(path, "UTF-8")).getParentFile().getPath();
    } catch (Exception ex) {
        Logger.getLogger(JPMain.class.getName()).log(Level.SEVERE, "decodePath", ex);
    }
    File id = new File(decodedPath + "/access_token.txt");
    String accessToken = "";
    System.out.println("id_file exists:" + id.exists());
    if (!id.exists()) {
        try {
            String[] buttons = { new String(r.getString("automatically").getBytes(), "UTF-8"),
                    new String(r.getString("manually").getBytes(), "UTF-8"),
                    new String(r.getString("cancel").getBytes(), "UTF-8") };
            int rc = JOptionPane.showOptionDialog(null,
                    new String(r.getString("login_to_osm").getBytes(), "UTF-8"),
                    new String(r.getString("confirmation").getBytes(), "UTF-8"),
                    JOptionPane.INFORMATION_MESSAGE, 0, null, buttons, buttons[0]);
            String token = "";
            System.out.println("GetOSMUser");
            switch (rc) {
            case 0:
                String usr = "";
                String psw = "";
                JTextField tf = new JTextField();
                JPasswordField pf = new JPasswordField();
                rc = JOptionPane.showConfirmDialog(null, tf,
                        new String(r.getString("email_osm_usr").getBytes(), "UTF-8"),
                        JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
                if (rc == JOptionPane.OK_OPTION) {
                    usr = tf.getText();
                } else {
                    return;
                }

                rc = JOptionPane.showConfirmDialog(null, pf,
                        new String(r.getString("enter_password").getBytes(), "UTF-8"),
                        JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
                if (rc == JOptionPane.OK_OPTION) {
                    psw = new String(pf.getPassword());
                } else {
                    return;
                }
                token = GetOSMUser(usr, psw);
                break;
            case 1:
                token = GetOSMUser();
                break;
            case 2:
                return;

            }
            Path targetPath = Paths.get("./access_token.txt");
            byte[] bytes = token.split("\\|")[0].getBytes(StandardCharsets.UTF_8);
            Files.write(targetPath, bytes, StandardOpenOption.CREATE);
            accessToken = token.split("\\|")[0];
            String accessSecret = token.split("\\|")[1];
            SendAuthTokens(accessToken, accessSecret);
        } catch (Exception ex) {
            Logger.getLogger(JPMain.class.getName()).log(Level.SEVERE, "GetOSMUser", ex);
        }
    } else {
        try {
            List<String> token = Files.readAllLines(Paths.get(id.getPath()));
            if (token.size() > 0) {
                accessToken = token.get(0); //read first line
            }
        } catch (Exception ex) {
            Logger.getLogger(JPMain.class.getName()).log(Level.SEVERE, "readAllLines", ex);
        }
    }
    System.out.println("Access Token obtained from file or OSM:" + accessToken);

    //Start processing list
    for (String item : listDir.getItems()) {
        System.out.println("Processing folder:" + item);
        Process(item, accessToken);
    }
    //um = new UploadManager(listDir.getItems());
    //um.start();

}

From source file:it.txt.access.capability.revocation.wizard.panel.PanelRevocationData.java

private void checkEditableTextBox(final javax.swing.JTextField textBox) {

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

        public void insertUpdate(DocumentEvent e) {
            sorroundIssuerDocumentChange(e);
        }//from w  w  w  .  j  ava 2  s  .  c o  m

        public void removeUpdate(DocumentEvent e) {
            sorroundIssuerDocumentChange(e);
        }

        public void changedUpdate(DocumentEvent e) {
            sorroundIssuerDocumentChange(e);
        }

        private void sorroundIssuerDocumentChange(DocumentEvent e) {
            if (textBox.getText().equals("")) {
                textBox.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
            } else {
                textBox.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0)));
            }
        }
    });
}

From source file:es.emergya.ui.gis.popups.SaveGPXDialog.java

private SaveGPXDialog(final List<Layer> capas) {
    super("Consulta de Posiciones GPS");
    setResizable(false);/*w  w w  .  ja  v  a 2  s .co m*/
    setAlwaysOnTop(true);
    try {
        setIconImage(((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame()
                .getIconImage());
    } catch (Throwable e) {
        LOG.error("There is no icon image", e);
    }

    this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    JPanel dialogo = new JPanel(new BorderLayout());
    dialogo.setBackground(Color.WHITE);
    dialogo.setBorder(new EmptyBorder(10, 10, 10, 10));

    JPanel central = new JPanel(new FlowLayout());
    central.setOpaque(false);
    final JTextField nombre = new JTextField(15);
    nombre.setEditable(false);
    central.add(nombre);
    final JButton button = new JButton("Examinar...", LogicConstants.getIcon("button_nuevo"));
    central.add(button);
    final JButton aceptar = new JButton("Guardar", LogicConstants.getIcon("button_save"));
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileChooser = new JFileChooser();
            if (fileChooser.showSaveDialog(SaveGPXDialog.this) == JFileChooser.APPROVE_OPTION) {
                nombre.setText(fileChooser.getSelectedFile().getAbsolutePath());
                aceptar.setEnabled(true);
            }
        }
    });

    dialogo.add(central, BorderLayout.CENTER);

    JPanel botones = new JPanel(new FlowLayout());
    botones.setOpaque(false);

    aceptar.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String base_url = nombre.getText() + "_";
            for (Layer layer : capas) {
                if (layer instanceof GpxLayer) {
                    GpxLayer gpxLayer = (GpxLayer) layer;
                    File f = new File(base_url + gpxLayer.name + ".gpx");

                    boolean sobreescribir = !f.exists();

                    try {
                        while (!sobreescribir) {
                            String original = f.getCanonicalPath();
                            f = checkFileOverwritten(nombre, f);
                            sobreescribir = !f.exists() || original.equals(f.getCanonicalPath());
                        }
                    } catch (NullPointerException t) {
                        log.debug("Cancelando creacion de fichero: " + t);
                        sobreescribir = false;
                    } catch (Throwable t) {
                        log.error("Error comprobando la sobreescritura", t);
                        sobreescribir = false;
                    }

                    if (sobreescribir) {
                        try {
                            f.createNewFile();
                        } catch (IOException e1) {
                            log.error(e1, e1);
                        }
                        if (!(f.isFile() && f.canWrite()))
                            JOptionPane.showMessageDialog(SaveGPXDialog.this,
                                    "No tengo permiso para escribir en " + f.getAbsolutePath());
                        else {
                            try {
                                OutputStream out = new FileOutputStream(f);
                                GpxWriter writer = new GpxWriter(out);
                                writer.write(gpxLayer.data);
                                out.close();
                            } catch (Throwable t) {
                                log.error("Error al escribir el gpx", t);
                                JOptionPane.showMessageDialog(SaveGPXDialog.this,
                                        "Ocurri un error al escribir en " + f.getAbsolutePath());
                            }
                        }
                    } else
                        log.error("Por errores anteriores no se escribio el fichero");
                } else
                    log.error("Una de las capas no era gpx: " + layer.name);
            }
            SaveGPXDialog.this.dispose();

        }

        private File checkFileOverwritten(final JTextField nombre, File f) throws Exception {
            String nueva = JOptionPane.showInputDialog(nombre, i18n.getString("savegpxdialog.overwrite"),
                    "Sobreescribir archivo", JOptionPane.QUESTION_MESSAGE, null, null, f.getCanonicalPath())
                    .toString();
            log.debug("Nueva ruta: " + nueva);
            return new File(nueva);
        }
    });

    JButton cancelar = new JButton("Cancelar", LogicConstants.getIcon("button_cancel"));

    cancelar.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            SaveGPXDialog.this.dispose();
        }
    });

    aceptar.setEnabled(false);
    botones.add(aceptar);
    botones.add(cancelar);
    dialogo.add(botones, BorderLayout.SOUTH);

    add(dialogo);
    setPreferredSize(new Dimension(300, 200));
    pack();

    int x;
    int y;

    Container myParent;
    try {
        myParent = ((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame()
                .getContentPane();
        java.awt.Point topLeft = myParent.getLocationOnScreen();
        Dimension parentSize = myParent.getSize();

        Dimension mySize = getSize();

        if (parentSize.width > mySize.width)
            x = ((parentSize.width - mySize.width) / 2) + topLeft.x;
        else
            x = topLeft.x;

        if (parentSize.height > mySize.height)
            y = ((parentSize.height - mySize.height) / 2) + topLeft.y;
        else
            y = topLeft.y;

        setLocation(x, y);
    } catch (Throwable e1) {
        LOG.error("There is no basic window!", e1);
    }

    this.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosed(WindowEvent e) {
            nombre.setText("");
            nombre.repaint();
        }

        @Override
        public void windowClosing(WindowEvent e) {
            nombre.setText("");
            nombre.repaint();
        }
    });
}