List of usage examples for javax.swing JTextField addKeyListener
public synchronized void addKeyListener(KeyListener l)
From source file:com.sec.ose.osi.ui.frm.main.identification.common.JComboLicenseName.java
public JComboLicenseName() { final JTextField editor; this.initLicenseComboBox(); this.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (isEnabled()) { if (e.getActionCommand().equals("comboBoxChanged") || e.getActionCommand().equals("comboBoxEdited")) { if (getSelectedIndex() > 0) { setSelectedIndex(getSelectedIndex()); IdentifyMediator.getInstance() .setSelectedLicenseName(String.valueOf(getSelectedItem())); log.debug("selected license name : " + IdentifyMediator.getInstance().getSelectedLicenseName()); } else { IdentifyMediator.getInstance().setSelectedLicenseName(""); }/*from www . ja v a2s .c o m*/ } } } }); editor = (JTextField) this.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) { hidePopup(); return; } String str = editor.getText(); if (getComponentCount() > 0) { removeAllItems(); } addItem(str); try { String tmpLicense = null; ArrayList<String> AllLicenseList = new ArrayList<String>(); AllLicenseList = LicenseAPIWrapper.getAllLicenseList(); if (str.length() > 0) { for (int i = 0; i < AllLicenseList.size(); i++) { tmpLicense = AllLicenseList.get(i); if (tmpLicense.toLowerCase().startsWith(str.toLowerCase())) addItem(tmpLicense); } } else { for (int i = 0; i < AllLicenseList.size(); i++) { addItem(AllLicenseList.get(i)); } } } catch (Exception e1) { log.warn(e1.getMessage()); } hidePopup(); if (str.length() > 0) showPopup(); } }); editor.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent e) { if (editor.getText().length() > 0) showPopup(); } public void focusLost(FocusEvent e) { hidePopup(); } }); }
From source file:edu.ku.brc.af.ui.forms.validation.ValFormattedTextField.java
/** * Creates the various UI Components for the formatter. *//*w w w .j a v a 2s .c o m*/ protected void createUI() { CellConstraints cc = new CellConstraints(); if (isViewOnly || (formatter != null && !formatter.isUserInputNeeded() && fields != null && fields.size() == 1)) { viewtextField = new JTextField(); setControlSize(viewtextField); // Remove by rods 12/5/08 this messes thihngs up // values don't get inserted correctly, shouldn't be needed anyway //JFormattedDoc document = new JFormattedDoc(viewtextField, formatter, formatter.getFields().get(0)); //viewtextField.setDocument(document); //document.addDocumentListener(this); //documents.add(document); ViewFactory.changeTextFieldUIForDisplay(viewtextField, false); PanelBuilder builder = new PanelBuilder(new FormLayout("1px,f:p:g,1px", "1px,f:p:g,1px"), this); builder.add(viewtextField, cc.xy(2, 2)); bgColor = viewtextField.getBackground(); } else { JTextField txt = new JTextField(); Font txtFont = txt.getFont(); Font font = new Font("Courier", Font.PLAIN, txtFont.getSize()); BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); Graphics2D g = bi.createGraphics(); g.setFont(font); FontMetrics fm = g.getFontMetrics(font); g.dispose(); Insets ins = txt.getBorder().getBorderInsets(txt); int baseWidth = ins.left + ins.right; bgColor = txt.getBackground(); StringBuilder sb = new StringBuilder("1px"); for (UIFieldFormatterField f : fields) { sb.append(","); if (f.getType() == FieldType.separator || f.getType() == FieldType.constant) { sb.append('p'); } else { sb.append(((fm.getMaxAdvance() * f.getSize()) + baseWidth) + "px"); } } sb.append(",1px"); PanelBuilder builder = new PanelBuilder(new FormLayout(sb.toString(), "1px,P:G,1px"), this); comps = new JComponent[fields.size()]; int inx = 0; for (UIFieldFormatterField f : fields) { JComponent comp = null; JComponent tfToAdd = null; if (f.getType() == FieldType.separator || f.getType() == FieldType.constant) { comp = createLabel(f.getValue()); if (f.getType() == FieldType.constant) { comp.setBackground(Color.WHITE); comp.setOpaque(true); } tfToAdd = comp; } else { JTextField tf = new BGTextField(f.getSize(), isViewOnly ? "" : f.getValue()); tfToAdd = tf; if (inx == 0) { tf.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { checkForPaste(e); } }); } JFormattedDoc document = new JFormattedDoc(tf, formatter, f); tf.setDocument(document); document.addDocumentListener(new DocumentAdaptor() { @Override protected void changed(DocumentEvent e) { isChanged = true; if (!shouldIgnoreNotifyDoc) { String fldStr = getText(); int len = StringUtils.isNotEmpty(fldStr) ? fldStr.length() : 0; if (formatter != null && len > 0 && formatter.isLengthOK(len)) { setState(formatter.isValid(fldStr) ? UIValidatable.ErrorType.Valid : UIValidatable.ErrorType.Error); repaint(); } //validateState(); if (changeListener != null) { changeListener.stateChanged(new ChangeEvent(this)); } if (documentListeners != null) { for (DocumentListener dl : documentListeners) { dl.changedUpdate(null); } } } currCachedValue = null; } }); documents.add(document); addFocusAdapter(tf); comp = tf; comp.setFont(font); if (f.isIncrementer()) { editTF = tf; cardLayout = new CardLayout(); cardPanel = new JPanel(cardLayout); cardPanel.add("edit", tf); viewTF = new BGTextField(f.getSize(), isViewOnly ? "" : f.getValue()); viewTF.setDocument(document); cardPanel.add("view", viewTF); cardLayout.show(cardPanel, "view"); comp = cardPanel; tfToAdd = cardPanel; } } setControlSize(tfToAdd); builder.add(comp, cc.xy(inx + 2, 2)); comps[inx] = tfToAdd; inx++; } } }
From source file:edu.ku.brc.specify.tasks.subpane.images.ImagesPane.java
/** * @return//from w ww .j a v a2s.c o m */ private void createColObjSearch() { if (searchType != SearchType.FromRecordSet) { searchForAllAttachments(); gridPanel.setItemList(rowsVector); JScrollPane sb = new JScrollPane(gridPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); add(sb, BorderLayout.CENTER); return; } CellConstraints cc = new CellConstraints(); String rowDef = searchType != SearchType.FromRecordSet ? "f:p:g" : "p,4px,f:p:g"; PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g,2px,p", rowDef)); int y = 1; coVBP = new ViewBasedDisplayPanel(null, "COImageSearch", CollectionObject.class.getName(), true, MultiView.NO_SCROLLBARS | MultiView.IS_SINGLE_OBJ | MultiView.IS_EDITTING); pb.add(coVBP, cc.xyw(1, y, 3)); y += 2; pb.add(gridPanel, cc.xyw(1, y, 3)); coVBP.setData(dataMap); FormViewObj fvo = coVBP.getMultiView().getCurrentViewAsFormViewObj(); JButton searchBtn = fvo.getCompById("2"); JTextField textField = fvo.getCompById("1"); y += 2; //fvo.setAlwaysGetDataFromUI(true); if (searchBtn != null) { final JButton searchBtnFinal = searchBtn; final JTextField textFieldFinal = textField; searchBtn.setEnabled(false); searchBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //searchForColObjImagesForTable(); gridPanel.setItemList(rowsVector); //invalidate(); //revalidate(); } }); textField.getDocument().addDocumentListener(new DocumentAdaptor() { @Override protected void changed(DocumentEvent e) { searchBtnFinal.setEnabled(textFieldFinal.getText().length() > 0); } }); textField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER && textFieldFinal.getText().length() > 0) { //searchForColObjImagesForTable(); } } }); } JScrollPane sb = new JScrollPane(pb.getPanel(), JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); add(sb, BorderLayout.CENTER); }
From source file:edu.ku.brc.specify.plugins.ipadexporter.iPadDBExporterPlugin.java
/** * // w w w . j a v a 2 s .co m */ private void createAccount() { Institution inst = iPadDBExporter.getCurrentInstitution(); if (StringUtils.isEmpty(inst.getGuid())) { UIRegistry.showError("Institution must have a GUID value."); return; } loadAndPushResourceBundle(RESOURCE_NAME); final JTextField userNameTF = createTextField(15); final JPasswordField passwordTF = createPasswordField(); final JLabel statusLbl = createLabel(" "); ImageIcon imgIcon = IconManager.getImage("SpecifySmalliPad128x128", IconManager.STD_ICON_SIZE.NonStd); JPanel loginPanel = DatabaseLoginPanel.createLoginPanel("Username", userNameTF, "USRNM_EMAIL_HINT", "Password", passwordTF, statusLbl, imgIcon); final CustomDialog dlg = new CustomDialog((Frame) getMostRecentWindow(), getResourceString("CREATE_INST_IN_CLOUD"), true, CustomDialog.OKCANCEL, loginPanel) { @Override protected void okButtonPressed() { // NOTE: THis call should fail indicating is is not being used // so it if is OK then it is an error String uName = userNameTF.getText(); if (iPadCloud.isUserNameOK(uName)) { setErrorMsg(statusLbl, getFormattedResStr("USRNM_IS_TAKEN", uName)); } else { super.okButtonPressed(); } } }; KeyAdapter ka = new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { String pwd = new String(passwordTF.getPassword()); boolean isOK = UIHelper.isValidEmailAddress(userNameTF.getText()) && pwd.length() > 4; dlg.getOkBtn().setEnabled(isOK); } }; userNameTF.addKeyListener(ka); passwordTF.addKeyListener(ka); dlg.setOkLabel(getResourceString("NEW_ACCOUNT")); dlg.createUI(); dlg.getOkBtn().setEnabled(false); centerAndShow(dlg); popResourceBundle(); if (!dlg.isCancelled()) { cloudInstId = iPadCloud.createInstitution(inst.getName(), inst.getUri(), inst.getCode(), inst.getGuid()); if (cloudInstId != null) { createAccountBtn.setEnabled(false); loginBtn.setEnabled(true); enableRemoveDatasetBtn(); checkInstitutionInfo(false); String uName = userNameTF.getText(); String pwd = new String(passwordTF.getPassword()); if (iPadCloud.addNewUser(uName, pwd, inst.getGuid())) { if (iPadCloud.login(uName, pwd)) { login(new Pair<String, String>(uName, pwd)); } } else { setErrorMsg(statusLbl, kErrorCreatingAcctMsg); } } else { UIRegistry.showError(kErrorCreatingAcctMsg); } } }
From source file:edu.ku.brc.specify.plugins.ipadexporter.iPadDBExporterPlugin.java
/** * @return//w w w .java 2 s . com */ private Pair<String, String> getExportLoginCreds(final String userName, final boolean wasInError) { loginBtn.setEnabled(false); loadAndPushResourceBundle(RESOURCE_NAME); try { final JTextField userNameTF = createTextField(15); final JPasswordField passwordTF = createPasswordField(); final JLabel statusLbl = createLabel(" "); if (wasInError) { setErrorMsg(statusLbl, "Your username or password was not correct."); } ImageIcon imgIcon = IconManager.getImage("SpecifySmalliPad128x128", IconManager.STD_ICON_SIZE.NonStd); JPanel loginPanel = DatabaseLoginPanel.createLoginPanel("Username", userNameTF, "USRNM_EMAIL_HINT", "Password", passwordTF, statusLbl, imgIcon); if (!iPadDBExporter.IS_TESTING) // ZZZ { while (true) { userNameTF.setText(userName); final CustomDialog dlg = new CustomDialog((Frame) getMostRecentWindow(), getResourceString("iPad Cloud Login"), true, CustomDialog.OKCANCELAPPLY, loginPanel) { @Override protected void applyButtonPressed() { String uName = userNameTF.getText(); if (iPadCloud.isUserNameOK(uName)) { setErrorMsg(statusLbl, getFormattedResStr("USRNM_IS_TAKEN", uName)); } else { super.applyButtonPressed(); } } }; KeyAdapter ka = new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { super.keyReleased(e); boolean isOK = UIHelper.isValidEmailAddress(userNameTF.getText()) && StringUtils.isNotEmpty(new String(passwordTF.getPassword())); dlg.getOkBtn().setEnabled(isOK); dlg.getApplyBtn().setEnabled(isOK); } }; userNameTF.addKeyListener(ka); passwordTF.addKeyListener(ka); dlg.setCloseOnApplyClk(true); dlg.setApplyLabel(getResourceString("NEW_USER")); dlg.setOkLabel(getResourceString("LOGIN")); dlg.createUI(); boolean enableBtns = StringUtils.isNotEmpty(userName); dlg.getOkBtn().setEnabled(enableBtns); dlg.getApplyBtn().setEnabled(enableBtns); centerAndShow(dlg); if (!dlg.isCancelled()) { boolean isOK = true; String uName = userNameTF.getText(); String pwd = new String(passwordTF.getPassword()); if (dlg.getBtnPressed() == CustomDialog.APPLY_BTN) { Institution inst = iPadDBExporter.getCurrentInstitution(); if (!iPadCloud.addNewUser(uName, pwd, inst.getGuid())) { setErrorMsg(statusLbl, kErrorCreatingAcctMsg); isOK = false; } } if (isOK) { return new Pair<String, String>(uName, pwd); } } else { return null; } } } return null;//new Pair<String, String>("testuser@ku.edu", "testuser@ku.edu"); } catch (Exception ex) { ex.printStackTrace(); } finally { popResourceBundle(); loginBtn.setEnabled(true); } return null; }
From source file:com.edduarte.protbox.ui.windows.RestoreFileWindow.java
private RestoreFileWindow(final PReg registry) { super();//from w w w. ja va 2s . c o m setLayout(null); final JTextField searchField = new JTextField(); searchField.setLayout(null); searchField.setBounds(2, 2, 301, 26); searchField.setBorder(new LineBorder(Color.lightGray)); searchField.setFont(Constants.FONT); add(searchField); final JLabel noBackupFilesLabel = new JLabel("<html>No backups files were found!<br><br>" + "<font color=\"gray\">If you think there is a problem with the<br>" + "backup system, please create an issue here:<br>" + "<a href=\"#\">https://github.com/com.edduarte/protbox/issues</a></font></html>"); noBackupFilesLabel.setLayout(null); noBackupFilesLabel.setBounds(20, 50, 300, 300); noBackupFilesLabel.setFont(Constants.FONT.deriveFont(14f)); noBackupFilesLabel.addMouseListener((OnMouseClick) e -> { String urlPath = "https://github.com/com.edduarte/protbox/issues"; try { if (Desktop.isDesktopSupported()) { Desktop.getDesktop().browse(new URI(urlPath)); } else { if (SystemUtils.IS_OS_WINDOWS) { Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + urlPath); } else { java.util.List<String> browsers = Lists.newArrayList("firefox", "opera", "safari", "mozilla", "chrome"); for (String browser : browsers) { if (Runtime.getRuntime().exec(new String[] { "which", browser }).waitFor() == 0) { Runtime.getRuntime().exec(new String[] { browser, urlPath }); break; } } } } } catch (Exception ex) { ex.printStackTrace(); } }); DefaultMutableTreeNode rootTreeNode = registry.buildEntryTree(); final JTree tree = new JTree(rootTreeNode); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); if (rootTreeNode.getChildCount() == 0) { searchField.setEnabled(false); add(noBackupFilesLabel); } expandTree(tree); tree.setLayout(null); tree.setRootVisible(false); tree.setEditable(false); tree.setCellRenderer(new SearchableTreeCellRenderer(searchField)); searchField.addKeyListener((OnKeyReleased) e -> { // update and expand tree DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); model.nodeStructureChanged((TreeNode) model.getRoot()); expandTree(tree); }); final JScrollPane scroll = new JScrollPane(tree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scroll.setBorder(new DropShadowBorder()); scroll.setBorder(new LineBorder(Color.lightGray)); scroll.setBounds(2, 30, 334, 360); add(scroll); JLabel close = new JLabel(new ImageIcon(Constants.getAsset("close.png"))); close.setLayout(null); close.setBounds(312, 7, 18, 18); close.setFont(Constants.FONT); close.setForeground(Color.gray); close.addMouseListener((OnMouseClick) e -> dispose()); add(close); final JLabel permanentDeleteButton = new JLabel(new ImageIcon(Constants.getAsset("permanent.png"))); permanentDeleteButton.setLayout(null); permanentDeleteButton.setBounds(91, 390, 40, 39); permanentDeleteButton.setBackground(Color.black); permanentDeleteButton.setEnabled(false); permanentDeleteButton.addMouseListener((OnMouseClick) e -> { if (permanentDeleteButton.isEnabled()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); PbxEntry entry = (PbxEntry) node.getUserObject(); if (JOptionPane.showConfirmDialog(null, "Are you sure you wish to permanently delete '" + entry.realName() + "'?\nThis file and its " + "backup copies will be deleted immediately. You cannot undo this action.", "Confirm Cancel", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) { registry.permanentDelete(entry); dispose(); RestoreFileWindow.getInstance(registry); } else { setVisible(true); } } }); add(permanentDeleteButton); final JLabel configBackupsButton = new JLabel(new ImageIcon(Constants.getAsset("config.png"))); configBackupsButton.setLayout(null); configBackupsButton.setBounds(134, 390, 40, 39); configBackupsButton.setBackground(Color.black); configBackupsButton.setEnabled(false); configBackupsButton.addMouseListener((OnMouseClick) e -> { if (configBackupsButton.isEnabled()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); PbxEntry entry = (PbxEntry) node.getUserObject(); if (entry instanceof PbxFile) { PbxFile pbxFile = (PbxFile) entry; JFrame frame = new JFrame("Choose backup policy"); Object option = JOptionPane.showInputDialog(frame, "Choose below the backup policy for this file:", "Choose backup", JOptionPane.QUESTION_MESSAGE, null, PbxFile.BackupPolicy.values(), pbxFile.getBackupPolicy()); if (option == null) { setVisible(true); return; } PbxFile.BackupPolicy pickedPolicy = PbxFile.BackupPolicy.valueOf(option.toString()); pbxFile.setBackupPolicy(pickedPolicy); } setVisible(true); } }); add(configBackupsButton); final JLabel restoreBackupButton = new JLabel(new ImageIcon(Constants.getAsset("restore.png"))); restoreBackupButton.setLayout(null); restoreBackupButton.setBounds(3, 390, 85, 39); restoreBackupButton.setBackground(Color.black); restoreBackupButton.setEnabled(false); restoreBackupButton.addMouseListener((OnMouseClick) e -> { if (restoreBackupButton.isEnabled()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); PbxEntry entry = (PbxEntry) node.getUserObject(); if (entry instanceof PbxFolder) { registry.restoreFolderFromEntry((PbxFolder) entry); } else if (entry instanceof PbxFile) { PbxFile pbxFile = (PbxFile) entry; java.util.List<String> snapshots = pbxFile.snapshotsToString(); if (snapshots.isEmpty()) { setVisible(true); return; } JFrame frame = new JFrame("Choose backup"); Object option = JOptionPane.showInputDialog(frame, "Choose below what backup snapshot would you like restore:", "Choose backup", JOptionPane.QUESTION_MESSAGE, null, snapshots.toArray(), snapshots.get(0)); if (option == null) { setVisible(true); return; } int pickedIndex = snapshots.indexOf(option.toString()); registry.restoreFileFromEntry((PbxFile) entry, pickedIndex); } dispose(); } }); add(restoreBackupButton); tree.addMouseListener((OnMouseClick) e -> { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node != null) { PbxEntry entry = (PbxEntry) node.getUserObject(); if ((entry instanceof PbxFolder && entry.areNativeFilesDeleted())) { permanentDeleteButton.setEnabled(true); restoreBackupButton.setEnabled(true); configBackupsButton.setEnabled(false); } else if (entry instanceof PbxFile) { permanentDeleteButton.setEnabled(true); restoreBackupButton.setEnabled(true); configBackupsButton.setEnabled(true); } else { permanentDeleteButton.setEnabled(false); restoreBackupButton.setEnabled(false); configBackupsButton.setEnabled(false); } } }); final JLabel cancel = new JLabel(new ImageIcon(Constants.getAsset("cancel.png"))); cancel.setLayout(null); cancel.setBounds(229, 390, 122, 39); cancel.setBackground(Color.black); cancel.addMouseListener((OnMouseClick) e -> dispose()); add(cancel); addWindowFocusListener(new WindowFocusListener() { private boolean gained = false; @Override public void windowGainedFocus(WindowEvent e) { gained = true; } @Override public void windowLostFocus(WindowEvent e) { if (gained) { dispose(); } } }); setSize(340, 432); setUndecorated(true); getContentPane().setBackground(Color.white); setResizable(false); getRootPane().setBorder(BorderFactory.createLineBorder(new Color(100, 100, 100))); Utils.setComponentLocationOnCenter(this); setVisible(true); }
From source file:CSSDFarm.UserInterface.java
private void btnAddFieldStationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddFieldStationActionPerformed JTextField id = new JTextField(); JTextField name = new JTextField(); //Space is needed to expand dialog JLabel verified = new JLabel(" "); JButton okButton = new JButton("Ok"); JButton cancelButton = new JButton("Cancel"); okButton.setEnabled(false);//from ww w. j a v a2 s . c o m okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { String idText = id.getText(); String nameText = name.getText(); addFieldStation(id.getText(), name.getText()); JOptionPane.getRootFrame().dispose(); listUserStations.setSelectedValue(server.getFieldStation(idText), false); } }); cancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { JOptionPane.getRootFrame().dispose(); } }); id.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent key) { boolean theid = id.getText().equals(""); boolean thename = name.getText().equals(""); if (server.verifyFieldStation(id.getText()) && !theid && !thename) { verified.setText(" Verified"); verified.setForeground(new Color(0, 102, 0)); okButton.setEnabled(true); } else { verified.setText(" Not Verified"); verified.setForeground(Color.RED); okButton.setEnabled(false); } } }); name.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent key) { boolean theid = id.getText().equals(""); boolean thename = name.getText().equals(""); if (server.verifyFieldStation(id.getText()) && !theid && !thename) { verified.setText(" Verified"); verified.setForeground(new Color(0, 102, 0)); okButton.setEnabled(true); } else { verified.setText(" Not Verified"); verified.setForeground(Color.RED); okButton.setEnabled(false); } } }); Object[] message = { "Field Station ID:", id, "Field Station Name:", name, verified }; int inputFields = JOptionPane.showOptionDialog(null, message, "Add Field Station", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] { okButton, cancelButton }, null); if (inputFields == JOptionPane.OK_OPTION) { System.out.print("Added Field Station!"); } }
From source file:eu.apenet.dpt.standalone.gui.eaccpf.EacCpfDescriptionPanel.java
/** * Builds placeEntry form part.//from www. jav a 2s . c o m */ private PanelBuilder buildPlaceEntry(PanelBuilder builder, CellConstraints cc, PlaceEntry placeEntry, boolean flag, int index, boolean filled) { JLabel jLabelPlace = new JLabel(this.labels.getString("eaccpf.description.place")); builder.add(jLabelPlace, cc.xy(1, rowNb)); if (placeEntry != null) { //placeEntry part TextFieldWithLanguage textFieldWithLanguage = new TextFieldWithLanguage(placeEntry.getContent(), placeEntry.getLang()); JTextField placeEntryTextField = textFieldWithLanguage.getTextField(); placeEntryTextField.addKeyListener(new CheckPlaceContent(placeEntryTextField, index)); builder.add(placeEntryTextField, cc.xy(3, rowNb)); JLabel jLabelLanguage = new JLabel(this.labels.getString("eaccpf.description.selectlanguage")); builder.add(jLabelLanguage, cc.xy(5, rowNb)); JComboBox placeEntryLanguage = textFieldWithLanguage.getLanguageBox(); placeEntryLanguage.setEnabled(filled); builder.add(placeEntryLanguage, cc.xy(7, rowNb)); appendPlaceEntryPlace(placeEntryTextField, placeEntryLanguage); } else { //empty one JTextField jTextfieldPlace = new JTextField(); jTextfieldPlace.addKeyListener(new CheckPlaceContent(jTextfieldPlace, index)); builder.add(jTextfieldPlace, cc.xy(3, rowNb)); JLabel jLabelLanguage = new JLabel(this.labels.getString("eaccpf.description.selectlanguage")); builder.add(jLabelLanguage, cc.xy(5, rowNb)); JComboBox jComboboxLanguage = buildLanguageJComboBox(/*flag*/); if (!flag) { jComboboxLanguage.setSelectedItem("---"); } // Disable combo action. jComboboxLanguage.setEnabled(filled); builder.add(jComboboxLanguage, cc.xy(7, rowNb)); appendPlaceEntryPlace(jTextfieldPlace, jComboboxLanguage); } setNextRow(); //second line JLabel jControlledPlaceLabel = new JLabel(this.labels.getString("eaccpf.description.linkvocabularyplaces")); builder.add(jControlledPlaceLabel, cc.xy(1, rowNb)); JTextField jTextfieldControlledLabelPlace = new JTextField(); if (placeEntry != null) { String vocabLink = placeEntry.getVocabularySource(); jTextfieldControlledLabelPlace.setText(vocabLink); } jTextfieldControlledLabelPlace.setEnabled(filled); builder.add(jTextfieldControlledLabelPlace, cc.xy(3, rowNb)); appendPlaceEntryVocabularyPlace(jTextfieldControlledLabelPlace); setNextRow(); //third line JLabel jCountryLabel = new JLabel(this.labels.getString("eaccpf.description.country")); builder.add(jCountryLabel, cc.xy(1, rowNb)); JComboBox jComboboxCountry = buildCountryJComboBox(); if (placeEntry != null) { String isoCountry = placeEntry.getCountryCode(); if (isoCountry != null && !isoCountry.isEmpty()) { jComboboxCountry.setSelectedItem(parseIsoToCountry(isoCountry)); } } jComboboxCountry.setEnabled(filled); builder.add(jComboboxCountry, cc.xy(3, rowNb)); appendPlaceEntryCountry(jComboboxCountry); setNextRow(); // role of the place has been moved from above to this part because placeEntry is needed // and there is not index (iterator var) by schema (if this part is between "add DATES" and // "add further address details" is impossible to put an index different from '0' JLabel jRolePlaceLabel = new JLabel(this.labels.getString("eaccpf.description.roleplace")); builder.add(jRolePlaceLabel, cc.xy(1, rowNb)); TextFieldWithComboBoxEacCpf jComboBoxRolePlace = null; if (placeEntry != null) { jComboBoxRolePlace = new TextFieldWithComboBoxEacCpf("", placeEntry.getLocalType(), TextFieldWithComboBoxEacCpf.TYPE_PLACE_ROLE, this.entityType, this.labels); } else { jComboBoxRolePlace = new TextFieldWithComboBoxEacCpf("", "", TextFieldWithComboBoxEacCpf.TYPE_PLACE_ROLE, this.entityType, this.labels); } jComboBoxRolePlace.getComboBox().setEnabled(filled); builder.add(jComboBoxRolePlace.getComboBox(), cc.xy(3, rowNb)); appendPlaceEntryRole(jComboBoxRolePlace); setNextRow(); return builder; }
From source file:edu.ku.brc.specify.plugins.ipadexporter.ManageDataSetsDlg.java
/** * /*from www .java 2s . c o m*/ */ private void addUserToDS() { final Vector<String> wsList = new Vector<String>(); final Vector<String> instItems = new Vector<String>(); String addStr = getResourceString("ADD"); instItems.add(addStr); wsList.add(addStr); for (String fullName : cloudHelper.getInstList()) { String[] toks = StringUtils.split(fullName, '\t'); instItems.add(toks[0]); wsList.add(toks[1]); } final JTextField userNameTF = createTextField(20); final JTextField passwordTF = createTextField(20); final JLabel pwdLbl = createI18NFormLabel("Password"); final JLabel statusLbl = createLabel(""); final JCheckBox isNewUser = UIHelper.createCheckBox("Is New User"); final JLabel instLbl = createI18NFormLabel("Insitution"); final JComboBox instCmbx = UIHelper.createComboBox(instItems.toArray()); if (instItems.size() == 2) { instCmbx.setSelectedIndex(1); } CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,f:p:g", "p,4px,p,4px,p,4px,p,4px,p,8px,p")); pb.add(createI18NLabel("Add New or Existing User to DataSet"), cc.xyw(1, 1, 3)); pb.add(createI18NFormLabel("Username"), cc.xy(1, 3)); pb.add(userNameTF, cc.xy(3, 3)); pb.add(pwdLbl, cc.xy(1, 5)); pb.add(passwordTF, cc.xy(3, 5)); pb.add(instLbl, cc.xy(1, 7)); pb.add(instCmbx, cc.xy(3, 7)); pb.add(isNewUser, cc.xy(3, 9)); pb.add(statusLbl, cc.xyw(1, 11, 3)); pb.setDefaultDialogBorder(); pwdLbl.setVisible(false); passwordTF.setVisible(false); instLbl.setVisible(false); instCmbx.setVisible(false); final CustomDialog dlg = new CustomDialog(this, "Add User", true, OKCANCEL, pb.getPanel()) { @Override protected void okButtonPressed() { String usrName = userNameTF.getText(); if (cloudHelper.isUserNameOK(usrName)) { String collGuid = datasetGUIDList.get(dataSetList.getSelectedIndex()); if (cloudHelper.addUserAccessToDataSet(usrName, collGuid)) { super.okButtonPressed(); } else { iPadDBExporterPlugin.setErrorMsg(statusLbl, String.format("Unable to add usr: %s to the DataSet guid: %s", usrName, collGuid)); } } else if (isNewUser.isSelected()) { String pwdStr = passwordTF.getText(); String guid = null; if (instCmbx.getSelectedIndex() == 0) { // InstDlg instDlg = new InstDlg(cloudHelper); // if (!instDlg.isInstOK()) // { // instDlg.createUI(); // instDlg.pack(); // centerAndShow(instDlg, 600, null); // if (instDlg.isCancelled()) // { // return; // } // //guid = instDlg.getGuid()(); // } } else { //webSite = wsList.get(instCmbx.getSelectedIndex()); } if (guid != null) { String collGuid = datasetGUIDList.get(dataSetList.getSelectedIndex()); if (cloudHelper.addNewUser(usrName, pwdStr, guid)) { if (cloudHelper.addUserAccessToDataSet(usrName, collGuid)) { ManageDataSetsDlg.this.loadUsersForDataSetsIntoJList(); super.okButtonPressed(); } else { iPadDBExporterPlugin.setErrorMsg(statusLbl, String.format("Unable to add%s to the DataSet %s", usrName, collGuid)); } } else { iPadDBExporterPlugin.setErrorMsg(statusLbl, String.format("Unable to add%s to the DataSet %s", usrName, collGuid)); } } else { // error } } else { iPadDBExporterPlugin.setErrorMsg(statusLbl, String.format("'%s' doesn't exist.", usrName)); } } }; KeyAdapter ka = new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { statusLbl.setText(""); String usrNmStr = userNameTF.getText(); boolean hasData = StringUtils.isNotEmpty(usrNmStr) && (!isNewUser.isSelected() || StringUtils.isNotEmpty(passwordTF.getText())) && UIHelper.isValidEmailAddress(usrNmStr); dlg.getOkBtn().setEnabled(hasData); } }; userNameTF.addKeyListener(ka); passwordTF.addKeyListener(ka); final Color textColor = userNameTF.getForeground(); FocusAdapter fa = new FocusAdapter() { @Override public void focusGained(FocusEvent e) { JTextField tf = (JTextField) e.getSource(); if (!tf.getForeground().equals(textColor)) { tf.setText(""); tf.setForeground(textColor); } } @Override public void focusLost(FocusEvent e) { JTextField tf = (JTextField) e.getSource(); if (tf.getText().length() == 0) { tf.setText("Enter email address"); tf.setForeground(Color.LIGHT_GRAY); } } }; userNameTF.addFocusListener(fa); userNameTF.setText("Enter email address"); userNameTF.setForeground(Color.LIGHT_GRAY); isNewUser.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { boolean isSel = isNewUser.isSelected(); pwdLbl.setVisible(isSel); passwordTF.setVisible(isSel); instLbl.setVisible(isSel); instCmbx.setVisible(isSel); Dimension s = dlg.getSize(); int hgt = isNewUser.getSize().height + 4 + instCmbx.getSize().height; s.height += isSel ? hgt : -hgt; dlg.setSize(s); } }); dlg.createUI(); dlg.getOkBtn().setEnabled(false); centerAndShow(dlg); if (!dlg.isCancelled()) { loadUsersForDataSetsIntoJList(); } }
From source file:org.apache.cayenne.modeler.CayenneModelerFrame.java
/** Initializes main toolbar. */ protected void initToolbar() { JToolBar toolBar = new JToolBar(); toolBar.add(getAction(NewProjectAction.class).buildButton()); toolBar.add(getAction(OpenProjectAction.class).buildButton()); toolBar.add(getAction(SaveAction.class).buildButton()); toolBar.addSeparator();//from w w w . j a va 2s . c o m toolBar.add(getAction(RemoveAction.class).buildButton()); toolBar.addSeparator(); toolBar.add(getAction(CutAction.class).buildButton()); toolBar.add(getAction(CopyAction.class).buildButton()); toolBar.add(getAction(PasteAction.class).buildButton()); toolBar.addSeparator(); toolBar.add(getAction(UndoAction.class).buildButton()); toolBar.add(getAction(RedoAction.class).buildButton()); toolBar.addSeparator(); toolBar.add(getAction(CreateNodeAction.class).buildButton()); toolBar.add(getAction(CreateDataMapAction.class).buildButton()); toolBar.addSeparator(); toolBar.add(getAction(CreateDbEntityAction.class).buildButton()); toolBar.add(getAction(CreateProcedureAction.class).buildButton()); toolBar.addSeparator(); toolBar.add(getAction(CreateObjEntityAction.class).buildButton()); toolBar.add(getAction(CreateEmbeddableAction.class).buildButton()); toolBar.add(getAction(CreateQueryAction.class).buildButton()); toolBar.addSeparator(); toolBar.add(getAction(NavigateBackwardAction.class).buildButton()); toolBar.add(getAction(NavigateForwardAction.class).buildButton()); JPanel east = new JPanel(new BorderLayout()); // is used to place search feature // components the most right on a // toolbar final JTextField findField = new JTextField(10); findField.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() != KeyEvent.VK_ENTER) { findField.setBackground(Color.white); } } public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { } }); findField.setAction(getAction(FindAction.class)); JLabel findLabel = new JLabel("Search:"); findLabel.setLabelFor(findField); Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { public void eventDispatched(AWTEvent event) { if (event instanceof KeyEvent) { if (((KeyEvent) event).getModifiers() == Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() && ((KeyEvent) event).getKeyCode() == KeyEvent.VK_F) { findField.requestFocus(); } } } }, AWTEvent.KEY_EVENT_MASK); JPanel box = new JPanel(); // is used to place label and text field one after // another box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS)); box.add(findLabel); box.add(findField); east.add(box, BorderLayout.EAST); toolBar.add(east); getContentPane().add(toolBar, BorderLayout.NORTH); }