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:
042: package org.netbeans.modules.refactoring.spi.impl;
043:
044: import java.awt.Color;
045: import java.awt.Container;
046: import java.awt.Dimension;
047: import java.awt.event.ActionEvent;
048: import java.text.MessageFormat;
049: import javax.swing.AbstractAction;
050: import javax.swing.JButton;
051: import org.netbeans.modules.refactoring.api.Problem;
052: import org.netbeans.modules.refactoring.api.ProblemDetails;
053: import org.netbeans.modules.refactoring.spi.impl.ParametersPanel;
054: import org.netbeans.modules.refactoring.spi.ui.RefactoringUI;
055: import org.openide.util.Cancellable;
056: import org.openide.util.NbBundle;
057:
058: /**
059: *
060: * @author Jan Becicka
061: */
062: public class ProblemComponent extends javax.swing.JPanel {
063:
064: private static Color bgColor = new Color(240, 240, 240);
065: private Problem problem;
066: private ProblemDetails details;
067: private RefactoringUI ui;
068: private static double buttonWidth;
069:
070: /**
071: * Creates new form ProblemComponent
072: */
073: public ProblemComponent(Problem problem, RefactoringUI ui,
074: boolean single) {
075: initComponents();
076: this .ui = ui;
077: icon.setIcon(problem.isFatal() ? ErrorPanel.getFatalErrorIcon()
078: : ErrorPanel.getNonfatalErrorIcon());
079: problemDescription.setText(problem.getMessage());
080: this .problem = problem;
081: this .details = problem.getDetails();
082: //setLightBackground();
083: if (!single && details != null) {
084: org.openide.awt.Mnemonics.setLocalizedText(showDetails,
085: details.getDetailsHint());
086: showDetails.setPreferredSize(new Dimension(
087: (int) buttonWidth, (int) showDetails
088: .getMinimumSize().getHeight()));
089: } else {
090: showDetails.setVisible(false);
091: }
092:
093: validate();
094: }
095:
096: static void initButtonSize(Problem problem) {
097: buttonWidth = -1.0;
098: while (problem != null) {
099: ProblemDetails pdi = problem.getDetails();
100: if (pdi != null) {
101: buttonWidth = Math.max(
102: new JButton(pdi.getDetailsHint())
103: .getMinimumSize().getWidth(),
104: buttonWidth);
105: }
106: problem = problem.getNext();
107: }
108:
109: }
110:
111: public void setLightBackground() {
112: setBackground(Color.WHITE);
113: problemDescription.setBackground(Color.WHITE);
114: icon.setBackground(Color.WHITE);
115: //showDetails.setBackground(Color.WHITE);
116: }
117:
118: public void setDarkBackground() {
119: Color bgColor = new Color(240, 240, 240);
120: setBackground(bgColor);
121: problemDescription.setBackground(bgColor);
122: icon.setBackground(bgColor);
123: //showDetails.setBackground(bgColor);
124: }
125:
126: /** This method is called from within the constructor to
127: * initialize the form.
128: * WARNING: Do NOT modify this code. The content of this method is
129: * always regenerated by the Form Editor.
130: */
131: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
132: private void initComponents() {
133: java.awt.GridBagConstraints gridBagConstraints;
134:
135: icon = new javax.swing.JLabel();
136: problemDescription = new javax.swing.JTextArea();
137: showDetails = new javax.swing.JButton();
138:
139: setLayout(new java.awt.GridBagLayout());
140:
141: setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3,
142: 3));
143: icon.setBackground(javax.swing.UIManager.getDefaults()
144: .getColor("TextArea.background"));
145: icon.setBorder(javax.swing.BorderFactory.createEmptyBorder(1,
146: 6, 1, 6));
147: gridBagConstraints = new java.awt.GridBagConstraints();
148: gridBagConstraints.gridx = 0;
149: gridBagConstraints.gridy = 0;
150: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
151: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
152: add(icon, gridBagConstraints);
153:
154: problemDescription.setEditable(false);
155: problemDescription.setLineWrap(true);
156: problemDescription.setWrapStyleWord(true);
157: gridBagConstraints = new java.awt.GridBagConstraints();
158: gridBagConstraints.gridx = 1;
159: gridBagConstraints.gridy = 0;
160: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
161: gridBagConstraints.weightx = 1.0;
162: add(problemDescription, gridBagConstraints);
163: problemDescription.getAccessibleContext().setAccessibleName(
164: org.openide.util.NbBundle.getMessage(
165: ProblemComponent.class,
166: "ACSD_ProblemDescriptionName"));
167: problemDescription.getAccessibleContext()
168: .setAccessibleDescription(
169: org.openide.util.NbBundle.getMessage(
170: ProblemComponent.class,
171: "ACSD_ProblemDescriptionDescription"));
172:
173: showDetails
174: .addActionListener(new java.awt.event.ActionListener() {
175: public void actionPerformed(
176: java.awt.event.ActionEvent evt) {
177: showDetailsActionPerformed(evt);
178: }
179: });
180:
181: gridBagConstraints = new java.awt.GridBagConstraints();
182: gridBagConstraints.gridx = 2;
183: gridBagConstraints.gridy = 0;
184: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
185: add(showDetails, gridBagConstraints);
186: showDetails.getAccessibleContext().setAccessibleName(
187: showDetails.getText());
188: showDetails.getAccessibleContext().setAccessibleDescription(
189: showDetails.getText());
190:
191: }
192:
193: // </editor-fold>//GEN-END:initComponents
194:
195: private void showDetailsActionPerformed(
196: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showDetailsActionPerformed
197: Container c = this ;
198: while (!(c instanceof ParametersPanel)) {
199: c = c.getParent();
200: }
201: final ParametersPanel parametersPanel = (ParametersPanel) c;
202: Cancellable doCloseParent = new Cancellable() {
203: public boolean cancel() {
204: parametersPanel.cancel.doClick();
205: return true;
206: }
207: };
208: ProblemDetails details = problem.getDetails();
209: if (details != null) {
210: details.showDetails(new CallbackAction(ui), doCloseParent);
211: }
212: }//GEN-LAST:event_showDetailsActionPerformed
213:
214: // Variables declaration - do not modify//GEN-BEGIN:variables
215: private javax.swing.JLabel icon;
216: private javax.swing.JTextArea problemDescription;
217: private javax.swing.JButton showDetails;
218:
219: // End of variables declaration//GEN-END:variables
220:
221: static class CallbackAction extends AbstractAction {
222: RefactoringUI ui;
223:
224: public CallbackAction(RefactoringUI ui) {
225: super (MessageFormat.format(NbBundle.getMessage(
226: ProblemComponent.class, "LBL_Rerun"),
227: new Object[] { ui.getName() }));
228: this .ui = ui;
229: }
230:
231: public void actionPerformed(ActionEvent event) {
232: new RefactoringPanel(ui).show();
233: }
234: }
235: }
|