//package cnp.demo;

import cnp.lc.*;
import java.util.*;
import java.awt.*;


public class CpDemoExamples
{

    public static CpAbstractChartLc createExampleChart()
    {
        Cp3DBarChartLc chartLc = new Cp3DBarChartLc();
        chartLc.setChartDataModel(createExampleChartModel());
        return chartLc;
    }

    public static CpChartDataModel createExampleChartModel()
    {
	    CpDataSeries dataSeries;
        double [] values;
        CpChartDataModel dataModel = new CpChartDataModel();
        values = new double[3];
        values[0] = 10;
        values[1] = 40;
        values[2] = 30;
        dataSeries = new CpDataSeries(values, new Color(255, 255, 204), "World Wide Widgets");
        dataModel.addDataSeries(dataSeries);
        values = new double[3];
        values[0] = 30;
        values[1] = 20;
        values[2] = 10;
        dataSeries = new CpDataSeries(values, new Color(153, 51, 102), "Yoyodyne");
        dataModel.addDataSeries(dataSeries);
        values = new double[3];
        values[0] = 80;
        values[1] = 20;
        values[2] = 80;
        dataSeries = new CpDataSeries(values, new Color(153, 153, 255), "ACME");
        dataModel.addDataSeries(dataSeries);
        values = new double[3];
        values[0] = 40;
        values[1] = 30;
        values[2] = 60;
        dataSeries = new CpDataSeries(values, new Color(166, 202, 240), "Acumen Software");
        dataModel.addDataSeries(dataSeries);
        Vector categories = new Vector(3);
        categories.addElement("1996");
        categories.addElement("1997");
        categories.addElement("1998");
        dataModel.setChartLabel("Very Meaningful Data");
        dataModel.setCategoriesLabel("Year");
        dataModel.setCategories(categories);
        dataModel.setSeriesLabel("Revenue ($M)");

        return dataModel;
    }

    public static CpGridLc basicCreateExampleSpreadSheet(boolean wantsVScroll, boolean wantsHScroll)
    {

        CpGridLc grid = new CpGridLc(wantsVScroll, wantsHScroll, new Dimension(5, 4));

        CpGridPane gridPane = grid.getGridPane();
        grid.setBackground(Color.lightGray);

        gridPane.selectRange(new Point(0, 0), new Point(0, 3), new Point(0, 0), false);
        gridPane.setType(CpBasicType.NUMBER);
        gridPane.setFormatString("#");
        gridPane.selectRange(new Point(1, 1), new Point(4, 3), new Point(1, 1), false);
        gridPane.setType(CpBasicType.NUMBER);
        gridPane.setFormatString("$#,###.00;($#,###.00)");
        gridPane.setHorizontalAlignment(CpAlignable.ALIGN_RIGHT);
        gridPane.selectRange(new Point(1, 0), new Point(4, 0), new Point(1, 0), false);
        gridPane.setHorizontalAlignment(CpAlignable.ALIGN_RIGHT);
        gridPane.selectCell(new Point(0, 0), false);
        gridPane.setColumnWidth(0, 50);
        gridPane.setColumnWidth(1, 142);
        gridPane.setColumnWidth(2, 105);
        gridPane.setColumnWidth(3, 85);
        gridPane.setColumnWidth(4, 120);

        return grid;
    }

    public static CpGridLc createExampleSpreadSheet()
    {
        CpGridLc gridLc = basicCreateExampleSpreadSheet(false, false);
        gridLc.toggleHeaders();
        gridLc.toggleGrid();
        gridLc.toggleEntry();
        gridLc.showSelection(false);
        new CpChartGridAdapter(gridLc.getGridPane(), createExampleChartModel());
        return gridLc;
    }

    public static CpRichTextEditorLc createExampleRichText()
    {
        CpRichTextEditorLc richtext = new CpRichTextEditorLc();
    	CpRichTextPane richpane = richtext.getPane();

	    CpParagraph para;

        para = new CpParagraph("A Word Processor by Cooper & Peters");
	    CpCharFormat format = CpCharFormat.getBold();
	    format.setPointSize(24);
        para.setFormat(0, 36, format);
	    richpane.addParagraph(para);

        para = new CpParagraph("");
	    richpane.addParagraph(para);

        para = new CpParagraph("This application supports a variety of character formatting, including multiple styles (bold, italic, and underline), and text coloring.  It also supports different fonts, like Helvetica and Courier as well as different point sizes like Eight and Twenty-Four.");
        para.setFormat(88, 4, CpCharFormat.getBold());
        para.setFormat(94, 6, CpCharFormat.getItalic());
        para.setFormat(106, 9, CpCharFormat.getUnderline());
	    format = new CpCharFormat();
	    format.setColor(Color.red);
        para.setFormat(122, 15, format);
	    format = new CpCharFormat();
	    format.setFontName("Helvetica");
        para.setFormat(177, 9, format);
	    format = new CpCharFormat();
	    format.setFontName("Courier");
        para.setFormat(191, 7, format);
	    format = new CpCharFormat();
	    format.setPointSize(8);
        para.setFormat(237, 5, format);
	    format = new CpCharFormat();
	    format.setPointSize(24);
        para.setFormat(247, 11, format);
	    richpane.addParagraph(para);

        para = new CpParagraph("");
	    richpane.addParagraph(para);

        para = new CpParagraph("There is also plenty of paragraph formatting.  You can set the horizontal alignment of the paragraph to left, right (for you poets), or centered, like this one.  You can also adjust the left and right margins, as well as the amount of indent for the first line of the paragraph.  These can be set by dragging the arrows in the ruler.");
	    para.setHorizontalAlignment(CpParagraph.CENTER);
	    para.setMargins(40, 40, 0);
	    richpane.addParagraph(para);

        para = new CpParagraph("");
	    richpane.addParagraph(para);

        para = new CpParagraph("Point 1, Bulleted paragraphs are supported.");
        para.setBulletMode(true);
        para.setMargins(120, 0, 0);
	    richpane.addParagraph(para);

        para = new CpParagraph("Point 2, Bulleted paragraphs are supported.");
        para.setBulletMode(true);
        para.setMargins(120, 0, 0);
	    richpane.addParagraph(para);

        para = new CpParagraph("");
	    richpane.addParagraph(para);
/*
        CpLabeledImageButtonLc example = new CpLabeledImageButtonLc("A Button");
        example.setBackground(Color.lightGray);
        example.setSize(100, 50);
        CpLcFormat lcFormat = new CpLcFormat(richpane, example);

        para = new CpParagraph("Finally, you can embed an image or any of our controls, like this button:  Try embedding a spreadsheet, a graph, or even a diagram using the insert button (top toolbar, far right)");
        para.insertChar(74, (char)0);
        para.setFormat(74, 1, lcFormat);
	    richpane.addParagraph(para);
	    */

	    richpane.rewrap();

	    return richtext;
	}
}

