⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 storagecanvas.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
字号:
//$Id: StorageCanvas.java,v 1.2 2002/08/27 08:32:26 per_nyfelt Exp $

package org.ozoneDB.core.monitor;

import org.ozoneDB.DxLib.*;
import java.awt.*;
import java.awt.event.*;


public class StorageCanvas extends Canvas {
    static Color fontColor = new Color( 0, 0, 0 );
    static Color bgColor = new Color( 230, 230, 240 );
    static Color bg1Color = new Color( 210, 210, 210 );
    static Color headColor = new Color( 200, 200, 170 );
    // static Color headColor = new Color (248, 248, 192);
    static Color activeColor = new Color( 245, 0, 0 );
    static Color passivColor = new Color( 89, 82, 238 );
    static Color deathColor = new Color( 0, 235, 0 );
    private static int gradientSteps = 5;
    private static Color[] gradientColors = gradient( passivColor, deathColor, gradientSteps );

    private Graphics dbg;
    private Image dbImage;


    /** */
    private static Color[] gradient( Color f, Color t, int steps ) {
        int rs = (t.getRed() - f.getRed()) / steps;
        int gs = (t.getGreen() - f.getGreen()) / steps;
        int bs = (t.getBlue() - f.getBlue()) / steps;
        Color[] colors = new Color[steps];
        for (int i = 0; i < steps; i++) {
            colors[i] = new Color( f.getRed() + rs * i, f.getGreen() + gs * i, f.getBlue() + bs * i );
        }
        return colors;
    }


    /** */
    public StorageCanvas() {
        setBackground( bg1Color );
    }


    /** */
    public void update( Graphics g ) {
        if (dbImage == null) {
            /* BUG 1: deprecated function: size() */
            dbImage = createImage( size().width, size().height );
            dbg = dbImage.getGraphics();
        }
        paint( dbg );
        g.drawImage( dbImage, 0, 0, this );
    }


    /** */
    public void paint( Graphics g ) {
        super.paint( g );
        Rectangle rect = getBounds();

        g.setColor( bg1Color );
        g.fillRect( 1, 1, rect.width - 2, rect.height - 2 );
        g.draw3DRect( 1, 1, rect.width - 2, rect.height - 2, true );
        g.setColor( headColor );
        g.fillRect( 3, 3, rect.width - 5, 13 );
        g.setColor( Color.white );
        g.drawString( "Storage View", 6, 13 );

        int viewHeight = (rect.height - 60) / 3;
        Rectangle osRect = new Rectangle( 10, rect.height - viewHeight * 3 - 40, rect.width - 20, viewHeight );
        updateOS( g, osRect );
        Rectangle csRect = new Rectangle( 10, rect.height - viewHeight * 2 - 25, rect.width - 20, viewHeight );
        updateCS( g, csRect );
        Rectangle psRect = new Rectangle( 10, rect.height - viewHeight - 10, rect.width - 20, viewHeight );
        updatePS( g, psRect );
    }


    /** */
    public void updateOS( Graphics g, Rectangle rect ) {
    /*
     *        g.setColor (fontColor);
        PersistenceSpace ps = Env.store.persistenceSpace;
        int percent = Env.store.dobjBuffer.size(); // + cl.size() > maxBufferSize
        String label = new String("ObjectSpace - " +
                       Env.store.maxBufferSize / 1024 + "K max - " +
                       new Integer(percent / 1024 ).toString() + "K used");
        g.drawString (label, rect.x, rect.y + 12);
        g.setColor (bgColor);
        g.fillRect (rect.x, rect.y + 14, rect.width, rect.height - 14);
        g.draw3DRect (rect.x, rect.y + 14, rect.width, rect.height - 14, false);

        int y = 0, x = 0;
        int basex = rect.x + 1, basey = rect.y + 14 + 1;
        int pixw = 1, pixh = 1;
        //pixel-groesse berechnen
        while ((((rect.width-2)/pixw) * ((rect.height-14-2)/pixh)) > Env.objectSpace.idTable.count()) {
            pixw++; pixh++;
            }
        pixw = Math.max (1, pixw-1);
        pixh = Math.max (1, pixh-1);

        DxIterator it = Env.objectSpace.idTable.iterator();
        ObjectContainer container;
        while ((container=(ObjectContainer)it.next()) != null) {
            if (container._object != null)
                g.setColor (activeColor);
            else if (container._clusterID == null || ps.containsKey (container._clusterID))
                g.setColor (deathColor);
            else
                g.setColor (passivColor);
            g.fillRect (basex + x, basey + y, pixw, pixh);
            x += pixw;
            if ((x + pixw) >= rect.width-2) {
                x = 0; y += pixh;
                }
            }
     */
    }


    /** */
    public void updateCS( Graphics g, Rectangle rect ) {
    /*
     *        g.setColor (fontColor);
        PersistenceSpace ps = Env.store.persistenceSpace;
        String label = new String("ClusterSpace - " +
                       new Integer(ps.count()).toString() + " clusters loaded");
        g.drawString (label, rect.x, rect.y + 12);
        g.setColor (bgColor);
        g.fillRect (rect.x, rect.y + 14, rect.width, rect.height - 14);
        g.draw3DRect (rect.x, rect.y + 14, rect.width, rect.height - 14, false);

        if (ps.count() > 0) {
            int x = 1;
            int cwidth = (rect.width-2) / Math.max(10, ps.count());
           // int cwidth = (rect.width-2) / (Env.store.maxBufferSize / Env.store.maxClusterSize );

            Cluster cl;
            int max = 0;
            //maximale cluster-groesse ermitteln
            DxIterator it = ps.iterator();
            while ((cl=(Cluster)it.next()) != null) {
                max = Math.max (max, cl.count());
                }

            it = ps.iterator();
            while ((cl=(Cluster)it.next()) != null) {
                int colorIndex = Math.round (((float)cl.count()/(float)max) * ((float)gradientSteps-1));
                g.setColor (gradientColors[colorIndex]);
                g.fill3DRect (rect.x+x, rect.y+14+2, cwidth-3, rect.height - 14 - 3, true);
                x += (cwidth - 1);
                }
            }
     */
    }


    /** */
    public void updatePS( Graphics g, Rectangle rect ) {
    /*
     *        g.setColor (fontColor);
        PersistenceSpace ps = Env.store.persistenceSpace;
        String label = new String("PersistenceSpace - " +
                       new Integer(ps.allClusters.count()).toString() + " clusters");
        g.drawString (label, rect.x, rect.y + 12);
        g.setColor (bgColor);
        g.fillRect (rect.x, rect.y + 14, rect.width, rect.height - 14);
        g.draw3DRect (rect.x, rect.y + 14, rect.width, rect.height - 14, false);

        DxIterator it = ps.allClusters.iterator();
        int x = 1;
        while (it.next()!=null) {
            ClusterID cid = (ClusterID)it.object();
            if (ps.containsKey (cid))
                g.setColor (deathColor);
            else
                g.setColor (passivColor);
            g.drawLine (rect.x+x, rect.y+14+1, rect.x+x, rect.y + rect.height - 1);
            x++;
            }
     */
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -