KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > util > diagnostics > ReporterFrame


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  * @version 1.01 June 6, 2000
26  * @author Byron Nevins
27  */

28 package com.sun.enterprise.util.diagnostics;
29
30 import java.awt.*;
31 import java.awt.event.*;
32 import javax.swing.*;
33 import javax.swing.text.*;
34 //Bug 4677074 begin
35
import java.util.logging.Logger JavaDoc;
36 import java.util.logging.Level JavaDoc;
37 import com.sun.logging.LogDomains;
38 //Bug 4677074 end
39

40 class ReporterFrame extends JFrame implements ActionListener
41 {
42 //Bug 4677074 begin
43
static Logger JavaDoc _logger=LogDomains.getLogger(LogDomains.UTIL_LOGGER);
44 //Bug 4677074 end
45
public void pr(String JavaDoc s)
46     {
47         //textArea.setText(textArea.getText() + s + "\n");//NOI18N
48
textArea.append(s + "\n");//NOI18N
49
}
50
51     //////////////////////////////////////////////////////////////
52

53     ReporterFrame(String JavaDoc title)
54     {
55         addButtonPanel();
56         addTextPanel();
57
58         setTitle(titleRoot + " -- " + title);//NOI18N
59
setSize(900, 300);
60         if(standAlone)
61         {
62             addWindowListener(new WindowAdapter()
63             {
64                 public void windowClosing(WindowEvent e)
65                 {
66                     System.exit(0);
67                 }
68             } );
69             
70             for(int i = 0; i < 1000; i++)
71                 textArea.append("This is line# " + i + "\n");//NOI18N
72

73             show();
74         }
75     }
76     ////////////////////////////////////////////////////////
77

78     private void addButtonPanel()
79     {
80         JPanel panel = new JPanel();
81         wrapButton = new JButton("Wrap");//NOI18N
82
panel.add(wrapButton);
83         wrapButton.addActionListener(this);
84
85         noWrapButton = new JButton("No wrap");//NOI18N
86
panel.add(noWrapButton);
87         noWrapButton.addActionListener(this);
88
89         getContentPane().add(panel, "South");//NOI18N
90
}
91     
92     //////////////////////////////////////////////////////////////
93

94     private void addTextPanel()
95     {
96         //textArea = new JTextPane();
97
textArea = new JTextArea(800, 200);
98         scrollPane = new JScrollPane(textArea);
99         getContentPane().add(scrollPane, "Center");//NOI18N
100
}
101     
102     //////////////////////////////////////////////////////////////
103

104     public void actionPerformed(ActionEvent evt)
105     {
106         Object JavaDoc source = evt.getSource();
107     
108         if(source == wrapButton)
109         {
110             textArea.setLineWrap(true);
111             scrollPane.validate();
112         }
113         else if(source == noWrapButton)
114         {
115             textArea.setLineWrap(false);
116             scrollPane.validate();
117         }
118
119         
120         
121         /* trying to make it auto-scroll!!!
122         //JViewport vp = textArea.getViewport();
123         JScrollBar vert = scrollPane.getVerticalScrollBar();
124
125 //Bug 4677074 System.out.println("*** vertSB.getMaximum(): " + vert.getMaximum());
126 //Bug 4677074 System.out.println("*** vertSB.getValue(): " + vert.getValue());
127 //Bug 4677074 System.out.println("*** getRows(): " + textArea.getRows());
128         //System.out.println("*** getRowHeight(): " + textArea.getRowHeight());
129 //Bug 4677074 System.out.println("*** getLineCount(): " + textArea.getLineCount());
130 //Bug 4677074 begin
131         _logger.log(Level.FINE,"*** vertSB.getMaximum(): " + vert.getMaximum());
132         _logger.log(Level.FINE,"*** vertSB.getValue(): " + vert.getValue());
133         _logger.log(Level.FINE,"*** getRows(): " + textArea.getRows());
134         // _logger.log(Level.FINE,"*** getRowHeight(): " + textArea.getRowHeight());
135         _logger.log(Level.FINE,"*** getLineCount(): " + textArea.getLineCount());
136 //Bug 4677074 end
137
138         final int numLines = textArea.getLineCount();
139         int endOffset;
140         try
141         {
142             endOffset= textArea.getLineEndOffset(numLines - 1);
143 //Bug 4677074 System.out.println("***** numLines: " + numLines + " endOffset: " + endOffset);
144 //Bug 4677074 begin
145             _logger.log(Level.FINE,"***** numLines: " + numLines + " endOffset: " + endOffset);
146 //Bug 4677074 end
147         }
148         catch(BadLocationException e)
149         {
150 //Bug 4677074 System.out.println("***** Exception: " + e);
151 //Bug 4677074 begin
152             _logger.log(Level.WARNING,"iplanet_util.badlocation_exception",e);
153 //Bug 4677074 end
154         }
155         */

156     }
157     
158     //////////////////////////////////////////////////////////////
159

160     
161     static void setStandAlone()
162     {
163 //Bug 4677074 System.err.println("setStandAlone() here!!!");//NOI18N
164
//Bug 4677074 begin
165
_logger.log(Level.FINE,"setStandAlone() here!!!");
166 //Bug 4677074 end
167
standAlone = true;
168     }
169     
170     //////////////////////////////////////////////////////////////
171

172     private JButton wrapButton;
173     private JButton noWrapButton;
174     //private JTextPane textArea;
175
private JTextArea textArea;
176     private JScrollPane scrollPane;
177     private final static String JavaDoc titleRoot = "iPlanet Reporter";//NOI18N
178
private static boolean standAlone = false;
179 }
180
181
Popular Tags