java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java
author František Kučera <franta-hg@frantovo.cz>
Sun, 22 Dec 2013 23:31:55 +0100
branchv_0
changeset 34 9335cf31c0f2
parent 32 5e412dbd9362
child 37 9e6f8e5d5f98
permissions -rw-r--r--
first working version
franta-hg@32
     1
/**
franta-hg@32
     2
 * SQL-DK
franta-hg@32
     3
 * Copyright © 2013 František Kučera (frantovo.cz)
franta-hg@32
     4
 *
franta-hg@32
     5
 * This program is free software: you can redistribute it and/or modify
franta-hg@32
     6
 * it under the terms of the GNU General Public License as published by
franta-hg@32
     7
 * the Free Software Foundation, either version 3 of the License, or
franta-hg@32
     8
 * (at your option) any later version.
franta-hg@32
     9
 *
franta-hg@32
    10
 * This program is distributed in the hope that it will be useful,
franta-hg@32
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@32
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@32
    13
 * GNU General Public License for more details.
franta-hg@32
    14
 *
franta-hg@32
    15
 * You should have received a copy of the GNU General Public License
franta-hg@32
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
franta-hg@32
    17
 */
franta-hg@32
    18
package info.globalcode.sql.dk.formatting;
franta-hg@32
    19
franta-hg@34
    20
import info.globalcode.sql.dk.ColorfulPrintWriter;
franta-hg@34
    21
franta-hg@32
    22
/**
franta-hg@32
    23
 *
franta-hg@32
    24
 * @author Ing. František Kučera (frantovo.cz)
franta-hg@32
    25
 */
franta-hg@32
    26
public class TabularFormatter extends AbstractFormatter {
franta-hg@32
    27
franta-hg@32
    28
	public static final String NAME = "tabular";
franta-hg@34
    29
	private ColorfulPrintWriter out;
franta-hg@32
    30
franta-hg@32
    31
	public TabularFormatter(FormatterContext formatterContext) {
franta-hg@32
    32
		super(formatterContext);
franta-hg@34
    33
		out = new ColorfulPrintWriter(formatterContext.getOutputStream());
franta-hg@34
    34
	}
franta-hg@34
    35
franta-hg@34
    36
	@Override
franta-hg@34
    37
	public void writeColumnValue(Object value) {
franta-hg@34
    38
		super.writeColumnValue(value);
franta-hg@34
    39
franta-hg@34
    40
		if (!isCurrentColumnFirst()) {
franta-hg@34
    41
			out.print(ColorfulPrintWriter.TerminalColor.Green, " | ");
franta-hg@34
    42
		}
franta-hg@34
    43
		
franta-hg@34
    44
		out.print(ColorfulPrintWriter.TerminalColor.Cyan, String.valueOf(value));
franta-hg@34
    45
	}
franta-hg@34
    46
franta-hg@34
    47
	@Override
franta-hg@34
    48
	public void writeEndRow() {
franta-hg@34
    49
		super.writeEndRow();
franta-hg@34
    50
		out.println();
franta-hg@34
    51
		out.flush();
franta-hg@32
    52
	}
franta-hg@32
    53
}