KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > DiningPhilosophers > cif > ObserverImpl


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.cif;
28
29 import DiningPhilosophers.*;
30
31 /**
32  * This is the implementation of the OMG IDL3 DiningPhilosophers::Observer
33  * component type.
34  *
35  * This class inherits from the skeleton
36  * generated by the OpenCCM's CIF to Java mapping generator.
37  *
38  * This class inherits from the local CCM_Observer interface
39  * generated by the OpenCCM's IDL3 to IDL2 mapping generator.
40  *
41  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
42  * @author <a HREF="mailto:Sylvain.Leblanc@lifl.fr">Sylvain Leblanc</a>
43  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
44  *
45  * @version 2.0
46  */

47
48 public class ObserverImpl
49      extends DiningPhilosophers.ObserverServiceComposition.ObserverService_impl
50 {
51     // ==================================================================
52
//
53
// Internal state.
54
//
55
// ==================================================================
56

57     /** Stores philosopher's states. */
58     private java.util.Hashtable JavaDoc philosopherStates_;
59
60     /** The main GUI. */
61     private javax.swing.JFrame JavaDoc frame_;
62
63     /** The philosopher's panels. */
64     private java.util.Hashtable JavaDoc philosopherPanels_;
65
66     /** The box panel used to store philosopher's panel GUI. */
67     private javax.swing.Box JavaDoc box_;
68
69     // ==================================================================
70
//
71
// Constructor.
72
//
73
// ==================================================================
74

75     /** The default constructor. */
76     public
77     ObserverImpl()
78     {
79         philosopherStates_ = new java.util.Hashtable JavaDoc();
80         philosopherPanels_ = new java.util.Hashtable JavaDoc();
81     }
82
83     // ==================================================================
84
//
85
// Internal methods.
86
//
87
// ==================================================================
88

89     // ==================================================================
90
//
91
// Public methods.
92
//
93
// ==================================================================
94

95     // ==================================================================
96
//
97
// Methods for OMG IDL Components::EnterpriseComponent
98
//
99
// ==================================================================
100

101     /**
102      * Complete the component configuration and launch the
103      * observer GUI.
104      *
105      * @exception org.omg.Components.InvalidConfiguration
106      * Thrown if the configuration is invalid.
107      */

108     public void
109     configuration_complete()
110     throws org.omg.Components.InvalidConfiguration
111     {
112         // Instantiating the GUI.
113

114         // Creates a Swing Frame.
115
frame_ = new javax.swing.JFrame JavaDoc("The Observer's GUI");
116         // Sets its size.
117
frame_.setSize(400, 300);
118
119         // Constructs and shows the GUI.
120
box_ = javax.swing.Box.createVerticalBox();
121         frame_.getContentPane().add(box_);
122         frame_.pack();
123         frame_.show();
124     }
125
126     // ==================================================================
127
//
128
// Methods for the OMG IDL org.omg.Components.SessionComponent
129
//
130
// ==================================================================
131

132     /**
133      * Container callback to signal that the component is removed.
134      *
135      * @throw org.omg.Components.CCMException For any problems.
136      */

137     public void
138     ccm_remove()
139     throws org.omg.Components.CCMException
140     {
141         // Release the associated frame.
142
frame_.dispose();
143         frame_ = null;
144     }
145
146     // ==================================================================
147
//
148
// Methods for OMG IDL dinner::StatusInfoConsumer
149
//
150
// ==================================================================
151

152     /**
153      * To receive DiningPhilosophers::StatusInfo events.
154      *
155      * Update the observer GUI with received status informations.
156      */

157     public synchronized void
158     push(StatusInfo event)
159     {
160         if (! philosopherPanels_.containsKey(event.name)) {
161             PhilosopherPanel panel = new PhilosopherPanel(event);
162             box_.add(panel);
163             philosopherPanels_.put(event.name, panel);
164             frame_.pack();
165             frame_.show();
166         } else {
167             PhilosopherPanel panel;
168             panel = (PhilosopherPanel)philosopherPanels_.get(event.name);
169             panel.updatePanel(event);
170         }
171     }
172 }
173
Popular Tags