KickJava   Java API By Example, From Geeks To Geeks.

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


1 package demo.notification.whiteboard;
2
3 import java.util.Iterator JavaDoc;
4 import java.util.List JavaDoc;
5
6 import org.omg.CORBA.ORB JavaDoc;
7 import org.omg.CosEventComm.Disconnected;
8 import org.omg.CosNotification.StructuredEvent;
9 import org.omg.CosNotifyChannelAdmin.StructuredProxyPushConsumer;
10
11 /**
12  * @author Alphonse Bendt
13  * @version $Id: ExtendedPixelImage.java,v 1.3 2004/04/28 13:52:02 alphonse.bendt Exp $
14  */

15
16 public class ExtendedPixelImage extends BrushSizePixelImage implements WhiteboardVars {
17
18     StructuredProxyPushConsumer myConsumer_;
19     StructuredEvent event_;
20     ORB JavaDoc orb_;
21
22     public void setPixels(int[] pixels) {
23         for (int x=0; x<m_pixels.length;x++)
24             m_pixels[x] = pixels[x];
25     }
26
27     public ExtendedPixelImage(int w, int h) {
28         super(w,h);
29     }
30
31     public void setOrb(ORB JavaDoc orb) {
32         orb_ = orb;
33     }
34
35     public void setEvent(StructuredEvent event) {
36         event_ = event;
37     }
38
39     // lo"schen mitschreiben und lo"schen
40
synchronized public void clearAll() {
41         WhiteboardUpdate _update = new WhiteboardUpdate();
42         _update.clear(true);
43         super.clearAll();
44     }
45
46     // lo"schen nur lokal
47
public void localClearAll() {
48         super.clearAll();
49     }
50
51     // dieses drawLine wird von 'remote' aufgerufen
52
// und merkt sich u"ber den aufruf die bei uns eingestellte
53
// brushSize
54
synchronized public void drawLine(int x0,
55                                       int y0,
56                                       int x1,
57                                       int y1,
58                                       int red,
59                                       int green,
60                                       int blue,
61                                       int brushSize) {
62         int x = getBrushSize();
63         setBrushSize(brushSize);
64         super.drawLine(x0,y0,x1,y1,red,green,blue);
65         setBrushSize(x);
66     }
67
68     // gezeichnete Linien mitschreiben ansonsten
69
// normal zeichnen
70
synchronized public void drawLine(int x0,
71                                       int y0,
72                                       int x1,
73                                       int y1,
74                                       int red,
75                                       int green,
76                                       int blue) {
77
78         WhiteboardUpdate _update = new WhiteboardUpdate();
79
80         super.drawLine(x0,y0,x1,y1,red,green,blue);
81         _update.line(new LineData(x0, y0, x1, y1, red, green, blue, getBrushSize()));
82
83         try {
84             if (myConsumer_ != null) {
85                 WhiteboardUpdateHelper.insert(event_.remainder_of_body, _update);
86                 myConsumer_.push_structured_event(event_);
87             }
88         } catch (Disconnected d) {
89             d.printStackTrace();
90             myConsumer_ = null;
91         }
92     }
93
94     // wird vom ghostWriter aufgerufen ...
95
// also A"nderung zeichnen
96
// und merken
97
synchronized public void drawLine(UpdateLine ul, boolean v) {
98         drawLine(ul);
99         //lines.addElement(ul);
100
}
101
102     // drawLine das auf UpdateLine Objekten arbeitet
103
void drawLine(UpdateLine ul) {
104         if ( !ul.clearScreen() )
105             drawLine( ul.getX0(),
106                       ul.getY0(),
107                       ul.getX1(),
108                       ul.getY1(),
109                       ul.getRed(),
110                       ul.getGreen(),
111                       ul.getBlue(),
112                       ul.getBrushSize() );
113         else
114             super.clearAll();
115     }
116
117     // UpdateLines auspacken und alle einzeichnen
118
public void drawLine(List JavaDoc uls) {
119         Iterator JavaDoc i = uls.iterator();
120         while (i.hasNext()) {
121             drawLine((UpdateLine)i.next() );
122         }
123     }
124 }
125
Popular Tags