1 /***
2 * Redistribution and use in source and binary forms, with or without
3 * modification, are permitted provided that the following conditions are
4 * met :
5 *
6 * . Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 *
9 * . Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * . The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $Id$
29 */
30
31 package palmed.edit.text;
32
33 import java.io.IOException;
34 import java.io.InputStream;
35 import java.io.OutputStream;
36 import palmed.edit.util.Coordinate;
37 import palmed.io.ISerializable;
38
39 /***
40 * This interface defines text manipulations.
41 *
42 * @author Mathieu Champlon
43 * @version $Revision$ $Date$
44 */
45 public interface IText extends ISerializable
46 {
47 /***
48 * Retrieve the height of the text.
49 *
50 * @return the number of lines
51 */
52 int getHeight();
53
54 /***
55 * Retrieve a given line.
56 *
57 * @param y the number of the line to retrieve
58 * @return the content of the line or null
59 */
60 String getLine( int y );
61
62 /***
63 * Insert a character at a given position.
64 *
65 * @param position the insertion point
66 * @param c the character
67 */
68 void insert( Coordinate position, char c );
69
70 /***
71 * Split a line in two lines.
72 *
73 * @param position the insertion point
74 */
75 void insertNewLine( Coordinate position );
76
77 /***
78 * Remove the text between two positions.
79 * <p>
80 * The two positions must be ordered properly.
81 *
82 * @param from the first position
83 * @param to the second position
84 */
85 void remove( Coordinate from, Coordinate to );
86
87 /***
88 * Register a view for events notification.
89 *
90 * @param view the view to register
91 */
92 void register( ITextView view );
93
94 /***
95 * Clear the text.
96 */
97 void clear();
98
99 /***
100 * Write the text to the given stream.
101 *
102 * @param stream the stream to write to
103 * @throws IOException an io exception occurs
104 */
105 void write( OutputStream stream ) throws IOException;
106
107 /***
108 * Read the text from the given stream.
109 *
110 * @param stream the stream to read from
111 * @throws IOException an io exception occurs
112 */
113 void read( InputStream stream ) throws IOException;
114
115 /***
116 * Write a part of the text to the given stream.
117 *
118 * @param stream the stream to write to
119 * @param from the starting point
120 * @param to the ending point
121 * @throws IOException an io exception occurs
122 */
123 void write( OutputStream stream, Coordinate from, Coordinate to ) throws IOException;
124
125 /***
126 * Insert a part of text from the given stream.
127 *
128 * @param stream the stream to read from
129 * @param from the insertion point
130 * @throws IOException an io exception occurs
131 */
132 void read( InputStream stream, Coordinate from ) throws IOException;
133
134 /***
135 * Delete any resource associated to the text.
136 */
137 void delete();
138
139 /***
140 * Change the line separator.
141 * <p>
142 * To reset to the default mode preserving file format use null.
143 *
144 * @param separator a string value or null to reset
145 */
146 void setLineSeparator( String separator );
147 }