/*--------------------------------------------------------------------------- -- JAWAA 2.0 -- Copyright information: Susan H Rodger, Pretesh Patel, Diana Jackson, Ayonike Akingbade Computer Science Department Duke University August 2001 Supported by National Science Foundation DUE-9752583 Copyright (c) 2002 All rights reserved Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, advertising materials, and other materials related to such distribution and use acknowledge that the software was developed by the author The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE ---------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------- File: ChangeParamCommandjava Package: JAWAA Version 2.0 Author: Pretesh Patel, Diana Jackson, Ayonike Akingbade Date: August 2002 Description of Contents: This class implements the Jawaa changeParam command It is used to change the graphical attributes of many of the objects used in the Jawaa Language --------------------------------------------------------------------------*/ package jawaa.command; import jawaa.object.*; import jawaa.structure.*; import jawaa.extras.arrow.*; import jawaa.command.MoveRelativeCommand; import jawaa.util.*; import jawaa.anim.*; import java.awt.*; import java.util.*; import java.util.Enumeration; public class ChangeParamCommand extends JawaaCommand implements JawaaListener { public ChangeParamCommand(String[] args) { super("ChangeParam"); try { myTarget = args[1]; myParam = args[2]; myNewValue = args[3]; } catch (ArrayIndexOutOfBoundsException e) { ErrorHandler.error(this, "not enough arguments", true); } catch (Exception e) { ErrorHandler.error(this, "syntax error"); } } public boolean step () { if (myThread == null) { JawaaObject obj = (JawaaObject)myData.get(myTarget); if (obj != null) { myParam = myParam.toLowerCase(); if (myParam.equals("color")) { return colorStep(obj); } else if(myParam.equals("text")) { return textStep(obj); } else if (myParam.equals("bkgrd") || myParam.equals("background")) { return bkgrdStep(obj); } else if(myParam.equals("textcolor")) { return textColorStep(obj); } else if(myParam.equals("width")) { return dimStep(obj, 0); } else if(myParam.equals("height")) { return dimStep(obj, 1); } else if(myParam.equals("target")) { return ListStep(myTarget, myNewValue); } else if(myParam.equals("arrowcolor")) { return ArrowStep(myTarget); } else if(myParam.equals("direction")) { return DirectionStep(myTarget, myNewValue); } else if(myParam.equals("point")) { return pointStep(obj); } else if(myParam.equals("index")) { return indexStep(obj); } else if(myParam.equals("switch")) { JawaaObject obj2 = (JawaaObject)myData.get(myNewValue); return switchStep(obj, obj2); } else if(myParam.equals("swap")) { JawaaObject obj2 = (JawaaObject)myData.get(myNewValue); return swapStep(obj, obj2); } else if((myParam.indexOf("x") != -1) || (myParam.indexOf("X") != -1)) { return locStep(obj, 0); } else if((myParam.indexOf("y") != -1) || (myParam.indexOf("Y") != -1)) { return locStep(obj, 1); } else { ErrorHandler.error(this, myParam + " is not a valid parameter to change"); return false; } } else { ErrorHandler.error(this, myTarget + ": no such object"); return false; } } return colorstuff; } private boolean pointStep(JawaaObject obj) { if(obj instanceof JawaaText) { try{ int[] size = {Integer.parseInt(myNewValue)}; ((Scalable)obj).setSize(size); } catch(NumberFormatException e){ ErrorHandler.error(this, myNewValue + " is not a valid point size"); } } else if (obj instanceof JawaaNode) { try { int[] size = {Integer.parseInt(myNewValue)}; ((JawaaNode)obj).setTextSize(size[0]); } catch(NumberFormatException e){ ErrorHandler.error(this, myNewValue + " is not a valid point size"); } } else if (obj instanceof JawaaGroupObject) { JawaaHash hash = JawaaHash.getInstance(); targets=((JawaaGroupObject)obj).getTargets(); for (int i=0; i