KickJava   Java API By Example, From Geeks To Geeks.

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

19
20 package org.netbeans.modules.xml.multiview.ui;
21
22 import javax.swing.UIManager JavaDoc;
23 import org.netbeans.modules.xml.multiview.Error;
24 //import org.netbeans.modules.xml.multiview.cookies.ErrorComponentContainer;
25

26 /**
27  * A panel for error messages.
28  *
29  * Created on November 19, 2004, 10:44 AM
30  * @author mkuchtiak
31  */

32 public class ErrorPanel extends javax.swing.JPanel JavaDoc {
33
34     private Error JavaDoc error;
35     private ErrorLabel errorLabel;
36     private String JavaDoc errorMessage;
37
38
39     /** Creates new form ErrorPanel */
40     public ErrorPanel(final ToolBarDesignEditor editor) {
41         initComponents();
42         
43         errorLabel = new ErrorLabel();
44         errorLabel.addMouseListener(new java.awt.event.MouseAdapter JavaDoc() {
45             public void mousePressed(java.awt.event.MouseEvent JavaDoc evt) {
46                 Error JavaDoc error = getError();
47                 if (error!=null) {
48                     Error.ErrorLocation JavaDoc errorLocation = error.getErrorLocation();
49                     if (errorLocation!=null) {
50                         SectionPanel sectPanel = ((SectionView)editor.getContentView()).findSectionPanel(errorLocation.getKey());
51                         if (sectPanel.getInnerPanel()==null) sectPanel.open();
52                         sectPanel.scroll();
53                         javax.swing.JComponent JavaDoc errorComp = sectPanel.getErrorComponent(errorLocation.getComponentId());
54                         if (errorComp!=null) errorComp.requestFocus();
55                     }
56                 }
57             }
58         });
59         add(errorLabel,java.awt.BorderLayout.CENTER);
60         
61     }
62
63     public String JavaDoc getErrorMessage() {
64         return errorMessage;
65     }
66     /*
67     public ErrorComponentContainer getErrorComponentContainer() {
68         return errorContainer;
69     }
70     */

71     public Error JavaDoc getError() {
72         return error;
73     }
74     
75     /** This method is called from within the constructor to
76      * initialize the form.
77      * WARNING: Do NOT modify this code. The content of this method is
78      * always regenerated by the Form Editor.
79      */

80     private void initComponents() {//GEN-BEGIN:initComponents
81

82         setLayout(new java.awt.BorderLayout JavaDoc());
83
84     }//GEN-END:initComponents
85

86     
87     // Variables declaration - do not modify//GEN-BEGIN:variables
88
// End of variables declaration//GEN-END:variables
89

90     
91     public void setError(Error JavaDoc error) {
92         switch (error.getErrorType()) {
93             case Error.ERROR_MESSAGE : {
94                 errorMessage="Error: "+error.getErrorMessage();
95                 break;
96             }
97             case Error.WARNING_MESSAGE : {
98                 errorMessage="Warning: "+error.getErrorMessage();
99                 break;
100             }
101             case Error.MISSING_VALUE_MESSAGE : {
102                 errorMessage="Missing Value: "+error.getErrorMessage();
103                 break;
104             }
105             case Error.DUPLICATE_VALUE_MESSAGE : {
106                 errorMessage="Duplicate Value: "+error.getErrorMessage();
107                 break;
108             }
109         }
110         this.error=error;
111         errorLabel.setText(errorMessage);
112         errorLabel.setIcon(new javax.swing.ImageIcon JavaDoc(
113             getClass().getResource("/org/netbeans/modules/xml/multiview/resources/error-glyph.gif"))); //NOI18N
114
}
115     
116     public void clearError() {
117         error=null;
118         errorLabel.setIcon(null);
119         errorLabel.setText("");
120         errorMessage="";
121     }
122     
123     private class ErrorLabel extends javax.swing.JLabel JavaDoc {
124         ErrorLabel() {
125             super();
126             //setForeground(SectionVisualTheme.hyperlinkColor);
127
setForeground(UIManager.getDefaults().getColor("ToolBar.dockingForeground")); //NOI18N
128
setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
129             setText(""); //NOI18N
130
}
131
132         public void setText(String JavaDoc text) {
133             if (text.length()==0) super.setText(" "); //NOI18N
134
else super.setText("<html><u>"+text+"</u></html>"); //NOI18N
135
}
136     }
137     
138
139 }
140
Popular Tags