List of usage examples for java.awt.event FocusAdapter FocusAdapter
FocusAdapter
From source file:edu.ku.brc.af.ui.forms.validation.ValPasswordField.java
/** * Setup colors and listeners.// w w w. ja v a 2 s . c om */ public void init() { setControlSize(this); bgColor = getBackground(); if (valTextColor == null || requiredFieldColor == null) { valTextColor = AppPrefsCache.getColorWrapper("ui", "formatting", "valtextcolor"); requiredFieldColor = AppPrefsCache.getColorWrapper("ui", "formatting", "requiredfieldcolor"); } AppPrefsCache.addChangeListener("ui.formatting.requiredfieldcolor", this); addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { isNew = false; repaint(); } }); getDocument().addDocumentListener(new DocumentAdaptor() { @Override protected void changed(DocumentEvent e) { isChanged = true; } }); }
From source file:edu.ku.brc.specify.datamodel.busrules.SpecifyUserBusRules.java
@Override public void initialize(final Viewable viewableArg) { if (viewableArg == null || pwdTxt != null) { return;/*from ww w.jav a2 s. c o m*/ } super.initialize(viewableArg); pwdTxt = formViewObj.getCompById("3"); keyTxt = formViewObj.getCompById("key"); showPwdBtn = formViewObj.getCompById("ShowPwd"); pwdStrenthUI = formViewObj.getCompById("6"); genBtn = formViewObj.getCompById("GenerateKey"); copyBtn = formViewObj.getCompById("CopyToCB"); // This is in case the BusRules are used without the form. if (pwdTxt == null) { return; } Institution institution = AppContextMgr.getInstance().getClassObject(Institution.class); minPwdLen = (int) institution.getMinimumPwdLength(); pwdTxt.setMinLen(minPwdLen); pwdStrenthUI.setMinPwdLen(minPwdLen); final char echoChar = pwdTxt.getEchoChar(); currEcho = echoChar; pwdTxt.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { super.focusLost(e); String pwdStr = new String(pwdTxt.getPassword()); if (StringUtils.isNotEmpty(pwdStr) && pwdStr.length() < PWD_LEN_THRESHOLD) { // make sure the password has changed if (currentPlainTextPWD == null || !currentPlainTextPWD.equals(pwdStr)) { // this means the password is new currentPlainTextPWD = pwdStr; } } } }); if (showPwdBtn != null) { showPwdBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { currEcho = currEcho == echoChar ? 0 : echoChar; pwdTxt.setEchoChar(currEcho); showPwdBtn.setText( UIRegistry.getResourceString(currEcho == echoChar ? "SHOW_PASSWORD" : "HIDE_PASSWORD")); } }); } if (copyBtn != null) { copyBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { UIHelper.setTextToClipboard(new String(pwdTxt.getPassword())); } }); } if (genBtn != null) { genBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (StringUtils.isNotEmpty(currentPlainTextPWD) && currentPlainTextPWD.length() >= minPwdLen) { String key = createEncryptMasterKey(currentPlainTextPWD); if (key != null) { if (keyTxt != null) { keyTxt.setText(key); } UIHelper.setTextToClipboard(key); UIRegistry.showLocalizedMsg("SPUSR_KEYGEN"); } } } }); genBtn.setEnabled(false); copyBtn.setEnabled(false); pwdTxt.getDocument().addDocumentListener(new DocumentAdaptor() { @Override protected void changed(DocumentEvent e) { super.changed(e); char[] chars = pwdTxt.getPassword(); boolean enable = chars != null && chars.length >= minPwdLen; genBtn.setEnabled(enable); copyBtn.setEnabled(enable); } }); } if (pwdStrenthUI == null) { return; } pwdStrenthUI.setPasswordField(pwdTxt, null); }
From source file:org.scify.talkandplay.gui.configuration.EntertainmentTab.java
private void setListeners() { musicPathTextField.addMouseListener(new MouseAdapter() { @Override/*w w w . j a v a2 s. c o m*/ public void mouseClicked(MouseEvent me) { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle(" "); chooser.setAcceptAllFileFilterUsed(false); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { musicPathTextField.setText(chooser.getSelectedFile().getAbsolutePath()); } } }); videoPathTextField.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent me) { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle(" "); chooser.setAcceptAllFileFilterUsed(false); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { videoPathTextField.setText(chooser.getSelectedFile().getAbsolutePath()); } } }); musicPathTextField.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent fe) { if (" ".equals(musicPathTextField.getText())) { musicPathTextField.setText(""); } } public void focusLost(FocusEvent fe) { if (musicPathTextField.getText().isEmpty()) { musicPathTextField.setText(" "); } else if (!musicPathTextField.getText().endsWith("/")) { musicPathTextField.setText(musicPathTextField.getText() + "/"); } } }); videoPathTextField.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent fe) { if (" video".equals(videoPathTextField.getText())) { videoPathTextField.setText(""); } } public void focusLost(FocusEvent fe) { if (videoPathTextField.getText().isEmpty()) { videoPathTextField.setText(" video"); } else if (!videoPathTextField.getText().endsWith("/")) { videoPathTextField.setText(videoPathTextField.getText() + "/"); } } }); songSumTextField.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent fe) { if ("".equals(songSumTextField.getText())) { songSumTextField.setText(""); } } public void focusLost(FocusEvent fe) { if (songSumTextField.getText().isEmpty()) { songSumTextField.setText(""); } } }); backButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent me) { parent.goBack(); } }); }
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 w w w . j a v a 2 s . 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:gtu._work.etc.EnglishAdd.java
private void initGUI() { try {/*from www . java 2s . co m*/ BorderLayout thisLayout = new BorderLayout(); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); getContentPane().setLayout(thisLayout); this.setPreferredSize(new java.awt.Dimension(400, 211)); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); jTabbedPane1.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { if (jTabbedPane1.getSelectedIndex() == 2) { // XXX } } }); { jPanel1 = new JPanel(); FlowLayout jPanel1Layout = new FlowLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("add", null, jPanel1, null); jPanel1.setPreferredSize(new java.awt.Dimension(387, 233)); { showwordText = new JTextField(); jPanel1.add(showwordText); showwordText.setPreferredSize(new java.awt.Dimension(271, 23)); showwordText.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { if (evt.getKeyCode() == KeyEvent.VK_ENTER) { scanWord(); } } }); showwordText.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent evt) { scanWord(); } }); } { netChkBox = new JCheckBox(); jPanel1.add(netChkBox); netChkBox.setSelected(true); } { jScrollPane2 = new JScrollPane(); jPanel1.add(jScrollPane2); jScrollPane2.setPreferredSize(new java.awt.Dimension(364, 80)); { showChineseArea = new JTextArea(); jScrollPane2.setViewportView(showChineseArea); showChineseArea.setPreferredSize(new java.awt.Dimension(364, 80)); } } { setFileBtn = new JButton(); jPanel1.add(setFileBtn); setFileBtn.setText("set file"); setFileBtn.setPreferredSize(new java.awt.Dimension(261, 30)); setFileBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { File file = JCommonUtil._jFileChooser_selectFileOnly(); if (file == null) { JCommonUtil._jOptionPane_showMessageDialog_error("?!"); return; } currentFile = file; StringBuffer sb = new StringBuffer(); try { BufferedReader reader = new BufferedReader( new InputStreamReader(new FileInputStream(currentFile), "BIG5")); for (String line = null; (line = reader.readLine()) != null;) { sb.append(line + "\r\n"); } reader.close(); } catch (IOException e) { e.printStackTrace(); } wordTextArea.setText(sb.toString()); } }); } } { jPanel3 = new JPanel(); BorderLayout jPanel3Layout = new BorderLayout(); jPanel3.setLayout(jPanel3Layout); jTabbedPane1.addTab("word", null, jPanel3, null); { jScrollPane1 = new JScrollPane(); jPanel3.add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.setPreferredSize(new java.awt.Dimension(387, 224)); { wordTextArea = new JTextArea(); jScrollPane1.setViewportView(wordTextArea); } } } } setDefaultSave(); pack(); this.setSize(400, 211); } catch (Exception e) { // add your error handling code here e.printStackTrace(); } }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopLookupField.java
public DesktopLookupField() { composition = new JPanel(); composition.setLayout(new BorderLayout()); composition.setFocusable(false);/*ww w . j a v a2 s . c o m*/ comboBox = new ExtendedComboBox() { @Override public void flushValue() { super.flushValue(); flushSelectedValue(); } }; comboBox.setEditable(true); comboBox.setPrototypeDisplayValue("AAAAAAAAAAAA"); autoComplete = AutoCompleteSupport.install(comboBox, items); for (int i = 0; i < comboBox.getComponentCount(); i++) { java.awt.Component component = comboBox.getComponent(i); component.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { initOptions(); // update text representation based on entity properties updateTextRepresentation(); } @Override public void focusLost(FocusEvent e) { // Reset invalid value checkSelectedValue(); } }); } // set value only on PopupMenu closing to avoid firing listeners on keyboard navigation comboBox.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { comboBox.updatePopupWidth(); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { if (!autoComplete.isEditableState()) { // Only if really item changed Object selectedItem = comboBox.getSelectedItem(); if (selectedItem instanceof ValueWrapper) { Object selectedValue = ((ValueWrapper) selectedItem).getValue(); setValue(selectedValue); } else if (selectedItem instanceof String && newOptionAllowed && newOptionHandler != null) { restorePreviousItemText(); newOptionHandler.addNewOption((String) selectedItem); } else if ((selectedItem != null) && !newOptionAllowed) { updateComponent(prevValue); } updateMissingValueState(); fireUserSelectionListeners(); } } @Override public void popupMenuCanceled(PopupMenuEvent e) { } }); comboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (settingValue || disableActionListener) return; Object selectedItem = comboBox.getSelectedItem(); if (selectedItem instanceof String && newOptionAllowed && newOptionHandler != null) { restorePreviousItemText(); newOptionHandler.addNewOption((String) selectedItem); } updateMissingValueState(); } }); setFilterMode(DEFAULT_FILTER_MODE); textField = new JTextField(); textField.setEditable(false); UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME); valueFormatter = new DefaultValueFormatter(sessionSource.getLocale()); composition.add(comboBox, BorderLayout.CENTER); impl = comboBox; DesktopComponentsHelper.adjustSize(comboBox); DesktopComponentsHelper.adjustSize(textField); textField.setMinimumSize( new Dimension(comboBox.getMinimumSize().width, textField.getPreferredSize().height)); initClearShortcut(); }
From source file:edu.ku.brc.af.ui.forms.validation.ValTextField.java
/** * /* ww w . ja v a2 s . co m*/ */ protected void init() { setControlSize(this); setDocument(new ValPlainTextDocument()); bgColor = getBackground(); if (valTextColor == null || requiredFieldColor == null) { valTextColor = AppPrefsCache.getColorWrapper("ui", "formatting", "valtextcolor"); requiredFieldColor = AppPrefsCache.getColorWrapper("ui", "formatting", "requiredfieldcolor"); } AppPrefsCache.addChangeListener("ui.formatting.requiredfieldcolor", this); addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { isNew = false; repaint(); } }); getDocument().addDocumentListener(new DocumentAdaptor() { @Override protected void changed(DocumentEvent e) { isChanged = true; } }); }
From source file:au.org.ala.delta.editor.ui.image.ImageSettingsDialog.java
private void addEventHandlers() { ActionMap actions = Application.getInstance().getContext().getActionMap(this); btnOk.setAction(actions.get("okImageSettingsChanges")); btnApply.setAction(actions.get("applyImageSettingsChanges")); btnCancel.setAction(actions.get("cancelImageSettingsChanges")); imagePathButton.setAction(actions.get("addToImagePath")); javax.swing.Action defaultFontChange = actions.get("defaultFontPropertyChanged"); defaultFontCombo.setAction(defaultFontChange); defaultSizeCombo.setAction(defaultFontChange); defaultBoldCheckBox.setAction(defaultFontChange); defaultBoldCheckBox.setText(""); defaultItalicCheckBox.setAction(defaultFontChange); defaultItalicCheckBox.setText(""); FocusListener defaultFontFocusListener = new FocusAdapter() { @Override/* w ww . ja v a 2 s. c o m*/ public void focusGained(FocusEvent e) { defaultFontPropertyChanged(); } }; defaultFontCombo.addFocusListener(defaultFontFocusListener); defaultSizeCombo.addFocusListener(defaultFontFocusListener); javax.swing.Action featureFontChange = actions.get("featureFontPropertyChanged"); featureFontCombo.setAction(featureFontChange); featureSizeCombo.setAction(featureFontChange); featureBoldCheckBox.setAction(featureFontChange); featureBoldCheckBox.setText(""); featureItalicCheckBox.setAction(featureFontChange); featureItalicCheckBox.setText(""); FocusListener featureFontFocusListener = new FocusAdapter() { @Override public void focusGained(FocusEvent e) { featureFontPropertyChanged(); } }; featureFontCombo.addFocusListener(featureFontFocusListener); featureSizeCombo.addFocusListener(featureFontFocusListener); javax.swing.Action buttonFontChange = actions.get("buttonFontPropertyChanged"); buttonFontCombo.setAction(buttonFontChange); buttonSizeCombo.setAction(buttonFontChange); buttonBoldCheckBox.setAction(buttonFontChange); buttonBoldCheckBox.setText(""); buttonItalicCheckBox.setAction(buttonFontChange); buttonItalicCheckBox.setText(""); FocusListener buttonFontFocusListener = new FocusAdapter() { @Override public void focusGained(FocusEvent e) { buttonFontPropertyChanged(); } }; buttonFontCombo.addFocusListener(buttonFontFocusListener); buttonSizeCombo.addFocusListener(buttonFontFocusListener); chooseColourButton.setAction(actions.get("displayColourChooser")); }
From source file:org.openconcerto.erp.core.common.ui.DeviseField.java
@Override public void init(String sqlName, Set<SQLField> fields) { this.field = CollectionUtils.getSole(fields); this.sqlName = sqlName; this.helper = new EmptyObjectHelper(this, new Predicate() { public boolean evaluate(Object object) { return object == null; // final String val = GestionDevise.currencyToString(((Long) // object).longValue()); }/*from w w w. ja v a2 s .co m*/ }); // TODO use JFormattedTextField => conflit getValue() // DefaultFormatterFactory NumberFormatter (getAllowsInvalid) NumberFormat addFilteringKeyListener(this); // select all on focus gained // except if the user is selecting with the mouse this.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent e) { DeviseField.this.gained = true; DeviseField.this.initialText = getText(); if (!DeviseField.this.mousePressed) { selectAll(); } } }); this.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { DeviseField.this.mousePressed = true; } public void mouseReleased(MouseEvent e) { // don't override the user selection if (DeviseField.this.gained && getSelectedText() == null) { selectAll(); } // don't select all for each mouse released DeviseField.this.gained = false; DeviseField.this.mousePressed = false; } }); this.addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent keyEvent) { // Sert a annuler une saisie if (keyEvent.getKeyChar() == KeyEvent.VK_ESCAPE) { DeviseField.this.setValue(DeviseField.this.initialText); selectAll(); } } }); }
From source file:ru.codemine.pos.ui.salespanel.QuantitySetupWindow.java
public void showWindow() { if (!actionListenersInit) setupActionListeners();/*from w ww . ja va 2s .com*/ mainWindow.blockBarcodeInput(); Product product = salesPanel.getChequeSetupPanel().getSelectedProduct(); if (product == null) { mainWindow.unblockBarcodeInput(); return; } int maxQuantity = storeService.getAvaibleStocksOnRetail(product); onStoresLabel.setText("?: " + String.valueOf(maxQuantity) + " ."); setTitle("? - " + product.getName()); spinner.setModel(new SpinnerNumberModel(1, 1, maxQuantity, 1)); JTextField ft = ((WebSpinner.DefaultEditor) spinner.getEditor()).getTextField(); ft.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { final JTextComponent txtcomp = (JTextComponent) e.getSource(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { txtcomp.selectAll(); } }); } }); ft.requestFocus(); setVisible(true); }