KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > refactoring > ui > j > ui > 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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.xml.refactoring.ui.j.ui;
20 import java.awt.Color JavaDoc;
21 import java.awt.Dimension JavaDoc;
22 import java.awt.GridBagConstraints JavaDoc;
23 import java.util.List JavaDoc;
24 import javax.swing.ImageIcon JavaDoc;
25 import javax.swing.JPanel JavaDoc;
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 /**
32  *
33  * @author Jan Becicka
34  */

35 public class ErrorPanel extends javax.swing.JPanel JavaDoc {
36
37
38     private static final long serialVersionUID = 1L;
39     private static ImageIcon JavaDoc fatalImage = null, nonFatalImage = null;
40     private boolean canContinueWithWarnings = true;
41     
42     private transient RefactoringUI ui;
43     /** Creates new form ErrorPanel */
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 JavaDoc(510, 200));
50     }
51     
52     public ErrorPanel(List JavaDoc<ErrorItem> errorItems, RefactoringUI ui, boolean canContinueWithWarnings) {
53         this(ui,canContinueWithWarnings);
54         setProblems(errorItems);
55     }
56     
57     public void setProblems(List JavaDoc<ErrorItem> errorItems) {
58         errors.removeAll();
59         int i = 0;
60 // ProblemComponent.initButtonSize(problem);
61
for (ErrorItem error:errorItems){
62             GridBagConstraints JavaDoc gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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                 //TODO straighten out usability issue of Safe Delete whether to allow
80
// cascade delete where possible
81
break; // for now just a hack to show only first one assuming all entailed cascade delete not supported.
82
}
83         }
84
85         GridBagConstraints JavaDoc gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc jp = new JPanel JavaDoc();
93         jp.setBackground(Color.WHITE);
94         errors.add(jp, gridBagConstraints);
95     }
96     
97     static ImageIcon JavaDoc getFatalErrorIcon() {
98         if (fatalImage == null) {
99             fatalImage = new ImageIcon JavaDoc(Utilities.loadImage(
100                     "org/netbeans/modules/refactoring/api/resources/error.png")); // NOI18N
101
}
102         return fatalImage;
103     }
104     
105     static ImageIcon JavaDoc getNonfatalErrorIcon() {
106         if (nonFatalImage == null) {
107             nonFatalImage = new ImageIcon JavaDoc(Utilities.loadImage(
108                     "org/netbeans/modules/refactoring/api/resources/warning.png")); //NOI18N
109
}
110         return nonFatalImage;
111     }
112     
113     /** This method is called from within the constructor to
114      * initialize the form.
115      * WARNING: Do NOT modify this code. The content of this method is
116      * always regenerated by the Form Editor.
117      */

118     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
119
private void initComponents() {
120         listPanel = new javax.swing.JPanel JavaDoc();
121         errorLabel = new javax.swing.JLabel JavaDoc();
122         listScrollPane = new javax.swing.JScrollPane JavaDoc();
123         errors = new javax.swing.JPanel JavaDoc();
124         explanationPanel = new javax.swing.JPanel JavaDoc();
125         fatalError = new javax.swing.JLabel JavaDoc();
126         nonFatalError = new javax.swing.JLabel JavaDoc();
127         headLine = new javax.swing.JTextArea JavaDoc();
128
129         setLayout(new java.awt.BorderLayout JavaDoc());
130
131         listPanel.setLayout(new java.awt.BorderLayout JavaDoc());
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 JavaDoc());
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 JavaDoc(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     }// </editor-fold>//GEN-END:initComponents
170

171     
172     // Variables declaration - do not modify//GEN-BEGIN:variables
173
private javax.swing.JLabel JavaDoc errorLabel;
174     private javax.swing.JPanel JavaDoc errors;
175     private javax.swing.JPanel JavaDoc explanationPanel;
176     private javax.swing.JLabel JavaDoc fatalError;
177     private javax.swing.JTextArea JavaDoc headLine;
178     private javax.swing.JPanel JavaDoc listPanel;
179     private javax.swing.JScrollPane JavaDoc listScrollPane;
180     private javax.swing.JLabel JavaDoc nonFatalError;
181     // End of variables declaration//GEN-END:variables
182

183 }
184
Popular Tags