KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > common > util > diagnostics > ReporterWriter


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24
25 package com.sun.enterprise.tools.common.util.diagnostics;
26
27 import java.io.*;
28 import java.util.*;
29 import com.sun.enterprise.tools.common.util.StringUtils;
30
31 /** The basic mechanism used to "report".
32  *
33  * sends output to a Swing window.
34  */

35 public class ReporterWriter implements IReporterEnum
36 {
37     /** Create a new place (or mechanism) for routing output from the Reporter classes.
38      *
39      * @param title The title of the output window
40      */

41     protected ReporterWriter(String JavaDoc title)
42     {
43         this.title = title;
44         out = System.out;
45     }
46
47     ///////////////////////////////////////////////////////////////
48

49         /** puts a message in the window.
50          *
51          * Subclasses should redefine this function to change the report output destination.
52          * @param severity The severity level of the message. This is translated into one of the named constants
53          * for output.
54          * @param s The text of the message to "report".
55          */

56     protected void println(int severity, String JavaDoc s)
57     {
58         String JavaDoc type;
59         String JavaDoc msg;
60         
61         /*
62         if(severity > WARN)
63         {
64             type = "<B>" + severityNames[severity] + "</B>";
65             msg = StringUtils.padRight(type, longestSeverityLength + 7) + s;
66         }
67         else
68         */

69         {
70             type = severityNames[severity];
71             msg = StringUtils.padRight(severityNames[severity], longestSeverityLength) + s;
72         }
73
74         out.println(msg);
75         getFrame().pr(msg);
76     }
77
78     ///////////////////////////////////////////////////////////////
79

80     private ReporterFrame getFrame()
81     {
82         if(frame == null)
83         {
84             // first call!!
85
frame = new ReporterFrame(title);
86             frame.show();
87             calcLongestString();
88         }
89
90         return frame;
91     }
92
93     ///////////////////////////////////////////////////////////////
94

95     private void calcLongestString()
96     {
97         int maxLen = 0;
98
99         for(int i = 0; i < severityNames.length; i++)
100         {
101             int len = severityNames[i].length();
102
103             if(len > maxLen)
104                 maxLen = len;
105         }
106         longestSeverityLength = maxLen + 2;
107     }
108
109     ///////////////////////////////////////////////////////////////
110

111     private PrintStream out;
112     private ReporterFrame frame = null;
113     private int longestSeverityLength;
114     private String JavaDoc title;
115
116 }
117
118
Popular Tags