0N/A/*
2362N/A * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.tools.jstat;
0N/A
0N/Aimport java.util.*;
0N/A
0N/A/**
0N/A * A class to represent the format for a column of data.
0N/A *
0N/A * @author Brian Doherty
0N/A * @since 1.5
0N/A */
0N/Apublic class ColumnFormat extends OptionFormat {
0N/A private int number;
0N/A private int width;
0N/A private Alignment align = Alignment.CENTER;
0N/A private Scale scale = Scale.RAW;
0N/A private String format;
0N/A private String header;
0N/A private Expression expression;
0N/A private Object previousValue;
0N/A
0N/A public ColumnFormat(int number) {
0N/A super("Column" + number);
0N/A this.number = number;
0N/A }
0N/A
0N/A /*
0N/A * method to apply various validation rules to the ColumnFormat object.
0N/A */
0N/A public void validate() throws ParserException {
0N/A
0N/A // if we allow column spanning, then this method must change. it
0N/A // should allow null data statments
0N/A
0N/A if (expression == null) {
0N/A // current policy is that a data statment must be specified
0N/A throw new ParserException("Missing data statement in column " + number);
0N/A }
0N/A if (header == null) {
0N/A // current policy is that if a header is not specified, then we
0N/A // will use the last component of the name as the header and
0N/A // insert the default anchor characters for center alignment..
0N/A throw new ParserException("Missing header statement in column " + number);
0N/A }
0N/A if (format == null) {
0N/A // if no formating is specified, then the format is set to output
0N/A // the raw data.
0N/A format="0";
0N/A }
0N/A }
0N/A
0N/A public void setWidth(int width) {
0N/A this.width = width;
0N/A }
0N/A
0N/A public void setAlignment(Alignment align) {
0N/A this.align = align;
0N/A }
0N/A
0N/A public void setScale(Scale scale) {
0N/A this.scale = scale;
0N/A }
0N/A
0N/A public void setFormat(String format) {
0N/A this.format = format;
0N/A }
0N/A
0N/A public void setHeader(String header) {
0N/A this.header = header;
0N/A }
0N/A
0N/A public String getHeader() {
0N/A return header;
0N/A }
0N/A
0N/A public String getFormat() {
0N/A return format;
0N/A }
0N/A
0N/A public int getWidth() {
0N/A return width;
0N/A }
0N/A
0N/A public Alignment getAlignment() {
0N/A return align;
0N/A }
0N/A
0N/A public Scale getScale() {
0N/A return scale;
0N/A }
0N/A
0N/A public Expression getExpression() {
0N/A return expression;
0N/A }
0N/A
0N/A public void setExpression(Expression e) {
0N/A this.expression = e;
0N/A }
0N/A
0N/A public void setPreviousValue(Object o) {
0N/A this.previousValue = o;
0N/A }
0N/A
0N/A public Object getPreviousValue() {
0N/A return previousValue;
0N/A }
0N/A
0N/A public void printFormat(int indentLevel) {
0N/A String indentAmount = " ";
0N/A
0N/A StringBuilder indent = new StringBuilder("");
0N/A for (int j = 0; j < indentLevel; j++) {
0N/A indent.append(indentAmount);
0N/A }
0N/A
0N/A System.out.println(indent + name + " {");
0N/A System.out.println(indent + indentAmount + "name=" + name
0N/A + ";data=" + expression.toString() + ";header=" + header
0N/A + ";format=" + format + ";width=" + width
0N/A + ";scale=" + scale.toString() + ";align=" + align.toString());
0N/A
0N/A for (Iterator i = children.iterator(); i.hasNext(); /* empty */) {
0N/A OptionFormat of = (OptionFormat)i.next();
0N/A of.printFormat(indentLevel+1);
0N/A }
0N/A
0N/A System.out.println(indent + "}");
0N/A }
0N/A
0N/A public String getValue() {
0N/A return null;
0N/A }
0N/A}