/******************************************************************************* * Copyright (c) 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.swt.custom; /** * Clients may implement the StyledTextContent interface to provide a * custom store for the StyledText widget content. The StyledText widget * interacts with its StyledTextContent in order to access and update * the text that is being displayed and edited in the widget. * A custom content implementation can be set in the widget using the * StyledText.setContent API. */ public interface StyledTextContent { /** * Called by StyledText to add itself as an Observer to content changes. * See TextChangeListener for a description of the listener methods that * are called when text changes occur. *
* * @param listener the listener * @exception IllegalArgumentException
* * @return the number of characters in the content. */ public int getCharCount(); /** * Return the line at the given line index without delimiters. *
* * @param lineIndex index of the line to return. Does not include * delimiters of preceding lines. Index 0 is the first line of the * content. * @return the line text without delimiters */ public String getLine(int lineIndex); /** * Return the line index at the given character offset. *
* * @param offset offset of the line to return. The first character of the * document is at offset 0. An offset of getLength() is valid and should * answer the number of lines. * @return the line index. The first line is at index 0. If the character * at offset is a delimiter character, answer the line index of the line * that is delimited. * For example, if text = "\r\n\r\n", and delimiter = "\r\n", then: *
* * @return the number of lines. For example: *
* * @return the line delimiter that should be used by the StyledText widget * when inserting new lines. */ public String getLineDelimiter(); /** * Return the character offset of the first character of the given line. *
* NOTE: When there is no text (i.e., no lines), getOffsetAtLine(0) * is a valid call that should return 0. *
* * @param lineIndex index of the line. The first line is at index 0. * @return offset offset of the first character of the line. The first * character of the document is at offset 0. The return value should * include line delimiters. * For example, if text = "\r\ntest\r\n" and delimiter = "\r\n", then: ** * @param start the start offset of the text to return. Offset 0 is the * first character of the document. * @param length the length of the text to return * @return the text at the given range */ public String getTextRange(int start, int length); /** * Remove the specified text changed listener. *
* * @param listener the listener which should no longer be notified * * @exception IllegalArgumentException
* Implementors have to notify the TextChangeListeners that were added
* using addTextChangeListener
before and after the content
* is changed. A TextChangingEvent
has to be sent to the
* textChanging method before the content is changed and a
* TextChangedEvent
has to be sent to the textChanged method
* after the content has changed.
* The text change that occurs after the TextChangingEvent
* has been sent has to be consistent with the data provided in the
* TextChangingEvent
.
* This data will be cached by the widget and will be used when the
* TextChangedEvent
is received.
*
* The TextChangingEvent
should be set as follows:
*
TextChangedEvent
to the
* textSet method of the TextChangeListeners that were added using
* addTextChangeListener
.
* * * @param text the new text * @see TextChangeListener */ public void setText(String text); }