KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > common > 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.tools.common.util.diagnostics;
29
30 import java.awt.*;
31 import java.awt.event.*;
32 import javax.swing.*;
33 import javax.swing.text.*;
34
35 class ReporterFrame extends JFrame implements ActionListener
36 {
37     public void pr(String JavaDoc s)
38     {
39         //textArea.setText(textArea.getText() + s + "\n");//NOI18N
40
textArea.append(s + "\n");//NOI18N
41
}
42
43     //////////////////////////////////////////////////////////////
44

45     ReporterFrame(String JavaDoc title)
46     {
47         addButtonPanel();
48         addTextPanel();
49
50         setTitle(titleRoot + " -- " + title);//NOI18N
51
setSize(900, 300);
52         if(standAlone)
53         {
54             addWindowListener(new WindowAdapter()
55             {
56                 public void windowClosing(WindowEvent e)
57                 {
58                     System.exit(0);
59                 }
60             } );
61             
62             for(int i = 0; i < 1000; i++)
63                 textArea.append("This is line# " + i + "\n");//NOI18N
64

65             show();
66         }
67     }
68     ////////////////////////////////////////////////////////
69

70     private void addButtonPanel()
71     {
72         JPanel panel = new JPanel();
73         wrapButton = new JButton("Wrap");//NOI18N
74
panel.add(wrapButton);
75         wrapButton.addActionListener(this);
76
77         noWrapButton = new JButton("No wrap");//NOI18N
78
panel.add(noWrapButton);
79         noWrapButton.addActionListener(this);
80
81         getContentPane().add(panel, "South");//NOI18N
82
}
83     
84     //////////////////////////////////////////////////////////////
85

86     private void addTextPanel()
87     {
88         //textArea = new JTextPane();
89
textArea = new JTextArea(800, 200);
90         scrollPane = new JScrollPane(textArea);
91         getContentPane().add(scrollPane, "Center");//NOI18N
92
}
93     
94     //////////////////////////////////////////////////////////////
95

96     public void actionPerformed(ActionEvent evt)
97     {
98         Object JavaDoc source = evt.getSource();
99     
100         if(source == wrapButton)
101         {
102             textArea.setLineWrap(true);
103             scrollPane.validate();
104         }
105         else if(source == noWrapButton)
106         {
107             textArea.setLineWrap(false);
108             scrollPane.validate();
109         }
110
111         
112         
113         /* trying to make it auto-scroll!!!
114         //JViewport vp = textArea.getViewport();
115         JScrollBar vert = scrollPane.getVerticalScrollBar();
116
117         System.out.println("*** vertSB.getMaximum(): " + vert.getMaximum());
118         System.out.println("*** vertSB.getValue(): " + vert.getValue());
119         System.out.println("*** getRows(): " + textArea.getRows());
120         //System.out.println("*** getRowHeight(): " + textArea.getRowHeight());
121         System.out.println("*** getLineCount(): " + textArea.getLineCount());
122
123         final int numLines = textArea.getLineCount();
124         int endOffset;
125         try
126         {
127             endOffset= textArea.getLineEndOffset(numLines - 1);
128             System.out.println("***** numLines: " + numLines + " endOffset: " + endOffset);
129         }
130         catch(BadLocationException e)
131         {
132             System.out.println("***** Exception: " + e);
133         }
134         */

135     }
136     
137     //////////////////////////////////////////////////////////////
138

139     
140     static void setStandAlone()
141     {
142         System.err.println("setStandAlone() here!!!");//NOI18N
143
standAlone = true;
144     }
145     
146     //////////////////////////////////////////////////////////////
147

148     private JButton wrapButton;
149     private JButton noWrapButton;
150     //private JTextPane textArea;
151
private JTextArea textArea;
152     private JScrollPane scrollPane;
153     private final static String JavaDoc titleRoot = "iPlanet Reporter";//NOI18N
154
private static boolean standAlone = false;
155 }
156
157
Popular Tags