1 /* Msg.java */
2
3 package org.quilt.runner;
4
5 /***
6 * Debug message module.
7 *
8 * @author <a href="jdd@dixons.org">Jim Dixon</a>
9 */
10 public class Msg {
11
12 private String baseName;
13 private static final int DEFAULT_WIDTH = 60;
14 private static final char DEFAULT_BIG = '=';
15 private static final char DEFAULT_SMALL = '-';
16
17 /*** If false, nothing is output */
18 private boolean talking = true;
19 /*** Number of fill characters in banner, excluding newline. */
20 private int bannerWidth;
21 /*** Fill character for 'big' banners. */
22 private char bigChar = '=';
23 /*** Fill character for normal banners. */
24 private char smallChar = '-';
25 /*** String filled with 'big' fill character, ends with newline */
26 private String myBigBanner;
27 /*** String filled with normal fill character, ends with newline */
28 private String myBanner;
29
30 // CONSTRUCTORS /////////////////////////////////////////////////
31 // @todo add a way to specify where the output goes
32
33 /*** @param base Name of class or other module. */
34 public Msg (final String base) {
35 this(base, DEFAULT_WIDTH, DEFAULT_BIG, DEFAULT_SMALL);
36 }
37 /***
38 * @param base Name of module.
39 * @param width Width in characters of banners (default = 60)
40 */
41 public Msg (final String base, final int width) {
42 this(base, width, DEFAULT_BIG, DEFAULT_SMALL);
43 }
44 /***
45 * @param base Name of module.
46 * @param width Width of banners.
47 * @param big Fill character in 'big' banners (default is =).
48 */
49 public Msg (final String base, final int width, final char big) {
50 this(base, width, big, DEFAULT_SMALL);
51 }
52 /***
53 * @param base Name of module.
54 * @param width Width of banners.
55 * @param big Fill character in 'big' banners.
56 * @param small Fill character in normal banners (default is -).
57 */
58 public Msg (final String base, final int width, final char big,
59 final char small) {
60 baseName = base;
61 // EXCEPTION IF width < 1, characters are not printing //////
62 bannerWidth = width;
63 bigChar = big;
64 smallChar = small;
65
66 // there must be a cheaper way of doing this!
67 StringBuffer bigUn = new StringBuffer (width + 1);
68 StringBuffer smallUn = new StringBuffer (width + 1);
69 for (int i = 0; i < width; i++) {
70 bigUn.append(big);
71 smallUn.append(big);
72 }
73 bigUn.append('\n');
74 myBigBanner = bigUn.toString();
75
76 smallUn.append('\n');
77 myBanner = smallUn.toString();
78 }
79 // OTHER METHODS ////////////////////////////////////////////////
80 /***
81 * Turns output off or on.
82 * @param b If true, there will be output; if false, not.
83 */
84 public void talk (final boolean b) {
85 talking = b;
86 }
87 public void trace(final String where) {
88 if (talking) {
89 System.out.println ("---> " + baseName + where );
90 }
91 }
92 public void banner (final String where) {
93 if (talking) {
94 System.out.print (
95 myBanner + baseName + where + "\n" + myBanner );
96 }
97 }
98 public void bannerAnd (final String where, final String stuff) {
99 if (talking) {
100 System.out.print ( myBanner + baseName + where
101 + "\n" + myBanner + stuff + "\n");
102 }
103 }
104 public void bigBanner (final String where) {
105 if (talking) {
106 System.out.print ( myBigBanner + baseName + where
107 + "\n" + myBigBanner );
108 }
109 }
110 public boolean isTalking() {
111 return talking;
112 }
113 }
This page was automatically generated by Maven