KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > core > monitor > StorageCanvas


1 //$Id: StorageCanvas.java,v 1.2 2002/08/27 08:32:26 per_nyfelt Exp $
2

3 package org.ozoneDB.core.monitor;
4
5 import org.ozoneDB.DxLib.*;
6 import java.awt.*;
7 import java.awt.event.*;
8
9
10 public class StorageCanvas extends Canvas {
11     static Color fontColor = new Color( 0, 0, 0 );
12     static Color bgColor = new Color( 230, 230, 240 );
13     static Color bg1Color = new Color( 210, 210, 210 );
14     static Color headColor = new Color( 200, 200, 170 );
15     // static Color headColor = new Color (248, 248, 192);
16
static Color activeColor = new Color( 245, 0, 0 );
17     static Color passivColor = new Color( 89, 82, 238 );
18     static Color deathColor = new Color( 0, 235, 0 );
19     private static int gradientSteps = 5;
20     private static Color[] gradientColors = gradient( passivColor, deathColor, gradientSteps );
21
22     private Graphics dbg;
23     private Image dbImage;
24
25
26     /** */
27     private static Color[] gradient( Color f, Color t, int steps ) {
28         int rs = (t.getRed() - f.getRed()) / steps;
29         int gs = (t.getGreen() - f.getGreen()) / steps;
30         int bs = (t.getBlue() - f.getBlue()) / steps;
31         Color[] colors = new Color[steps];
32         for (int i = 0; i < steps; i++) {
33             colors[i] = new Color( f.getRed() + rs * i, f.getGreen() + gs * i, f.getBlue() + bs * i );
34         }
35         return colors;
36     }
37
38
39     /** */
40     public StorageCanvas() {
41         setBackground( bg1Color );
42     }
43
44
45     /** */
46     public void update( Graphics g ) {
47         if (dbImage == null) {
48             /* BUG 1: deprecated function: size() */
49             dbImage = createImage( size().width, size().height );
50             dbg = dbImage.getGraphics();
51         }
52         paint( dbg );
53         g.drawImage( dbImage, 0, 0, this );
54     }
55
56
57     /** */
58     public void paint( Graphics g ) {
59         super.paint( g );
60         Rectangle rect = getBounds();
61
62         g.setColor( bg1Color );
63         g.fillRect( 1, 1, rect.width - 2, rect.height - 2 );
64         g.draw3DRect( 1, 1, rect.width - 2, rect.height - 2, true );
65         g.setColor( headColor );
66         g.fillRect( 3, 3, rect.width - 5, 13 );
67         g.setColor( Color.white );
68         g.drawString( "Storage View", 6, 13 );
69
70         int viewHeight = (rect.height - 60) / 3;
71         Rectangle osRect = new Rectangle( 10, rect.height - viewHeight * 3 - 40, rect.width - 20, viewHeight );
72         updateOS( g, osRect );
73         Rectangle csRect = new Rectangle( 10, rect.height - viewHeight * 2 - 25, rect.width - 20, viewHeight );
74         updateCS( g, csRect );
75         Rectangle psRect = new Rectangle( 10, rect.height - viewHeight - 10, rect.width - 20, viewHeight );
76         updatePS( g, psRect );
77     }
78
79
80     /** */
81     public void updateOS( Graphics g, Rectangle rect ) {
82     /*
83      * g.setColor (fontColor);
84         PersistenceSpace ps = Env.store.persistenceSpace;
85         int percent = Env.store.dobjBuffer.size(); // + cl.size() > maxBufferSize
86         String label = new String("ObjectSpace - " +
87                        Env.store.maxBufferSize / 1024 + "K max - " +
88                        new Integer(percent / 1024 ).toString() + "K used");
89         g.drawString (label, rect.x, rect.y + 12);
90         g.setColor (bgColor);
91         g.fillRect (rect.x, rect.y + 14, rect.width, rect.height - 14);
92         g.draw3DRect (rect.x, rect.y + 14, rect.width, rect.height - 14, false);
93
94         int y = 0, x = 0;
95         int basex = rect.x + 1, basey = rect.y + 14 + 1;
96         int pixw = 1, pixh = 1;
97         //pixel-groesse berechnen
98         while ((((rect.width-2)/pixw) * ((rect.height-14-2)/pixh)) > Env.objectSpace.idTable.count()) {
99             pixw++; pixh++;
100             }
101         pixw = Math.max (1, pixw-1);
102         pixh = Math.max (1, pixh-1);
103
104         DxIterator it = Env.objectSpace.idTable.iterator();
105         ObjectContainer container;
106         while ((container=(ObjectContainer)it.next()) != null) {
107             if (container._object != null)
108                 g.setColor (activeColor);
109             else if (container._clusterID == null || ps.containsKey (container._clusterID))
110                 g.setColor (deathColor);
111             else
112                 g.setColor (passivColor);
113             g.fillRect (basex + x, basey + y, pixw, pixh);
114             x += pixw;
115             if ((x + pixw) >= rect.width-2) {
116                 x = 0; y += pixh;
117                 }
118             }
119      */

120     }
121
122
123     /** */
124     public void updateCS( Graphics g, Rectangle rect ) {
125     /*
126      * g.setColor (fontColor);
127         PersistenceSpace ps = Env.store.persistenceSpace;
128         String label = new String("ClusterSpace - " +
129                        new Integer(ps.count()).toString() + " clusters loaded");
130         g.drawString (label, rect.x, rect.y + 12);
131         g.setColor (bgColor);
132         g.fillRect (rect.x, rect.y + 14, rect.width, rect.height - 14);
133         g.draw3DRect (rect.x, rect.y + 14, rect.width, rect.height - 14, false);
134
135         if (ps.count() > 0) {
136             int x = 1;
137             int cwidth = (rect.width-2) / Math.max(10, ps.count());
138            // int cwidth = (rect.width-2) / (Env.store.maxBufferSize / Env.store.maxClusterSize );
139
140             Cluster cl;
141             int max = 0;
142             //maximale cluster-groesse ermitteln
143             DxIterator it = ps.iterator();
144             while ((cl=(Cluster)it.next()) != null) {
145                 max = Math.max (max, cl.count());
146                 }
147
148             it = ps.iterator();
149             while ((cl=(Cluster)it.next()) != null) {
150                 int colorIndex = Math.round (((float)cl.count()/(float)max) * ((float)gradientSteps-1));
151                 g.setColor (gradientColors[colorIndex]);
152                 g.fill3DRect (rect.x+x, rect.y+14+2, cwidth-3, rect.height - 14 - 3, true);
153                 x += (cwidth - 1);
154                 }
155             }
156      */

157     }
158
159
160     /** */
161     public void updatePS( Graphics g, Rectangle rect ) {
162     /*
163      * g.setColor (fontColor);
164         PersistenceSpace ps = Env.store.persistenceSpace;
165         String label = new String("PersistenceSpace - " +
166                        new Integer(ps.allClusters.count()).toString() + " clusters");
167         g.drawString (label, rect.x, rect.y + 12);
168         g.setColor (bgColor);
169         g.fillRect (rect.x, rect.y + 14, rect.width, rect.height - 14);
170         g.draw3DRect (rect.x, rect.y + 14, rect.width, rect.height - 14, false);
171
172         DxIterator it = ps.allClusters.iterator();
173         int x = 1;
174         while (it.next()!=null) {
175             ClusterID cid = (ClusterID)it.object();
176             if (ps.containsKey (cid))
177                 g.setColor (deathColor);
178             else
179                 g.setColor (passivColor);
180             g.drawLine (rect.x+x, rect.y+14+1, rect.x+x, rect.y + rect.height - 1);
181             x++;
182             }
183      */

184     }
185 }
186
Popular Tags