001: /* Msg.java */
002:
003: package org.quilt.runner;
004:
005: /**
006: * Debug message module.
007: *
008: * @author <a href="jdd@dixons.org">Jim Dixon</a>
009: */
010: public class Msg {
011:
012: private String baseName;
013: private static final int DEFAULT_WIDTH = 60;
014: private static final char DEFAULT_BIG = '=';
015: private static final char DEFAULT_SMALL = '-';
016:
017: /** If false, nothing is output */
018: private boolean talking = true;
019: /** Number of fill characters in banner, excluding newline. */
020: private int bannerWidth;
021: /** Fill character for 'big' banners. */
022: private char bigChar = '=';
023: /** Fill character for normal banners. */
024: private char smallChar = '-';
025: /** String filled with 'big' fill character, ends with newline */
026: private String myBigBanner;
027: /** String filled with normal fill character, ends with newline */
028: private String myBanner;
029:
030: // CONSTRUCTORS /////////////////////////////////////////////////
031: // @todo add a way to specify where the output goes
032:
033: /** @param base Name of class or other module. */
034: public Msg(final String base) {
035: this (base, DEFAULT_WIDTH, DEFAULT_BIG, DEFAULT_SMALL);
036: }
037:
038: /**
039: * @param base Name of module.
040: * @param width Width in characters of banners (default = 60)
041: */
042: public Msg(final String base, final int width) {
043: this (base, width, DEFAULT_BIG, DEFAULT_SMALL);
044: }
045:
046: /**
047: * @param base Name of module.
048: * @param width Width of banners.
049: * @param big Fill character in 'big' banners (default is =).
050: */
051: public Msg(final String base, final int width, final char big) {
052: this (base, width, big, DEFAULT_SMALL);
053: }
054:
055: /**
056: * @param base Name of module.
057: * @param width Width of banners.
058: * @param big Fill character in 'big' banners.
059: * @param small Fill character in normal banners (default is -).
060: */
061: public Msg(final String base, final int width, final char big,
062: final char small) {
063: baseName = base;
064: // EXCEPTION IF width < 1, characters are not printing //////
065: bannerWidth = width;
066: bigChar = big;
067: smallChar = small;
068:
069: // there must be a cheaper way of doing this!
070: StringBuffer bigUn = new StringBuffer(width + 1);
071: StringBuffer smallUn = new StringBuffer(width + 1);
072: for (int i = 0; i < width; i++) {
073: bigUn.append(big);
074: smallUn.append(big);
075: }
076: bigUn.append('\n');
077: myBigBanner = bigUn.toString();
078:
079: smallUn.append('\n');
080: myBanner = smallUn.toString();
081: }
082:
083: // OTHER METHODS ////////////////////////////////////////////////
084: /**
085: * Turns output off or on.
086: * @param b If true, there will be output; if false, not.
087: */
088: public void talk(final boolean b) {
089: talking = b;
090: }
091:
092: public void trace(final String where) {
093: if (talking) {
094: System.out.println("---> " + baseName + where);
095: }
096: }
097:
098: public void banner(final String where) {
099: if (talking) {
100: System.out.print(myBanner + baseName + where + "\n"
101: + myBanner);
102: }
103: }
104:
105: public void bannerAnd(final String where, final String stuff) {
106: if (talking) {
107: System.out.print(myBanner + baseName + where + "\n"
108: + myBanner + stuff + "\n");
109: }
110: }
111:
112: public void bigBanner(final String where) {
113: if (talking) {
114: System.out.print(myBigBanner + baseName + where + "\n"
115: + myBigBanner);
116: }
117: }
118:
119: public boolean isTalking() {
120: return talking;
121: }
122: }
|