KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > refactoring > spi > impl > ProblemComponent


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.refactoring.spi.impl;
21
22 import java.awt.Color JavaDoc;
23 import java.awt.Container JavaDoc;
24 import java.awt.Dimension JavaDoc;
25 import java.awt.event.ActionEvent JavaDoc;
26 import java.text.MessageFormat JavaDoc;
27 import javax.swing.AbstractAction JavaDoc;
28 import javax.swing.JButton JavaDoc;
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 /**
37  *
38  * @author Jan Becicka
39  */

40 public class ProblemComponent extends javax.swing.JPanel JavaDoc {
41     
42     private static Color JavaDoc bgColor = new Color JavaDoc(240, 240, 240);
43     private Problem problem;
44     private ProblemDetails details;
45     private RefactoringUI ui;
46     private static double buttonWidth;
47     
48     /**
49      * Creates new form ProblemComponent
50      */

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         //setLightBackground();
59
if (!single && details != null) {
60             org.openide.awt.Mnemonics.setLocalizedText(showDetails, details.getDetailsHint());
61             showDetails.setPreferredSize(new Dimension JavaDoc((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 JavaDoc(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         //showDetails.setBackground(Color.WHITE);
86
}
87     
88     public void setDarkBackground() {
89         Color JavaDoc bgColor = new Color JavaDoc(240, 240, 240);
90         setBackground(bgColor);
91         problemDescription.setBackground(bgColor);
92         icon.setBackground(bgColor);
93         //showDetails.setBackground(bgColor);
94
}
95     
96     /** This method is called from within the constructor to
97      * initialize the form.
98      * WARNING: Do NOT modify this code. The content of this method is
99      * always regenerated by the Form Editor.
100      */

101     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
102
private void initComponents() {
103         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
104
105         icon = new javax.swing.JLabel JavaDoc();
106         problemDescription = new javax.swing.JTextArea JavaDoc();
107         showDetails = new javax.swing.JButton JavaDoc();
108
109         setLayout(new java.awt.GridBagLayout JavaDoc());
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 JavaDoc();
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 JavaDoc();
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 JavaDoc() {
134             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
135                 showDetailsActionPerformed(evt);
136             }
137         });
138
139         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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     // </editor-fold>//GEN-END:initComponents
149

150     private void showDetailsActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_showDetailsActionPerformed
151
Container JavaDoc 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     }//GEN-LAST:event_showDetailsActionPerformed
167

168     
169     // Variables declaration - do not modify//GEN-BEGIN:variables
170
private javax.swing.JLabel JavaDoc icon;
171     private javax.swing.JTextArea JavaDoc problemDescription;
172     private javax.swing.JButton JavaDoc showDetails;
173     // End of variables declaration//GEN-END:variables
174

175     static class CallbackAction extends AbstractAction JavaDoc {
176         RefactoringUI ui;
177         
178         public CallbackAction(RefactoringUI ui) {
179             super(MessageFormat.format(NbBundle.getMessage(ProblemComponent.class, "LBL_Rerun"), new Object JavaDoc[]{ui.getName()}));
180             this.ui = ui;
181         }
182         
183         public void actionPerformed(ActionEvent JavaDoc event) {
184             new RefactoringPanel(ui).show();
185         }
186     }
187 }
188
Popular Tags