001: /*
002: * $Id: RtfTabGroup.java 2776 2007-05-23 20:01:40Z hallm $
003: * $Name$
004: *
005: * Copyright 2001, 2002, 2003, 2004 by Mark Hall
006: *
007: * The contents of this file are subject to the Mozilla Public License Version 1.1
008: * (the "License"); you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
010: *
011: * Software distributed under the License is distributed on an "AS IS" basis,
012: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
013: * for the specific language governing rights and limitations under the License.
014: *
015: * The Original Code is 'iText, a free JAVA-PDF library'.
016: *
017: * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
018: * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
019: * All Rights Reserved.
020: * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
021: * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
022: * Co-Developer of the code is Mark Hall. Portions created by the Co-Developer are
023: * Copyright (C) 2006 by Mark Hall. All Rights Reserved
024: *
025: * Contributor(s): all the names of the contributors are added in the source code
026: * where applicable.
027: *
028: * Alternatively, the contents of this file may be used under the terms of the
029: * LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
030: * provisions of LGPL are applicable instead of those above. If you wish to
031: * allow use of your version of this file only under the terms of the LGPL
032: * License and not to allow others to use your version of this file under
033: * the MPL, indicate your decision by deleting the provisions above and
034: * replace them with the notice and other provisions required by the LGPL.
035: * If you do not delete the provisions above, a recipient may use your version
036: * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
037: *
038: * This library is free software; you can redistribute it and/or modify it
039: * under the terms of the MPL as stated above or under the terms of the GNU
040: * Library General Public License as published by the Free Software Foundation;
041: * either version 2 of the License, or any later version.
042: *
043: * This library is distributed in the hope that it will be useful, but WITHOUT
044: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
045: * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
046: * details.
047: *
048: * If you didn't download this code from the following link, you should check if
049: * you aren't using an obsolete version:
050: * http://www.lowagie.com/iText/
051: */
052:
053: package com.lowagie.text.rtf.text;
054:
055: import java.io.ByteArrayOutputStream;
056: import java.io.IOException;
057: import java.io.OutputStream;
058: import java.util.ArrayList;
059:
060: import com.lowagie.text.rtf.RtfAddableElement;
061:
062: /**
063: * The RtfTabGroup is a convenience class if the same tabs are to be added
064: * to multiple paragraphs.<br /><br />
065: *
066: * <code>RtfTabGroup tabs = new RtfTabGroup();<br />
067: * tabs.add(new RtfTab(70, RtfTab.TAB_LEFT_ALIGN));<br />
068: * tabs.add(new RtfTab(160, RtfTab.TAB_CENTER_ALIGN));<br />
069: * tabs.add(new RtfTab(250, RtfTab.TAB_DECIMAL_ALIGN));<br />
070: * tabs.add(new RtfTab(500, RtfTab.TAB_RIGHT_ALIGN));<br />
071: * Paragraph para = new Paragraph();<br />
072: * para.add(tabs);<br />
073: * para.add("\tLeft aligned\tCentre aligned\t12,45\tRight aligned");</code>
074: *
075: * @version $Id: RtfTabGroup.java 2776 2007-05-23 20:01:40Z hallm $
076: * @author Mark Hall (mhall@edu.uni-klu.ac.at)
077: * @author Thomas Bickel (tmb99@inode.at)
078: */
079: public class RtfTabGroup extends RtfAddableElement {
080: /**
081: * The tabs to add.
082: */
083: private ArrayList tabs = null;
084:
085: /**
086: * Constructs an empty RtfTabGroup.
087: */
088: public RtfTabGroup() {
089: this .tabs = new ArrayList();
090: }
091:
092: /**
093: * Constructs a RtfTabGroup with a set of tabs.
094: *
095: * @param tabs An ArrayList with the RtfTabs to group in this RtfTabGroup.
096: */
097: public RtfTabGroup(ArrayList tabs) {
098: this .tabs = new ArrayList();
099: for (int i = 0; i < tabs.size(); i++) {
100: if (tabs.get(i) instanceof RtfTab) {
101: this .tabs.add(tabs.get(i));
102: }
103: }
104: }
105:
106: /**
107: * Adds a RtfTab to the list of grouped tabs.
108: *
109: * @param tab The RtfTab to add.
110: */
111: public void add(RtfTab tab) {
112: this .tabs.add(tab);
113: }
114:
115: /**
116: * Combines the tab output form all grouped tabs.
117: *
118: * @deprecated replaced by {@link #writeContent(OutputStream)}
119: */
120: public byte[] write() {
121: ByteArrayOutputStream result = new ByteArrayOutputStream();
122: try {
123: writeContent(result);
124: } catch (IOException ioe) {
125: ioe.printStackTrace();
126: }
127: return result.toByteArray();
128: }
129:
130: /**
131: * Combines the tab output form all grouped tabs.
132: */
133: public void writeContent(final OutputStream result)
134: throws IOException {
135: for (int i = 0; i < this .tabs.size(); i++) {
136: RtfTab rt = (RtfTab) this .tabs.get(i);
137: //.result.write((rt).write());
138: rt.writeContent(result);
139: }
140: }
141:
142: }
|