KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > upgrade > gui > ProgressPanel


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  * ProgressPanel.java
26  *
27  * Created on September 3, 2003, 3:14 PM
28  */

29
30 package com.sun.enterprise.tools.upgrade.gui;
31
32 /**
33  *
34  * @author prakash
35  */

36 import javax.swing.*;
37 import java.awt.*;
38 import com.sun.enterprise.tools.upgrade.common.*;
39 import java.util.logging.*;
40 import com.sun.enterprise.util.i18n.StringManager;
41 import com.sun.enterprise.tools.upgrade.logging.*;
42
43 public class ProgressPanel extends javax.swing.JPanel JavaDoc {
44     
45     private FlowLabel flowProgressLabel;
46     private JTextArea resultTextArea;
47     private ProgressBar progressBar;
48     private JScrollPane jscrollpane;
49     
50     private StringManager stringManager = StringManager.getManager("com.sun.enterprise.tools.upgrade.gui");
51     private Logger logger = com.sun.enterprise.tools.upgrade.common.CommonInfoModel.getDefaultLogger();
52     
53     /** Creates a new instance of ProgressPanel */
54     public ProgressPanel() {
55         initialize();
56     }
57   
58     private void initialize(){
59         this.setLayout(new BorderLayout());
60         HeaderPanel headerPanel = new HeaderPanel(stringManager.getString("upgrade.gui.progresspanel.headerPanel"));
61         headerPanel.setInsets(new java.awt.Insets JavaDoc(12, 10, 12, 10));
62         add(headerPanel, "North");
63         add(getWizardPanel(), "Center");
64         
65     }
66     private JPanel getWizardPanel(){
67         JPanel panel = new JPanel(new GridBagLayout());
68         FlowLabel flowTopLabel = new FlowLabel();
69         FlowLabel flowTextAreaLabel = new FlowLabel();
70         flowProgressLabel = new FlowLabel();
71         progressBar = new ProgressBar();
72         resultTextArea = new JTextArea(){
73             public boolean isFocusTraversable()
74             {
75                 return false;
76             }
77         };
78         resultTextArea.setEditable(false);
79         resultTextArea.setLineWrap(true);
80         jscrollpane = new JScrollPane(resultTextArea, 20, 30);
81         jscrollpane.setAutoscrolls(true);
82         resultTextArea.setAutoscrolls(true);
83         
84         flowTopLabel.setText(stringManager.getString("upgrade.gui.progresspanel.flowContentLabel"));
85         GridBagConstraints gridBagConstraints = new GridBagConstraints();
86         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
87         gridBagConstraints.gridx = 0;
88         gridBagConstraints.gridy = 0;
89         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
90         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 10, 10, 0);
91         gridBagConstraints.weightx = 1.0;
92         panel.add(flowTopLabel, gridBagConstraints);
93         
94         flowTextAreaLabel.setText(stringManager.getString("upgrade.gui.progresspanel.textAreaText"));
95         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
96         gridBagConstraints.gridx = 0;
97         gridBagConstraints.gridy = 1;
98         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
99         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 10, 0, 10);
100         gridBagConstraints.weightx = 1.0;
101         panel.add(flowTextAreaLabel, gridBagConstraints);
102         
103         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
104         gridBagConstraints.gridx = 0;
105         gridBagConstraints.gridy = 2;
106         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
107         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 10, 10, 10);
108         gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0;
109         panel.add(jscrollpane, gridBagConstraints);
110         
111         flowProgressLabel.setText(stringManager.getString("upgrade.gui.progresspanel.progressLabel"));
112         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
113         gridBagConstraints.gridx = 0;
114         gridBagConstraints.gridy = 3;
115         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
116         gridBagConstraints.insets = new java.awt.Insets JavaDoc(10, 10, 0, 10);
117         gridBagConstraints.weightx = 1.0;
118         panel.add(flowProgressLabel, gridBagConstraints);
119         
120         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
121         gridBagConstraints.gridx = 0;
122         gridBagConstraints.gridy = 4;
123         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
124         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 10, 10, 10);
125         gridBagConstraints.weightx = 1.0;
126         panel.add(progressBar, gridBagConstraints);
127         
128         return panel;
129     }
130     public void updateLog(LogMessageEvent evt){
131         java.util.logging.LogRecord JavaDoc logRecord = evt.getLogRecord();
132         if(logRecord != null){
133             if((logRecord.getLevel().equals(Level.SEVERE)) || (logRecord.getLevel().equals(Level.WARNING))){
134                 //java.awt.Font origFont = this.resultTextArea.getFont();
135
//java.awt.Font spFont = new java.awt.Font(this.resultTextArea.getFont().getName(), java.awt.Font.BOLD, this.resultTextArea.getFont().getSize());
136
//this.resultTextArea.setFont(spFont);
137
this.resultTextArea.append(logRecord.getMessage());
138                 this.resultTextArea.revalidate();
139                 //jscrollpane.getVerticalScrollBar().setValue(jscrollpane.getVerticalScrollBar().getMaximum());
140
//jscrollpane.getVerticalScrollBar().setVisibleAmount(jscrollpane.getVerticalScrollBar().getMaximum());
141
//this.resultTextArea.setFont(origFont);
142
}else{
143                 this.resultTextArea.append(logRecord.getMessage());
144             }
145             this.resultTextArea.append("\n");
146         }else{
147             this.resultTextArea.append(evt.getMessage());
148         }
149         this.resultTextArea.revalidate();
150         jscrollpane.getVerticalScrollBar().setValue(jscrollpane.getVerticalScrollBar().getMaximum());
151         jscrollpane.getVerticalScrollBar().setVisibleAmount(jscrollpane.getVerticalScrollBar().getMaximum());
152     }
153     public void updateProgress(UpgradeUpdateEvent evt){
154         int progressState = evt.getProgressState();
155         String JavaDoc labelText = null;
156         if(evt.getProgressState() == 100){
157                 labelText = stringManager.getString("upgrade.gui.progresspanel.progressLabel.DONE");
158         }
159         if(evt.getProgressState() == -1){
160             progressState = 0;
161             labelText = stringManager.getString("upgrade.gui.progresspanel.progressLabel.ERROR");
162             javax.swing.JOptionPane.showMessageDialog(this, stringManager.getString("upgrade.gui.progresspanel.errorProgressMsg"),
163                               stringManager.getString("upgrade.gui.progresspanel.errorProgressMsgTitle"),
164                               javax.swing.JOptionPane.ERROR_MESSAGE);
165         }
166         this.progressBar.setProgress(progressState);
167         if(labelText != null)
168             flowProgressLabel.setText(labelText);
169     }
170 }
171
Popular Tags