View Javadoc

1   package fr.ove.errordialog;
2   
3   import java.awt.*;
4   import java.awt.event.*;
5   import fr.ove.errordialog.*;
6   //import fr.ove.utils.PanelImage;
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  	    // Le panel qui contient tout ce qui est information de l'erreur (le nom, les messages, ...)
46  		setLayout(new BorderLayout(0,0));
47  		panelError = new Panel();
48  		panelError.setLayout(new BorderLayout(0,0));
49  		add("North", panelError);
50  		
51  		// Le panel qui contient le nom de l'erreur (avec le smiley)
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  		    // Comme PanelImage est dans un autre package que le courant il faut que l'on donne
59  		    // le chemin de l'image ? charger relativement au package de PanelImage.
60  		    // Donc :
61  		    //      PanelImage est dans le package fr.ove.utils
62  		    //      L'instance dans le package fr.ove.errordialog, rÈpertoire ou se trouve smiley.gif
63  		    //      D'o? le chemin ../errordialog/smiley.gif
64      		//smileyL = new PanelImage("../errordialog/smiley.gif");
65      		
66      		// Bon on verra cette histoire si on refait passer PanelImage dans fr.ove.utils et l'image
67      		// ailleurs
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      		//smileyR = new PanelImage("../errordialog/smiley.gif");
82      		smileyR = new PanelImage("smiley.gif");
83      		panelErrorName.add("East", smileyR);
84      	}
85      	catch(Exception e) {
86      	    e.printStackTrace();
87      	}
88  
89  		// Le panel qui contient tous les messages et boutons de commande
90  		panelErrorMesgs = new Panel();
91  		panelErrorMesgs.setLayout(new GridLayout(4,1,0,0));
92  		panelError.add("Center", panelErrorMesgs);
93  		
94  		// Un message d'erreur
95  		labelMesg1 = new Label("",Label.CENTER);
96  		labelMesg1.setFont(commonFont);
97  		panelErrorMesgs.add(labelMesg1);
98  		
99  		// Un autre message d'erreur
100 		labelMesg2 = new Label("",Label.CENTER);
101 		labelMesg2.setFont(commonFont);
102 		panelErrorMesgs.add(labelMesg2);
103 		
104 		// Et le dernier
105 		labelMesg3 = new Label("",Label.CENTER);
106 		labelMesg3.setFont(commonFont);
107 		panelErrorMesgs.add(labelMesg3);
108 		
109 		// Le panel qui contient les boutons de commande
110 		panelButton = new Panel();
111 		panelButton.setLayout(new FlowLayout(FlowLayout.CENTER,80,5));
112 		panelErrorMesgs.add(panelButton);
113 
114 		// On ferme la la fenÍtre qui contient notre instance
115 		buttonCloseWindow = new Button();
116 		buttonCloseWindow.setLabel("Close Window");
117 		buttonCloseWindow.setFont(commonFont);
118 		panelButton.add(buttonCloseWindow);
119 		
120 		// On montre ou cache les dÈtails
121 		buttonDetails = new Button();
122 		buttonDetails.setLabel("Show Details >>");
123 		buttonDetails.setFont(commonFont);
124 		panelButton.add(buttonDetails);
125 		
126 		// Les Èventuels dÈtails de l'erreur
127 		details = new TextArea();
128 		//add("Center", details);
129         
130         // La gestion des actions
131         
132         // On affiche ou on cache les dÈtails de l'erreur
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         // On ferme le fenÍtre d'erreur
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