// Decompiled by DJ v3.0.0.63 Copyright 2002 Atanas Neshkov  Date: 12/09/2002 06:57:30
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   GameLevel.java

import java.awt.*;

public class GameLevel extends Canvas
{

    public GameLevel(int i, Color color, Color color1, String s, String s1, int j)
    {
        level = 1;
        mouseInside = false;
        numBars = i;
        foreground = color;
        background = color1;
        msgLevel = s;
        msgSelectLevel = s1;
        msgMaxLength = j;
    }

    private void initialize()
    {
        uiFont = new Font("Helvetica", 1, 12);
        fieldDimension = size();
        offImage = createImage(fieldDimension.width, fieldDimension.height);
        offGraphics = offImage.getGraphics();
        paintUI();
    }

    public void update(Graphics g)
    {
        if(offImage == null)
            initialize();
        paintUI();
        g.drawImage(offImage, 0, 0, this);
    }

    public void paint(Graphics g)
    {
        requestFocus();
        update(g);
    }

    public boolean mouseMove(Event event, int i, int j)
    {
        mouseInside = true;
        level = (i - 24) / 14 + 1;
        level = level >= 1 ? level : 1;
        level = level <= numBars ? level : numBars;
        repaint();
        return true;
    }

    public boolean mouseExit(Event event, int i, int j)
    {
        mouseInside = false;
        repaint();
        return true;
    }

    public int getLevel()
    {
        return level;
    }

    public void increaseLevel()
    {
        if(level < numBars)
            level++;
        repaint();
    }

    public void decreaseLevel()
    {
        if(level > 1)
            level--;
        repaint();
    }

    private void paintUI()
    {
        offGraphics.setColor(background);
        offGraphics.fillRect(0, 0, fieldDimension.width, fieldDimension.height);
        offGraphics.setColor(foreground);
        offGraphics.setFont(uiFont);
        int i = offGraphics.getFontMetrics(uiFont).getHeight();
        int j = offGraphics.getFontMetrics(uiFont).stringWidth(msgLevel);
        offGraphics.drawString(msgLevel, fieldDimension.width / 2 - j / 2, 16);
        offGraphics.fillRect(8, 16 - i / 2, fieldDimension.width / 2 - j / 2 - 12, 2);
        offGraphics.fillRect(fieldDimension.width / 2 + j / 2 + 4, 16 - i / 2, fieldDimension.width / 2 - j / 2 - 12, 2);
        int k = 24;
        for(int l = 0; l < numBars; l++)
        {
            offGraphics.fillRect(k + 8, (27 - l * 2) * 2, 2, (8 + l * 2) * 2);
            offGraphics.fillRect(k, 70, 10, 2);
            if(l + 1 <= level)
                offGraphics.fillRect(k - 2, (26 - l * 2) * 2, 8, (8 + l * 2) * 2);
            k += 14;
        }

        if(mouseInside)
        {
            String as[] = GameUtil.wrapText(offGraphics, msgSelectLevel, msgMaxLength);
            offGraphics.drawString(as[0], 12, 90);
            if(as[1].length() > 0)
                offGraphics.drawString(as[1], 12, 94 + i);
        }
    }

    private static final int SCALE = 2;
    private static final int BAR_X = 12;
    private static final int BAR_Y = 35;
    private static final int BAR_HEIGHT = 8;
    private static final int BAR_WIDTH = 7;
    private Image offImage;
    private Graphics offGraphics;
    private int numBars;
    private Color foreground;
    private Color background;
    private String msgLevel;
    private String msgSelectLevel;
    private int msgMaxLength;
    private Font uiFont;
    private Dimension fieldDimension;
    private int level;
    private boolean mouseInside;
}