/** * Read a single character. * * @return the character or -1 if the end of the document has been reached. */ @Override public int read(){ if (this.position < this.document.getLength()){ try { char c = this.document.getText((int)this.position, 1).charAt(0); this.position++; return c; } catch (BadLocationException e){ // Ignore IgnoreMessageException exceptionIgnored = new IgnoreMessageException(e); LOGGER.trace(exceptionIgnored, exceptionIgnored); return -1; } } else { return -1; } }
String s = this.document.getText((int)this.position, length); this.position += length; for (int i=0; i<length; i++){
/** Stores the text contained within the specified portion of the document in a segment. @param offset The offset into the document representing the desired start of the text. @param length The length of the text. @param text The segment in which to store the text. @exception BadLocationException If the given offset and length does not represent a valid range in the document. **/ public synchronized void getText (int offset, int length, Segment text) throws BadLocationException { document_.getText (offset, length, text); }
/** Returns the text contained within the specified portion of the document. @param offset The offset into the document representing the desired start of the text. @param length The length of the text. @return The text. @exception BadLocationException If the given offset and length does not represent a valid range in the document. **/ public synchronized String getText (int offset, int length) throws BadLocationException { return document_.getText (offset, length); }
/** Stores the text contained within the specified portion of the document in a segment. @param offset The offset into the document representing the desired start of the text. @param length The length of the text. @param text The segment in which to store the text. @exception BadLocationException If the given offset and length does not represent a valid range in the document. **/ public synchronized void getText (int offset, int length, Segment text) throws BadLocationException { document_.getText (offset, length, text); }
/** Returns the text contained within the specified portion of the document. @param offset The offset into the document representing the desired start of the text. @param length The length of the text. @return The text. @exception BadLocationException If the given offset and length does not represent a valid range in the document. **/ public synchronized String getText (int offset, int length) throws BadLocationException { return document_.getText (offset, length); }
/** * Read a single character. * * @return the character or -1 if the end of the document has been reached. */ public int read(){ if (position < document.getLength()){ try { char c = document.getText((int)position, 1).charAt(0); position++; return c; } catch (BadLocationException x){ return -1; } } else { return -1; } }
import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.text.AttributeSet; import javax.swing.text.PlainDocument; /** * * @author cpp-qt */ public class HexDocument extends PlainDocument { private String text = ""; @Override public void insertString(int offset, String txt, AttributeSet a) { try { text = getText(0, getLength()); if ((text + txt).matches("[0-9a-fA-F]{0,7}")) { super.insertString(offset, txt, a); } } catch (Exception ex) { Logger.getLogger(HexDocument.class.getName()).log(Level.SEVERE, null, ex); } } }
int val = Integer.parseInt(getText(0,offs)); if (val == 0)
break; } else { if(this.getText(0, this.getLength()).contains(".")){ isValid = false; break;
String text = abstractDocument.getText(0, abstractDocument.getLength()); int newLength = text.length() + inputLength;
String currText = getText(0, getLength()); StringBuilder b = new StringBuilder(currText); b.insert(offs, str);
Element line = doc.getParagraphElement(offset); int lineStart = line.getStartOffset(), lineEnd = line.getEndOffset(); String content = doc.getText(lineStart, lineEnd - lineStart); int start = 0; while(content.charAt(start)==' ') {
String s = document.getText((int)position, length); position += length; for (int i=0; i<length; i++){
String text = getText(0, getLength());
@Override public int getOffsetOfDeepestStatementLocationAtPos( int caretPosition, boolean strict ) { Element root = getDocument().getDefaultRootElement(); int iElem = root.getElementIndex( caretPosition ); if( iElem < 0 ) { return -1; } Element elem = root.getElement( iElem ); try { int lineStart = elem.getStartOffset(); int lineEnd = elem.getEndOffset(); String text = getDocument().getText( lineStart, lineEnd - lineStart ); String trimmed = text.trim(); int whitespace = text.indexOf( trimmed ); if( whitespace == text.length() ) { // all whitespace return -1; } // location of first non-whitespace char in line return lineStart + whitespace; } catch( BadLocationException e ) { throw new RuntimeException( e ); } }
PlainDocument doc = ((PlainDocument)e.getDocument()); try { String value = doc.getText(0, doc.getLength()); changed = originalValue == null || !originalValue.equals(value); } catch(BadLocationException exc) {
/** Writes the contents of the document to the data queue.The entry replaces the current content. System and path must be set prior to calling this method. **/ public void write () { workingEventSupport_.fireStartWorking (); // Write the contents. try { dataQueue_.write (document_.getText (0, document_.getLength ())); } catch (Exception e) { errorEventSupport_.fireError (e); } workingEventSupport_.fireStopWorking (); }
/** Writes the contents of the document to the data queue.The entry replaces the current content. System and path must be set prior to calling this method. @param key The string that contains the key for this entry. **/ public void write (String key) { workingEventSupport_.fireStartWorking (); // Write the contents. try { dataQueue_.write (key, document_.getText (0, document_.getLength ())); } catch (Exception e) { errorEventSupport_.fireError (e); } workingEventSupport_.fireStopWorking (); }