/*
 * Decompiled with CFR 0_132.
 */
package DFT;

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;

public class Graph
extends JPanel {
    private static final long serialVersionUID = 1L;
    private float[] dft = new float[0];

    public void update(float[] dft) {
        this.dft = dft;
        this.repaint();
    }

    @Override
    public void paintComponent(Graphics g) {
        g.setColor(new Color(250, 250, 250));
        g.fillRect(0, 0, this.getWidth(), this.getHeight());
        float space = (float)(this.getWidth() - 30) / (float)this.dft.length;
        float max = 0.0f;
        float indexMax = 0.0f;
        float tmp = 0.0f;
        int i = 0;
        while (i < this.dft.length) {
            if ((max = Math.max(max, this.dft[i])) != tmp) {
                indexMax = i;
                tmp = max;
            }
            ++i;
        }
        float heightScale = (float)(this.getHeight() - 50) / max;
        g.setColor(Color.RED);
        g.drawLine(18, this.getHeight() - 20, this.getWidth() - 10, this.getHeight() - 20);
        g.drawLine(this.getWidth() - 10, this.getHeight() - 20, this.getWidth() - 15, this.getHeight() - 15);
        g.drawLine(this.getWidth() - 10, this.getHeight() - 20, this.getWidth() - 15, this.getHeight() - 25);
        g.drawString("N", this.getWidth() - 10, this.getHeight() - 5);
        g.drawLine(18, this.getHeight() - 20, 18, 20);
        g.drawLine(18, 20, 13, 25);
        g.drawLine(18, 20, 23, 25);
        g.drawString("mag", 2, 15);
        g.drawString(String.valueOf((int)max), (int)(indexMax * space) + 25, this.getHeight() - (int)(max * heightScale) - 20);
        g.translate(20, -20);
        g.setColor(Color.BLACK);
        i = 0;
        while (i < this.dft.length) {
            g.fillRect((int)((float)i * space), this.getHeight() - (int)(this.dft[i] * heightScale), 1, (int)(this.dft[i] * heightScale));
            ++i;
        }
        g.translate(-20, 20);
    }
}

