/* Spiro by Jimmc
 * Copyright 1996 Jim McBeath
 *
 * Permission to use, copy, and distribute Spiro, in source or binary form,
 * for personal non-commercial use is hereby granted without fee, provided
 * that this copyright notice appears in all copies, and that no charge is
 * associated with such copies.
 *
 * Permission to modify Spiro and make derivative works for personal
 * non-commercial use, and to distribute such modified versions, is hereby
 * granted without fee, provided that the users of such a modified version
 * are clearly notified that the work is a modified version of Spiro and
 * not the original Spiro.  As with unmodified distributions, this copyight
 * notice must appear in all modified copies, and no charge may be associated
 * with such copies.
 *
 * The author makes no representations about the suitability of this software
 * for any purpose.  It is provided "as-is", without any express or implied
 * warranty.  In no event will the author be held liable for any damages
 * arising from the use of this software.
 */
/* SpiroAdvanced - the advanced dialog for Spiro
 *
 * Jim McBeath, May 1996
 */

import java.awt.*;

class SpiroAdvanced extends Dialog {
	SpiroControls controls;
	GridBuilder gb;
	Label statusW;	//to output messages in the dialog
	TextField stepsW;
	Label actualStepsW;
	TextField dashW;
	Choice drawModeW;
	TextField chainW;
	Button addB;
	Button removeB;
	Button doneB;

	public SpiroAdvanced(Frame f, SpiroControls c) {
		super(f,"Spiro Advanced Paramters",false);
		controls = c;
		gb = new GridBuilder(this);

		addB = gb.addButton("Add Wheel");
		removeB = gb.addButton("Remove Wheel");
		doneB = gb.addButton("Done");

		gb.nextRow();
		gb.addLabel("Steps:");
		stepsW = gb.addTextField("0",8);
		actualStepsW = gb.addLabel("          ");

		gb.nextRow();
		gb.addLabel("Dashes:");
		dashW = gb.addTextField("",8);

		gb.nextRow();
		gb.addLabel("DrawMode:");
		drawModeW = gb.addChoice();
		drawModeW.addItem("Backing");
		drawModeW.addItem("Direct");
		drawModeW.addItem("Synchronous");
		drawModeW.select("Direct");	//set the default

		gb.nextRow();
		gb.addLabel("Chain:");
		chainW = gb.addTextField("",8);

		gb.nextRow();
		gb.constraints.gridwidth = 2;
		statusW = gb.addLabel("                               ");
	}

	public void show() {
		pack();
		super.show();
	}

	protected void setActualSteps(int lcmsteps, int usersteps) {
		String lcmstr = Integer.toString(lcmsteps);
		if (usersteps==0)
			actualStepsW.setText(lcmstr);
		else
			actualStepsW.setText("("+lcmstr+")");
	}

	protected void getState(SpiroState state) {
		String stepStr = stepsW.getText().trim();
		if (stepStr.length()>0)
			state.steps = Integer.parseInt(stepStr);
		else
			state.steps = 0;
		String dashStr = dashW.getText().trim();
		if (dashStr.length()>0) {
			IntVector v = new IntVector(dashStr);
			int a[] = v.getArray();
			state.dashPattern = a;
		} else
			state.dashPattern = null;
		state.drawMode = drawModeW.getSelectedItem();
		state.chain = chainW.getText().trim();
	}

	protected void setState(SpiroState state) {
		stepsW.setText(Integer.toString(state.steps));
		if (state.dashPattern!=null)
			dashW.setText(state.dashPattern.toString());
		else
			dashW.setText("");
		drawModeW.select(state.drawMode);
		if (state.chain!=null)
			chainW.setText(state.chain);
		else
			chainW.setText("");
	}

	public boolean action(Event ev, Object arg) {
		if (ev.target instanceof Button) {
			//Button btn = (Button)(ev.target);
			if (ev.target==doneB) {
				hide();		//take down the dialog
				return true;
			}
			if (ev.target==addB) {
				controls.addWheelCallback();
				statusMessage(
				    "Resize your main window to fix layout");
				return true;
			}
			if (ev.target==removeB) {
				controls.removeWheelCallback();
				statusMessage(
				    "Resize your main window to fix layout");
				return true;
			}
		}
		return false;
	}

	private void statusMessage(String s) {
		statusW.setText(s);
		layout();	/* get text the right size */
	}
}

/* end */
