// * This code is licensed under:
// * JSlovo License, Version 1.0
// * - for license details see http://jslovo.sourceforge.net/License.txt
// *
// * Copyright (c) 2005 by the S.Chekanov (chekanov@sdf.lonestar.org). 
// * All rights reserved.

package japlot;

import japlot.jaxodraw.JaxoMainPanel;

import java.awt.*;

import jplot.DataArray;
import jplot.LinePars;

import javax.swing.*;

import jplot3d.JColor;
import jplot3d.Utils;

import javax.swing.border.*;

import jhplot.jadraw.JaAxes;

public class DataPanel extends JTabbedPane {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JaxoMainPanel frame;
	private DataArray da;
	private JComboBox symbolList;
	private JComboBox symbolSize;
	private JColor color;
        private JColor colorErrX;
        private JColor colorErrY;
        private JColor colorErrSysX;
        private JColor colorErrSysY;

 
	private JCheckBox chkFillError;
	private JCheckBox chkFillErrorSys;
	private JColor colorFillError;
	private JColor colorFillErrorSys;

	private JCheckBox[] chkErr;
	private JCheckBox[] chkErrSys;

	private JSpinner spnLineWidth;
        private JSpinner spnLineWidthErr;
        private JSpinner spnLineWidthErrSys;
        private JSpinner spnLineWidthTick;

	private JTextField jtname;
	private Icon[] images;
	private String[] images_text;
	private String[] intSizes;

	private final int MaxSymbols = 16;
	private final int MaxSizes = 20;
	private JPanel jglobal;
	private JPanel jerror;
	private JPanel jerrorSys;
	final private Font fdefo = new Font("SansSerif", Font.BOLD, 14);

	public DataPanel(JaAxes ja, JaxoMainPanel frame) {

		this.frame = frame;

		images_text = new String[MaxSymbols];
		intSizes = new String[MaxSizes];

		images = new Icon[MaxSymbols];
		Integer[] intArray = new Integer[MaxSymbols];

		int i;
		for (i = 0; i < 13; i++) {
			intArray[i] = new Integer(i);
			images_text[i] = Integer.toString(i);
			images[i] = new KeyIcon(Color.black, false, i, 7);
		}

		// line
		i = 13;
		intArray[i] = new Integer(i);
		images_text[i] = Integer.toString(20);
		images[i] = new KeyIcon(Color.black, false, 20, 7);

		// non-filled histogram
		i = 14;
		intArray[i] = new Integer(i);
		images_text[i] = Integer.toString(21);
		images[i] = new KeyIcon(Color.black, false, 21, 7);

		// filled
		i = 15;
		intArray[i] = new Integer(i);
		images_text[i] = Integer.toString(22);
		images[i] = new KeyIcon(Color.blue, false, 22, 7);

		// set sizes
		for (i = 0; i < MaxSizes; i++)
			intSizes[i] = Integer.toString(i);

		symbolList = new JComboBox(intArray);
		symbolList.setBorder(new TitledBorder(null, "Symbols:",
				TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION,
				new java.awt.Font("Dialog", 1, 8)));
		ComboBoxRenderer renderer = new ComboBoxRenderer(images, images_text);
		// symbolList.setPreferredSize(new Dimension(100, 40));
		symbolList.setRenderer(renderer);

		// Create the combo box.
		// symbolList = new JComboBox(intArray);
		symbolSize = new JComboBox(intSizes);
		symbolSize.setBorder(new TitledBorder(null, "Size:",
				TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION,
				new java.awt.Font("Dialog", 1, 8)));

		jglobal = new JPanel();
		jerror = new JPanel();
		jerrorSys = new JPanel();

//		jerror.setLayout(new GridLayout(5, 1));
//		jerrorSys.setLayout(new GridLayout(5, 1));

		add("Global", jglobal);
		add("Errors", jerror);
		add("Sys Errors", jerrorSys);

		// Lay out the demo.
		jglobal.add(Utils.labeledComponent("Name:",
				jtname = new JTextField(15), true), null);

		jtname.setFont(fdefo);

		jglobal.add(symbolList);
		jglobal.add(symbolSize);

		jglobal.add(Utils.labeledComponent("Color:",
				color = new JColor(50, 20), true), null);

		jglobal.add(Utils.labeledComponent("Width:",
				spnLineWidth = new JSpinner(new SpinnerNumberModel(1, 0,
						10, 1)), true));

                 jglobal.add(Utils.labeledComponent("Tick size:",
                                spnLineWidthTick = new JSpinner(new SpinnerNumberModel(1, 0,
                                                10, 1)), true));


		chkErr = new JCheckBox[2];
		chkErrSys = new JCheckBox[2];

                 jerror.add(Utils.labeledComponent("Line Width:",
                                spnLineWidthErr = new JSpinner(new SpinnerNumberModel(1, 0,
                                                10, 1)), true));

                 jerror.add(Utils.labeledComponent("X Color:",
                                colorErrX = new JColor(50, 20), true), null);

                 jerror.add(Utils.labeledComponent("Y Color:",
                                colorErrY = new JColor(50, 20), true), null);


		jerror.add(chkFillError = new JCheckBox("Fill"), null);

		jerror.add(Utils.labeledComponent("Fill Color:",
				colorFillError = new JColor(50, 20), true), null);


                jerrorSys.add(Utils.labeledComponent("Line Width:",
                        spnLineWidthErrSys = new JSpinner(new SpinnerNumberModel(1, 0,
                                                10, 1)), true));

                jerrorSys.add(Utils.labeledComponent("X Color:",
                                colorErrSysX = new JColor(50, 20), true), null);
                  
                jerrorSys.add(Utils.labeledComponent("Y Color:",
                                colorErrSysY = new JColor(50, 20), true), null);


		jerrorSys.add(chkFillErrorSys = new JCheckBox("Fill"), null);
		jerrorSys.add(Utils.labeledComponent("Fill Color:",
				colorFillErrorSys = new JColor(50, 20), true), null);

		jerror.add(chkErr[0] = new JCheckBox("show X"), null);

		jerror.add(chkErr[1] = new JCheckBox("show Y"), null);

		jerrorSys.add(chkErrSys[0] = new JCheckBox("show X"), null);

		jerrorSys.add(chkErrSys[1] = new JCheckBox("show  Y"), null);

	}

	public void setDataArray(DataArray da) {

		this.da = da;
		getStyle();
	}

	/**
	 * Set the style from GUI
	 */

	public void setStyle() {

		da.setColor(color.getColor());
                da.setColorErrorsX(colorErrX.getColor());
                da.setColorErrorsY(colorErrY.getColor());
                da.setColorErrorsSysX(colorErrSysX.getColor());
                da.setColorErrorsSysY(colorErrSysY.getColor());
 

		String s = jtname.getText();
		s = s.trim();
		if (s != null)
			da.setName(jtname.getText());

		int id = symbolList.getSelectedIndex();
		if (id > -1 && id < 13) {
                        da.setGraphStyle(0);
                        da.setDrawLine(false);
                        da.setSymbol(id);
                        da.setDrawSymbol(true);
                        da.setType(LinePars.P1D);

		}
		if (id == 13) {
                        da.setGraphStyle(0);
                        da.setDrawLine(true);
			da.setGraphStyle(LinePars.LINES);
			da.setType(LinePars.P1D);
		}
		if (id == 14) {
                        da.setGraphStyle(1);
                        da.setSymbol(21); 
                        da.setDrawLine(false);
                        da.setDrawSymbol(false);
			da.setGraphStyle(LinePars.HISTO);
			da.setType(LinePars.H1D);
		}
		if (id == 15) {
                        da.setGraphStyle(1);
			da.setSymbol(22);
                        da.setDrawLine(false);
                        da.setDrawSymbol(false);
			da.setGraphStyle(LinePars.HISTO);
			da.setType(LinePars.H1D);

		}
		da.setSymbolSize((float) symbolSize.getSelectedIndex());

		da.errorsX(chkErr[0].isSelected());
		da.errorsY(chkErr[1].isSelected());
		da.errorsSysX(chkErrSys[0].isSelected());
		da.errorsSysY(chkErrSys[1].isSelected());
		int w = ((Integer) spnLineWidth.getValue());
		da.setPenWidth((float)w);
                w = ((Integer) spnLineWidthErr.getValue());
                da.setPenWidthErr((float)w);
                w = ((Integer) spnLineWidthErrSys.getValue());
                da.setPenWidthErrSys((float)w);
                w = ((Integer) spnLineWidthTick.getValue());
                da.setErrTicSize((float)w);


		da.errorsFill(chkFillError.isSelected());
		da.errorsFillSys(chkFillErrorSys.isSelected());
		da.setColorErrorsFill(colorFillError.getColor());
		da.setColorErrorsFillSys(colorFillErrorSys.getColor());

	}

	/**
	 * Set the style from GUI
	 */

	public void getStyle() {


                if (da.drawLine() && da.getGraphStyle() == LinePars.LINES) {

                     symbolList.setSelectedIndex(13);

                } else if (da.getType() == LinePars.H1D && da.fill() == false) {  

                     symbolList.setSelectedIndex(14);

                } else if (da.getType() == LinePars.H1D && da.fill() == true) {

                     symbolList.setSelectedIndex(15);

                } else if (da.drawSymbol() ) {
      
                    symbolList.setSelectedIndex(da.getSymbol()); 
                } 



		symbolSize.setSelectedIndex((int) da.getSymbolSize());
		color.setColor(da.getColor());
                colorErrX.setColor(da.getColorErrorsX());
                colorErrY.setColor(da.getColorErrorsY());
                colorErrSysX.setColor(da.getColorErrorsSysX());
                colorErrSysY.setColor(da.getColorErrorsSysY());

               spnLineWidthTick.setValue(new Integer((int)da.getErrTicSize() ));
		spnLineWidth.setValue(new Integer((int)da.getPenWidth()));
                 spnLineWidthErr.setValue(new Integer((int)da.getPenWidthErr()));
                   spnLineWidthErrSys.setValue(new Integer((int)da.getPenWidthErrSys()));


		chkErr[0].setSelected(da.getErrorsX());
		chkErr[1].setSelected(da.getErrorsY());
		chkErrSys[0].setSelected(da.getErrorsSysX());
		chkErrSys[1].setSelected(da.getErrorsSysY());
		chkFillError.setSelected(da.getErrorsFill());
		chkFillErrorSys.setSelected(da.getErrorsFillSys());
		colorFillError.setColor(da.getColorErrorsFill());
		colorFillErrorSys.setColor(da.getColorErrorsFillSys());
		jtname.setText(da.getName().trim());

	}

}

 

Ads help maintain this website.