KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > DiningPhilosophers > monolithic > ObserverPdaImpl


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 USTL - LIFL - GOAL
5 Contact: openccm-team@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Philippe Merle, Sylvain Leblanc.
23 Contributor(s): Christophe Demarey.
24
25 ====================================================================*/

26
27 package DiningPhilosophers.monolithic;
28
29 import DiningPhilosophers.*;
30
31 /**
32  * This is the implementation of the OMG IDL3 DiningPhilosophers::Observer
33  * component type. This implementation is designed to be used with a PDA.
34  *
35  * The info event sink is directly implemented
36  * by the component class by implementing the
37  * DiningPhilosophers::StatusInfoConsumer interface.
38  *
39  * This class inherits from the local CCM_Observer interface
40  * generated by the OpenCCM's IDL3 to IDL2 mapping generator.
41  *
42  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
43  * @author <a HREF="mailto:Sylvain.Leblanc@lifl.fr">Sylvain Leblanc</a>
44  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
45  *
46  * @version 2.0
47  */

48
49 public class ObserverPdaImpl
50      extends org.omg.CORBA.LocalObject JavaDoc
51   implements CCM_Observer,
52              CCM_StatusInfoConsumer,
53              org.omg.Components.SessionComponent
54 {
55     // ==================================================================
56
//
57
// Internal state.
58
//
59
// ==================================================================
60

61     /** The CCM Observer context. */
62     private CCM_Observer_Context the_context_;
63
64     /** Stores philosopher's states. */
65     private java.util.Hashtable JavaDoc philosopherStates_;
66
67     /** The main GUI. */
68     private java.awt.Frame JavaDoc frame_;
69
70     /** The philosopher's panels. */
71     private java.util.Hashtable JavaDoc philosopherPanels_;
72
73     /** The panel used to store philosopher's panel GUI. */
74     private java.awt.Panel JavaDoc panel_;
75
76     // ==================================================================
77
//
78
// Constructor.
79
//
80
// ==================================================================
81

82     /** The default constructor. */
83     public
84     ObserverPdaImpl()
85     {
86         philosopherPanels_ = new java.util.Hashtable JavaDoc();
87     }
88
89     // ==================================================================
90
//
91
// Internal methods.
92
//
93
// ==================================================================
94

95     // ==================================================================
96
//
97
// Public methods.
98
//
99
// ==================================================================
100

101     // ==================================================================
102
//
103
// Methods for OMG IDL Components::CCMObject interface.
104
//
105
// ==================================================================
106

107     /**
108      * Complete the component configuration and launch the
109      * observer GUI.
110      *
111      * @exception org.omg.Components.InvalidConfiguration
112      * Thrown if the configuration is invalid.
113      */

114     public void
115     configuration_complete()
116     throws org.omg.Components.InvalidConfiguration
117     {
118         // Instantiating the GUI.
119

120         // Creates a Swing Frame.
121
frame_ = new java.awt.Frame JavaDoc("The Observer's GUI");
122         // Sets its size.
123
frame_.setSize(400, 300);
124
125         // Constructs and shows the GUI.
126
panel_ = new java.awt.Panel JavaDoc(new java.awt.GridLayout JavaDoc(0, 1));
127         // Using a scroll pane
128
java.awt.ScrollPane JavaDoc scroll_panel = new java.awt.ScrollPane JavaDoc();
129         scroll_panel.add(panel_);
130         frame_.add(scroll_panel);
131         frame_.pack();
132         frame_.show();
133     }
134
135     // ==================================================================
136
//
137
// Methods for the OMG IDL org.omg.Components.SessionComponent
138
//
139
// ==================================================================
140

141     /**
142      * Setting the session component context.
143      *
144      * @param context The session component context.
145      */

146     public void
147     set_session_context(org.omg.Components.SessionContext context)
148     throws org.omg.Components.CCMException
149     {
150         the_context_ = (CCM_Observer_Context)context;
151     }
152
153     /**
154      * Container callback to signal that the component is activated.
155      *
156      * @throw org.omg.Components.CCMException For any problems.
157      */

158     public void
159     ccm_activate()
160     throws org.omg.Components.CCMException
161     {
162         // Nothing to do currently.
163
}
164
165     /**
166      * Container callback to signal that the component is activated.
167      *
168      * @throw org.omg.Components.CCMException For any problems.
169      */

170     public void
171     ccm_passivate()
172     throws org.omg.Components.CCMException
173     {
174         // Nothing to do currently.
175
}
176
177     /**
178      * Container callback to signal that the component is removed.
179      *
180      * @throw org.omg.Components.CCMException For any problems.
181      */

182     public void
183     ccm_remove()
184     throws org.omg.Components.CCMException
185     {
186         // Release the associated frame.
187
frame_.dispose();
188         frame_ = null;
189     }
190
191     // ==================================================================
192
//
193
// Methods for OMG IDL CCM_Observer
194
//
195
// ==================================================================
196

197     /**
198      * To receive dinner::StatusInfo events published
199      * by Philosopher components.
200      */

201     public void
202     push_info(StatusInfo event)
203     {
204         push(event);
205     }
206
207     // ==================================================================
208
//
209
// Methods for OMG IDL dinner::StatusInfoConsumer
210
//
211
// ==================================================================
212

213     /**
214      * To receive DiningPhilosophers::StatusInfo events.
215      *
216      * Update the observer GUI with received status informations.
217      */

218     public synchronized void
219     push(StatusInfo event)
220     {
221         if (! philosopherPanels_.containsKey(event.name)) {
222             PhilosopherPdaPanel panel = new PhilosopherPdaPanel(event);
223             panel_.add(panel);
224             philosopherPanels_.put(event.name, panel);
225             frame_.pack();
226             frame_.show();
227         } else {
228             PhilosopherPdaPanel panel;
229             panel = (PhilosopherPdaPanel)philosopherPanels_.get(event.name);
230             panel.updatePanel(event);
231         }
232     }
233 }
234
Popular Tags