1 19 package org.netbeans.modules.xml.refactoring.ui.j.ui; 20 import java.awt.Color ; 21 import java.awt.Dimension ; 22 import java.awt.GridBagConstraints ; 23 import java.util.List ; 24 import javax.swing.ImageIcon ; 25 import javax.swing.JPanel ; 26 import org.netbeans.modules.xml.refactoring.DeleteRequest; 27 import org.netbeans.modules.xml.refactoring.ErrorItem; 28 import org.netbeans.modules.xml.refactoring.ui.j.spi.ui.RefactoringUI; 29 import org.openide.util.Utilities; 30 31 35 public class ErrorPanel extends javax.swing.JPanel { 36 37 38 private static final long serialVersionUID = 1L; 39 private static ImageIcon fatalImage = null, nonFatalImage = null; 40 private boolean canContinueWithWarnings = true; 41 42 private transient RefactoringUI ui; 43 44 public ErrorPanel(RefactoringUI ui, boolean canContinueWithWarnings) { 45 this.ui = ui; 46 this.canContinueWithWarnings = canContinueWithWarnings; 47 initComponents(); 48 headLine.setText(canContinueWithWarnings?org.openide.util.NbBundle.getBundle(ErrorPanel.class).getString("LBL_ErrorPanelDescription"):org.openide.util.NbBundle.getBundle(ErrorPanel.class).getString("LBL_ErrorPanelDescription_Cannot_Continue_with_Warnings")); 49 setPreferredSize(new Dimension (510, 200)); 50 } 51 52 public ErrorPanel(List <ErrorItem> errorItems, RefactoringUI ui, boolean canContinueWithWarnings) { 53 this(ui,canContinueWithWarnings); 54 setProblems(errorItems); 55 } 56 57 public void setProblems(List <ErrorItem> errorItems) { 58 errors.removeAll(); 59 int i = 0; 60 for (ErrorItem error:errorItems){ 62 GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints (); 63 gridBagConstraints.gridx = 0; 64 gridBagConstraints.gridy = i++; 65 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 66 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 67 gridBagConstraints.weightx = 1.0; 68 69 ProblemComponent c = new ProblemComponent(error, ui); 70 errors.add(c, gridBagConstraints); 71 72 73 if (i%2 == 0) 74 c.setLightBackground(); 75 else 76 c.setDarkBackground(); 77 78 if (ui.getRefactorRequest() instanceof DeleteRequest) { 79 break; } 83 } 84 85 GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints (); 86 gridBagConstraints.gridx = 0; 87 gridBagConstraints.gridy = i; 88 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 89 gridBagConstraints.weightx = 1.0; 90 gridBagConstraints.weighty = 1.0; 91 92 JPanel jp = new JPanel (); 93 jp.setBackground(Color.WHITE); 94 errors.add(jp, gridBagConstraints); 95 } 96 97 static ImageIcon getFatalErrorIcon() { 98 if (fatalImage == null) { 99 fatalImage = new ImageIcon (Utilities.loadImage( 100 "org/netbeans/modules/refactoring/api/resources/error.png")); } 102 return fatalImage; 103 } 104 105 static ImageIcon getNonfatalErrorIcon() { 106 if (nonFatalImage == null) { 107 nonFatalImage = new ImageIcon (Utilities.loadImage( 108 "org/netbeans/modules/refactoring/api/resources/warning.png")); } 110 return nonFatalImage; 111 } 112 113 118 private void initComponents() { 120 listPanel = new javax.swing.JPanel (); 121 errorLabel = new javax.swing.JLabel (); 122 listScrollPane = new javax.swing.JScrollPane (); 123 errors = new javax.swing.JPanel (); 124 explanationPanel = new javax.swing.JPanel (); 125 fatalError = new javax.swing.JLabel (); 126 nonFatalError = new javax.swing.JLabel (); 127 headLine = new javax.swing.JTextArea (); 128 129 setLayout(new java.awt.BorderLayout ()); 130 131 listPanel.setLayout(new java.awt.BorderLayout ()); 132 133 org.openide.awt.Mnemonics.setLocalizedText(errorLabel, org.openide.util.NbBundle.getMessage(ErrorPanel.class, "LBL_ErrorsList")); 134 listPanel.add(errorLabel, java.awt.BorderLayout.NORTH); 135 136 listScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); 137 errors.setLayout(new java.awt.GridBagLayout ()); 138 139 listScrollPane.setViewportView(errors); 140 141 listPanel.add(listScrollPane, java.awt.BorderLayout.CENTER); 142 143 add(listPanel, java.awt.BorderLayout.CENTER); 144 145 explanationPanel.setLayout(new java.awt.FlowLayout (java.awt.FlowLayout.LEFT)); 146 147 fatalError.setIcon(getFatalErrorIcon()); 148 org.openide.awt.Mnemonics.setLocalizedText(fatalError, org.openide.util.NbBundle.getMessage(ErrorPanel.class, "LBL_FatalError")); 149 fatalError.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 20)); 150 explanationPanel.add(fatalError); 151 152 nonFatalError.setIcon(getNonfatalErrorIcon()); 153 org.openide.awt.Mnemonics.setLocalizedText(nonFatalError, org.openide.util.NbBundle.getMessage(ErrorPanel.class, "LBL_NonFatalError")); 154 explanationPanel.add(nonFatalError); 155 156 add(explanationPanel, java.awt.BorderLayout.SOUTH); 157 158 headLine.setBackground(javax.swing.UIManager.getDefaults().getColor("Panel.background")); 159 headLine.setEditable(false); 160 headLine.setFont(errorLabel.getFont()); 161 headLine.setLineWrap(true); 162 headLine.setText(canContinueWithWarnings?org.openide.util.NbBundle.getBundle(ErrorPanel.class).getString("LBL_ErrorPanelDescription"):org.openide.util.NbBundle.getBundle(ErrorPanel.class).getString("LBL_ErrorPanelDescription_Cannot_Continue_with_Warnings")); 163 headLine.setWrapStyleWord(true); 164 headLine.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 10, 1)); 165 add(headLine, java.awt.BorderLayout.NORTH); 166 headLine.getAccessibleContext().setAccessibleName(null); 167 headLine.getAccessibleContext().setAccessibleDescription(null); 168 169 } 171 172 private javax.swing.JLabel errorLabel; 174 private javax.swing.JPanel errors; 175 private javax.swing.JPanel explanationPanel; 176 private javax.swing.JLabel fatalError; 177 private javax.swing.JTextArea headLine; 178 private javax.swing.JPanel listPanel; 179 private javax.swing.JScrollPane listScrollPane; 180 private javax.swing.JLabel nonFatalError; 181 183 } 184 | Popular Tags |