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