1 23 24 29 30 package com.sun.enterprise.tools.upgrade.gui; 31 32 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 { 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 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 (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 (); 87 gridBagConstraints.gridx = 0; 88 gridBagConstraints.gridy = 0; 89 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 90 gridBagConstraints.insets = new java.awt.Insets (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 (); 96 gridBagConstraints.gridx = 0; 97 gridBagConstraints.gridy = 1; 98 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 99 gridBagConstraints.insets = new java.awt.Insets (5, 10, 0, 10); 100 gridBagConstraints.weightx = 1.0; 101 panel.add(flowTextAreaLabel, gridBagConstraints); 102 103 gridBagConstraints = new java.awt.GridBagConstraints (); 104 gridBagConstraints.gridx = 0; 105 gridBagConstraints.gridy = 2; 106 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 107 gridBagConstraints.insets = new java.awt.Insets (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 (); 113 gridBagConstraints.gridx = 0; 114 gridBagConstraints.gridy = 3; 115 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 116 gridBagConstraints.insets = new java.awt.Insets (10, 10, 0, 10); 117 gridBagConstraints.weightx = 1.0; 118 panel.add(flowProgressLabel, gridBagConstraints); 119 120 gridBagConstraints = new java.awt.GridBagConstraints (); 121 gridBagConstraints.gridx = 0; 122 gridBagConstraints.gridy = 4; 123 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 124 gridBagConstraints.insets = new java.awt.Insets (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 logRecord = evt.getLogRecord(); 132 if(logRecord != null){ 133 if((logRecord.getLevel().equals(Level.SEVERE)) || (logRecord.getLevel().equals(Level.WARNING))){ 134 this.resultTextArea.append(logRecord.getMessage()); 138 this.resultTextArea.revalidate(); 139 }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 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 |