1 19 24 25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.common; 26 27 import java.awt.Container ; 28 import java.awt.GridBagConstraints ; 29 import java.awt.GridBagLayout ; 30 import java.awt.Insets ; 31 import java.util.Iterator ; 32 import java.util.ResourceBundle ; 33 import javax.swing.JLabel ; 34 import javax.swing.JPanel ; 35 36 41 public class ErrorSupport implements ErrorSupportClient{ 42 43 private static final ResourceBundle bundle = ResourceBundle.getBundle( 44 "org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.Bundle"); 46 private java.util.List errorList; 47 private javax.swing.JPanel errorPanel; 48 private javax.swing.JComponent focusedComponent; 49 50 private ErrorSupportClient client; 51 52 53 public ErrorSupport() { 54 initialize(); 55 this.client = (ErrorSupportClient) this; 56 } 57 58 59 public ErrorSupport(ErrorSupportClient client) { 60 initialize(); 61 this.client = client; 62 } 63 64 65 private void initialize(){ 66 errorList = new java.util.ArrayList (); 67 errorPanel = null; 68 focusedComponent = null; 69 } 70 71 72 75 public void showErrors(){ 76 removeAllErrors(); 80 java.util.Collection errors = client.getErrors(); 81 if(errors != null){ 82 java.util.Iterator iterator = errors.iterator(); 83 while(iterator.hasNext()){ 84 Object object = iterator.next(); 85 if(object instanceof java.lang.String ){ 86 addError((String )object); 87 } 88 } 89 } 90 91 Container parentPanel = client.getErrorPanelParent(); 92 if(parentPanel != null){ 93 if(errorList.size() != 0){ 94 if(errorPanel == null) { 95 errorPanel = new JPanel (new GridBagLayout ()); 96 parentPanel.add(errorPanel, client.getErrorPanelConstraints()); 97 } else { 98 errorPanel.removeAll(); 99 } 100 101 for(Iterator iter = errorList.iterator(); iter.hasNext(); ) { 102 String message = (String ) iter.next(); 103 104 JLabel label = new JLabel (); 106 label.setIcon(BaseCustomizer.errorMessageIcon); 107 label.setText(message); 108 label.getAccessibleContext().setAccessibleName(bundle.getString("ASCN_ErrorMessage")); label.getAccessibleContext().setAccessibleDescription(message); 110 label.setForeground(getMessageForegroundColor()); 111 112 GridBagConstraints constraints = new GridBagConstraints (); 113 constraints.gridwidth = GridBagConstraints.REMAINDER; 114 constraints.fill = GridBagConstraints.HORIZONTAL; 115 constraints.weightx = 1.0; 116 errorPanel.add(label, constraints); 117 } 118 119 } else { 123 if(errorPanel != null) { 124 parentPanel.remove(errorPanel); 125 errorPanel = null; 126 } 127 } 128 129 parentPanel.validate(); 130 } 131 } 132 133 134 137 public boolean hasErrors(){ 138 return (errorList.size()==0?false:true); 139 } 140 141 142 145 public void addError(String error){ 146 errorList.add(error); 147 } 148 149 150 155 public void addError(javax.swing.JComponent focusedComponent, String error){ 156 setFocusedComponent(focusedComponent); 157 errorList.add(error); 158 } 159 160 161 165 public void setFocusedComponent(javax.swing.JComponent comp){ 166 focusedComponent = comp; 167 } 168 169 170 173 public javax.swing.JComponent getFocusedComponent(){ 174 return focusedComponent; 175 } 176 177 178 181 public void removeAllErrors(){ 182 errorList.clear(); 183 focusedComponent = null; 184 } 185 186 187 public java.util.Collection getErrors(){ 188 return null; 189 } 190 191 192 public java.awt.Container getErrorPanelParent(){ 193 return null; 194 } 195 196 197 public java.awt.GridBagConstraints getErrorPanelConstraints(){ 198 GridBagConstraints gridBagConstraints = new GridBagConstraints (); 199 gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; 200 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 201 gridBagConstraints.weightx = 1.0; 202 gridBagConstraints.insets = new Insets (6,12,11,11); 203 return gridBagConstraints; 204 } 205 206 public java.awt.Color getMessageForegroundColor() { 207 return BaseCustomizer.getErrorForegroundColor(); 208 } 209 } 210 | Popular Tags |