KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > DiningPhilosophers > cif > 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.cif;
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 skeleton
40  * generated by the OpenCCM's CIF to Java 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 DiningPhilosophers.ObserverServiceComposition.ObserverService_impl
51 {
52     // ==================================================================
53
//
54
// Internal state.
55
//
56
// ==================================================================
57

58     /** Stores philosopher's states. */
59     private java.util.Hashtable JavaDoc philosopherStates_;
60
61     /** The main GUI. */
62     private java.awt.Frame JavaDoc frame_;
63
64     /** The philosopher's panels. */
65     private java.util.Hashtable JavaDoc philosopherPanels_;
66
67     /** The panel used to store philosopher's panel GUI. */
68     private java.awt.Panel JavaDoc panel_;
69
70     // ==================================================================
71
//
72
// Constructor.
73
//
74
// ==================================================================
75

76     /** The default constructor. */
77     public
78     ObserverPdaImpl()
79     {
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::CCMObject interface.
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 java.awt.Frame JavaDoc("The Observer's GUI");
116         // Sets its size.
117
frame_.setSize(400, 300);
118
119         // Constructs and shows the GUI.
120
panel_ = new java.awt.Panel JavaDoc(new java.awt.GridLayout JavaDoc(0, 1));
121         // Using a scroll pane
122
java.awt.ScrollPane JavaDoc scroll_panel = new java.awt.ScrollPane JavaDoc();
123         scroll_panel.add(panel_);
124         frame_.add(scroll_panel);
125         frame_.pack();
126         frame_.show();
127     }
128
129     // ==================================================================
130
//
131
// Methods for the OMG IDL org.omg.Components.SessionComponent
132
//
133
// ==================================================================
134

135     /**
136      * Container callback to signal that the component is removed.
137      *
138      * @throw org.omg.Components.CCMException For any problems.
139      */

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

155     /**
156      * To receive DiningPhilosophers::StatusInfo events.
157      *
158      * Update the observer GUI with received status informations.
159      */

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