1 /* FormatBuffer.java -- General interface to build attributed strings.
2 Copyright (C) 2004, 2012 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
37 package gnu.java.text;
39 import java.text.AttributedCharacterIterator;
40 import java.util.List;
43 import static java.text.AttributedCharacterIterator.Attribute;
46 * This interface describes a modifiable buffer which contains attributed
47 * characters. The implementation may or may not implements attributes. It
48 * aims to greatly simplify and clarify the implementation of java.text
49 * formatters. The buffer may be appended or have its tail cut. It may also
50 * be completely cleant up.
52 * @author Guilhem Lavaux <guilhem@kaffe.org>
53 * @date April 10, 2004
55 public interface FormatBuffer
58 * This method appends a simple string to the buffer. This part of
59 * the buffer will be attributed using the default attribute.
61 * @param s The string to append to the buffer.
63 public void append(String s);
66 * This method appends a simple string to the buffer. This part of
67 * the buffer will have the specified attribute (and only this one).
68 * The default attribute may be changed after calling this method.
70 * @param s The string to append to the buffer.
71 * @param attr Attribute to use for the string in the buffer.
73 public void append(String s, Attribute attr);
76 * This method appends a simple string to the buffer. This part of
77 * the buffer will be attributed using the specified ranges and attributes.
78 * To have an example on how to specify ranges see {@link gnu.java.text.FormatCharacterIterator}.
80 * @param s The string to append to the buffer.
81 * @param ranges The ranges describing how the attributes should be applied
83 * @param attrs The attributes of the string in the buffer.
85 public void append(String s, int[] ranges, List<Map<Attribute,Object>> attrs);
88 * This method appends a simple char to the buffer. This part of
89 * the buffer will be attributed using the default attribute.
91 * @param c The character to append to the buffer.
93 public void append(char c);
96 * This method appends a simple character to the buffer. This part of
97 * the buffer will have the specified attribute (and only this one).
98 * The default attribute may be changed after calling this method.
100 * @param c The character to append to the buffer.
101 * @param attr Attribute to use for the character in the buffer.
103 public void append(char c, Attribute attr);
106 * This method changes the current default attribute for the next string
107 * or character which will be appended to the buffer.
109 * @param attr The attribute which will be used by default.
111 public void setDefaultAttribute(Attribute attr);
114 * This method returns the current default attribute for the buffer.
116 * @return The default attribute for the buffer.
118 public Attribute getDefaultAttribute();
121 * This method cuts the last characters of the buffer. The number of
122 * characters to cut is given by "length".
124 * @param length Number of characters to cut at the end of the buffer.
126 public void cutTail(int length);
129 * This method resets completely the buffer.
134 * This method returns the number of character in the buffer.
136 * @return The number of character in the buffer.