001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.refactoring.spi.impl;
042:
043: import java.awt.Color;
044: import java.awt.Dimension;
045: import java.awt.GridBagConstraints;
046: import javax.swing.ImageIcon;
047: import javax.swing.JPanel;
048: import org.netbeans.modules.refactoring.api.Problem;
049: import org.netbeans.modules.refactoring.spi.ui.RefactoringUI;
050:
051: /**
052: *
053: * @author Jan Becicka
054: */
055: public class ErrorPanel extends javax.swing.JPanel {
056:
057: private static ImageIcon fatalImage = null, nonFatalImage = null;
058:
059: private RefactoringUI ui;
060:
061: /** Creates new form ErrorPanel */
062: public ErrorPanel(RefactoringUI ui) {
063: this .ui = ui;
064: initComponents();
065: headLine.setBackground(javax.swing.UIManager.getDefaults()
066: .getColor("Panel.background")); // NOI18N
067: setPreferredSize(new Dimension(510, 200));
068: }
069:
070: public ErrorPanel(Problem problem, RefactoringUI ui) {
071: this (ui);
072: setProblems(problem);
073: }
074:
075: public void setProblems(Problem problem) {
076: errors.removeAll();
077: int i = 0;
078: ProblemComponent.initButtonSize(problem);
079: boolean single = problem.getNext() == null;
080: while (problem != null) {
081: GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
082: gridBagConstraints.gridx = 0;
083: gridBagConstraints.gridy = i++;
084: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
085: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
086: gridBagConstraints.weightx = 1.0;
087:
088: ProblemComponent c = new ProblemComponent(problem, ui,
089: single);
090: errors.add(c, gridBagConstraints);
091:
092: problem = problem.getNext();
093:
094: if (i % 2 == 0)
095: c.setLightBackground();
096: else
097: c.setDarkBackground();
098: }
099:
100: GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
101: gridBagConstraints.gridx = 0;
102: gridBagConstraints.gridy = i;
103: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
104: gridBagConstraints.weightx = 1.0;
105: gridBagConstraints.weighty = 1.0;
106:
107: JPanel jp = new JPanel();
108: jp.setBackground(Color.WHITE);
109: errors.add(jp, gridBagConstraints);
110: }
111:
112: static ImageIcon getFatalErrorIcon() {
113: if (fatalImage == null) {
114: fatalImage = new ImageIcon(
115: ErrorPanel.class
116: .getResource("/org/netbeans/modules/refactoring/api/resources/error.png")); //NOI18N
117: }
118: return fatalImage;
119: }
120:
121: static ImageIcon getNonfatalErrorIcon() {
122: if (nonFatalImage == null) {
123: nonFatalImage = new ImageIcon(
124: ErrorPanel.class
125: .getResource("/org/netbeans/modules/refactoring/api/resources/warning.png")); //NOI18N
126: }
127: return nonFatalImage;
128: }
129:
130: /** This method is called from within the constructor to
131: * initialize the form.
132: * WARNING: Do NOT modify this code. The content of this method is
133: * always regenerated by the Form Editor.
134: */
135: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
136: private void initComponents() {
137:
138: listPanel = new javax.swing.JPanel();
139: errorLabel = new javax.swing.JLabel();
140: listScrollPane = new javax.swing.JScrollPane();
141: errors = new javax.swing.JPanel();
142: explanationPanel = new javax.swing.JPanel();
143: fatalError = new javax.swing.JLabel();
144: nonFatalError = new javax.swing.JLabel();
145: headLine = new javax.swing.JTextArea();
146:
147: setLayout(new java.awt.BorderLayout());
148:
149: listPanel.setLayout(new java.awt.BorderLayout());
150:
151: errorLabel.setLabelFor(errors);
152: org.openide.awt.Mnemonics
153: .setLocalizedText(
154: errorLabel,
155: org.openide.util.NbBundle
156: .getBundle(
157: "org/netbeans/modules/refactoring/spi/impl/Bundle")
158: .getString("LBL_ErrorsList")); // NOI18N
159: listPanel.add(errorLabel, java.awt.BorderLayout.NORTH);
160:
161: listScrollPane
162: .setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
163:
164: errors.setLayout(new java.awt.GridBagLayout());
165: listScrollPane.setViewportView(errors);
166:
167: listPanel.add(listScrollPane, java.awt.BorderLayout.CENTER);
168:
169: add(listPanel, java.awt.BorderLayout.CENTER);
170:
171: explanationPanel.setLayout(new java.awt.FlowLayout(
172: java.awt.FlowLayout.LEFT));
173:
174: fatalError
175: .setIcon(new javax.swing.ImageIcon(
176: getClass()
177: .getResource(
178: "/org/netbeans/modules/refactoring/api/resources/error.png"))); // NOI18N
179: org.openide.awt.Mnemonics
180: .setLocalizedText(
181: fatalError,
182: org.openide.util.NbBundle
183: .getBundle(
184: "org/netbeans/modules/refactoring/spi/impl/Bundle")
185: .getString("LBL_FatalError")); // NOI18N
186: fatalError.setBorder(javax.swing.BorderFactory
187: .createEmptyBorder(1, 1, 1, 20));
188: explanationPanel.add(fatalError);
189:
190: nonFatalError
191: .setIcon(new javax.swing.ImageIcon(
192: getClass()
193: .getResource(
194: "/org/netbeans/modules/refactoring/api/resources/warning.png"))); // NOI18N
195: org.openide.awt.Mnemonics
196: .setLocalizedText(
197: nonFatalError,
198: org.openide.util.NbBundle
199: .getBundle(
200: "org/netbeans/modules/refactoring/spi/impl/Bundle")
201: .getString("LBL_NonFatalError")); // NOI18N
202: explanationPanel.add(nonFatalError);
203:
204: add(explanationPanel, java.awt.BorderLayout.SOUTH);
205:
206: headLine.setBackground(javax.swing.UIManager.getDefaults()
207: .getColor("Panel.background"));
208: headLine.setEditable(false);
209: headLine.setFont(errorLabel.getFont());
210: headLine.setLineWrap(true);
211: headLine.setText(org.openide.util.NbBundle.getBundle(
212: "org/netbeans/modules/refactoring/spi/impl/Bundle")
213: .getString("LBL_ErrorPanelDescription")); // NOI18N
214: headLine.setWrapStyleWord(true);
215: headLine.setBorder(javax.swing.BorderFactory.createEmptyBorder(
216: 1, 1, 10, 1));
217: add(headLine, java.awt.BorderLayout.NORTH);
218: headLine.getAccessibleContext().setAccessibleName("null");
219: headLine.getAccessibleContext()
220: .setAccessibleDescription("null");
221:
222: getAccessibleContext().setAccessibleName(
223: org.openide.util.NbBundle.getBundle(ErrorPanel.class)
224: .getString("ACSD_ErrorPanelName")); // NOI18N
225: getAccessibleContext().setAccessibleDescription(
226: org.openide.util.NbBundle.getBundle(ErrorPanel.class)
227: .getString("ACSD_ErrorPanelDescription")); // NOI18N
228: }// </editor-fold>//GEN-END:initComponents
229:
230: // Variables declaration - do not modify//GEN-BEGIN:variables
231: private javax.swing.JLabel errorLabel;
232: private javax.swing.JPanel errors;
233: private javax.swing.JPanel explanationPanel;
234: private javax.swing.JLabel fatalError;
235: private javax.swing.JTextArea headLine;
236: private javax.swing.JPanel listPanel;
237: private javax.swing.JScrollPane listScrollPane;
238: private javax.swing.JLabel nonFatalError;
239: // End of variables declaration//GEN-END:variables
240:
241: }
|