1 19 20 package org.netbeans.modules.refactoring.spi.impl; 21 22 import java.awt.Color ; 23 import java.awt.Container ; 24 import java.awt.Dimension ; 25 import java.awt.event.ActionEvent ; 26 import java.text.MessageFormat ; 27 import javax.swing.AbstractAction ; 28 import javax.swing.JButton ; 29 import org.netbeans.modules.refactoring.api.Problem; 30 import org.netbeans.modules.refactoring.api.ProblemDetails; 31 import org.netbeans.modules.refactoring.spi.impl.ParametersPanel; 32 import org.netbeans.modules.refactoring.spi.ui.RefactoringUI; 33 import org.openide.util.Cancellable; 34 import org.openide.util.NbBundle; 35 36 40 public class ProblemComponent extends javax.swing.JPanel { 41 42 private static Color bgColor = new Color (240, 240, 240); 43 private Problem problem; 44 private ProblemDetails details; 45 private RefactoringUI ui; 46 private static double buttonWidth; 47 48 51 public ProblemComponent(Problem problem, RefactoringUI ui, boolean single) { 52 initComponents(); 53 this.ui = ui; 54 icon.setIcon(problem.isFatal()?ErrorPanel.getFatalErrorIcon():ErrorPanel.getNonfatalErrorIcon()); 55 problemDescription.setText(problem.getMessage()); 56 this.problem = problem; 57 this.details = problem.getDetails(); 58 if (!single && details != null) { 60 org.openide.awt.Mnemonics.setLocalizedText(showDetails, details.getDetailsHint()); 61 showDetails.setPreferredSize(new Dimension ((int) buttonWidth, (int) showDetails.getMinimumSize().getHeight())); 62 } else { 63 showDetails.setVisible(false); 64 } 65 66 validate(); 67 } 68 69 static void initButtonSize(Problem problem) { 70 buttonWidth = -1.0; 71 while (problem != null) { 72 ProblemDetails pdi = problem.getDetails(); 73 if (pdi != null) { 74 buttonWidth = Math.max(new JButton (pdi.getDetailsHint()).getMinimumSize().getWidth(), buttonWidth); 75 } 76 problem = problem.getNext(); 77 } 78 79 } 80 81 public void setLightBackground() { 82 setBackground(Color.WHITE); 83 problemDescription.setBackground(Color.WHITE); 84 icon.setBackground(Color.WHITE); 85 } 87 88 public void setDarkBackground() { 89 Color bgColor = new Color (240, 240, 240); 90 setBackground(bgColor); 91 problemDescription.setBackground(bgColor); 92 icon.setBackground(bgColor); 93 } 95 96 101 private void initComponents() { 103 java.awt.GridBagConstraints gridBagConstraints; 104 105 icon = new javax.swing.JLabel (); 106 problemDescription = new javax.swing.JTextArea (); 107 showDetails = new javax.swing.JButton (); 108 109 setLayout(new java.awt.GridBagLayout ()); 110 111 setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3)); 112 icon.setBackground(javax.swing.UIManager.getDefaults().getColor("TextArea.background")); 113 icon.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 6, 1, 6)); 114 gridBagConstraints = new java.awt.GridBagConstraints (); 115 gridBagConstraints.gridx = 0; 116 gridBagConstraints.gridy = 0; 117 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 118 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 119 add(icon, gridBagConstraints); 120 121 problemDescription.setEditable(false); 122 problemDescription.setLineWrap(true); 123 problemDescription.setWrapStyleWord(true); 124 gridBagConstraints = new java.awt.GridBagConstraints (); 125 gridBagConstraints.gridx = 1; 126 gridBagConstraints.gridy = 0; 127 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 128 gridBagConstraints.weightx = 1.0; 129 add(problemDescription, gridBagConstraints); 130 problemDescription.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ProblemComponent.class, "ACSD_ProblemDescriptionName")); 131 problemDescription.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ProblemComponent.class, "ACSD_ProblemDescriptionDescription")); 132 133 showDetails.addActionListener(new java.awt.event.ActionListener () { 134 public void actionPerformed(java.awt.event.ActionEvent evt) { 135 showDetailsActionPerformed(evt); 136 } 137 }); 138 139 gridBagConstraints = new java.awt.GridBagConstraints (); 140 gridBagConstraints.gridx = 2; 141 gridBagConstraints.gridy = 0; 142 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 143 add(showDetails, gridBagConstraints); 144 showDetails.getAccessibleContext().setAccessibleName(showDetails.getText()); 145 showDetails.getAccessibleContext().setAccessibleDescription(showDetails.getText()); 146 147 } 148 150 private void showDetailsActionPerformed(java.awt.event.ActionEvent evt) { Container c = this; 152 while (!(c instanceof ParametersPanel)) { 153 c = c.getParent(); 154 } 155 final ParametersPanel parametersPanel = (ParametersPanel) c; 156 Cancellable doCloseParent = new Cancellable() { 157 public boolean cancel() { 158 parametersPanel.cancel.doClick(); 159 return true; 160 } 161 }; 162 ProblemDetails details = problem.getDetails(); 163 if (details != null) { 164 details.showDetails(new CallbackAction(ui), doCloseParent); 165 } 166 } 168 169 private javax.swing.JLabel icon; 171 private javax.swing.JTextArea problemDescription; 172 private javax.swing.JButton showDetails; 173 175 static class CallbackAction extends AbstractAction { 176 RefactoringUI ui; 177 178 public CallbackAction(RefactoringUI ui) { 179 super(MessageFormat.format(NbBundle.getMessage(ProblemComponent.class, "LBL_Rerun"), new Object []{ui.getName()})); 180 this.ui = ui; 181 } 182 183 public void actionPerformed(ActionEvent event) { 184 new RefactoringPanel(ui).show(); 185 } 186 } 187 } 188 | Popular Tags |