001: /* $Id $ */
002: /*
003: * Copyright 2000,2005 wingS development team.
004: *
005: * This file is part of wingS (http://wingsframework.org).
006: *
007: * wingS is free software; you can redistribute it and/or modify
008: * it under the terms of the GNU Lesser General Public License
009: * as published by the Free Software Foundation; either version 2.1
010: * of the License, or (at your option) any later version.
011: *
012: * Please see COPYING for the complete licence.
013: */
014: package org.wings.text;
015:
016: import org.wings.SDelayedEventModel;
017: import org.wings.event.SDocumentListener;
018:
019: import javax.swing.text.BadLocationException;
020:
021: import java.awt.event.ActionListener;
022: import java.io.Serializable;
023:
024: /**
025: * @author hengels
026: */
027: public interface SDocument extends Serializable, SDelayedEventModel {
028: /**
029: * Returns number of characters of content currently
030: * in the document.
031: *
032: * @return number of characters >= 0
033: */
034: public int getLength();
035:
036: /**
037: * Returns an array of all the <code>SDocumentListener</code>s added
038: * to this SDocument via addDocumentListener().
039: *
040: * @return all of the <code>SDocumentListener</code>s added or an
041: * empty array if no listeners are present
042: * @see SDocument#addDocumentListener
043: * @see SDocument#removeDocumentListener
044: */
045: public SDocumentListener[] getDocumentListeners();
046:
047: /**
048: * Registers the given observer to begin receiving notifications
049: * when changes are made to the document.
050: *
051: * @param listener the observer to register
052: * @see SDocument#removeDocumentListener
053: */
054: public void addDocumentListener(SDocumentListener listener);
055:
056: /**
057: * Unregisters the given observer from the notification list
058: * so it will no longer receive change updates.
059: *
060: * @param listener the observer to register
061: * @see SDocument#addDocumentListener
062: */
063: public void removeDocumentListener(SDocumentListener listener);
064:
065: /**
066: * Removes a portion of the content of the document.
067: * This will cause a DocumentEvent of type
068: * DocumentEvent.EventType.REMOVE to be sent to the
069: * registered DocumentListeners, unless an exception
070: * is thrown. The notification will be sent to the
071: * listeners by calling the removeUpdate method on the
072: * DocumentListeners.
073: *
074: * @param offs the offset from the beginning >= 0
075: * @param len the number of characters to remove >= 0
076: * @throws BadLocationException some portion of the removal range
077: * was not a valid part of the document. The location in the exception
078: * is the first bad position encountered.
079: * @see javax.swing.event.DocumentEvent
080: * @see javax.swing.event.DocumentListener
081: * @see javax.swing.event.UndoableEditEvent
082: * @see javax.swing.event.UndoableEditListener
083: */
084: public void remove(int offs, int len) throws BadLocationException;
085:
086: /**
087: * Inserts a string of content. This will cause a DocumentEvent
088: * of type DocumentEvent.EventType.INSERT to be sent to the
089: * registered DocumentListers, unless an exception is thrown.
090: * The DocumentEvent will be delivered by calling the
091: * insertUpdate method on the DocumentListener.
092: * The offset and length of the generated DocumentEvent
093: * will indicate what change was actually made to the Document.
094: *
095: * @param offset the offset into the document to insert the content >= 0.
096: * All positions that track change at or after the given location
097: * will move.
098: * @param string the string to insert
099: */
100: public void insert(int offset, String string)
101: throws BadLocationException;
102:
103: /**
104: * Fetches the text contained within the given portion
105: * of the document.
106: *
107: * @param offset the offset into the document representing the desired
108: * start of the text >= 0
109: * @param length the length of the desired string >= 0
110: * @return the text, in a String of length >= 0
111: * @throws BadLocationException some portion of the given range
112: * was not a valid part of the document. The location in the exception
113: * is the first bad position encountered.
114: */
115: public String getText(int offset, int length)
116: throws BadLocationException;
117:
118: public String getText();
119:
120: public void setText(String text);
121: }
|