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: * The Original Software is NetBeans. The Initial Developer of the Original
026: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
027: * Microsystems, Inc. All Rights Reserved.
028: *
029: * If you wish your version of this file to be governed by only the CDDL
030: * or only the GPL Version 2, indicate your decision by adding
031: * "[Contributor] elects to include this software in this distribution
032: * under the [CDDL or GPL Version 2] license." If you do not indicate a
033: * single choice of license, a recipient has the option to distribute
034: * your version of this file under either the CDDL, the GPL Version 2 or
035: * to extend the choice of license to its licensees as provided above.
036: * However, if you add GPL Version 2 code and therefore, elected the GPL
037: * Version 2 license, then the option applies only if the new code is
038: * made subject to such option by the copyright holder.
039: */
040:
041: package org.netbeans.modules.profiler.attach.panels.components;
042:
043: import java.awt.Color;
044: import java.text.MessageFormat;
045: import java.util.Iterator;
046: import java.util.List;
047: import java.util.ResourceBundle;
048: import javax.swing.UIManager;
049: import org.netbeans.lib.profiler.ui.UIUtils;
050: import org.netbeans.modules.profiler.attach.spi.IntegrationProvider;
051:
052: /**
053: *
054: * @author Jaroslav Bachorik
055: */
056: public class StepsPanelComponent extends javax.swing.JPanel {
057: private final ResourceBundle messages = ResourceBundle
058: .getBundle("org/netbeans/modules/profiler/attach/panels/components/StepsPanelComponent"); // NOI18N
059: private final String STEP = messages.getString("STEP"); // NOI18N
060: private final String WARNINGS = messages.getString("WARNINGS"); // NOI18N
061: private final String NOTES = messages.getString("NOTES"); // NOI18N
062: private final String WARNING = messages.getString("WARNING"); //NOI18N
063: private final String NOTE = messages.getString("NOTE"); // NOI18N
064:
065: private final String EMPTY_HINT = "<html>\n <head>\n \n </head>\n <body>\n </body>\n</html>\n"; // NOI18N
066:
067: private final int LOCATION_TOP = 1;
068: private final int LOCATION_MIDDLE = 2;
069: private final int LOCATION_BOTTOM = 3;
070:
071: private boolean warningsFirst = true;
072: private boolean isLabelHidden = false;
073:
074: private double lastLabelHeight = -1d;
075:
076: /**
077: * Creates new form StepsPanelComponent
078: */
079: public StepsPanelComponent() {
080: initComponents();
081: }
082:
083: /** This method is called from within the constructor to
084: * initialize the form.
085: * WARNING: Do NOT modify this code. The content of this method is
086: * always regenerated by the Form Editor.
087: */
088: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
089: private void initComponents() {
090:
091: stepsScroller = new javax.swing.JScrollPane();
092: areaSteps = new org.netbeans.lib.profiler.ui.components.HTMLTextArea();
093: label = new javax.swing.JLabel();
094: labelHints = new org.netbeans.lib.profiler.ui.components.HTMLLabel();
095:
096: setMaximumSize(new java.awt.Dimension(800, 600));
097: setMinimumSize(new java.awt.Dimension(400, 100));
098: setPreferredSize(new java.awt.Dimension(400, 200));
099: setRequestFocusEnabled(false);
100: setLayout(new java.awt.BorderLayout());
101:
102: stepsScroller.setMaximumSize(new java.awt.Dimension(800, 600));
103: stepsScroller.setMinimumSize(new java.awt.Dimension(300, 100));
104: stepsScroller
105: .setPreferredSize(new java.awt.Dimension(380, 100));
106: stepsScroller.setViewportView(areaSteps);
107:
108: add(stepsScroller, java.awt.BorderLayout.CENTER);
109:
110: label.setLabelFor(areaSteps);
111: org.openide.awt.Mnemonics.setLocalizedText(label,
112: org.openide.util.NbBundle.getMessage(
113: StepsPanelComponent.class,
114: "StepsPanelComponent.label.text")); // NOI18N
115: label.setBorder(javax.swing.BorderFactory.createEmptyBorder(3,
116: 3, 3, 3));
117: add(label, java.awt.BorderLayout.NORTH);
118:
119: labelHints.setBorder(javax.swing.BorderFactory
120: .createEmptyBorder(3, 3, 3, 3));
121: labelHints.setText(org.openide.util.NbBundle.getMessage(
122: StepsPanelComponent.class,
123: "StepsPanelComponent.labelHints.text")); // NOI18N
124: labelHints.setMaximumSize(new java.awt.Dimension(300, 100));
125: labelHints.setMinimumSize(new java.awt.Dimension(300, 0));
126: labelHints.setPreferredSize(new java.awt.Dimension(300, 60));
127: Color panelBackground = UIManager.getColor("Panel.background"); // NOI18N;
128: Color hintBackground = UIUtils.getSafeColor(panelBackground
129: .getRed() - 10, panelBackground.getGreen() - 10,
130: panelBackground.getBlue() - 10);
131: labelHints.setDisabledTextColor(Color.darkGray);
132: labelHints.setBackground(hintBackground);
133: add(labelHints, java.awt.BorderLayout.SOUTH);
134: labelHints
135: .getAccessibleContext()
136: .setAccessibleName(
137: org.openide.util.NbBundle
138: .getMessage(StepsPanelComponent.class,
139: "StepsPanelComponent.labelHints.AccessibleContext.accessibleName")); // NOI18N
140: }// </editor-fold>//GEN-END:initComponents
141:
142: // Variables declaration - do not modify//GEN-BEGIN:variables
143: private org.netbeans.lib.profiler.ui.components.HTMLTextArea areaSteps;
144: private javax.swing.JLabel label;
145: private org.netbeans.lib.profiler.ui.components.HTMLLabel labelHints;
146: private javax.swing.JScrollPane stepsScroller;
147:
148: // End of variables declaration//GEN-END:variables
149:
150: /**
151: * Getter for property title.
152: * @return Value of property title.
153: */
154: public String getTitle() {
155: return label.getText();
156: }
157:
158: /**
159: * Setter for property title.
160: * @param title New value of property title.
161: */
162: public void setTitle(String title) {
163: org.openide.awt.Mnemonics.setLocalizedText(label, title);
164: }
165:
166: /**
167: * Holds value of property steps.
168: */
169: private IntegrationProvider.IntegrationHints steps;
170:
171: /**
172: * Getter for property steps.
173: * @return Value of property steps.
174: */
175: public IntegrationProvider.IntegrationHints getSteps() {
176: return this .steps;
177: }
178:
179: /**
180: * Setter for property steps.
181: * @param steps New value of property steps.
182: */
183: public void setSteps(IntegrationProvider.IntegrationHints steps) {
184: this .steps = steps;
185:
186: if (steps == null) {
187: areaSteps.setText(""); // NOI18N
188: return;
189: }
190:
191: StringBuffer hintText = new StringBuffer();
192: if (steps.isWarningsFirst()) {
193: appendWarnings(hintText);
194: }
195: appendSteps(hintText);
196: if (!steps.isWarningsFirst()) {
197: appendWarnings(hintText);
198: }
199: appendHints(hintText);
200:
201: hintText.append("<br>"); // NOI18N
202:
203: areaSteps.setText(hintText.toString());
204: areaSteps.setCaretPosition(0); // scroll to the top of the text
205: }
206:
207: private void appendHints(final StringBuffer hintText) {
208: if (this .steps.getHints().size() > 0) {
209: exportAsHtmlList(this .steps.getHints(), NOTE, true,
210: hintText);
211: }
212: }
213:
214: private void appendWarnings(final StringBuffer hintText) {
215: final boolean isLast = !steps.isWarningsFirst()
216: && steps.getHints().size() == 0;
217: if (this .steps.getWarnings().size() > 0) {
218: exportAsHtmlList(this .steps.getWarnings(), WARNING,
219: "#594FBF", isLast, hintText); // NOI18N
220: }
221: }
222:
223: private void appendSteps(final StringBuffer buffer) {
224: final boolean isLast = (steps.isWarningsFirst() && steps
225: .getHints().size() == 0)
226: || (steps.getHints().size() == 0 && steps.getWarnings()
227: .size() == 0);
228: exportAsHtmlList(this .steps.getSteps(), STEP, isLast, buffer);
229: }
230:
231: private void exportAsHtmlList(final List listToExport,
232: final String prefix, final boolean isLast,
233: StringBuffer buffer) {
234: exportAsHtmlList(listToExport, prefix, null, isLast, buffer);
235: }
236:
237: private void exportAsHtmlList(final List listToExport,
238: final String prefix, final String color,
239: final boolean isLast, StringBuffer buffer) {
240: int stepCounter = 1;
241: for (Iterator it = listToExport.iterator(); it.hasNext();) {
242: buffer.append("<p>").append("<b>").append(
243: MessageFormat
244: .format(prefix, new Object[] { new Integer(
245: stepCounter++) })).append("</b>")
246: .append(" "); // NOI18N
247: StringBuffer innerMessage = new StringBuffer();
248: innerMessage.append(it.next()).append("</p>"); // NOI18N
249: if (color != null) {
250: buffer.append("<span style='color:").append(color)
251: .append("'>").append(innerMessage).append(
252: "</span>"); // NOI18N
253: } else {
254: buffer.append(innerMessage);
255: }
256: }
257: if (!isLast) {
258: buffer.append("<br><hr>"); // NOI18N
259: }
260: }
261:
262: /**
263: * Getter for property hintText.
264: * @return Value of property hintText.
265: */
266: public String getHintText() {
267: return labelHints.getText();
268: }
269:
270: /**
271: * Setter for property hintText.
272: * @param hintText New value of property hintText.
273: */
274: public void setHintText(String hintText) {
275: labelHints.setText(hintText);
276: if (hintText == null || hintText.length() == 0
277: || labelHints.getText().equals(EMPTY_HINT)) {
278: labelHints.setVisible(false);
279: } else {
280: labelHints.setVisible(true);
281: }
282: revalidate();
283: }
284: }
|