001 /*
002 * Copyright (C) 2010 eXo Platform SAS.
003 *
004 * This is free software; you can redistribute it and/or modify it
005 * under the terms of the GNU Lesser General Public License as
006 * published by the Free Software Foundation; either version 2.1 of
007 * the License, or (at your option) any later version.
008 *
009 * This software is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * You should have received a copy of the GNU Lesser General Public
015 * License along with this software; if not, write to the Free
016 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
017 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
018 */
019
020 package org.crsh.shell.ui;
021
022 import org.crsh.shell.io.ShellWriter;
023 import org.crsh.text.Style;
024
025 import java.io.IOException;
026 import java.util.ArrayList;
027 import java.util.List;
028
029 /**
030 * @author <a href="mailto:alain.defrance@exoplatform.com">Alain Defrance</a>
031 */
032 public class RowElement extends Element {
033
034 /** . */
035 private List<Element> cols;
036
037 public RowElement() {
038 this.cols = new ArrayList<Element>();
039 }
040
041 @Override
042 public void print(UIWriterContext ctx, ShellWriter writer) throws IOException {
043 doPrint(ctx, writer);
044 }
045
046 @Override
047 void doPrint(UIWriterContext ctx, ShellWriter writer) throws IOException {
048
049 int i = 0;
050 TableElement table = (TableElement) getParent();
051 List<Integer> colsSize = table.getColsSize();
052
053 for (Element e : cols) {
054
055 //
056 ctx.pad(writer);
057 if (ctx.needLF) {
058 writer.append("\n");
059 ctx.parentUIContext.pad(writer);
060 }
061 ctx.stack.clear();
062 ctx.padStyle = null;
063
064 //
065 e.print(ctx, writer);
066
067 //
068 ctx.padStyle = Style.style(e.getDecoration(), e.getForeground(), e.getBackground());
069 for (int j = 0; j < colsSize.get(i) - e.width(); ++j) {
070 ctx.stack.add(Pad.SPACE);
071 }
072
073 //
074 ++i;
075 ctx.needLF = false;
076
077 }
078
079 ctx.needLF = true;
080
081 }
082
083 @Override
084 int width() {
085 return 0;
086 }
087
088 public void addValue(Element element) {
089 this.cols.add(element);
090 }
091
092 public List<Element> getValues() {
093 return cols;
094 }
095
096 }