List of usage examples for javax.swing.event DocumentEvent getLength
public int getLength();
From source file:ca.uhn.hl7v2.testpanel.ui.editor.Hl7V2MessageEditorPanel.java
private void initLocal() { myDocumentListener = new DocumentListener() { public void changedUpdate(DocumentEvent theE) { ourLog.info("Document change: " + theE); handleChange(theE);//from ww w . ja v a2 s . c o m } private void handleChange(DocumentEvent theE) { myDontRespondToSourceMessageChanges = true; try { long start = System.currentTimeMillis(); String newSource = myMessageEditor.getText(); int changeStart = theE.getOffset(); int changeEnd = changeStart + theE.getLength(); myMessage.updateSourceMessage(newSource, changeStart, changeEnd); ourLog.info("Handled document update in {} ms", System.currentTimeMillis() - start); } finally { myDontRespondToSourceMessageChanges = false; } } public void insertUpdate(DocumentEvent theE) { ourLog.info("Document insert: " + theE); handleChange(theE); } public void removeUpdate(DocumentEvent theE) { ourLog.info("Document removed: " + theE); handleChange(theE); } }; myMessageEditor.getDocument().addDocumentListener(myDocumentListener); myMessageEditor.addCaretListener(new CaretListener() { public void caretUpdate(final CaretEvent theE) { removeMostHighlights(); if (!myDisableCaretUpdateHandling) { myController.invokeInBackground(new Runnable() { @Override public void run() { myMessage.setHighlitedPathBasedOnRange(new Range(theE.getDot(), theE.getMark())); myTreePanel.repaint(); } }); } } }); updateOutboundConnectionsBox(); myOutboundConnectionsListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent theEvt) { updateOutboundConnectionsBox(); } }; myController.getOutboundConnectionList().addPropertyChangeListener(OutboundConnectionList.PROP_LIST, myOutboundConnectionsListener); myOutboundInterfaceCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent theE) { if (!myOutboundInterfaceComboModelIsUpdating) { updateSendButton(); } } }); JMenuItem copyMenuItem = new JMenuItem("Copy to Clipboard"); copyMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent theE) { String selection = myTerserPathTextField.getText(); StringSelection data = new StringSelection(selection); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(data, data); } }); myTerserPathPopupMenu.add(copyMenuItem); myProfilesListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent theEvt) { myProfileComboboxModel.update(); registerProfileNamesListeners(); } }; myController.getProfileFileList().addPropertyChangeListener(ProfileFileList.PROP_FILES, myProfilesListener); registerProfileNamesListeners(); myProfilesNamesListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent theEvt) { myProfileComboboxModel.update(); } }; }
From source file:org.languagetool.gui.LanguageToolSupport.java
private void init() { try {/* ww w . j a v a2s .c o m*/ config = new Configuration(new File(System.getProperty("user.home")), CONFIG_FILE, null); } catch (IOException ex) { throw new RuntimeException("Could not load configuration", ex); } Language defaultLanguage = config.getLanguage(); if (defaultLanguage == null) { defaultLanguage = Languages.getLanguageForLocale(Locale.getDefault()); } /** * Warm-up: we have a lot of lazy init in LT, which causes the first check to * be very slow (several seconds) for languages with a lot of data and a lot of * rules. We just assume that the default language is the language that the user * often uses and init the LT object for that now, not just when it's first used. * This makes the first check feel much faster: */ reloadLanguageTool(defaultLanguage); checkExecutor = new ScheduledThreadPoolExecutor(1, new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setDaemon(true); t.setPriority(Thread.MIN_PRIORITY); t.setName(t.getName() + "-lt-background"); return t; } }); check = new AtomicInteger(0); this.textComponent.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { mustDetectLanguage = config.getAutoDetect(); recalculateSpans(e.getOffset(), e.getLength(), false); if (backgroundCheckEnabled) { checkDelayed(null); } } @Override public void removeUpdate(DocumentEvent e) { mustDetectLanguage = config.getAutoDetect(); recalculateSpans(e.getOffset(), e.getLength(), true); if (backgroundCheckEnabled) { checkDelayed(null); } } @Override public void changedUpdate(DocumentEvent e) { mustDetectLanguage = config.getAutoDetect(); if (backgroundCheckEnabled) { checkDelayed(null); } } }); mouseListener = new MouseListener() { @Override public void mouseClicked(MouseEvent me) { } @Override public void mousePressed(MouseEvent me) { if (me.isPopupTrigger()) { showPopup(me); } } @Override public void mouseReleased(MouseEvent me) { if (me.isPopupTrigger()) { showPopup(me); } } @Override public void mouseEntered(MouseEvent me) { } @Override public void mouseExited(MouseEvent me) { } }; this.textComponent.addMouseListener(mouseListener); actionListener = e -> _actionPerformed(e); mustDetectLanguage = config.getAutoDetect(); if (!this.textComponent.getText().isEmpty() && backgroundCheckEnabled) { checkImmediately(null); } }
From source file:tufts.vue.RichTextBox.java
public void changedUpdate(DocumentEvent de) { if (TestDebug || DEBUG.TEXT) out("changeUpdate " + de.getType() + " len=" + de.getLength()); handleChange();// w ww. ja v a 2 s. c o m }