List of usage examples for javax.swing JTextField getText
public String getText()
TextComponent
. 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 {/*from w w w .j a va 2s. co 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)); } } }
From source file:org.codinjutsu.tools.jenkins.view.validator.UrlValidator.java
public void validate(JTextField component) throws ConfigurationException { String value = component.getText(); if (StringUtils.isEmpty(value)) { return;/*from ww w .java 2 s . c om*/ } try { URL url = new URL(value); String userInfo = url.getUserInfo(); if (StringUtils.isEmpty(userInfo)) { return; } throw new ConfigurationException( "Credentials should not be embedded in the url. Use the above form instead."); } catch (MalformedURLException ex) { throw new ConfigurationException(String.format("URL '%s' is malformed", value)); } }
From source file:org.docx4all.swing.ExternalHyperlinkDialog.java
private JPanel createContentPanel(String sourceFileVFSUrlPath, HyperlinkML hyperlinkML) { JPanel thePanel = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); fillRow1(thePanel, c);/*ww w . j av a 2s . co m*/ fillRow2(thePanel, c); fillRow3(thePanel, c); fillRow4(thePanel, c); fillRow5(thePanel, c); //Display Text Field if (hyperlinkML.getDisplayText() != null) { this.displayTextField.setText(hyperlinkML.getDisplayText()); } this.displayTextFieldAutoUpdate = (this.displayTextField.getText().length() == 0); //Set DisplayTextFieldAutoUpdate flag this.displayTextField.addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent e) { JTextField field = (JTextField) e.getSource(); if (field.getText().length() == 0) { ExternalHyperlinkDialog.this.displayTextFieldAutoUpdate = true; } else { ExternalHyperlinkDialog.this.displayTextFieldAutoUpdate = false; } } }); //Tooltip Field if (hyperlinkML.getTooltip() != null) { this.tooltipField.setText(hyperlinkML.getTooltip()); } //Target Field is split into documentNameField and directoryPathField. //These two fields are in friendly format; ie: no user credentials String target = HyperlinkML.encodeTarget(hyperlinkML, getSourceFileObject(), true); if (target != null) { int idx = target.lastIndexOf("/"); this.documentNameField.setText(target.substring(idx + 1)); if (target.startsWith(FILE_PREFIX)) { target = target.substring(FILE_PREFIX.length(), idx); } else { target = target.substring(0, idx); } this.directoryPathField.setText(target); } else { //A brand new HyperlinkML may be ? target = VFSUtils.getFriendlyName(this.sourceFileVFSUrlPath); int idx = target.lastIndexOf("/"); //Leave this.documentNameField blank this.directoryPathField.setText(target.substring(0, idx)); } //Install DocumentNameFieldListener so that Display Text Field //can be automatically updated. this.documentNameField.getDocument().addDocumentListener(new DocumentNameFieldListener()); //We also need to keep a reference to target in complete VFS url format; //ie: include user credentials in the reference. target = HyperlinkML.encodeTarget(hyperlinkML, getSourceFileObject(), false); if (target != null) { int idx = target.lastIndexOf("/"); this.directoryUrlPath = target.substring(0, idx); } else { //A brand new HyperlinkML may be ? int idx = this.sourceFileVFSUrlPath.lastIndexOf("/"); this.directoryUrlPath = this.sourceFileVFSUrlPath.substring(0, idx); } return thePanel; }
From source file:org.eclim.installer.step.VimStep.java
/** * {@inheritDoc}/* w ww. j a v a 2 s .c o m*/ * @see org.formic.wizard.step.GuiStep#init() */ public Component init() { GuiForm form = createForm(); String files = fieldName("files"); fileChooser = new FileChooser(JFileChooser.DIRECTORIES_ONLY); // allow just .vim dirs to not be hidden fileChooser.getFileChooser().setFileHidingEnabled(false); fileChooser.getFileChooser().addChoosableFileFilter(new FileFilter() { public boolean accept(java.io.File f) { String path = f.getAbsolutePath(); return f.isDirectory() && (path.matches(".*/\\.vim(/.*|$)") || !path.matches(".*/\\..*")); } public String getDescription() { return null; } }); String skip = fieldName("skip"); skipCheckBox = new JCheckBox(Installer.getString(skip)); skipCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean selected = ((JCheckBox) e.getSource()).isSelected(); JTextField fileField = fileChooser.getTextField(); fileField.setEnabled(!selected); fileChooser.getButton().setEnabled(!selected); if (dirList != null) { dirList.setEnabled(!selected); } // hacky Validator validator = (Validator) fileField.getClientProperty("validator"); setValid(selected || validator.isValid(fileField.getText())); } }); panel = new JPanel(new MigLayout("wrap 2", "[fill]", "[] [] [] [fill, grow]")); panel.add(form.createMessagePanel(), "span"); panel.add(new JLabel(Installer.getString(files)), "split"); panel.add(fileChooser, "skip"); panel.add(skipCheckBox, "span"); form.bind(files, fileChooser.getTextField(), new ValidatorBuilder().required().isDirectory().fileExists().isWritable().validator()); return panel; }
From source file:org.executequery.gui.browser.SSHTunnelConnectionPanel.java
private boolean hasValue(JTextField textField) { return StringUtils.isNotBlank(textField.getText()); }
From source file:org.gofleet.module.routing.RoutingMap.java
private Map<String, String> getValues(LatLon from) { final Map<String, String> mapa = new HashMap<String, String>(); final JDialog frame = new JDialog(basicWindow.getFrame(), "Configuration"); JPanel panel = new JPanel(new GridLayout(0, 2)); int width = 10; final JTextField maxDistance = new JTextField(width); maxDistance.setText("10"); final JTextField maxTime = new JTextField(width); maxTime.setText("8"); final JTextField origin_x = new JTextField(width / 2); origin_x.setText((new Double(from.getX())).toString()); final JTextField origin_y = new JTextField(width / 2); origin_y.setText((new Double(from.getY())).toString()); final JTextField startTime = new JTextField(width); startTime.setText("7"); final JTextField timeSpentOnStop = new JTextField(width); timeSpentOnStop.setText("1"); JLabel lmaxDistance = new JLabel("Maximum Distance (km)"); lmaxDistance.setLabelFor(maxDistance); JLabel lmaxTime = new JLabel("Maximum Time (hours)"); lmaxTime.setLabelFor(maxTime);//from w w w .j a va 2s. c o m JLabel lorigin = new JLabel("Point of Origin"); lorigin.setLabelFor(origin_x); JLabel lstartTime = new JLabel("Start Time of Plan (0-24)"); lstartTime.setLabelFor(startTime); JLabel ltimeSpentOnStop = new JLabel("Time Spent on Stop (hours)"); ltimeSpentOnStop.setLabelFor(timeSpentOnStop); JButton close = new JButton("OK"); close.addActionListener(new AbstractAction() { private static final long serialVersionUID = -8912729211256933464L; @Override public void actionPerformed(ActionEvent arg0) { try { mapa.put("maxDistance", maxDistance.getText()); mapa.put("maxTime", maxTime.getText()); mapa.put("origin_x", origin_x.getText()); mapa.put("origin_y", origin_y.getText()); mapa.put("startTime", startTime.getText()); mapa.put("timeSpentOnStop", timeSpentOnStop.getText()); frame.dispose(); } catch (Throwable t) { log.error("Error configuring New Route Plan" + t); JOptionPane.showMessageDialog(RoutingMap.this, "Some values are wrong. Check them again."); } } }); panel.add(lmaxDistance); panel.add(maxDistance); panel.add(lmaxTime); panel.add(maxTime); panel.add(lorigin); JPanel panel_origin = new JPanel(); panel_origin.add(origin_x); panel_origin.add(origin_y); panel.add(panel_origin); panel.add(lstartTime); panel.add(startTime); panel.add(ltimeSpentOnStop); panel.add(timeSpentOnStop); panel.add(close); frame.add(panel, BorderLayout.CENTER); frame.pack(); frame.setModalityType(ModalityType.APPLICATION_MODAL); frame.setVisible(true); return mapa; }
From source file:org.hibernate.search.demo.SearchDemo.java
private void initWidgets() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setDefaultLookAndFeelDecorated(true); BorderLayout borderLayout = new BorderLayout(); getContentPane().setLayout(borderLayout); // the main table model = new DefaultTableModel(headers, 0) { public boolean isCellEditable(int row, int column) { // at the moment only allows the editing of the title return column == 2; }/*from w ww . j a v a 2 s .co m*/ }; modelListener = new TableModelListener() { public void tableChanged(TableModelEvent e) { int row = e.getFirstRow(); int column = e.getColumn(); TableModel model = (TableModel) e.getSource(); Object data = model.getValueAt(row, column); EntityManager em = emf.createEntityManager(); updateTitle((Long) model.getValueAt(row, 0), (String) data); log.info("new value: {}", data); } }; model.addTableModelListener(modelListener); final JTable table = new JTable(model); table.setFont(new Font("Courier New", Font.PLAIN, 14)); getContentPane().add(new JScrollPane(table), BorderLayout.CENTER); // build the controls JPanel controlPanel = new JPanel(); controlPanel.setLayout(new FlowLayout()); final JTextField searchField = new JTextField(30); controlPanel.add(searchField); JButton searchButton = new JButton("Search"); searchButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { List<Product> products; try { products = search(searchField.getText()); } catch (ParseException pe) { JOptionPane.showMessageDialog(null, pe.getMessage(), "alert", JOptionPane.ERROR_MESSAGE); return; } DefaultTableModel model = (DefaultTableModel) table.getModel(); model.removeTableModelListener(modelListener); model.setRowCount(0); for (int i = 0; i < products.size(); i++) { Object[] data = new Object[headers.length]; Product p = products.get(i); data[0] = p.getProductId(); data[1] = p.getASIN(); data[2] = p.getTitle(); //data[3] = p.getDescription(); String actors = ""; for (Actor actor : p.getActors()) { actors = actors + actor.getName() + ", "; } data[3] = actors.length() == 0 ? actors : actors.substring(0, actors.length() - 2); String categories = ""; for (Category category : p.getCategories()) { categories = categories + category.getName() + ", "; } data[4] = categories.length() == 0 ? categories : categories.substring(0, categories.length() - 2); model.insertRow(i, data); } model.addTableModelListener(modelListener); } }); controlPanel.add(searchButton); JButton indexButton = new JButton("Index"); indexButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { index(); } }); controlPanel.add(indexButton); JButton purgeButton = new JButton("Purge"); purgeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { purge(); } }); controlPanel.add(purgeButton); getContentPane().add(controlPanel, BorderLayout.NORTH); getRootPane().setDefaultButton(searchButton); setSize(800, 200); setVisible(true); }
From source file:org.interreg.docexplore.DocExploreTool.java
@SuppressWarnings("serial") protected static File askForHome(String text) { final File[] file = { null }; final JDialog dialog = new JDialog((Frame) null, XMLResourceBundle.getBundledString("homeLabel"), true); JPanel content = new JPanel(new LooseGridLayout(0, 1, 10, 10, true, false, SwingConstants.CENTER, SwingConstants.TOP, true, false)); content.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10)); JLabel message = new JLabel(text, ImageUtils.getIcon("free-64x64.png"), SwingConstants.LEFT); message.setIconTextGap(20);//from w ww. j av a 2s . c o m //message.setFont(Font.decode(Font.SANS_SERIF)); content.add(message); final JPanel pathPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 10)); pathPanel.add(new JLabel("<html><b>" + XMLResourceBundle.getBundledString("homeLabel") + ":</b></html>")); final JTextField pathField = new JTextField(System.getProperty("user.home") + File.separator + "DocExplore", 40); pathPanel.add(pathField); pathPanel.add(new JButton(new AbstractAction(XMLResourceBundle.getBundledString("browseLabel")) { JNativeFileDialog nfd = null; public void actionPerformed(ActionEvent arg0) { if (nfd == null) { nfd = new JNativeFileDialog(); nfd.acceptFiles = false; nfd.acceptFolders = true; nfd.multipleSelection = false; nfd.title = XMLResourceBundle.getBundledString("homeLabel"); } nfd.setCurrentFile(new File(pathField.getText())); if (nfd.showOpenDialog()) pathField.setText(nfd.getSelectedFile().getAbsolutePath()); } })); content.add(pathPanel); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 10)); buttonPanel.add(new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgOkLabel")) { public void actionPerformed(ActionEvent e) { File res = new File(pathField.getText()); if (res.exists() && !res.isDirectory() || !res.exists() && !res.mkdirs()) JOptionPane.showMessageDialog(dialog, XMLResourceBundle.getBundledString("homeErrorMessage"), XMLResourceBundle.getBundledString("errorLabel"), JOptionPane.ERROR_MESSAGE); else { file[0] = res; dialog.setVisible(false); } } })); buttonPanel.add(new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgCancelLabel")) { public void actionPerformed(ActionEvent e) { dialog.setVisible(false); } })); content.add(buttonPanel); dialog.getContentPane().add(content); dialog.pack(); dialog.setResizable(false); GuiUtils.centerOnScreen(dialog); dialog.setVisible(true); return file[0]; }
From source file:org.isatools.isacreator.filechooser.FileChooserUI.java
private JPanel createTopPanel() { final JTextField uri = new RoundedJTextField(20); final JTextField username = new RoundedJTextField(20); final JPasswordField password = new RoundedJPasswordField(20); final JPanel topContainer = new JPanel(); topContainer.setLayout(new BoxLayout(topContainer, BoxLayout.PAGE_AXIS)); topContainer.setBackground(UIHelper.BG_COLOR); HUDTitleBar titlePanel = new HUDTitleBar(null, null, true); add(titlePanel, BorderLayout.NORTH); titlePanel.installListeners();/*from www.j a v a 2s . c om*/ topContainer.add(titlePanel); JPanel buttonPanel = new JPanel(new GridLayout(1, 1)); buttonPanel.setOpaque(false); JPanel fileSystemPanel = new JPanel(); fileSystemPanel.setLayout(new BoxLayout(fileSystemPanel, BoxLayout.LINE_AXIS)); fileSystemPanel.setBackground(UIHelper.BG_COLOR); localFsChoice = new JLabel(localFileSystemIcon, JLabel.LEFT); localFsChoice.setBackground(UIHelper.BG_COLOR); localFsChoice.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent event) { SwingUtilities.invokeLater(new Runnable() { public void run() { localFsChoice.setIcon(localFileSystemIconOver); remoteFsChoice.setIcon(remoteFileSystemIcon); ftpConnectionContainer.setVisible(false); topContainer.revalidate(); status.setText(""); fileBrowser = new LocalBrowser(); try { updateTree(fileBrowser.getHomeDirectory()); } catch (IOException e) { FileBrowserTreeNode defaultFTPNode = new FileBrowserTreeNode("problem occurred!", false, FileBrowserTreeNode.DIRECTORY); updateTree(defaultFTPNode); } } }); } }); fileSystemPanel.add(localFsChoice); fileSystemPanel.add(Box.createHorizontalStrut(5)); remoteFsChoice = new JLabel(remoteFileSystemIcon, JLabel.LEFT); remoteFsChoice.setBackground(UIHelper.BG_COLOR); remoteFsChoice.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent event) { SwingUtilities.invokeLater(new Runnable() { public void run() { localFsChoice.setIcon(localFileSystemIcon); remoteFsChoice.setIcon(remoteFileSystemIconOver); ftpConnectionContainer.setVisible(true); topContainer.revalidate(); } }); // immediately try to call FTP manager to get last sessions details final FTPAuthentication lastSession; if ((lastSession = ftpManager.getLastSession()) != null) { Thread remoteConnector = new Thread(new Runnable() { public void run() { connectToFTP(lastSession.getUri(), lastSession.getUsername(), lastSession.getPassword()); } }); remoteConnector.start(); } else { errorAction("no ftp location"); } } }); fileSystemPanel.add(remoteFsChoice); fileSystemPanel.add(Box.createHorizontalStrut(5)); status = UIHelper.createLabel("", UIHelper.VER_10_BOLD, UIHelper.DARK_GREEN_COLOR); status.setHorizontalAlignment(JLabel.RIGHT); fileSystemPanel.add(status); buttonPanel.add(fileSystemPanel); topContainer.add(buttonPanel); // now create panel to configure the FTP site ftpConnectionContainer = new JPanel(new GridLayout(1, 1)); ftpConnectionContainer.setBackground(UIHelper.BG_COLOR); JPanel userAuthFTP = new JPanel(); userAuthFTP.setLayout(new BoxLayout(userAuthFTP, BoxLayout.LINE_AXIS)); userAuthFTP.setOpaque(false); // add field to add URI JPanel uriPanel = new JPanel(new GridLayout(1, 2)); uriPanel.setBackground(UIHelper.BG_COLOR); JLabel uriLab = UIHelper.createLabel("FTP URI: ", UIHelper.VER_10_BOLD, UIHelper.DARK_GREEN_COLOR); UIHelper.renderComponent(uri, UIHelper.VER_10_PLAIN, UIHelper.DARK_GREEN_COLOR, false); uriPanel.add(uriLab); uriPanel.add(uri); userAuthFTP.add(uriPanel); // add field to add username JPanel usernamePanel = new JPanel(new GridLayout(1, 2)); usernamePanel.setBackground(UIHelper.BG_COLOR); JLabel usernameLab = UIHelper.createLabel("Username: ", UIHelper.VER_10_BOLD, UIHelper.DARK_GREEN_COLOR); UIHelper.renderComponent(username, UIHelper.VER_10_PLAIN, UIHelper.DARK_GREEN_COLOR, false); uriPanel.add(usernameLab); uriPanel.add(username); userAuthFTP.add(usernamePanel); // add field to add password JPanel passwordPanel = new JPanel(new GridLayout(1, 2)); passwordPanel.setBackground(UIHelper.BG_COLOR); JLabel passwordLab = UIHelper.createLabel("Password: ", UIHelper.VER_10_BOLD, UIHelper.DARK_GREEN_COLOR); UIHelper.renderComponent(password, UIHelper.VER_10_PLAIN, UIHelper.DARK_GREEN_COLOR, false); passwordPanel.add(passwordLab); passwordPanel.add(password); userAuthFTP.add(passwordPanel); JLabel connectLab = new JLabel(connectIcon); connectLab.setOpaque(false); connectLab.setToolTipText("<html><b>Connect</b><p>Connect to the FTP source defined!</p></html>"); connectLab.addMouseListener(new CommonMouseAdapter() { public void mousePressed(MouseEvent event) { super.mousePressed(event); if (uri.getText() != null && !uri.getText().trim().equals("")) { String user = (username.getText() != null) ? username.getText() : ""; String pass = (password.getPassword() != null) ? new String(password.getPassword()) : ""; final FTPAuthentication newFTPLocation = new FTPAuthentication(uri.getText(), user, pass); Thread remoteConnector = new Thread(new Runnable() { public void run() { connectToFTP(newFTPLocation.getUri(), newFTPLocation.getUsername(), newFTPLocation.getPassword()); } }); remoteConnector.start(); } } }); userAuthFTP.add(connectLab); JLabel historyLab = new JLabel(viewHistoryIcon); historyLab.setOpaque(false); historyLab.setToolTipText( "<html><b>Search previously connected to FTP locations</b><p>Connect to a previously defined FTP location</p></html>"); historyLab.addMouseListener(new CommonMouseAdapter() { public void mousePressed(MouseEvent event) { super.mousePressed(event); SelectFromFTPHistory selectFTP = new SelectFromFTPHistory(); selectFTP.addPropertyChangeListener("locationSelected", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (event.getNewValue() != null) { final FTPAuthentication ftpRecord = ftpManager .retrieveFTPAuthenticationObject(event.getNewValue().toString()); Thread remoteConnector = new Thread(new Runnable() { public void run() { connectToFTP(ftpRecord.getUri(), ftpRecord.getUsername(), ftpRecord.getPassword()); } }); remoteConnector.start(); } } }); selectFTP.createGUI(); showJDialogAsSheet(selectFTP); } }); userAuthFTP.add(historyLab); ftpConnectionContainer.add(userAuthFTP); ftpConnectionContainer.setVisible(false); topContainer.add(ftpConnectionContainer); return topContainer; }
From source file:org.javaswift.cloudie.CloudiePanel.java
private ContainerSpecification doGetContainerSpec() { JTextField name = new JTextField(); JCheckBox priv = new JCheckBox("private container"); if (JOptionPane.showConfirmDialog(this, new Object[] { "Name", name, priv }, "Create Container", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { return new ContainerSpecification(name.getText(), priv.isSelected()); }/*from ww w . j a v a 2s . c o m*/ return null; }