1 package fr.ove.errordialog;
2
3 import java.awt.*;
4 import java.awt.event.*;
5 import fr.ove.errordialog.*;
6
7
8 /***
9 * A panel to insert in the <CODE>fr.ove.errordialog.ErrorDialod</CODE> dialog
10 * box to display an error.
11 * The instance can display specific error message and give more details about
12 * the error.
13 *
14 * @author © 1998 DIRAT Laurent
15 * @version 1.0 13/04/99
16 */
17 public class MainPanelError extends Panel {
18 Panel panelError;
19
20 Panel panelErrorName;
21 PanelImage smileyL, smileyR;
22 Label labelErrorName;
23
24 Panel panelErrorMesgs;
25 Label labelMesg1;
26 Label labelMesg2;
27 Label labelMesg3;
28
29 Panel panelButton;
30 Button buttonCloseWindow;
31 Button buttonDetails;
32
33 TextArea details;
34
35 Window window;
36
37 /***
38 * The constructor
39 */
40 public MainPanelError (Window theWindow, String errorMessage) {
41 window = theWindow;
42
43 Font commonFont = new Font("Dialog", Font.PLAIN, 14);
44
45
46 setLayout(new BorderLayout(0,0));
47 panelError = new Panel();
48 panelError.setLayout(new BorderLayout(0,0));
49 add("North", panelError);
50
51
52 panelErrorName = new Panel();
53 panelErrorName.setLayout(new BorderLayout(0,0));
54 panelErrorName.setBackground(Color.white);
55 panelError.add("North", panelErrorName);
56
57 try {
58
59
60
61
62
63
64
65
66
67
68
69 smileyL = new PanelImage("smiley.gif");
70 panelErrorName.add("West", smileyL);
71 }
72 catch(Exception e) {
73 e.printStackTrace();
74 }
75
76 labelErrorName = new Label(errorMessage, Label.CENTER);
77 labelErrorName.setFont(new Font("Dialog", Font.PLAIN, 20));
78 panelErrorName.add("Center", labelErrorName);
79
80 try {
81
82 smileyR = new PanelImage("smiley.gif");
83 panelErrorName.add("East", smileyR);
84 }
85 catch(Exception e) {
86 e.printStackTrace();
87 }
88
89
90 panelErrorMesgs = new Panel();
91 panelErrorMesgs.setLayout(new GridLayout(4,1,0,0));
92 panelError.add("Center", panelErrorMesgs);
93
94
95 labelMesg1 = new Label("",Label.CENTER);
96 labelMesg1.setFont(commonFont);
97 panelErrorMesgs.add(labelMesg1);
98
99
100 labelMesg2 = new Label("",Label.CENTER);
101 labelMesg2.setFont(commonFont);
102 panelErrorMesgs.add(labelMesg2);
103
104
105 labelMesg3 = new Label("",Label.CENTER);
106 labelMesg3.setFont(commonFont);
107 panelErrorMesgs.add(labelMesg3);
108
109
110 panelButton = new Panel();
111 panelButton.setLayout(new FlowLayout(FlowLayout.CENTER,80,5));
112 panelErrorMesgs.add(panelButton);
113
114
115 buttonCloseWindow = new Button();
116 buttonCloseWindow.setLabel("Close Window");
117 buttonCloseWindow.setFont(commonFont);
118 panelButton.add(buttonCloseWindow);
119
120
121 buttonDetails = new Button();
122 buttonDetails.setLabel("Show Details >>");
123 buttonDetails.setFont(commonFont);
124 panelButton.add(buttonDetails);
125
126
127 details = new TextArea();
128
129
130
131
132
133 buttonDetails.addActionListener(
134 new ActionListener() {
135 public void actionPerformed(ActionEvent event) {
136 Button button = (Button) event.getSource();
137 String label = button.getLabel();
138 Dimension size = window.getSize();
139
140 if (label.equals("Show Details >>")) {
141 button.setLabel("Hide Details <<");
142 MainPanelError.this.add("Center", details);
143 size.height += 250;
144 }
145 else {
146 button.setLabel("Show Details >>");
147 MainPanelError.this.remove(details);
148 size.height -= 250;
149 }
150
151 window.setSize(size);
152 window.validate();
153 }
154 }
155 );
156
157
158 buttonCloseWindow.addActionListener(
159 new ActionListener() {
160 public void actionPerformed(ActionEvent event) {
161 window.setVisible(false);
162 }
163 }
164 );
165 }
166
167 /***
168 * Sets the first of the three messages that can be displayed
169 * @param mesg the error message
170 */
171 public void setMesg1(String mesg) {
172 labelMesg1.setText(mesg);
173 }
174
175 /***
176 * Sets the second of the three messages that can be displayed
177 * @param mesg the error message
178 */
179 public void setMesg2(String mesg) {
180 labelMesg2.setText(mesg);
181 }
182
183 /***
184 * Sets the third of the three messages that can be displayed
185 * @param mesg the error message
186 */
187 public void setMesg3(String mesg) {
188 labelMesg3.setText(mesg);
189 }
190
191 /***
192 * Sets the details of the error
193 * @param theDetails the details of the error
194 */
195 public void setDetails(String theDetails) {
196 details.setText(theDetails);
197 }
198 }
199