KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > notification > whiteboard > WorkgroupFrame


1 package demo.notification.whiteboard;
2
3 import java.awt.BorderLayout JavaDoc;
4 import java.awt.Frame JavaDoc;
5 import java.awt.Menu JavaDoc;
6 import java.awt.MenuBar JavaDoc;
7 import java.awt.MenuItem JavaDoc;
8 import java.awt.event.ActionEvent JavaDoc;
9 import java.awt.event.ActionListener JavaDoc;
10 import java.util.ArrayList JavaDoc;
11 import java.util.Collections JavaDoc;
12 import java.util.List JavaDoc;
13
14 import org.apache.log.Hierarchy;
15 import org.apache.log.Logger;
16
17 /**
18  * @author Alphonse Bendt
19  * @version $Id: WorkgroupFrame.java,v 1.4 2004/04/28 13:52:02 alphonse.bendt Exp $
20  */

21
22 public class WorkgroupFrame extends Frame JavaDoc implements IWorkgroupFrame {
23
24     Logger logger_ = Hierarchy.getDefaultHierarchy().getLoggerFor("WorkgroupFrame");
25
26     BrushSizeDrawCanvas drawCanvas_;
27     SelectDialog dialog;
28     GhostPainter ghost;
29     // PicView pic = new PicView("Daemon.jpg");
30
WorkgroupController controller_;
31
32     public BrushSizeDrawCanvas getDrawCanvas() {
33         return drawCanvas_;
34     }
35
36     public Frame JavaDoc getFrame() {
37     return this;
38     }
39
40     public List JavaDoc getList() {
41         String JavaDoc[] s = controller_.getListOfWhiteboards();
42         List JavaDoc v = new ArrayList JavaDoc();
43         for (int n=0; n<s.length; n++) {
44             v.add(s[n]);
45     }
46         return Collections.unmodifiableList(v);
47     }
48
49     public void setCurrentBoardText(String JavaDoc name) {
50     currentBoard.setText(name);
51     }
52
53     public void setLeaveMenuItem(boolean value) {
54     leaveMenuItem_.setEnabled(value);
55     }
56
57     /** Initializes the Form */
58     public WorkgroupFrame(WorkgroupController wg, String JavaDoc name) {
59         super(name);
60
61     logger_.debug("init");
62
63         controller_ = wg;
64
65         initComponents();
66         pack ();
67     }
68
69     public WorkgroupFrame(WorkgroupController wg) {
70         this(wg, "Whiteboard");
71     }
72
73     private void initComponents () {
74         addWindowListener (new java.awt.event.WindowAdapter JavaDoc () {
75         public void windowClosing (java.awt.event.WindowEvent JavaDoc evt) {
76             exitForm(evt);
77         }
78         });
79         setLayout (new java.awt.BorderLayout JavaDoc ());
80
81         drawCanvas_ = new BrushSizeDrawCanvas(controller_, 400,400);
82         add(drawCanvas_, BorderLayout.CENTER);
83
84         menuBar1 = new MenuBar JavaDoc ();
85         menu1 = new Menu JavaDoc ();
86         menu1.setLabel ("Menu");
87         select = new MenuItem JavaDoc ();
88         select.setLabel ("Select");
89         select.setName ("select");
90         select.addActionListener (new ActionListener JavaDoc () {
91         public void actionPerformed (ActionEvent JavaDoc evt) {
92             selectActionPerformed (evt);
93         }
94         });
95         menu1.add(select);
96
97         leaveMenuItem_ = new java.awt.MenuItem JavaDoc ();
98         leaveMenuItem_.setEnabled (false);
99         leaveMenuItem_.setLabel ("Leave");
100         leaveMenuItem_.setName ("leave");
101         leaveMenuItem_.addActionListener (new ActionListener JavaDoc () {
102         public void actionPerformed (ActionEvent JavaDoc evt) {
103             leaveActionPerformed (evt);
104         }
105         });
106         menu1.add(leaveMenuItem_);
107
108         activateGhost = new java.awt.MenuItem JavaDoc();
109         activateGhost.setLabel("Start Daemon");
110         activateGhost.addActionListener (new java.awt.event.ActionListener JavaDoc() {
111         public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
112             activateGhostActionPerformed();
113         }
114         });
115     // menu1.add(activateGhost);
116

117         exit = new java.awt.MenuItem JavaDoc ();
118         exit.setLabel ("Exit");
119         exit.setName ("exit");
120         exit.addActionListener (new java.awt.event.ActionListener JavaDoc () {
121         public void actionPerformed (java.awt.event.ActionEvent JavaDoc evt) {
122             exitActionPerformed (evt);
123         }
124         });
125         menu1.add(exit);
126
127         menuBar1.add(menu1);
128
129         setMenuBar(menuBar1);
130         panel1 = new java.awt.Panel JavaDoc ();
131         panel1.setLayout (new java.awt.FlowLayout JavaDoc ());
132
133     // pic.setVisible(false);
134
// panel1.add(pic);
135

136         draw = new java.awt.Button JavaDoc ();
137         draw.setLabel ("Draw");
138         draw.addActionListener (new java.awt.event.ActionListener JavaDoc () {
139         public void actionPerformed (java.awt.event.ActionEvent JavaDoc evt) {
140             drawActionPerformed (evt);
141         }
142         });
143         panel1.add (draw);
144
145         delete = new java.awt.Button JavaDoc ();
146         delete.setLabel ("Delete");
147         delete.setName ("delete");
148         delete.addActionListener (new java.awt.event.ActionListener JavaDoc () {
149         public void actionPerformed (java.awt.event.ActionEvent JavaDoc evt) {
150             deleteActionPerformed (evt);
151         }
152         });
153         panel1.add (delete);
154
155         clear = new java.awt.Button JavaDoc ();
156         clear.setLabel ("Clear");
157         clear.setName ("clear");
158         clear.addActionListener (new java.awt.event.ActionListener JavaDoc () {
159         public void actionPerformed (java.awt.event.ActionEvent JavaDoc evt) {
160             clearActionPerformed (evt);
161         }
162         });
163         panel1.add (clear);
164
165         currentBoard = new java.awt.TextField JavaDoc(12);
166         currentBoard.setName("currentboard");
167         currentBoard.setEditable(false);
168         currentBoard.setText("No Selection");
169         panel1.add(currentBoard);
170
171         add (panel1, "South");
172     }
173
174     private void activateGhostActionPerformed() {
175         if (activateGhost.getLabel() == "Start Daemon" ) {
176             ghost = new GhostPainter(this,400,400);
177             ghost.start();
178             activateGhost.setLabel("Stop Daemon");
179         // pic.setVisible(true);
180
} else {
181             ghost.shutdown();
182             activateGhost.setLabel("Start Daemon");
183         // pic.setVisible(false);
184
}
185     }
186
187 // public void selectOk(String r) {
188
// leave.setEnabled(true);
189
// currentBoard.setText(r);
190
// // drawCanvas_.localClearAll();
191
// // workgroup_.joinWhiteboard(r);
192
// }
193

194     private void clearActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {
195         drawCanvas_.clearAll();
196     }
197
198     private void deleteActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {
199         drawCanvas_.setDrawColor(0,0,0);
200         drawCanvas_.setBrushSize(5);
201     }
202
203     private void drawActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {
204         drawCanvas_.setDrawColor(255,255,255);
205         drawCanvas_.setBrushSize(1);
206     }
207
208     private void exitActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {
209     controller_.exit();
210     }
211
212     private void leaveActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {
213         leaveMenuItem_.setEnabled(false);
214         currentBoard.setText("No Selection");
215         controller_.leaveWhiteboard();
216     }
217
218     private void selectActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {
219         dialog = new SelectDialog(this, controller_);
220         dialog.show();
221     }
222
223     /** Exit the Application */
224     private void exitForm(java.awt.event.WindowEvent JavaDoc evt) {
225     controller_.exit();
226     }
227
228     private java.awt.Panel JavaDoc panel1;
229     private java.awt.Button JavaDoc draw,delete,clear;
230     private java.awt.MenuBar JavaDoc menuBar1;
231     private java.awt.Menu JavaDoc menu1;
232     private java.awt.MenuItem JavaDoc select,exit,activateGhost,leaveMenuItem_;
233     private java.awt.TextField JavaDoc currentBoard;
234 }
235
236
Popular Tags