List of usage examples for javax.swing.event DocumentEvent getDocument
public Document getDocument();
From source file:org.openmicroscopy.shoola.agents.metadata.editor.PropertiesUI.java
/** * Fires property indicating that some text has been entered. * @see DocumentListener#insertUpdate(DocumentEvent) *//*from ww w. j av a 2 s. c om*/ public void insertUpdate(DocumentEvent e) { handleNameChanged(e.getDocument()); firePropertyChange(EditorControl.SAVE_PROPERTY, Boolean.valueOf(false), Boolean.valueOf(true)); }
From source file:org.openmicroscopy.shoola.agents.metadata.editor.PropertiesUI.java
/** * Fires property indicating that some text has been entered. * @see DocumentListener#removeUpdate(DocumentEvent) */// ww w.jav a 2 s . co m public void removeUpdate(DocumentEvent e) { handleNameChanged(e.getDocument()); firePropertyChange(EditorControl.SAVE_PROPERTY, Boolean.valueOf(false), Boolean.valueOf(true)); }
From source file:org.paxle.desktop.impl.event.MultipleChangesListener.java
public void insertUpdate(DocumentEvent e) { setState(e.getDocument(), System.currentTimeMillis()); }
From source file:org.paxle.desktop.impl.event.MultipleChangesListener.java
public void removeUpdate(DocumentEvent e) { setState(e.getDocument(), System.currentTimeMillis()); }
From source file:org.photovault.swingui.PhotoInfoEditor.java
/** DocumentEvent is generated when text field (or to be more exact, its document) is modified.//from w w w.ja v a2s . c o m @param ev The DocumentEvent describing the change. */ public void insertUpdate(DocumentEvent ev) { Document changedDoc = ev.getDocument(); PhotoInfoFields changedField = (PhotoInfoFields) changedDoc.getProperty(FIELD); Set fieldValues = ctrl.getFieldValues(changedField); /* Avoid emptying model when the field has multiple values in the model. */ Object value = getField(changedField); StringBuffer debugMsg = new StringBuffer(); debugMsg.append("insertUpdate ").append(changedField).append(": ").append(value); debugMsg.append("\nOld values: ["); boolean first = true; for (Object oldValue : fieldValues) { if (!first) debugMsg.append(", "); debugMsg.append(oldValue); first = false; } debugMsg.append("]"); log.debug(debugMsg.toString()); if ((fieldValues.size() == 1 && !fieldValues.iterator().next().equals(value)) || (fieldValues.size() != 1 && changedDoc.getLength() > 0)) { ctrl.viewChanged(this, changedField, value); } }
From source file:org.rockyroadshub.planner.core.gui.calendar.FormPane.java
private void update(DocumentEvent e) { DefaultStyledDocument doc = (DefaultStyledDocument) e.getDocument(); if (doc.equals(documentEvt)) { update0(eventLimit, formatEvt, doc); } else if (doc.equals(documentLoc)) { update0(locationLimit, formatLoc, doc); } else if (doc.equals(documentDsc)) { update0(descriptionLimit, formatDsc, doc); }/*from www . j a v a 2 s . c o m*/ }
From source file:org.yccheok.jstock.gui.AjaxAutoCompleteJComboBox.java
private DocumentListener getDocumentListener() { return new DocumentListener() { @Override//from ww w . j a v a2 s . c om public void insertUpdate(DocumentEvent e) { try { final String string = e.getDocument().getText(0, e.getDocument().getLength()).trim(); _handle(string); } catch (BadLocationException ex) { log.error(null, ex); } } @Override public void removeUpdate(DocumentEvent e) { try { final String string = e.getDocument().getText(0, e.getDocument().getLength()).trim(); _handle(string); } catch (BadLocationException ex) { log.error(null, ex); } } @Override public void changedUpdate(DocumentEvent e) { try { final String string = e.getDocument().getText(0, e.getDocument().getLength()).trim(); _handle(string); } catch (BadLocationException ex) { log.error(null, ex); } } private void _handle(final String string) { // We are no longer busy. busySubject.notify(AjaxAutoCompleteJComboBox.this, false); if (AjaxAutoCompleteJComboBox.this.getSelectedItem() != null) { if (AjaxAutoCompleteJComboBox.this.getSelectedItem().toString().equals(string)) { // We need to differentiate, whether "string" is from user // typing, or drop down list selection. This is because when // user perform selection, document change event will be triggered // too. When string is from drop down list selection, user // are not expecting any auto complete suggestion. Return early. return; } } if (string.isEmpty()) { // Empty string. Return early. Do not perform hidePopup and // removeAllItems right here. As when user performs list // selection, previous text field item will be removed, and // cause us fall into this scope. We do not want to hidePopup // and removeAllItems when user is selecting his item. // // hidePopup and removeAllItems when user clears off all items // in text field, will be performed through keyReleased. return; } // We are busy contacting server right now. busySubject.notify(AjaxAutoCompleteJComboBox.this, true); canRemoveAllItems = true; ajaxYahooSearchEngineMonitor.clearAndPut(string); ajaxGoogleSearchEngineMonitor.clearAndPut(string); } }; }
From source file:org.yccheok.jstock.gui.AutoCompleteJComboBox.java
private DocumentListener getDocumentListener() { return new DocumentListener() { private volatile boolean ignore = false; @Override// www. j a va 2 s . c o m public void insertUpdate(DocumentEvent e) { try { final String string = e.getDocument().getText(0, e.getDocument().getLength()).trim(); handle(string); } catch (BadLocationException ex) { log.error(null, ex); } } @Override public void removeUpdate(DocumentEvent e) { try { final String string = e.getDocument().getText(0, e.getDocument().getLength()).trim(); handle(string); } catch (BadLocationException ex) { log.error(null, ex); } } @Override public void changedUpdate(DocumentEvent e) { try { final String string = e.getDocument().getText(0, e.getDocument().getLength()).trim(); handle(string); } catch (BadLocationException ex) { log.error(null, ex); } } private void _handle(final String string) { // We are no longer busy. busySubject.notify(AutoCompleteJComboBox.this, false); if (AutoCompleteJComboBox.this.getSelectedItem() != null) { // Remember to use toString(). As getSelectedItem() can be // either StockInfo, or ResultSet. if (AutoCompleteJComboBox.this.getSelectedItem().toString().equals(string)) { // We need to differentiate, whether "string" is from user // typing, or drop down list selection. This is because when // user perform selection, document change event will be triggered // too. When string is from drop down list selection, user // are not expecting any auto complete suggestion. Return early. return; } } if (string.isEmpty()) { // Empty string. Return early. Do not perform hidePopup and // removeAllItems right here. As when user performs list // selection, previous text field item will be removed, and // cause us fall into this scope. We do not want to hidePopup // and removeAllItems when user is selecting his item. // // hidePopup and removeAllItems when user clears off all items // in text field, will be performed through keyReleased. return; } // Use to avoid endless DocumentEvent triggering. ignore = true; // During _handle operation, there will be a lot of ListDataListeners // trying to modify the content of our text field. We will not allow // them to do so. // // Without setReadOnly(true), when we type the first character "w", IME // will suggest ... However, when we call removeAllItems and addItem, // JComboBox will "commit" this suggestion to JComboBox's text field. // Hence, if we continue to type second character "m", the string displayed // at JComboBox's text field will be ... // AutoCompleteJComboBox.this.jComboBoxEditor.setReadOnly(true); // Must hide popup. If not, the pop up windows will not be // resized. AutoCompleteJComboBox.this.hidePopup(); AutoCompleteJComboBox.this.removeAllItems(); boolean shouldShowPopup = false; if (AutoCompleteJComboBox.this.stockInfoDatabase != null) { java.util.List<StockInfo> stockInfos = greedyEnabled ? stockInfoDatabase.greedySearchStockInfos(string) : stockInfoDatabase.searchStockInfos(string); sortStockInfosIfPossible(stockInfos); if (stockInfos.isEmpty() == false) { // Change to offline mode before adding any item. changeMode(Mode.Offline); } for (StockInfo stockInfo : stockInfos) { AutoCompleteJComboBox.this.addItem(stockInfo); shouldShowPopup = true; } if (shouldShowPopup) { AutoCompleteJComboBox.this.showPopup(); } else { } // if (shouldShowPopup) } // if (AutoCompleteJComboBox.this.stockInfoDatabase != null) if (shouldShowPopup == false) { // OK. We found nothing from offline database. Let's // ask help from online database. // We are busy contacting server right now. // TODO // Only enable ajaxYahooSearchEngineMonitor, till we solve // http://sourceforge.net/apps/mediawiki/jstock/index.php?title=TechnicalDisability busySubject.notify(AutoCompleteJComboBox.this, true); canRemoveAllItems = true; ajaxYahooSearchEngineMonitor.clearAndPut(string); ajaxGoogleSearchEngineMonitor.clearAndPut(string); } // When we are in windows look n feel, the text will always be selected. We do not want that. final Component component = AutoCompleteJComboBox.this.getEditor().getEditorComponent(); if (component instanceof JTextField) { JTextField jTextField = (JTextField) component; jTextField.setSelectionStart(jTextField.getText().length()); jTextField.setSelectionEnd(jTextField.getText().length()); jTextField.setCaretPosition(jTextField.getText().length()); } // Restore. AutoCompleteJComboBox.this.jComboBoxEditor.setReadOnly(false); ignore = false; } private void handle(final String string) { if (ignore) { return; } // Submit to GUI event queue. Used to avoid // Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Attempt to mutate in notification SwingUtilities.invokeLater(new Runnable() { @Override public void run() { _handle(string); } }); } }; }
From source file:se.trixon.mapollage.ui.config.ModuleDescriptionPanel.java
private void init() { DocumentListener documentListener = new DocumentListener() { @Override//from w ww . java 2s .com public void changedUpdate(DocumentEvent e) { saveOption(e.getDocument()); notifyPhotoDescriptionListener(); } @Override public void insertUpdate(DocumentEvent e) { saveOption(e.getDocument()); notifyPhotoDescriptionListener(); } @Override public void removeUpdate(DocumentEvent e) { saveOption(e.getDocument()); notifyPhotoDescriptionListener(); } private void saveOption(Document document) { if (document == customTextArea.getDocument()) { mDescription.setCustomValue(customTextArea.getText()); } else if (document == externalFileTextField.getDocument()) { mDescription.setExternalFileValue(externalFileTextField.getText()); } } }; customTextArea.getDocument().addDocumentListener(documentListener); externalFileTextField.getDocument().addDocumentListener(documentListener); }
From source file:simplealbum.mvc.autocomplete.JTextPaneX.java
protected void fireText(DocumentEvent e) { Document document = e.getDocument(); String text = ""; try {/*from ww w. j a v a 2 s . c o m*/ text = document.getText(0, document.getLength()); } catch (BadLocationException ex) { Logger.getLogger(JTextPaneX.class.getName()).log(Level.SEVERE, null, ex); } firePropertyChange("text", null, text); }