package edu.csusb.danby.graph;


import javax.swing.JPanel;
import java.awt.*;
import java.awt.Color;
import java.awt.Font;
//import java.text.NumberFormat;
import java.awt.geom.*;
import java.io.Serializable;

/**
* Parent class of PdfPlot and Probability Plot
* 
* @author Charles S. Stanton
* @version January 15, 2001
*/
public class GraphPanel extends JPanel implements Serializable {
    //constants for layout
    public static final int HORIZONTAL=0;
    public static final int VERTICAL =1;
    public static final int LOW =0;
    public static final int HIGH =1;

    //offset indices
    public static final int LEFT=0;
    public static final int RIGHT=1;
    public static final int TOP=2;
    public static final int BOTTOM=3;

    //protected float deltaX;
    //protected float[] xPlotPoints; // array of ordinates for which plotpoints are given

    //transformation values
    //protected float a; //horizontal scale factor
    //protected float b; //vertical scale factor * -1
    //protected float c; // horizontal translation
    //protected float d; // vertical translation
    
            
    // pdfPlotData provides the values for the graph
    //protected PdfPlotable pdfPlotData;
    
    ;
    
    
    protected Color graphColor=Color.black; 
    
    protected Color scaleColor=Color.blue;
    protected Color fontColor = Color.black;
    protected Color backgroundColor = Color.white;
    // current panel width & height
    protected int panelWidth, panelHeight; 
    //left, right, top, bottom
    protected int[] offset ={28,18,20,28};
    //offsets for borders and axes
    protected int graphWidth, graphHeight;
    protected int[] graphSize;
    protected boolean drawHorizontalAxis = true; // whether to draw axis
    protected boolean drawVerticalAxis = true;
    //whether to draw at edges or at x=0,y=0.
    protected boolean drawAtEdges = true;
    protected boolean labelAxes = false;
    protected String hAxisLabel ="x";
    protected String vAxisLabel ="y";

    //whether to title the graph.
    protected boolean drawTitle = true;
    protected String title = "";

    protected double[] vGrid, hGrid;
    
    
    final static double log10 = Math.log(10.0);
    //font for labeling axes
    protected Font scaleFont = new Font("Serif", Font.PLAIN,12); 
    protected Font titleFont = new Font("Serif", Font.PLAIN, 24);
    //NumberFormat nf = NumberFormat.getNumberInstance();

/**
* no-argument constructor for GraphPanel 
*/
    public GraphPanel(){
graphSize = new int[2];
    }




    


    protected void drawTitle(Graphics g){
        g.setFont(titleFont);
        //SHOULD USE FONT METRICS
        g.drawString(title,40,20);
    }

    




/*
* Below come the public accessor methods
*/
    
    public void setGraphColor(Color color){
        graphColor = color;
    }

    public void setScaleColor(Color color){
        scaleColor = color;
    }
    
    public void setFontColor(Color color){
        fontColor = color;
    }

    public void setBackgroundColor(Color color){
        backgroundColor = color;
    }
    
    public void doDrawHorizontalAxis(boolean value){
        drawHorizontalAxis = value;
    }

    public void doDrawVerticalAxis(boolean value){
        drawVerticalAxis= value;
    }
        
    public void drawScaleAtEdges(boolean value){
        drawAtEdges = value;
    }

    public void setTitle(String aTitle){
        title = aTitle;
        drawTitle = true;
        offset[TOP] = 40;
    }
    
    public void setHAxisLabel(String label){
        hAxisLabel = label;
        labelAxes = true;
    }

    public void setVAxisLabel(String label){
        vAxisLabel = label;
        labelAxes = true;
    }
}
