List of usage examples for javax.swing.event DocumentEvent getDocument
public Document getDocument();
From source file:com.ansorgit.plugins.bash.editor.inspections.inspections.FixShebangInspection.java
private void updateShebangLines(DocumentEvent documentEvent) { validShebangCommands.clear();//from ww w . ja v a 2 s . c o m try { Document doc = documentEvent.getDocument(); for (String item : doc.getText(0, doc.getLength()).split("\n")) { if (item.trim().length() != 0) { validShebangCommands.add(item); } } } catch (BadLocationException e) { throw new RuntimeException("Could not save shebang inspection settings input", e); } }
From source file:Main.java
private void initComponents() { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane textPane = new JTextPane(); ((AbstractDocument) textPane.getDocument()).addDocumentListener(new DocumentListener() { @Override// w w w . ja va 2 s . c om public void insertUpdate(final DocumentEvent de) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { StyledDocument doc = (StyledDocument) de.getDocument(); int start = Utilities.getRowStart(textPane, Math.max(0, de.getOffset() - 1)); int end = Utilities.getWordStart(textPane, de.getOffset() + de.getLength()); String text = doc.getText(start, end - start); for (String emoticon : imageTokens) { int i = text.indexOf(emoticon); while (i >= 0) { final SimpleAttributeSet attrs = new SimpleAttributeSet( doc.getCharacterElement(start + i).getAttributes()); if (StyleConstants.getIcon(attrs) == null) { switch (emoticon) { case imageToken: StyleConstants.setIcon(attrs, anImage); break; } doc.remove(start + i, emoticon.length()); doc.insertString(start + i, emoticon, attrs); } i = text.indexOf(emoticon, i + emoticon.length()); } } } catch (BadLocationException ex) { ex.printStackTrace(); } } }); } @Override public void removeUpdate(DocumentEvent e) { } @Override public void changedUpdate(DocumentEvent e) { } }); JScrollPane scrollPane = new JScrollPane(textPane); scrollPane.setPreferredSize(new Dimension(300, 300)); frame.add(scrollPane); frame.pack(); frame.setVisible(true); }
From source file:LiveParenMatcher.java
public void removeUpdate_2(DocumentEvent de) { // print some debugging information before matching the parens ElementIterator iter = new ElementIterator(de.getDocument()); for (Element elem = iter.first(); elem != null; elem = iter.next()) { DocumentEvent.ElementChange change = de.getChange(elem); if (change != null) { // null means there was no change in elem System.out.println("Element " + elem.getName() + " (depth " + iter.depth() + ") changed its children: " + change.getChildrenRemoved().length + " children removed, " + change.getChildrenAdded().length + " children added.\n"); }// ww w.j av a 2 s . co m } SwingUtilities.invokeLater(this); // will call run() }
From source file:de.unentscheidbar.validation.swing.trigger.DocumentChangeTrigger.java
private void notify(DocumentEvent e) { /* Multiple components sharing a document instance is rare but we've got it covered */ for (Wrapper<JComponent> component : documentMap.get(Beans.identity(e.getDocument()))) { fireEvent(component.get());/*from www . j av a 2 s . c o m*/ } }
From source file:eu.delving.sip.frames.OutputFrame.java
private JPanel createOutputPanel() { final JPanel p = new JPanel(new BorderLayout()); p.setBorder(BorderFactory.createTitledBorder("Output record")); outputArea = new JTextArea(sipModel.getRecordCompileModel().getOutputDocument()); outputArea.setLineWrap(true);//from w w w. ja v a2 s.co m outputArea.setFont(MONOSPACED); outputArea.setWrapStyleWord(true); outputArea.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent documentEvent) { try { String first = documentEvent.getDocument().getText(0, 1); final boolean error = first.startsWith("#"); setError(outputArea, error); sipModel.exec(new Swing() { @Override public void run() { outputArea.setCaretPosition(0); } }); } catch (BadLocationException e) { // who cares } } @Override public void removeUpdate(DocumentEvent documentEvent) { } @Override public void changedUpdate(DocumentEvent documentEvent) { } }); outputArea.getInputMap().put(KeystrokeHelper.DOWN, "next"); outputArea.getInputMap().put(KeystrokeHelper.RIGHT, "next"); outputArea.getInputMap().put(KeystrokeHelper.UP, "prev"); outputArea.getInputMap().put(KeystrokeHelper.LEFT, "prev"); outputArea.getActionMap().put("next", new NextAction()); outputArea.getActionMap().put("prev", new PrevAction()); searchField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { found.clear(); foundSelected = 0; String xml = outputArea.getText().toLowerCase(); String sought = searchField.getText().toLowerCase(); if (!sought.isEmpty()) { int start = 0; while (found.size() < 30) { int pos = xml.indexOf(sought, start); if (pos < 0) break; found.add(pos); start = pos + sought.length(); } } selectFound(); } }); JPanel sp = new JPanel(); JLabel label = new JLabel("Search:", JLabel.RIGHT); label.setLabelFor(searchField); sp.add(label); sp.add(searchField); sp.add(new JLabel("Press ENTER, then use arrow keys")); p.add(scrollVH(outputArea), BorderLayout.CENTER); p.add(sp, BorderLayout.SOUTH); return p; }
From source file:com.mirth.connect.client.ui.editors.BasicModeSettingsDialog.java
private void changeAbbreviation(DocumentEvent evt) { String text = ""; try {//from w ww . ja va2 s. co m text = evt.getDocument().getText(0, evt.getDocument().getLength()).trim(); } catch (BadLocationException e) { } if (evt.getDocument().equals(startOfMessageBytesField.getDocument())) { startOfMessageAbbreviation = TcpUtil.convertHexToAbbreviation(text); actionListener.actionPerformed(new ActionEvent(startOfMessageBytesField, ActionEvent.ACTION_PERFORMED, BasicModePlugin.CHANGE_START_BYTES_COMMAND)); } else if (evt.getDocument().equals(endOfMessageBytesField.getDocument())) { endOfMessageAbbreviation = TcpUtil.convertHexToAbbreviation(text); actionListener.actionPerformed(new ActionEvent(endOfMessageBytesField, ActionEvent.ACTION_PERFORMED, BasicModePlugin.CHANGE_END_BYTES_COMMAND)); } changeAbbreviation(); }
From source file:edu.ku.brc.specify.tasks.subpane.wb.EditFormControlDlg.java
public void insertUpdate(DocumentEvent e) { changeTracker.put(e.getDocument(), true); }
From source file:edu.ku.brc.specify.tasks.subpane.wb.EditFormControlDlg.java
public void removeUpdate(DocumentEvent e) { changeTracker.put(e.getDocument(), true); }
From source file:edu.ku.brc.specify.tasks.subpane.wb.EditFormControlDlg.java
public void changedUpdate(DocumentEvent e) { changeTracker.put(e.getDocument(), true); }
From source file:com.codeasylum.liquibase.Liquidate.java
private void documentUpdate(DocumentEvent documentEvent) { if (changeSensitive) { if (documentEvent.getDocument() == hostTextField.getDocument()) { config.setHost(hostTextField.getText()); } else if (documentEvent.getDocument() == portTextField.getDocument() && (portTextField.getText() != null) && (portTextField.getText().length() > 0)) { config.setPort(Integer.parseInt(portTextField.getText())); } else if ((documentEvent.getDocument() == schemaTextField.getDocument())) { config.setSchema(schemaTextField.getText()); } else if (documentEvent.getDocument() == userTextField.getDocument()) { config.setUser(userTextField.getText()); } else if (documentEvent.getDocument() == passwordField.getDocument()) { config.setPassword(new String(passwordField.getPassword())); } else if (documentEvent.getDocument() == changeLogTextField.getDocument()) { config.setChangeLog(changeLogTextField.getText()); } else if (documentEvent.getDocument() == outputTextField.getDocument()) { config.setOutput(outputTextField.getText()); }/*w ww . ja va 2 s.com*/ } }