KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.netbeans.modules.refactoring.spi.impl;
20 import java.awt.Color JavaDoc;
21 import java.awt.Dimension JavaDoc;
22 import java.awt.GridBagConstraints JavaDoc;
23 import javax.swing.ImageIcon JavaDoc;
24 import javax.swing.JPanel JavaDoc;
25 import org.netbeans.modules.refactoring.api.Problem;
26 import org.netbeans.modules.refactoring.spi.ui.RefactoringUI;
27
28 /**
29  *
30  * @author Jan Becicka
31  */

32 public class ErrorPanel extends javax.swing.JPanel JavaDoc {
33
34     private static ImageIcon JavaDoc fatalImage = null, nonFatalImage = null;
35
36     private RefactoringUI ui;
37     /** Creates new form ErrorPanel */
38     public ErrorPanel(RefactoringUI ui) {
39         this.ui = ui;
40         initComponents();
41         setPreferredSize(new Dimension JavaDoc(510, 200));
42     }
43     
44     public ErrorPanel(Problem problem, RefactoringUI ui) {
45         this(ui);
46         setProblems(problem);
47     }
48     
49     public void setProblems(Problem problem) {
50         errors.removeAll();
51         int i = 0;
52         ProblemComponent.initButtonSize(problem);
53         boolean single = problem.getNext()==null;
54         while (problem != null) {
55             GridBagConstraints JavaDoc gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
56             gridBagConstraints.gridx = 0;
57             gridBagConstraints.gridy = i++;
58             gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
59             gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
60             gridBagConstraints.weightx = 1.0;
61             
62             ProblemComponent c = new ProblemComponent(problem, ui, single);
63             errors.add(c, gridBagConstraints);
64             
65             problem = problem.getNext();
66             
67             if (i%2 == 0)
68                 c.setLightBackground();
69             else
70                 c.setDarkBackground();
71         }
72
73         GridBagConstraints JavaDoc gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
74         gridBagConstraints.gridx = 0;
75         gridBagConstraints.gridy = i;
76         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
77         gridBagConstraints.weightx = 1.0;
78         gridBagConstraints.weighty = 1.0;
79         
80         JPanel JavaDoc jp = new JPanel JavaDoc();
81         jp.setBackground(Color.WHITE);
82         errors.add(jp, gridBagConstraints);
83     }
84     
85     static ImageIcon JavaDoc getFatalErrorIcon() {
86         if (fatalImage == null) {
87             fatalImage = new ImageIcon JavaDoc(ErrorPanel.class.getResource("/org/netbeans/modules/refactoring/api/resources/error.png")); //NOI18N
88
}
89         return fatalImage;
90     }
91     
92     static ImageIcon JavaDoc getNonfatalErrorIcon() {
93         if (nonFatalImage == null) {
94             nonFatalImage = new ImageIcon JavaDoc(ErrorPanel.class.getResource("/org/netbeans/modules/refactoring/api/resources/warning.png")); //NOI18N
95
}
96         return nonFatalImage;
97     }
98     
99     /** This method is called from within the constructor to
100      * initialize the form.
101      * WARNING: Do NOT modify this code. The content of this method is
102      * always regenerated by the Form Editor.
103      */

104     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
105
private void initComponents() {
106         listPanel = new javax.swing.JPanel JavaDoc();
107         errorLabel = new javax.swing.JLabel JavaDoc();
108         listScrollPane = new javax.swing.JScrollPane JavaDoc();
109         errors = new javax.swing.JPanel JavaDoc();
110         explanationPanel = new javax.swing.JPanel JavaDoc();
111         fatalError = new javax.swing.JLabel JavaDoc();
112         nonFatalError = new javax.swing.JLabel JavaDoc();
113         headLine = new javax.swing.JTextArea JavaDoc();
114
115         setLayout(new java.awt.BorderLayout JavaDoc());
116
117         listPanel.setLayout(new java.awt.BorderLayout JavaDoc());
118
119         org.openide.awt.Mnemonics.setLocalizedText(errorLabel, org.openide.util.NbBundle.getBundle("org/netbeans/modules/refactoring/spi/impl/Bundle").getString("LBL_ErrorsList"));
120         listPanel.add(errorLabel, java.awt.BorderLayout.NORTH);
121
122         listScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
123         errors.setLayout(new java.awt.GridBagLayout JavaDoc());
124
125         listScrollPane.setViewportView(errors);
126
127         listPanel.add(listScrollPane, java.awt.BorderLayout.CENTER);
128
129         add(listPanel, java.awt.BorderLayout.CENTER);
130
131         explanationPanel.setLayout(new java.awt.FlowLayout JavaDoc(java.awt.FlowLayout.LEFT));
132
133         fatalError.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/org/netbeans/modules/refactoring/api/resources/error.png")));
134         org.openide.awt.Mnemonics.setLocalizedText(fatalError, org.openide.util.NbBundle.getBundle("org/netbeans/modules/refactoring/spi/impl/Bundle").getString("LBL_FatalError"));
135         fatalError.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 20));
136         explanationPanel.add(fatalError);
137
138         nonFatalError.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/org/netbeans/modules/refactoring/api/resources/warning.png")));
139         org.openide.awt.Mnemonics.setLocalizedText(nonFatalError, org.openide.util.NbBundle.getBundle("org/netbeans/modules/refactoring/spi/impl/Bundle").getString("LBL_NonFatalError"));
140         explanationPanel.add(nonFatalError);
141
142         add(explanationPanel, java.awt.BorderLayout.SOUTH);
143
144         headLine.setBackground(javax.swing.UIManager.getDefaults().getColor("Panel.background"));
145         headLine.setEditable(false);
146         headLine.setFont(errorLabel.getFont());
147         headLine.setLineWrap(true);
148         headLine.setText(org.openide.util.NbBundle.getBundle("org/netbeans/modules/refactoring/spi/impl/Bundle").getString("LBL_ErrorPanelDescription"));
149         headLine.setWrapStyleWord(true);
150         headLine.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 10, 1));
151         add(headLine, java.awt.BorderLayout.NORTH);
152         headLine.getAccessibleContext().setAccessibleName(null);
153         headLine.getAccessibleContext().setAccessibleDescription(null);
154
155     }// </editor-fold>//GEN-END:initComponents
156

157     
158     // Variables declaration - do not modify//GEN-BEGIN:variables
159
private javax.swing.JLabel JavaDoc errorLabel;
160     private javax.swing.JPanel JavaDoc errors;
161     private javax.swing.JPanel JavaDoc explanationPanel;
162     private javax.swing.JLabel JavaDoc fatalError;
163     private javax.swing.JTextArea JavaDoc headLine;
164     private javax.swing.JPanel JavaDoc listPanel;
165     private javax.swing.JScrollPane JavaDoc listScrollPane;
166     private javax.swing.JLabel JavaDoc nonFatalError;
167     // End of variables declaration//GEN-END:variables
168

169 }
170
Popular Tags