01: /*
02: * The contents of this file are subject to the terms of the Common Development
03: * and Distribution License (the License). You may not use this file except in
04: * compliance with the License.
05: *
06: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
07: * or http://www.netbeans.org/cddl.txt.
08: *
09: * 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:
20: package org.netbeans.modules.xslt.mapper.view;
21:
22: import java.awt.Dimension;
23: import java.awt.Graphics;
24: import java.awt.Graphics2D;
25: import java.awt.RenderingHints;
26: import javax.swing.JComponent;
27: import javax.swing.JEditorPane;
28: import javax.swing.border.EmptyBorder;
29: import javax.swing.text.html.HTMLEditorKit;
30:
31: public class ErrorPanel extends JEditorPane {
32: private XsltMapper mapper;
33: private boolean installed = false;
34: private static final long serialVersionUID = 1;
35:
36: public ErrorPanel(XsltMapper mapper) {
37: this .mapper = mapper;
38:
39: setEditorKitForContentType("text/html", new HTMLEditorKit()); // NOI18N
40: setEditable(false);
41: setPreferredSize(new Dimension(200, 200));
42: setBorder(new EmptyBorder(20, 20, 20, 20));
43: setContentType("text/html"); // NOI18N
44: setBackground(mapper.getBackground());
45: }
46:
47: public void install() {
48: if (!installed) {
49: JComponent parent = (JComponent) mapper.getParent();
50: parent.remove(mapper);
51: parent.add(this );
52: parent.revalidate();
53: parent.repaint();
54:
55: installed = true;
56: }
57: }
58:
59: public void uninstall() {
60: if (installed) {
61:
62: JComponent parent = (JComponent) getParent();
63: parent.remove(this );
64: parent.add(mapper);
65: parent.invalidate();
66: parent.repaint();
67:
68: installed = false;
69: }
70: }
71:
72: public void setMessage(String message) {
73: StringBuffer s = new StringBuffer();
74: s
75: .append("<html><body><font face=sans-serif size=3 color=#990000>"); // NOI18N
76: s.append(message); // NOI18N
77: s.append("</font><br><br></body></html>"); // NOI18N
78: setText(s.toString());
79: }
80:
81: protected void paintComponent(Graphics g) {
82: Graphics2D g2 = (Graphics2D) g.create();
83: g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
84: RenderingHints.VALUE_ANTIALIAS_ON);
85: g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
86: RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
87: super.paintComponent(g2);
88: }
89: }
|