Frames | No Frames |
1: /* FormatBuffer.java -- General interface to build attributed strings. 2: Copyright (C) 2004, 2012 Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 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) 9: any later version. 10: 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. 15: 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 19: 02110-1301 USA. 20: 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 24: combination. 25: 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; 38: 39: import java.text.AttributedCharacterIterator; 40: import java.util.List; 41: import java.util.Map; 42: 43: import static java.text.AttributedCharacterIterator.Attribute; 44: 45: /** 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. 51: * 52: * @author Guilhem Lavaux <guilhem@kaffe.org> 53: * @date April 10, 2004 54: */ 55: public interface FormatBuffer 56: { 57: /** 58: * This method appends a simple string to the buffer. This part of 59: * the buffer will be attributed using the default attribute. 60: * 61: * @param s The string to append to the buffer. 62: */ 63: public void append(String s); 64: 65: /** 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. 69: * 70: * @param s The string to append to the buffer. 71: * @param attr Attribute to use for the string in the buffer. 72: */ 73: public void append(String s, Attribute attr); 74: 75: /** 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}. 79: * 80: * @param s The string to append to the buffer. 81: * @param ranges The ranges describing how the attributes should be applied 82: * to the string. 83: * @param attrs The attributes of the string in the buffer. 84: */ 85: public void append(String s, int[] ranges, List<Map<Attribute,Object>> attrs); 86: 87: /** 88: * This method appends a simple char to the buffer. This part of 89: * the buffer will be attributed using the default attribute. 90: * 91: * @param c The character to append to the buffer. 92: */ 93: public void append(char c); 94: 95: /** 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. 99: * 100: * @param c The character to append to the buffer. 101: * @param attr Attribute to use for the character in the buffer. 102: */ 103: public void append(char c, Attribute attr); 104: 105: /** 106: * This method changes the current default attribute for the next string 107: * or character which will be appended to the buffer. 108: * 109: * @param attr The attribute which will be used by default. 110: */ 111: public void setDefaultAttribute(Attribute attr); 112: 113: /** 114: * This method returns the current default attribute for the buffer. 115: * 116: * @return The default attribute for the buffer. 117: */ 118: public Attribute getDefaultAttribute(); 119: 120: /** 121: * This method cuts the last characters of the buffer. The number of 122: * characters to cut is given by "length". 123: * 124: * @param length Number of characters to cut at the end of the buffer. 125: */ 126: public void cutTail(int length); 127: 128: /** 129: * This method resets completely the buffer. 130: */ 131: public void clear(); 132: 133: /** 134: * This method returns the number of character in the buffer. 135: * 136: * @return The number of character in the buffer. 137: */ 138: public int length(); 139: }