KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > examples > readers > ReadCanvas


1 /*
2 * ################################################################
3 *
4 * ProActive: The Java(TM) library for Parallel, Distributed,
5 * Concurrent computing with Security and Mobility
6 *
7 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
8 * Contact: proactive-support@inria.fr
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 * Initial developer(s): The ProActive Team
26 * http://www.inria.fr/oasis/ProActive/contacts.html
27 * Contributor(s):
28 *
29 * ################################################################
30 */

31 package org.objectweb.proactive.examples.readers;
32
33 import java.awt.Color JavaDoc;
34 import java.awt.Dimension JavaDoc;
35
36 public class ReadCanvas extends javax.swing.JPanel JavaDoc {
37
38   private int[] readers;
39   private int[] writers;
40
41
42   public ReadCanvas() {
43     readers = new int[3];
44     writers = new int[3];
45     this.setPreferredSize(new Dimension JavaDoc(300, 300));
46   }
47
48
49   public void setRead(int id, boolean state) {
50     readers[id] = (state) ? 1 : 0; // Casting bool into int..
51
repaint();
52   }
53
54
55   public void setWrite(int id, boolean state) {
56     writers[id] = (state) ? 1 : 0; // Casting bool into int..
57
repaint();
58   }
59
60
61   public void setWait(int id, boolean isReader) {
62     if (isReader) {
63       readers[id] = -1;
64     } else {
65       writers[id] = -1;
66     }
67   }
68
69
70   protected void paintComponent(java.awt.Graphics JavaDoc g) {
71     super.paintComponent(g);
72     // Text layout
73
g.setColor(Color.black);
74     g.drawString("Readers", 10, 10);
75     g.drawString("Writers", 10, 140);
76
77     for (int current = 0; current < 3; current++) {
78       // Reader's image
79
if (readers[current] == 1)
80         g.setColor(Color.red);
81       else if (readers[current] == -1)
82         g.setColor(Color.orange);
83       else
84         g.setColor(Color.green);
85       g.fillRect(10 + (current * 50), 30, 40, 60);
86       
87       // Writer's image
88
if (writers[current] == 1)
89         g.setColor(Color.red);
90       else if (writers[current] == -1)
91         g.setColor(Color.orange);
92       else
93         g.setColor(Color.green);
94       g.fillRect(10 + (current * 50), 170, 40, 60);
95     }
96
97     // Legende
98
g.setColor(Color.green);
99     g.fillRect(160, 120, 10, 10); // vert
100
g.setColor(Color.orange);
101     g.fillRect(160, 140, 10, 10); // orange
102
g.setColor(Color.red);
103     g.fillRect(160, 160, 10, 10); // rouge
104

105     g.setColor(Color.black);
106     g.drawString(" : Inactive", 170, 128);
107     g.drawString(" : Waiting", 170, 148);
108     g.drawString(" : Active", 170, 168);
109   }
110 }
111
112
Popular Tags