blob: bd125631b74546980fd4549665c4c4eedb84b7f5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/*
$RCSfile$
$Author$
Last Update: $Date$
$Revision$
REVISION HISTORY:
$Log$
Revision 1.1 1997/01/31 01:11:11 sumedh
Added the Nexus II source code files.
# Revision 1.4 1996/12/07 06:22:49 rajeev
# taking a backup !
#
# Revision 1.3 1996/12/06 06:20:07 rajeev
# Changes to include leave handler
#
# Revision 1.2 1996/12/06 04:49:44 rajeev
# working now hopefully !
#
# Revision 1.1 1996/12/06 03:44:32 rajeev
# Initial revision
#
*/
// per room
import java.awt.* ;
import awtCommand.* ;
import java.io.* ;
import java.net.* ;
//import NexusII.client.* ;
//import NexusII.util.* ;
//import NexusII.networking.*;
public class roomHandler implements Runnable,consts{
String roomName_ ;
MT_Bounded_Queue read_q_ ;
MT_Bounded_Queue write_q_ ;
RoomFrame rf_;
Thread mainThread ;
NexusClientApplet applet_ ;
// I dont know what to do currently
public roomHandler(String roomName, MT_Bounded_Queue reader_q,MT_Bounded_Queue writer_q,NexusClientApplet applet) {
roomName_ = roomName ;
read_q_ = reader_q ;
write_q_ = writer_q ;
applet_ = applet ;
rf_ = new RoomFrame(write_q_,applet_,roomName_);
// whenever this frame gets the mouse focus, handler will be called
FrameHandler fh_ = new FrameHandler(applet_);
rf_.setGotFocusCommand(fh_);
mainThread = new Thread(this);
mainThread.start();
}
public void mystop() {
// dispose the graphics part here
if(DEBUG)
System.out.println("Roomhandlers stop called \n");
rf_.hide();
rf_.dispose();
// no longer need the roomframe
rf_ = null ;
mainThread.stop();
}
public void run() {
if(DEBUG) {
System.out.println("Room receiver running ---- ");
}
while(Thread.currentThread() == mainThread) {
// get the data packet
dataPacket packet = (dataPacket)(read_q_.dq()) ;
if(DEBUG)
System.out.println("Room - I got something\n");
// if the packet is of text type -- display it
if(packet.contentType().trim().equalsIgnoreCase("TEXT")) {
rf_.addText(packet.content());
}
// if the packet is a url address -- pull the image across
// this url has to be an image as of now
if(packet.contentType().equalsIgnoreCase("URL")) {
Image im = null ;
try {
im = applet_.getImage(new URL(packet.content()));
} catch (MalformedURLException i) {
// nothing as of now
}
// display the image
rf_.updateImage(im);
}
if (DEBUG)
System.out.println("roomhandler" + roomName_ + " got data");
}
}
public String toString() {
return roomName_ ;
}
} // of class roomHandler
// is executed when the room frame gets mouse focus
class FrameHandler implements Command {
NexusClientApplet applet_ ;
public FrameHandler(NexusClientApplet applet) {
applet_ = applet ;
}
public void execute(Object target, Event evt, Object what) {
if(target instanceof Frame) {
applet_.SetRoomName(((RoomFrame)target).getTitle());
}
}
}
|