diff --git a/README.md b/README.md index d7d3ca5..4ec42dc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,25 @@ # VisualNQC An iconic language to for the Lego MindStorms RCX, which generates NQC code. Support is included to facilitate integrating the NQC compilation and deployment processes. (This project was formerly known as fUNSoftWare.) +This has personally been one of the more intriguing software finds for the RCX. + +Only one release and version of the source code were posted to the original [SourceForge project site](http://funsoftware.sourceforge.net/). +Over the intervening period before republishing here, I have updated the project follows, but these updates never saw any response upstream. +The earliest patches were posted to SourceForge [here](https://sourceforge.net/p/funsoftware/patches/1/). + +In particular, these modifications include the following: +* Fixed bug preventing creation of arithmetic conditions (branch, loop) inside global event monitors +* Enabled use of non-USB IR towers by checking the RCXTTY environment variable before defaulting to USB +* Changed default file writes (e.g. config.txt, intermediate NQC code file) to occur under the user's directory to resolve permissions issues +* Updated check in Windows for whether to use command.com or cmd.exe +* Added a "Device" menu (for potential future enhancement; for now, is set to RCX2) +* Modularized some property values into an AppProperties class +* Changed window layout to increase the programming area; added UNSW CSE logo and URL to the about dialog +* Updated GUI to be able resize well to other screen sizes; removed the manual screen resizing code and reworked the code to use components with built-in resizing capabilities. + +Development currently seems to work best with NetBeans IDE 8.2. + + ---------------- ----- fUNSoftWare ----- ---------------- diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..95dc041 --- /dev/null +++ b/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project VisualNQC. + + + diff --git a/doc/flash_presentation/funTutorial.html b/doc/flash_presentation/funTutorial.html new file mode 100644 index 0000000..e869cd1 --- /dev/null +++ b/doc/flash_presentation/funTutorial.html @@ -0,0 +1,229 @@ + + + + +Created by Camtasia Studio 3 + + + + + + + + + + + + + + + + + + + diff --git a/doc/flash_presentation/funTutorial.swf b/doc/flash_presentation/funTutorial.swf new file mode 100644 index 0000000..d4526c7 Binary files /dev/null and b/doc/flash_presentation/funTutorial.swf differ diff --git a/doc/flash_presentation/funTutorial_config.xml b/doc/flash_presentation/funTutorial_config.xml new file mode 100644 index 0000000..42ce8a0 --- /dev/null +++ b/doc/flash_presentation/funTutorial_config.xml @@ -0,0 +1,92 @@ +
+ + 0 + 0 + 1 + 0 + 1020 + 736 + + 1020 + 736 + 427 + 15 + 0 + funTutorial.swf + + + 0 + 0 + 0 + 0 + 30 + funTutorial_PIP.flv + + + 0 + 0 + 0 + 0 + + + + + + + + + + + + + + + 0xA4A4A4 + 0xC0C0C0 + 10 + solid + 0x000000 + _sans + 12 + none + left + none + 0 + 0x000000 + 0x000000 + 0 + 0 + + 1 + FFFFFF + 1 + 1 + 50 + 3 + 0xC0C0C0 + 1 + + MM:SS + 1 + 1 + Arial + 0x000000 + This action is not allowed by the default Flash Player security settings when the content is played from a hard drive or CD. Once the content is moved to a web server, it should function as expected, and you should not see this message. + +For other distribution methods, or to understand how the Flash Player security settings affect this content, please see the "Flash Player Security" topic in the Camtasia Studio help file. + + + + + + + 0 + + + + + + + + +
\ No newline at end of file diff --git a/doc/flash_presentation/funTutorial_controller.swf b/doc/flash_presentation/funTutorial_controller.swf new file mode 100644 index 0000000..bd4dea1 Binary files /dev/null and b/doc/flash_presentation/funTutorial_controller.swf differ diff --git a/doc/flash_presentation/funTutorial_nofp_bg.gif b/doc/flash_presentation/funTutorial_nofp_bg.gif new file mode 100644 index 0000000..3651333 Binary files /dev/null and b/doc/flash_presentation/funTutorial_nofp_bg.gif differ diff --git a/doc/flash_presentation/funTutorial_preload.swf b/doc/flash_presentation/funTutorial_preload.swf new file mode 100644 index 0000000..656a769 Binary files /dev/null and b/doc/flash_presentation/funTutorial_preload.swf differ diff --git a/doc/readme.txt b/doc/readme.txt new file mode 100644 index 0000000..2521c77 --- /dev/null +++ b/doc/readme.txt @@ -0,0 +1,64 @@ +fUNSoftWare v1.0 + +Please read this document before using the program. + +System requirements: +1. Java Virtual Machine +2. NQC +3. 15 MB hard disk space + + +This software is designed to run on a Java Virtual Machine, so it is cross platform compatible. +It has been tested to run on Windows XP, Windows 2000 and MacOs. + + +Installation steps: +----------------- + +======================================== +For Windows 98, Windows 2000, Windows XP users +======================================== + +Download and install a Java Virtual Machine that supports at least Java 1.5 from: http://java.sun.com/j2se/1.5.0/download.jsp + +Download and install an NQC compiler from: http://bricxcc.sourceforge.net/nqc/release/index.html +Please have the NQC executable file in the same directory as your .jar file(s) + +1. Go to My Computer. +2. Select the folder in which to place your fun.zip file +3. Unzip the file using WinZip +4. Please keep the configuration of the files. Do not change the relative location of the files. If you would like to move the .jar files somewhere else, +please move the other files within fun.zip accordingly. +5. Double click on the fUNSoftWareRCX1.jar file icon if you are using the RCX1.0 brick. +6. Double click on the fUNSoftWareRCX2.jar file icon if you are using the RCX2.0 brick. + + +================ +For Mac OS X users +================ + +Download and install Java 1.5 at http://www.apple.com/support/downloads/java2se50release1.html + +Download and install MacNQC at http://homepage.mac.com/rbate/MacNQC/ + +In order to use the newly installed Java 1.5 rather than the pre-installed Java 1.4, launch a Terminal and type the following commands: + +cd /System/Library/Frameworks/JavaVM.framework/Versions +sudo mv Current Current.old +sudo ln -s 1.5 Current + + +Now say that you have created a directory named Lego under Documents, and copied the fun.zip file +In the Terminal type: + +open ~/Documents/Lego/fun/fUNSoftWareRCX1.jar & + + + + +To run the program's flash presentation manually, go to the flash_presentation folder and using your web browser, +open the funTutorial.html file. + +Please check the fUNSoftWare website on sourceforge regularly for any notices or updates on the program. + +URL: http://funsoftware.sourceforge.net \ No newline at end of file diff --git a/manifest.mf b/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..715aa94 --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1403 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..6cc827e --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=9eed2be5 +build.xml.script.CRC32=751bd14e +build.xml.stylesheet.CRC32=8064a381@1.80.1.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=9eed2be5 +nbproject/build-impl.xml.script.CRC32=3f14dd05 +nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..47c0cc6 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,70 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +application.title=NetBeans +application.vendor=msheets +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/VisualNQC.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes=**/Thumbs.db +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.junit_4.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=funsoftware.inter.Splasher +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.src.dir=src diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..2eaa6cf --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,14 @@ + + + org.netbeans.modules.java.j2seproject + + + VisualNQC + 1.6.5 + + + + + + + diff --git a/src/funsoftware/comp/Translator.java b/src/funsoftware/comp/Translator.java new file mode 100644 index 0000000..50f3fad --- /dev/null +++ b/src/funsoftware/comp/Translator.java @@ -0,0 +1,1644 @@ +/* + * Translator.java + * + * Created on 14 July 2005, 23:29 + */ + +package funsoftware.comp; + +import funsoftware.ic.*; +import funsoftware.ic.obj.*; +import funsoftware.ic.bran.*; +import funsoftware.ic.loo.*; +import funsoftware.ic.others.*; +import funsoftware.ic.func.*; +import funsoftware.ic.tsk.*; +import funsoftware.ic.ev.*; +import funsoftware.ic.var.*; +import funsoftware.consts.*; +import funsoftware.functs.*; +import funsoftware.tasks.*; +import funsoftware.events.*; +import funsoftware.struct.*; +import funsoftware.var.*; +import funsoftware.properties.*; + +/** + * This class takes in all the information of a created iconic program to create two types of text. + * The first one being an algorithm representation and the second one being an NQC code. + * @author Thomas Legowo + */ +public class Translator { + + // the private variables + private static java.util.Vector objects; // the object icons lookup table + private static java.util.Vector branches; // the branch icons lookup table + private static java.util.Vector loops; // the loop icons lookup table + + // the variables determining the notations for the algorithm translation + private static String id_separator; // between the icon's type and its identifier code + private static String id_att_separator; // between the identifier and the attributes + private static String att_boundary_begin; // encloses the boundary (begin) + private static String att_boundary_end; // encloses the boundary (end) + private static String att_value_connector; // between the attribute to its value + private static String att_separator; // between the attributes + + /** + * Initializes the vectors and notations + */ + public static void init_lookup_table(){ + // do the object lookup table + objects = new java.util.Vector(); + objects.addElement(new motorIcon()); + objects.addElement(new stopMotorIcon()); + objects.addElement(new directionalMotorIcon()); + objects.addElement(new timerIcon()); + objects.addElement(new beepIcon()); + objects.addElement(new lampIcon()); + objects.addElement(new clearSensorIcon()); + objects.addElement(new clearTimerIcon()); + objects.addElement(new playAnyNoteIcon()); + objects.addElement(new beginTaskIcon()); + objects.addElement(new stopTaskIcon()); + objects.addElement(new ArithOpIcon()); + objects.addElement(new floatMotorIcon()); + objects.addElement(new playSpecificNote()); + objects.addElement(new startEvent()); + objects.addElement(new returnIcon()); + objects.addElement(new waitTouchIcon()); + objects.addElement(new waitLightIcon()); + objects.addElement(new waitCelciusIcon()); + objects.addElement(new waitRotationalIcon()); + objects.addElement(new waitTimerIcon()); + + // do the branch lookup table + branches = new java.util.Vector(); + branches.addElement(new BtouchSensorIcon()); + branches.addElement(new BlightSensorIcon()); + branches.addElement(new BcelciusSensorIcon()); + branches.addElement(new BrotationSensorIcon()); + branches.addElement(new BtimerIcon()); + branches.addElement(new BrandomIcon()); + branches.addElement(new BarithmeticIcon()); + + // do the loop lookup table + loops = new java.util.Vector(); + loops.addElement(new repeatIcon()); + loops.addElement(new lightSensorLoopIcon()); + loops.addElement(new infiniteLoopIcon()); + loops.addElement(new timerLoopIcon()); + loops.addElement(new celciusSensorLoopIcon()); + loops.addElement(new rotationSensorLoopIcon()); + loops.addElement(new touchSensorLoopIcon()); + loops.addElement(new arithmeticLoopIcon()); + + // initialise the notations + id_separator = "#"; + id_att_separator = ">>"; + att_boundary_begin = "["; + att_boundary_end = "]"; + att_value_connector = ":"; + att_separator = ">"; + } + + /** + * Returns the id-attribute separator notation of this class + * @return Id-attribute separator notation + */ + public static String getId_Att_Separator() + { + return id_att_separator; + } + /** + * Returns the id separator notation of this class + * @return Id separator notation + */ + public static String getId_Separator() + { + return id_separator; + } + + /** + * Returns the attribute list begin notation of this class + * @return Attribute list begin notation + */ + public static String getAtt_Boundary_Begin() + { + return att_boundary_begin; + } + /** + * Returns the attribute list end notation of this class + * @return Attribute list end notation + */ + public static String getAtt_Boundary_End() + { + return att_boundary_end; + } + /** + * Returns the attribute value separator notation of this class + * @return Attribute-value separator notation + */ + public static String getAtt_Value_Connector() + { + return att_value_connector; + } + /** + * Returns the attribute separator notation of this class + * @return Attribute separator notation + */ + public static String getAtt_Separator() + { + return att_separator; + } + + /** + * Return an icon as specified by its identifier on a text representation as well as setting its attributes + * @param rep String representation of an icon's attributes + * @param a The auxiliary this icon resides in + * @return The formed icon + */ + public static Icon getIcon(String rep, auxiliary a) + { + Icon tmp_icon = new Icon(); + String[] sp = new String[2]; // the identifiers + String[] sp2 = new String[5]; // an icon's attributes can be up to 5 in total + String line = new String(); + int pos = 0; + + sp2 = rep.split(id_att_separator); + sp = sp2[0].split(id_separator); + pos = Integer.parseInt(sp[1]) - 1; + if(sp[0].compareTo("branch") == 0) + { + tmp_icon = branches.get(pos); + String tmp_string[] = rep.split("\n"); // the temporary string that represent only the branch icon + sp2 = tmp_string[0].split(id_att_separator); + sp = sp2[0].split(id_separator); + + if(pos == 6) // SPECIAL for arithmetic operation + { + line = tmp_string[0].substring(tmp_string[0].indexOf(att_boundary_begin), tmp_string[0].lastIndexOf(att_boundary_end)+1); + } + else + { + line = sp2[1]; + line = line.substring(line.indexOf(att_boundary_begin)+1, line.indexOf(att_boundary_end)); + } + + if(pos == 0) + { + BtouchSensorIcon ic = ((BtouchSensorIcon)tmp_icon).Clone(); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 1) + { + BlightSensorIcon ic = ((BlightSensorIcon)tmp_icon).Clone(); + ic.setAux(a); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 2) + { + BcelciusSensorIcon ic = ((BcelciusSensorIcon)tmp_icon).Clone(); + ic.setAux(a); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 3) + { + BrotationSensorIcon ic = ((BrotationSensorIcon)tmp_icon).Clone(); + ic.setAux(a); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 4) + { + BtimerIcon ic = ((BtimerIcon)tmp_icon).Clone(); + ic.setAux(a); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 5) + { + BrandomIcon ic = ((BrandomIcon)tmp_icon).Clone(); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 6) + { + BarithmeticIcon ic = ((BarithmeticIcon)tmp_icon).Clone(); + ic.setAux(a); + ic.setAttributes(line, att_value_connector, att_separator, id_att_separator); // special !! + ic.setImage(); + return ic; + } + } + else if(sp[0].compareTo("loop") == 0) + { + tmp_icon = loops.get(pos); + String tmp_string[] = rep.split("\n"); // the temporary string that represent only the loop icon + sp2 = tmp_string[0].split(id_att_separator); + sp = sp2[0].split(id_separator); + + if(pos == 7) // SPECIAL for arithmetic operation + { + line = tmp_string[0].substring(tmp_string[0].indexOf(att_boundary_begin), tmp_string[0].lastIndexOf(att_boundary_end)+1); + } + else + { + line = sp2[1]; + line = line.substring(line.indexOf(att_boundary_begin)+1, line.indexOf(att_boundary_end)); + } + + if(pos == 0) + { + repeatIcon ic = ((repeatIcon)tmp_icon).Clone(); + ic.setAux(a); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 1) + { + lightSensorLoopIcon ic = ((lightSensorLoopIcon)tmp_icon).Clone(); + ic.setAux(a); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 2) + { + infiniteLoopIcon ic = ((infiniteLoopIcon)tmp_icon).Clone(); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 3) + { + timerLoopIcon ic = ((timerLoopIcon)tmp_icon).Clone(); + ic.setAux(a); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 4) + { + celciusSensorLoopIcon ic = ((celciusSensorLoopIcon)tmp_icon).Clone(); + ic.setAux(a); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 5) + { + rotationSensorLoopIcon ic = ((rotationSensorLoopIcon)tmp_icon).Clone(); + ic.setAux(a); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 6) + { + touchSensorLoopIcon ic = ((touchSensorLoopIcon)tmp_icon).Clone(); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 7) + { + arithmeticLoopIcon ic = ((arithmeticLoopIcon)tmp_icon).Clone(); + ic.setAux(a); + ic.setAttributes(line, att_value_connector, att_separator, id_att_separator); // special !! + ic.setImage(); + return ic; + } + } + else if(sp[0].compareTo("object") == 0) + { + tmp_icon = objects.get(pos); + if(pos == 11) // SPECIAL for arithmetic operation + { + line = rep.substring(rep.indexOf(att_boundary_begin), rep.lastIndexOf(att_boundary_end)+1); + } + else + { + line = sp2[1]; + line = line.substring(line.indexOf(att_boundary_begin)+1, line.indexOf(att_boundary_end)); + } + + if(pos == 0) + { + motorIcon ic = ((motorIcon)tmp_icon).Clone(); + ic.setAux(a); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 1) + { + stopMotorIcon ic = ((stopMotorIcon)tmp_icon).Clone(); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 2) + { + directionalMotorIcon ic = ((directionalMotorIcon)tmp_icon).Clone(); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 3) + { + timerIcon ic = ((timerIcon)tmp_icon).Clone(); + ic.setAux(a); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 4) + { + beepIcon ic = ((beepIcon)tmp_icon).Clone(); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 5) + { + lampIcon ic = ((lampIcon)tmp_icon).Clone(); + ic.setAux(a); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 6) + { + clearSensorIcon ic = ((clearSensorIcon)tmp_icon).Clone(); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 7) + { + clearTimerIcon ic = ((clearTimerIcon)tmp_icon).Clone(); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 8) + { + playAnyNoteIcon ic = ((playAnyNoteIcon)tmp_icon).Clone(); + ic.setAux(a); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 9) + { + beginTaskIcon ic = ((beginTaskIcon)tmp_icon).Clone(); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 10) + { + stopTaskIcon ic = ((stopTaskIcon)tmp_icon).Clone(); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 11) + { + ArithOpIcon ic = ((ArithOpIcon)tmp_icon).Clone(); + ic.setAux(a); + ic.setAttributes(line, att_value_connector, att_separator, id_att_separator); // special !! + ic.setImage(); + return ic; + } + else if(pos == 12) + { + floatMotorIcon ic = ((floatMotorIcon)tmp_icon).Clone(); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 13) + { + playSpecificNote ic = ((playSpecificNote)tmp_icon).Clone(); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 14) + { + startEvent ic = ((startEvent)tmp_icon).Clone(); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 15) + { + returnIcon ic = ((returnIcon)tmp_icon).Clone(); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 16) + { + waitTouchIcon ic = ((waitTouchIcon)tmp_icon).Clone(); + ic.setAux(a); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 17) + { + waitLightIcon ic = ((waitLightIcon)tmp_icon).Clone(); + ic.setAux(a); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 18) + { + waitCelciusIcon ic = ((waitCelciusIcon)tmp_icon).Clone(); + ic.setAux(a); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 19) + { + waitRotationalIcon ic = ((waitRotationalIcon)tmp_icon).Clone(); + ic.setAux(a); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + else if(pos == 20) + { + waitTimerIcon ic = ((waitTimerIcon)tmp_icon).Clone(); + ic.setAux(a); + ic.setAttributes(line, att_value_connector, att_separator); + ic.setImage(); + return ic; + } + } + else if(sp[0].compareTo("function") == 0) + { + line = sp2[1]; + line = rep.substring(rep.indexOf(att_boundary_begin)+1, rep.lastIndexOf(att_boundary_end)); + + functionIcon ic = (new functionIcon()).Clone(); + ic.setAttributes(line, att_value_connector, att_separator, id_att_separator, att_boundary_end, a); + ic.setImage(); + return ic; + } + return tmp_icon; + } + + /** + * Given a line of a algorithm, this method determines what kind of icon it is, either object, branch, loop, function or variable + * @param line A line of algorithm + * @return 0 for undefined, 1 for object, 2 for branch, 3 for loop, 4 for function and 5 for variable + */ + public static int checkOBLTag(String line) + { + int ret_val = 0; + String[] tmp = new String[2]; + String[] tmp2 = new String[3]; + + tmp = line.split(id_att_separator); + tmp2 = tmp[0].split(id_separator); + if(tmp2[0].compareTo("object") == 0) + { + ret_val = 1; + } + else if(tmp2[0].compareTo("branch") == 0) + { + ret_val = 2; + } + else if(tmp2[0].compareTo("loop") == 0) + { + ret_val = 3; + } + else if(tmp2[0].compareTo("function") == 0) + { + ret_val = 4; + } + else if(tmp2[0].compareTo("variable") == 0) + { + ret_val = 5; + } + return ret_val; + } + + + /** + * Given a line of a algorithm, this method determines whether it is a function, a task, a variable, an event, or a monitorevent + * @param line A line of algorithm + * @return 0 for undefined, 1 for function, 2 for task, 3 for variable, 4 for event, 5 for monitorevent + */ + public static int checkTFTag(String line) + { + int ret_val = 0; + String[] tmp = new String[2]; + String[] tmp2 = new String[2]; // big difference!, check OBLTag has 3 not 2 + + tmp = line.split(id_att_separator); + tmp2 = tmp[0].split(id_separator); + if(tmp2[0].compareTo("function") == 0) + { + ret_val = 1; + } + else if(tmp2[0].compareTo("task") == 0) + { + ret_val = 2; + } + else if(tmp2[0].compareTo("variable") == 0) + { + ret_val = 3; + } + else if(tmp2[0].compareTo("event") == 0) + { + ret_val = 4; + } + else if(tmp2[0].compareTo("monitorevent") == 0) + { + ret_val = 5; + } + return ret_val; + } + + /** + * Gets the end tag of a branch, a loop, a function, a task or a monitorevent + * @param line A line of algorithm + * @return The end tag + */ + public static String getEndTag(String line) + { + String ret_val = new String(); + String[] tmp = new String[2]; + String[] tmp2 = new String[3]; + + tmp = line.split(id_att_separator); + tmp2 = tmp[0].split(id_separator); + if(tmp2[0].compareTo("branch") == 0) + { + ret_val = "endbranch"; + ret_val += id_separator; + ret_val += tmp2[2]; + ret_val += "."; + } + else if(tmp2[0].compareTo("loop") == 0) + { + ret_val = "endloop"; + ret_val += id_separator; + ret_val += tmp2[2]; + ret_val += "."; + } + else if(tmp2[0].compareTo("function") == 0) + { + ret_val = "endfunction"; + ret_val += id_separator; + ret_val += tmp2[1]; + ret_val += "."; + } + else if(tmp2[0].compareTo("task") == 0) + { + ret_val = "endtask"; + ret_val += id_separator; + ret_val += tmp2[1]; + ret_val += "."; + } + else if(tmp2[0].compareTo("monitorevent") == 0) + { + ret_val = "endmonitorevent"; + ret_val += id_separator; + ret_val += tmp2[1]; + ret_val += "."; + } + else + { + return null; + } + return ret_val; + } + + // methods to get the six begin tags --> task, function, loop, if, endif, else and endelse + + /** + * Get the task tag given a line of algorithm + * @param line A line of algorithm + * @return The task tag + */ + public static String getTaskTag(String line) + { + String ret_val = new String(); + String[] tmp = new String[2]; + String[] tmp2 = new String[3]; + + tmp = line.split(id_att_separator); + tmp2 = tmp[0].split(id_separator); + if(tmp2[0].compareTo("task") == 0) + { + ret_val = "starttask"; + ret_val += id_separator; + ret_val += tmp2[1]; + } + else + { + return null; + } + return ret_val; + } + + /** + * Given a task first line algorithm, this method returns a task's name + * @param line A line of algorithm + * @return The task name + */ + public static String getTaskName(String line) + { + String task_name = new String(); + line = line.substring(0, line.indexOf("\n")); + String[] sp = line.split(id_att_separator); + task_name = sp[1]; + task_name = task_name.substring(1, task_name.indexOf(att_boundary_end)); + sp = task_name.split(att_value_connector); + task_name = sp[1]; + return task_name; + } + + /** + * Get the event monitor tag given a line of algorithm + * @param line A line of algorithm + * @return The envent monitor tag + */ + public static String getEventMonitorTag(String line) + { + String ret_val = new String(); + String[] tmp = new String[2]; + String[] tmp2 = new String[3]; + + tmp = line.split(id_att_separator); + tmp2 = tmp[0].split(id_separator); + if(tmp2[0].compareTo("monitorevent") == 0) + { + ret_val = "startmonitorevent"; + ret_val += id_separator; + ret_val += tmp2[1]; + } + else + { + return null; + } + return ret_val; + } + + /** + * Given a event monitor first line algorithm, this method returns a event monitor's name + * @param line A line of algorithm + * @return The event monitor name + */ + public static String getEventMonitorName(String line) + { + String event_name = new String(); + line = line.substring(line.indexOf(att_boundary_begin)+1, line.indexOf("\n")); + String[] sp = line.split(att_value_connector); + event_name = sp[1]; + event_name = event_name.substring(0, event_name.indexOf(att_separator)); + return event_name; + } + + /** + * Given an event first line algorithm, this method returns the event's attributes + * @param line A line of algorithm + * @return The event attributes + */ + public static String[] getEventAtt(String line) + { + String[] function_att = new String[6]; + String argument = new String(); + line = line.substring(line.indexOf(att_boundary_begin)+1, line.lastIndexOf(att_boundary_end)); + + String[] sp = line.split(att_separator); + + // do the first one --> name + argument = line.substring(0, line.indexOf(att_separator)); + sp = argument.split(att_value_connector); + function_att[0] = sp[1]; + + line = line.substring(line.indexOf(att_separator)+1); + + // second one --> port + argument = line.substring(0, line.indexOf(att_separator)); + sp = argument.split(att_value_connector); + function_att[1] = sp[1]; + + line = line.substring(line.indexOf(att_separator)+1); + + // third one --> sensor type + argument = line.substring(0, line.indexOf(att_separator)); + sp = argument.split(att_value_connector); + function_att[2] = sp[1]; + + line = line.substring(line.indexOf(att_separator)+1); + + // fourth one --> sensor comparator + argument = line.substring(0, line.indexOf(att_separator)); + sp = argument.split(att_value_connector); + function_att[3] = sp[1]; + + line = line.substring(line.indexOf(att_separator)+1); + + // fifth one --> threshold + argument = line.substring(line.indexOf(att_value_connector)+1); + function_att[4] = argument.substring(0, 1); + + line = line.substring(line.indexOf(att_value_connector)+1); + if(line.compareTo(".") != 0) + { + line = line.substring(line.indexOf(id_att_separator)+2); + + // sixth one --> threshold's constant value + sp = line.split(att_value_connector); + argument = sp[1]; + argument = argument.substring(0, argument.indexOf(att_boundary_end)); + function_att[5] = argument; + } + + + return function_att; + } + + /** + * Given an event monitor first line algorithm, this method returns the event monitor's attributes + * @param line A line of algorithm + * @return The event monitor attributes + */ + public static java.util.Vector getEventMonitorAtt(String line) + { + java.util.Vector function_att = new java.util.Vector(); + String argument = new String(); + int total_events = 0; + line = line.substring(line.indexOf(att_boundary_begin)+1, line.lastIndexOf(att_boundary_end)); + + String[] sp = line.split(att_separator); + + // do the first one --> name + argument = line.substring(0, line.indexOf(att_separator)); + sp = argument.split(att_value_connector); + function_att.addElement(sp[1]); + + line = line.substring(line.indexOf(att_separator)+1); + + // second one --> type + argument = line.substring(0, line.indexOf(att_separator)); + sp = argument.split(att_value_connector); + function_att.addElement(sp[1]); + + line = line.substring(line.indexOf(att_separator)+1); + + // third one --> level + argument = line.substring(0, line.indexOf(att_separator)); + sp = argument.split(att_value_connector); + function_att.addElement(sp[1]); + + line = line.substring(line.indexOf(att_separator)+1); + + // fourth one --> auxiliary + argument = line.substring(0, line.indexOf(att_separator)); + sp = argument.split(att_value_connector); + function_att.addElement(sp[1]); + + line = line.substring(line.indexOf(att_separator)+1); + + // fifth one --> number of monitored events + argument = line.substring(0, line.indexOf(att_separator)); + sp = argument.split(att_value_connector); + total_events = Integer.parseInt(sp[1]); + + line = line.substring(line.indexOf(att_separator)+1); + + // sixth one --> the monitored events + for(int i=0; i= total_events - 1) + { + argument = line; + sp = argument.split(att_value_connector); + function_att.addElement(sp[1]); + break; + } + else + { + argument = line.substring(0, line.indexOf(att_separator)); + sp = argument.split(att_value_connector); + function_att.addElement(sp[1]); + line = line.substring(line.indexOf(att_separator)+1); + } + } + + return function_att; + } + + /** + * Given a function first line algorithm, this method returns the function's attributes + * @param line A line of algorithm + * @return The function attributes + */ + public static String[] getFunctionAtt(String line) + { + String[] function_att = new String[2]; + line = line.substring(line.indexOf(att_boundary_begin)+1, line.indexOf(att_boundary_end)); + + // do the first one --> name + String[] sp = line.split(att_separator); + String[] sp2 = sp[0].split(att_value_connector); + function_att[0] = sp2[1]; + + // second one --> level + sp2 = sp[1].split(att_value_connector); + function_att[1] = sp2[1]; + + return function_att; + } + + /** + * Get the function tag given a line of algorithm + * @param line A line of algorithm + * @return The function tag + */ + public static String getFunctionTag(String line) + { + String ret_val = new String(); + String[] tmp = new String[2]; + String[] tmp2 = new String[3]; + + tmp = line.split(id_att_separator); + tmp2 = tmp[0].split(id_separator); + if(tmp2[0].compareTo("function") == 0) + { + ret_val = "startfunction"; + ret_val += id_separator; + ret_val += tmp2[1]; + } + else + { + return null; + } + return ret_val; + } + + /** + * Get if tag for a branch + * @param line A line of algorithm + * @return If tag + */ + public static String getIfTag(String line) + { + String ret_val = new String(); + String[] tmp = new String[2]; + String[] tmp2 = new String[3]; + + tmp = line.split(id_att_separator); + tmp2 = tmp[0].split(id_separator); + if(tmp2[0].compareTo("branch") == 0) + { + ret_val = "if"; + ret_val += id_separator; + ret_val += tmp2[2]; + ret_val += "."; + } + else + { + return null; + } + return ret_val; + } + + // 2nd method for the branch tags + /** + * Get ending tag for the if tag of a branch + * @param line A line of algorithm + * @return End if tag + */ + public static String getEndIfTag(String line) + { + String ret_val = new String(); + String[] tmp = new String[2]; + String[] tmp2 = new String[3]; + + tmp = line.split(id_att_separator); + tmp2 = tmp[0].split(id_separator); + if(tmp2[0].compareTo("branch") == 0) + { + ret_val = "endif"; + ret_val += id_separator; + ret_val += tmp2[2]; + ret_val += "."; + } + else + { + return null; + } + return ret_val; + } + + // 3rd method --> else + /** + * Gets else tag of a branch + * @param line A line of algorithm + * @return Else tag + */ + public static String getElseTag(String line) + { + String ret_val = new String(); + String[] tmp = new String[2]; + String[] tmp2 = new String[3]; + + tmp = line.split(id_att_separator); + tmp2 = tmp[0].split(id_separator); + if(tmp2[0].compareTo("branch") == 0) + { + ret_val = "else"; + ret_val += id_separator; + ret_val += tmp2[2]; + ret_val += "."; + } + else + { + return null; + } + return ret_val; + } + + // 4th method --> endelse + /** + * Gets the ending tag of an else part of a branch icon + * @param line A line of algorithm + * @return End else tag + */ + public static String getEndElseTag(String line) + { + String ret_val = new String(); + String[] tmp = new String[2]; + String[] tmp2 = new String[3]; + + tmp = line.split(id_att_separator); + tmp2 = tmp[0].split(id_separator); + if(tmp2[0].compareTo("branch") == 0) + { + ret_val = "endelse"; + ret_val += id_separator; + ret_val += tmp2[2]; + ret_val += "."; + } + else + { + return null; + } + return ret_val; + } + + /** + * Gets begin tag of a loop + * @param line A line of algorithm + * @return Begin loop tag + */ + public static String getBeginLoopTag(String line) + { + String ret_val = new String(); + String[] tmp = new String[2]; + String[] tmp2 = new String[3]; + + tmp = line.split(id_att_separator); + tmp2 = tmp[0].split(id_separator); + if(tmp2[0].compareTo("loop") == 0) + { + ret_val = "beginloop"; + ret_val += id_separator; + ret_val += tmp2[2]; + ret_val += "."; + } + else + { + return null; + } + return ret_val; + } + + /** + * Works in similar ways to the OBL, but it extracts event, event monitor, variable, task and function structures instead + * @param code Algorithm + * @return Set of algorithm pieces + */ + public static java.util.Vector getTFTags(String code) + { + java.util.Vector ret_val = new java.util.Vector(); + String argument = new String(); + String line = new String(); + // add code an ending case + code += "\nendingcase"; + + while(code.compareTo("endingcase") != 0 || code.indexOf("endingcase") == -1) + { + line = code.substring(0, code.indexOf("\n")); + // check if it is a branch, loop or object + int check = checkTFTag(line); + + if(check == 0) + { + return null; // undefined tag + } + else if(check == 1) // function + { + if(Translator.getEndTag(line) == null) // error in reading the end tag + { + return null; + } + argument = code.substring(0, code.indexOf(Translator.getEndTag(line))); + code = code.substring(code.indexOf(Translator.getEndTag(line))); + argument += code.substring(0, code.indexOf("\n")); // cut the code + code = code.substring(code.indexOf("\n")+1); // cut the code + } + else if(check == 2) // task + { + if(Translator.getEndTag(line) == null) // error in reading the end tag + { + return null; + } + argument = code.substring(0, code.indexOf(Translator.getEndTag(line))); + code = code.substring(code.indexOf(Translator.getEndTag(line))); + argument += code.substring(0, code.indexOf("\n")); // cut the code + code = code.substring(code.indexOf("\n")+1); // cut the code + } + else if(check == 3) // global variable + { + argument = line; + code = code.substring(code.indexOf("\n")+1); // cut the code + } + else if(check == 4) // events + { + argument = line; + code = code.substring(code.indexOf("\n")+1); // cut the code + } + else if(check == 5) // event monitor + { + if(Translator.getEndTag(line) == null) // error in reading the end tag + { + return null; + } + argument = code.substring(0, code.indexOf(Translator.getEndTag(line))); + code = code.substring(code.indexOf(Translator.getEndTag(line))); + argument += code.substring(0, code.indexOf("\n")); // cut the code + code = code.substring(code.indexOf("\n")+1); // cut the code + } + ret_val.addElement(argument); + } + return ret_val; + } + + + /** + * Divide an algorithm into icon definitions of one level (ie. it will disregard icons within branches and loops, instead + * treats the branches and loops as separate entities), OBL is not Osama Bin Laden, but it is Objects, Branches and Loops + * @param code Algorithm + * @return Set of algorithm pieces + */ + public static java.util.Vector getOBLTags(String code) + { + java.util.Vector ret_val = new java.util.Vector(); + String argument = new String(); + String line = new String(); + // add code an ending case + code += "\nendingcase"; + + while(code.compareTo("endingcase") != 0 || code.indexOf("endingcase") == -1) + { + line = code.substring(0, code.indexOf("\n")); + // check if it is a branch, loop or object + + int check = checkOBLTag(line); + if(check == 0) + { + return null; // undefined tag + } + else if(check == 1) + { + argument = line; + code = code.substring(code.indexOf("\n")+1); // cut the code + } + else if(check == 2) + { + if(Translator.getEndTag(line) == null) // error in reading the end tag + { + return null; + } + argument = code.substring(0, code.indexOf(Translator.getEndTag(line))); + code = code.substring(code.indexOf(Translator.getEndTag(line))); + argument += code.substring(0, code.indexOf("\n")); // cut the code + code = code.substring(code.indexOf("\n")+1); // cut the code + } + else if(check == 3) + { + if(Translator.getEndTag(line) == null) // error in reading the end tag + { + return null; + } + argument = code.substring(0, code.indexOf(Translator.getEndTag(line))); + code = code.substring(code.indexOf(Translator.getEndTag(line))); + argument += code.substring(0, code.indexOf("\n")); // cut the code + code = code.substring(code.indexOf("\n")+1); // cut the code + } + else if(check == 4) + { + argument = line; + code = code.substring(code.indexOf("\n")+1); // cut the code + } + else if(check == 5) // local variable + { + argument = line; + code = code.substring(code.indexOf("\n")+1); // cut the code + } + ret_val.addElement(argument); + } + return ret_val; + } + + /** + * To get a variable to set its own attributes + * @param v Variable + * @param code The line of code passed + */ + public static void setVarAttributes(variable v, String code) + { + String[] sp = new String[2]; // the identifiers + String line = new String(); + + sp = code.split(id_att_separator); + line = sp[1]; + line = line.substring(line.indexOf(att_boundary_begin)+1, line.indexOf(att_boundary_end)); + v.setAttributes(line, att_value_connector, att_separator); + } + + /** + * Get algorithm representation of the current program + * @param parent_icon First icon + * @return Algorithm + */ + public static String getAlgorithm(Icon parent_icon) + { + // created_sub_id = new java.util.Vector(); + String ret_val = AppProperties.getProgramTypeID(); + ret_val += "\nstart"; + ret_val += getGlobalVariablesAlgorithm(); + ret_val += getAuxAlgorithm(); + ret_val += "\nendprogram"; + return ret_val; + } + + /** + * Current string algorithm representation of the iconic program + * @return Algorithm + * @param parent_icon First icon + */ + public static String getIndividualAlgorithm(Icon parent_icon) + { + String code = new String(); + java.util.Vector ics; + + // commence the translation ! + + code += parent_icon.getTranslation(id_separator, id_att_separator, att_boundary_begin, + att_boundary_end, att_value_connector, att_separator); + // as the header, it should be the parent icon's translation + // e.g. the GREEN STARTING ICON should only have "start" + + if(parent_icon instanceof startTaskIcon) + { + // add the arguments where possible + startTaskIcon sti = (startTaskIcon)parent_icon; + java.util.Vector tmp_list_var = sti.getTask().getVariables(); + for(int i=1; i tmp_list_var = sfi.getFunction().getVariables(); + for(int i=1; i vars = var_list.Instance().getVariables(); + for(int i = 1; i < vars.size(); i++) + { + variable tmp_v = vars.get(i); + if(tmp_v != null && tmp_v.getNumId() > 3) + { + code += tmp_v.getTranslation(id_separator, id_att_separator, att_boundary_begin, + att_boundary_end, att_value_connector, att_separator); + } + } + return code; + } + + /** + * Returns an algorithm representation of a function or a task or an event or an event monitor (auxiliaries) and its definition + * @return code The algorithm + */ + public static String getAuxAlgorithm() + { + String code = new String(); + + aux_list alist = aux_list.Instance(); + java.util.Vector auxs = alist.getAuxiliaries(); + + // first do the tasks + for(int i=1; i event_list = event_number_tracker.Instance().getEvents(); + for(int i=1; i ics; + for(int i=0; i 2) // excluding join icons + { + NQCCode += indentation_outer; + NQCCode += "else\n"; + NQCCode += indentation_outer+"{\n"; + + for(int i=0; i vars = var_list.Instance().getVariables(); + if(vars.size() > 4) + { + ret_val += "\n/"+"*\n"+" Global variable declarations\n*/\n\n"; + for(int i=1; i 3) + { + ret_val += tmp_v.getNQCDeclaration(); + } + } + } + return ret_val; + } + + /** + * Returns the NQC representations of the functions and tasks + * @param num_indent Number of indentations + * @return NQC Code functions + */ + private static String getRCXNQCFunctionsTasks(int num_indent) + { + String ret_val = new String(); + + // to separate from the main task with the auxiliary functions + ret_val += "\n"; + + aux_list alist = aux_list.Instance(); + java.util.Vector auxs = alist.getAuxiliaries(); + + // do the tasks first + for(int i=1; i Note and octave = frequency + */ + public static int[][] frequencies = {{ 33, 35, 37, 39, 41, 44, 46, 49, 52, 55, 58, 62}, + { 65, 69, 73, 78, 82, 87, 92, 98, 104, 110, 117, 123}, + { 131, 139, 147, 156, 165, 175, 185, 196, 208, 220, 233, 247}, + { 262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494}, + { 523, 554, 587, 622, 659, 698, 740, 784, 831, 880, 932, 988}, + {1047, 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, 1865, 1976}, + {2093, 2217, 2349, 2489, 2637, 2794, 2960, 3136, 3322, 3520, 3951, 4186}}; + + +// /** +// * For horizontal resizing +// */ +// public static int horizontalWindowSize; +// +// /** +// * For vertical resizing +// */ +// public static int verticalWindowSize; + + /** + * To set the horizontal distance of programming grid + * @param ndx New horizontal distance + */ + public static void setGridDistanceX(int ndx) + { + gridDistanceX = ndx; + } + + /** + * To set the vertical distance of programming grid + * @param ndy New vertical distance + */ + public static void setGridDistanceY(int ndy) + { + gridDistanceY = ndy; + } + + /** + * To get the status of the grid lines + * 0 = Hide grid lines + * 1 = Show grid lines + */ + public static int getGridStatus() + { + return gridStatus; + } + + /** + * To set the status of the grid lines + * 0 = Hide grid lines + * 1 = Show grid lines + */ + public static void setGridStatus(int status) + { + gridStatus = status; + } + + /** + * To set the maximum horizontal size of the programming window + * @param h New maximum horizontal size of the programming window + */ + public static void setMaxHorizontalProgWindow(int h) + { + maxHorizontalProgWindow = h; + } + + /** + * To set the maximum vertical size of the programming window + * @param v New maximum vertical size of the programming window + */ + public static void setMaxVerticalProgWindow(int v) + { + maxVerticalProgWindow = v; + } + +// /** +// * To set horizontal size of the fUNSoftWare's window +// * @param h New horizontal size of the fUNSoftWare's window +// */ +// public static void setHorizontalWindowSize(int h) +// { +// horizontalWindowSize = h; +// } +// +// /** +// * To set vertical size of the fUNSoftWare's window +// * @param v New vertical size of the fUNSoftWare's window +// */ +// public static void setVerticalWindowSize(int v) +// { +// verticalWindowSize = v; +// } + + /** + * To track the width of the scrollbars as rendered by the system + * @param w Width of a scrollbar as rendered by the system + */ + public static void setScrollbarWidth(int w) + { + scrollbarWidth = w; + } +} diff --git a/src/funsoftware/consts/aux_list.java b/src/funsoftware/consts/aux_list.java new file mode 100644 index 0000000..6fe266b --- /dev/null +++ b/src/funsoftware/consts/aux_list.java @@ -0,0 +1,203 @@ +/* + * function_list.java + * + * Created on 27 September 2005, 22:19 + * + */ + +package funsoftware.consts; +import funsoftware.struct.*; +import funsoftware.tasks.*; +import funsoftware.functs.*; +import funsoftware.events.*; + +/** + * Just like the icons and wires list, this list has the feature of id recycling and it maintains a list of functions and tasks. + * @author Thomas Legowo + */ +public class aux_list { + + // BUT IT RECYCLES THE ID + // i.e. the element's id corresponds to its location in the vector for quick access + private java.util.Vector list_of_auxs; + private java.util.Vector list_of_available_id; + + // for singleton design pattern + private static aux_list instance = null; + + /** Creates a new instance of aux_list */ + protected aux_list() { + list_of_auxs = new java.util.Vector(); + list_of_auxs.setSize(1); + list_of_available_id = new java.util.Vector(); + } + + /** + * To ensure only one instance of the auxiliary list is used, use singleton design pattern + * @return Instance of this list + */ + public static aux_list Instance() + { + if(instance == null) + { + instance = new aux_list(); + } + return instance; + } + + /** + * Adds a function or a task or an event + * @param func The function to be added + */ + public void addAuxiliary(auxiliary func) + { + int id = getFirstAvailableId(); + + func.setNumId(id); + + if(id < list_of_auxs.size()) + { + list_of_auxs.setElementAt(func, id); + } + else + { + list_of_auxs.add(id, func); + } + } + + /** + * Deletes a function or a task, no need to decrease the size of the vector by 1 since the id is reusable + * @param num_id Function or Task to be deleted + */ + public void delAuxiliary(int num_id) + { + list_of_auxs.setElementAt(null, num_id); + list_of_available_id.addElement(num_id); + } + + /** + * Returns the first available id to be recycled, an id will never equal to zero. + * If there is no id available to be reused, this function will return the size of the list + * @return Id + */ + public int getFirstAvailableId() + { + int id; + if(list_of_available_id.size() > 0) // if there are any recycled id + { + id = list_of_available_id.get(0); // get the first available one + list_of_available_id.removeElementAt(0); // remove it of the list + } + else + { + id = list_of_auxs.size(); + } + return id; + } + + /** + * Gets the list of auxiliaries + * @return Set of auxiliary structures + */ + public java.util.Vector getAuxiliaries() + { + return list_of_auxs; + } + + /** + * Resets this class' list of auxiliaries + */ + public void resetAuxList() + { + list_of_auxs = new java.util.Vector(); + list_of_auxs.setSize(1); + list_of_available_id = new java.util.Vector(); + } + + /** + * Returns 1 if the name is not unique, 0 otherwise, 2 if does not conform to rules of allowed characters + * @param name The name to be checked + * @return The number to indicate the result of this process + */ + public int checkName(String name) + { + int maxIndex = list_of_auxs.size(); + for(int i=1; i= 65 && c <= 90) || (c >= 97 && c <= 122) || c == 95)) + || (index > 0 && ((c >=48 && c <= 57) || (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || c == 95))) + { + index++; + continue; + } + else + { + return 2; + } + } + return 0; + } + + /** + * (Special for variable name checking when an auxiliary is created) + * Returns 1 if the name is not unique, 0 otherwise, 2 if does not conform to rules of allowed characters + * @param name The name to be checked + * @return The number to indicate the result of this process + */ + public int checkNameForVar(String name) + { + int maxIndex = list_of_auxs.size(); + for(int i=1; i list_of_events; + private java.util.Vector list_of_available_id; + + // for singleton design pattern + private static event_number_tracker instance = null; + + /** Creates a new instance of event_number_tracker */ + protected event_number_tracker() { + list_of_events = new java.util.Vector(); + list_of_events.setSize(1); + list_of_available_id = new java.util.Vector(); + } + + /** + * To ensure only one instance of this class is used, use singleton design pattern + * @return Instance of this list + */ + public static event_number_tracker Instance() + { + if(instance == null) + { + instance = new event_number_tracker(); + } + return instance; + } + + /** + * Adds an event + * @param ev The event to be added + * @return Whether this process is successful + */ + public int addEvent(Event ev) + { + int ret_val = 0; // could be added, have not exceeded 16 events yet + int id = getFirstAvailableId(); + + if(id == 0) // this list is full, no more events are allowed + { + return 1; // no addition allowed + } + + ev.setEventId(id); + + if(id < list_of_events.size()) + { + list_of_events.setElementAt(ev, id); + } + else + { + list_of_events.add(id, ev); + } + + return ret_val; + } + + /** + * Deletes a Event, no need to decrease the size of the vector by 1 since the id is reusable + * @param num_id Event to be deleted + */ + public void delEvent(int num_id) + { + list_of_events.setElementAt(null, num_id); + list_of_available_id.addElement(num_id); + } + + /** + * Returns the first available id to be recycled, an id will never equal to zero. + * If there is no id available to be reused, this function will return the size of the list + * @return Id + */ + public int getFirstAvailableId() + { + int id; + if(list_of_available_id.size() > 0) // if there are any recycled id + { + id = list_of_available_id.get(0); // get the first available one + list_of_available_id.removeElementAt(0); // remove it of the list + } + else + { + id = list_of_events.size(); + } + + if(id > 16) // the guard that ensures a maximum of 16 events used + { + return 0; + } + return id; + } + + /** + * Gets the list of events + * @return Set of events structures + */ + public java.util.Vector getEvents() + { + return list_of_events; + } + + /** + * Resets this class + */ + public void resetEvList() + { + list_of_events = new java.util.Vector(); + list_of_events.setSize(1); + list_of_available_id = new java.util.Vector(); + } + + /** + * Returns 1 if the name is not unique, 0 otherwise, 2 if does not conform to rules of allowed characters + * @param name The name to be check + * @return Indicates the outcome of this process + */ + public int checkName(String name) + { + int maxIndex = list_of_events.size(); + for(int i=1; i= 65 && c <= 90) || (c >= 97 && c <= 122))) + || (index > 0 && ((c >=48 && c <= 57) || (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || c == 95))) + { + index++; + continue; + } + else + { + return 2; + } + } + return 0; + } + + /** + * For the reverse translation process + * @param name The name of the event to be retrieved + * @return The event + */ + public Event getEvent(String name) + { + Event tmp = null; + for(int i=1; i list_of_icons; + private java.util.Vector list_of_available_id; + + // for singleton design pattern + private static icons_list instance = null; + + /** Creates a new instance of icons_list */ + protected icons_list() { + list_of_icons = new java.util.Vector(); + list_of_icons.setSize(1); + list_of_available_id = new java.util.Vector(); + } + + /** + * To ensure only one instance of the icon list is used, use singleton design pattern + * @return Instance of this icon list + */ + public static icons_list Instance() + { + if(instance == null) + { + instance = new icons_list(); + } + return instance; + } + + /** + * Adds an icon to the list + * @param icon New icon + */ + public void addIcon(Icon icon) + { + int id = getFirstAvailableId(); + String tmp_id = Integer.toString(id); + String tmp_id2 = "I"; + tmp_id = tmp_id2.concat(tmp_id); + icon.setId(tmp_id); + + if(id < list_of_icons.size()) + { + list_of_icons.setElementAt(icon, id); + } + else + { + list_of_icons.add(id, icon); + } + } + + /** + * Deletes an icon, no need to decrease the size of the vector by 1 since the id is reusable + * @param icon Icon to be deleted + */ + public void delIcon(Icon icon) + { + list_of_icons.setElementAt(null, icon.getId()); + list_of_available_id.addElement(icon.getId()); + } + + + /** + * Returns the first available id to be recycled, an id will never equal to zero. + * If there is no id available to be reused, this function will return the size of the list. + * @return First available id + */ + public int getFirstAvailableId() + { + int id; + if(list_of_available_id.size() > 0) // if there are any recycled id + { + id = list_of_available_id.get(0); // get the first available one + list_of_available_id.removeElementAt(0); // remove it of the list + } + else + { + id = list_of_icons.size(); + } + return id; + } + + /** + * Get the icons of the list + * @return Set of icons + */ + public java.util.Vector getIcons() + { + return list_of_icons; + } + + /** + * FOR DEBUGGING PURPOSES -- Get set of avaiable recycled ids + * @return Set of ids + */ + public java.util.Vector getRId() + { + return list_of_available_id; + } + + /** + * Resets its list of icons + */ + public void resetIconList() + { + list_of_icons = new java.util.Vector(); + list_of_icons.setSize(1); + list_of_available_id = new java.util.Vector(); + } +} diff --git a/src/funsoftware/consts/radiobuttons.java b/src/funsoftware/consts/radiobuttons.java new file mode 100644 index 0000000..2912fd4 --- /dev/null +++ b/src/funsoftware/consts/radiobuttons.java @@ -0,0 +1,55 @@ +/* + * radiobuttons.java + * + * Created on 3 January 2006, 13:03 + * + */ + +package funsoftware.consts; + +/** + * This class caters for a group of radio buttons that contains both functions and tasks + * @author Thomas Legowo + */ +public class radiobuttons { + + private javax.swing.ButtonGroup group; + + // for singleton design pattern + private static radiobuttons instance = null; + + /** Creates a new instance of radiobuttons */ + protected radiobuttons() { + group = new javax.swing.ButtonGroup(); + } + + /** + * To ensure only one instance of the radiobuttons group is used, use singleton design pattern + * @return Instance of this icon list + */ + public static radiobuttons Instance() + { + if(instance == null) + { + instance = new radiobuttons(); + } + return instance; + } + + /** + * To reset the button group + */ + public void reset() + { + group = new javax.swing.ButtonGroup(); + } + + /** + * To return the radio button group managed by an instance of this class + * @return The button group + */ + public javax.swing.ButtonGroup getButtonGroup() + { + return group; + } +} diff --git a/src/funsoftware/consts/typeEventsCoordinator.java b/src/funsoftware/consts/typeEventsCoordinator.java new file mode 100644 index 0000000..1c0f37c --- /dev/null +++ b/src/funsoftware/consts/typeEventsCoordinator.java @@ -0,0 +1,31 @@ +/* + * typeEventsCoordinator.java + * + * Created on 2 February 2006, 12:22 + * + */ + +package funsoftware.consts; + +/** + * Maintains all event types and modes + * @author Thomas Legowo + */ +public class typeEventsCoordinator { + + /** + * The sensors as the sources of an event + */ + public static String[] event_source = {"SENSOR_TOUCH", "SENSOR_LIGHT", "SENSOR_ROTATION", "SENSOR_CELCIUS", "TIMER"}; + + /** + * The types of checking done for an event if the source is the touch sensor + */ + public static String[] event_type1 = {"EVENT_TYPE_PRESSED", "EVENT_TYPE_RELEASED"}; + + /** + * The types of checking done for an event if the source is not the touch sensor + */ + public static String[] event_type2 = {"EVENT_TYPE_LOW", "EVENT_TYPE_HIGH"}; + +} diff --git a/src/funsoftware/consts/var_list.java b/src/funsoftware/consts/var_list.java new file mode 100644 index 0000000..6daf771 --- /dev/null +++ b/src/funsoftware/consts/var_list.java @@ -0,0 +1,253 @@ +/* + * var_list.java + * + * Created on 10 January 2006, 13:27 + * + */ + +package funsoftware.consts; + +import funsoftware.var.*; +import funsoftware.struct.*; + +/** + * This class represents a global list that keeps track of all available GLOBAL variables + * @author Thomas Legowo + */ +public class var_list { + + // BUT IT RECYCLES THE ID + // i.e. the element's id corresponds to its location in the vector for quick access + private java.util.Vector list_of_vars; + private java.util.Vector list_of_available_id; + + // for singleton design pattern + private static var_list instance = null; + + /** Creates a new instance of var_list */ + protected var_list() { + list_of_vars = new java.util.Vector(); + list_of_vars.setSize(1); + list_of_available_id = new java.util.Vector(); + } + + /** + * To ensure only one instance of the variable list is used, use singleton design pattern + * @return Instance of this list + */ + public static var_list Instance() + { + if(instance == null) + { + instance = new var_list(); + } + return instance; + } + + /** + * Adds a variable + * @param var The variable to be added + */ + public void addVariable(variable var) + { + int id = getFirstAvailableId(); + + var.setNumId(id); + + if(id < list_of_vars.size()) + { + list_of_vars.setElementAt(var, id); + } + else + { + list_of_vars.add(id, var); + } + } + + /** + * Deletes a variable, no need to decrease the size of the vector by 1 since the id is reusable + * @param num_id Variable to be deleted + */ + public void delVariable(int num_id) + { + list_of_vars.setElementAt(null, num_id); + list_of_available_id.addElement(num_id); + } + + /** + * Returns the first available id to be recycled, an id will never equal to zero. + * If there is no id available to be reused, this function will return the size of the list + * @return Id The first available Id + */ + public int getFirstAvailableId() + { + int id; + if(list_of_available_id.size() > 0) // if there are any recycled id + { + id = list_of_available_id.get(0); // get the first available one + list_of_available_id.removeElementAt(0); // remove it of the list + } + else + { + id = list_of_vars.size(); + } + return id; + } + + /** + * Gets the list of variables + * @return Set of variable structures + */ + public java.util.Vector getVariables() + { + return list_of_vars; + } + + /** + * Resets this class' list of variables + */ + public void resetVarList() + { + list_of_vars = new java.util.Vector(); + list_of_vars.setSize(1); + list_of_available_id = new java.util.Vector(); + } + + /** + * Returns 1 if the name is not unique, 0 otherwise, 2 if does not conform to rules of allowed characters + * @param name The name to be checked + * @param num_id The id of the variable that possesses the name + * @return The result of the process + */ + public int checkName(String name, int num_id) + { + int maxIndex; + + if(num_id != 0 && name.compareTo(list_of_vars.get(num_id).getName()) == 0) // for unchanged name + { + } + else + { + maxIndex = list_of_vars.size(); + for(int i=1; i= 65 && c <= 90) || (c >= 97 && c <= 122) || c == 95)) + || (index > 0 && ((c >=48 && c <= 57) || (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || c == 95))) + { + index++; + continue; + } + else + { + return 2; + } + } + } + + return 0; + } + + /** + * (Special for auxiliary name checking when a variable is created) + * Returns 1 if the name is not unique, 0 otherwise, 2 if does not conform to rules of allowed characters + * @return The result of the process + * @param name The name to be checked + */ + public int checkNameForAux(String name) + { + int maxIndex; + maxIndex = list_of_vars.size(); + for(int i=1; i 4) + { + for(int i=4; i 1) + { + for(int i=1; i list_of_wires; + private java.util.Vector list_of_available_id; + + // for singleton design pattern + private static wires instance = null; + + /** Creates a new instance of wires */ + protected wires() { + list_of_wires = new java.util.Vector(); + list_of_wires.setSize(1); + list_of_available_id = new java.util.Vector(); + } + + /** + * Ensures only one instance of the wire list is used, use singleton design pattern + * @return Instance of this class + */ + public static wires Instance() + { + if(instance == null) + { + instance = new wires(); + } + return instance; + } + + /** + * Adds a new piece of wire into the wire list + * @param wire Wire + */ + public void addWire(Wire wire) + { + int id = getFirstAvailableId(); + String tmp_id = Integer.toString(id); + String tmp_id2 = "W"; + tmp_id = tmp_id2.concat(tmp_id); + wire.setId(tmp_id); + if(id < list_of_wires.size()) + { + list_of_wires.setElementAt(wire, id); + } + else + { + list_of_wires.add(id, wire); + } + } + + /** + * Deletes a piece of wire, no need to decrease the size of the vector by 1 since the id is reusable + * @param wire Wire to be deleted + */ + public void delWire(Wire wire) + { + list_of_wires.setElementAt(null, wire.getId()); + list_of_available_id.addElement(wire.getId()); + } + + + /** + * Returns the first available id to be recycled, an id will never equal to zero. + * If there is no id available to be reused, this function will return the size of the list. + * @return Id + */ + public int getFirstAvailableId() + { + int id; + if(list_of_available_id.size() > 0) // if there are any recycled id + { + id = list_of_available_id.get(0); // get the first available one + list_of_available_id.removeElementAt(0); // remove it of the list + } + else + { + id = list_of_wires.size(); + } + return id; + } + + /** + * Get the wires of the list + * @return Set of wires + */ + public java.util.Vector getWires() + { + return list_of_wires; + } + + /** + * Resets this class' list of wires + */ + public void resetWireList() + { + list_of_wires = new java.util.Vector(); + list_of_wires.setSize(1); + list_of_available_id = new java.util.Vector(); + } +} diff --git a/src/funsoftware/events/Event.java b/src/funsoftware/events/Event.java new file mode 100644 index 0000000..96e837f --- /dev/null +++ b/src/funsoftware/events/Event.java @@ -0,0 +1,281 @@ +/* + * Event.java + * + * Created on 20 January 2006, 18:17 + * + */ + +package funsoftware.events; + +import funsoftware.ic.*; +import funsoftware.consts.*; +import funsoftware.ic.var.*; +import funsoftware.st.*; +import funsoftware.ic.ev.*; +import funsoftware.struct.*; +import funsoftware.var.*; + +/** + * This class manages an event monitoring. It contains a sequence of icons that are to be executed while monitoring an event. + * @author Thomas Legowo + */ +public class Event{ + + private String name; // name of this event as given by the user + // the event window + private eventWindow ev_win; + + // for the NQC + private String source; // the input this event will monitor on (1, 2 and 3 are possible values for ports, and 0,1,2 and 3 are for timers) + private String type_of_sensor; + private String type_of_comparator; + private int event_number; // from the event_number_tracker + private Operand threshold; // can be a constant or a variable + + + /** Creates a new instance of Event */ + public Event() + { + super(); + name = "event"; // default name + } + + /** + * Alters the event Id for NQC translation + * @param i New event id + */ + public void setEventId(int i) + { + event_number = i; + } + + /** + * Returns the event Id for NQC translation, NumId is for event_monitor + * @return event id + */ + public int getEventId() + { + return event_number; + } + + /** + * Sets the major elements of this event + * @param source The port or timer number + * @param type_of_sensor Sensor used + * @param type_of_comparator Comparison process type + * @param threshold The threshold value in the comparison process + */ + public void setEventElements(String source, String type_of_sensor, String type_of_comparator, Operand threshold) + { + this.source = source; + this.type_of_sensor = type_of_sensor; + this.type_of_comparator = type_of_comparator; // null if it is an EVENT_TYPE_PRESSED OR EVENT_TYPE_RELEASED + this.threshold = threshold; + } + + /** + * Returns this event's source + * @return event source + */ + public String getSource() + { + return source; + } + + /** + * Returns this event's threshold + * @return event threshold + */ + public Operand getThreshold() + { + return threshold; + } + + /** + * Returns this event's source type (type of sensor used) + * @return event source type + */ + public String getEventSource() + { + return type_of_sensor; + } + + /** + * Returns this event's type of comparison (pressed, touched, low or high) + * @return event type of comparison + */ + public String getEventType() + { + return type_of_comparator; + } + + /** + * Sets the name of this event + * @param n New event name + */ + public void setName(String n) + { + name = n; + } + /** + * Returns this event icon's name + * @return event name + */ + public String getName() + { + return name; + } + + /** + * Get the help title of this event + * @return Help title + */ + public String getHelpTitle() + { + String s = "Event"; + return s; + } + + /** + * Get help message of this event + * @return Help message + */ + public String getHelpMsg() + { + String s = "DETAILS:"; + s+="\n\nName: "; + s+=name; + s+="\nSource: "; + s+=source; + s+="\nEvent-Source: "; + s+=type_of_sensor; + s+="\nEvent-Type: "; + s+=type_of_comparator; + if(type_of_sensor.compareTo("SENSOR_TOUCH") != 0) + { + s+="\nThreshold: "; + if(threshold instanceof constant) + { + constant c = (constant)threshold; + s+=c.getValue(); + } + else if(threshold instanceof variable) + { + variable v = (variable)threshold; + s+=v.getName(); + } + } + return s; + } + + + /** + * Algorithm translation for the Translator object to create a text representation of this icon + * @param id_separator To separate ids + * @param id_att_separator To separate id with attribute + * @param att_boundary_begin To start attributes + * @param att_boundary_end To end attributes + * @param att_value_connector To separate attributes and its values + * @param att_separator To separate attributes + * @return Translation + */ + public String getTranslation(String id_separator, String id_att_separator, + String att_boundary_begin, String att_boundary_end, String att_value_connector, String att_separator) + { + String algo = new String(); + algo += "\n"; // to begin with + algo += "event"; + algo += id_separator; + algo += event_number; + algo += id_att_separator; + algo += att_boundary_begin; + algo += "name"+att_value_connector; + algo += name; + algo += att_separator; + algo += "source"+att_value_connector; + algo += source; + algo += att_separator; + algo += "sensortype"+att_value_connector; + if(type_of_sensor == null) + { + algo += "."; // means it is empty + } + else + { + algo += type_of_sensor; + } + algo += att_separator; + algo += "sensorcomparator"+att_value_connector; + if(type_of_comparator == null) + { + algo += "."; // means it is empty + } + else + { + algo += type_of_comparator; + } + algo += att_separator; + algo += "threshold"+att_value_connector; + if(threshold == null) + { + algo += "."; // means it is empty + } + else + { + if(threshold instanceof constant) + { + constant c = (constant)threshold; + algo += c.getAOTranslation(id_separator, id_att_separator, att_boundary_begin, + att_boundary_end, att_value_connector, att_separator); + } + else if(threshold instanceof variable) + { + variable v = (variable)threshold; + algo += v.getAOTranslation(id_separator, id_att_separator, att_boundary_begin, + att_boundary_end, att_value_connector, att_separator); + } + } + algo += att_boundary_end; + + return algo; + } + + /** + * Returns the event header of this event + * @return The NQC Code events + * @param indentation How many indentations + */ + public String getNQCCode(String indentation) + { + // due to the id from the event tracker list to start from zero, for the purpose of translation it will be substracted 1 + String header = new String(); + header += indentation+"// an event set up\n"; + header += indentation+"SetEvent("+(event_number-1)+", "+source+", "+type_of_comparator+");\n"; + if(type_of_sensor.compareTo("SENSOR_TOUCH") != 0) + { + String display_threshold = new String(); + if(threshold instanceof variable) + { + variable tmp_v = (variable)threshold; + display_threshold = tmp_v.getName(); + } + else if(threshold instanceof constant) + { + constant tmp_c = (constant)threshold; + display_threshold = Integer.toString(tmp_c.getValue()); + } + header += indentation+"SetLowerLimit("+(event_number-1)+", "+display_threshold+");\n"; + header += indentation+"SetUpperLimit("+(event_number-1)+", "+display_threshold+");\n"; + } + return header; + } + + /** + * To clone this event infrastructure + * @return New instance of this event + */ + public Event Clone() + { + return new Event(); + } +} diff --git a/src/funsoftware/events/eventWindow.java b/src/funsoftware/events/eventWindow.java new file mode 100644 index 0000000..bbb0f94 --- /dev/null +++ b/src/funsoftware/events/eventWindow.java @@ -0,0 +1,252 @@ +/* + * eventWindow.java + * + * Created on 1 February 2006, 13:08 + * + */ + +package funsoftware.events; + +import funsoftware.ic.*; +import funsoftware.ic.ev.*; +import funsoftware.inter.*; +import funsoftware.consts.*; +import funsoftware.struct.*; +import funsoftware.st.*; +import funsoftware.var.*; +import funsoftware.functs.*; +import funsoftware.tasks.*; + +/** + * Just like VarWindow, this class displays labels of defined events. Events are useless if there are no + * monitorEvent defined to watch them. + * @author Thomas Legowo + */ +public class eventWindow extends javax.swing.JPanel{ + + // the private variables + private java.util.Vector Events; // the members, each being an event + + private java.awt.Dimension area; // the area of the panel + + private javax.swing.JFrame jFrame; + java.awt.GridBagConstraints gridBagConstraints; + + private auxiliary current_aux; + + /** + * Creates a new instance of eventWindow + * @param frame The frame that this panel points to + */ + public eventWindow(javax.swing.JFrame frame) + { + super(); + super.setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS)); + jFrame = frame; + Events = new java.util.Vector(); + setBackground(new java.awt.Color(247, 247, 247)); + } + + /** + * To paint this event window + * @param g Graphics + */ + protected void paintComponent(java.awt.Graphics g) + { + // update the radio buttons texts + int lim = getComponentCount(); + for(int i=0; i New + */ + public void reset() + { + removeAll(); + Events = new java.util.Vector(); + + refreshContainer(); + } + + /** + * Insert a new event label onto this event window + * @param evt The event to be inserted + */ + public void insertEvent(Event evt) + { + javax.swing.JLabel elb = new javax.swing.JLabel(evt.getName()); + elb.setBackground(new java.awt.Color(247, 247, 247)); + + Events.addElement(evt); + this.add(elb); + + // to set up the component pop up menu + javax.swing.JPopupMenu jpm = new javax.swing.JPopupMenu(); + javax.swing.JMenuItem jm = new javax.swing.JMenuItem(); + jm = new javax.swing.JMenuItem("Delete Event"); + final int num_id = evt.getEventId(); + final Event evt_tmp = evt; + + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + deleteEventPerformed(evt_tmp, num_id); + } + }); + jpm.add(jm); + jm = new javax.swing.JMenuItem("Edit Event"); + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + renameEventPerformed(num_id); + } + }); + jpm.add(jm); + jm = new javax.swing.JMenuItem("Event Properties"); + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent e) { + javax.swing.JOptionPane.showMessageDialog(null, + evt_tmp.getHelpMsg(), + evt_tmp.getHelpTitle(), + javax.swing.JOptionPane.INFORMATION_MESSAGE); + } + }); + jpm.add(jm); + + elb.setComponentPopupMenu(jpm); + + refreshContainer(); + } + + // to edit the event + private void renameEventPerformed(int num_id) + { + EventNameDialog evt_dialog = new EventNameDialog(jFrame, (Event)event_number_tracker.Instance().getEvents().get(num_id), 1); + evt_dialog.pack(); + evt_dialog.setLocationRelativeTo(jFrame); + evt_dialog.setVisible(true); + + String tmpName = event_number_tracker.Instance().getEvents().get(num_id).getName(); + String eventName = evt_dialog.getEventName(); + + Event tmp = (Event)event_number_tracker.Instance().getEvents().get(num_id); + if(eventName.compareTo("") != 0 && eventName.compareTo(tmpName) != 0) // not the current value and not an empty string + { + // change the names for this event and all of its associated event begin and stop icons + + tmp.setName(eventName); + + java.util.Vector ics = (icons_list.Instance()).getIcons(); + for(int i=1; i ics = aux_list.Instance().getAuxiliaries(); + for(int i=1; i ics; + + // a vector that is there to preserve the positions of the icons + private java.util.Vector backup_coord; + private ProgWindow prog_panel; + private javax.swing.JScrollPane scroller; + private javax.swing.JPanel panel; + + // the event monitor window + private monitorEventWindow ev_win; + + // for the NQC + private String type; // Local or global + private auxiliary aux_point; // if local, this is not null + + // a list of events to be monitored by an instance of this class + private java.util.Vector tobe_monitored; + + // the level of the event monitor + private int level; // the level starts from 1 + + /** Creates a new instance of monitorEvent */ + public monitorEvent() + { + super(); + num_id = 0; // not assigned originally, this id will be assigned by the auxiliary list + name = "em"; + ics = new java.util.Vector(); + backup_coord = new java.util.Vector(); + start_icon = (new startEventIcon()).Clone(); + end_icon = (new endEventIcon()).Clone(); + tobe_monitored = new java.util.Vector(); + type = "Global"; + level = 1; // by default + aux_point = null; + } + + /** + * Sets up the beginning, ending and the member icons to be together. Programming window and its connected panels are also set up here + * @param njDirectionsLabel The real time direction label + * @param njPanel17 The event monitor window + * @return The panel on top of the programming window to be + */ + public javax.swing.JPanel setUpAllIcons(TitlePanelLabel njDirectionsLabel, monitorEventWindow njPanel17) + { + int ndx = Constants.gridDistanceX; + int ndy = Constants.gridDistanceY; + // configure the parent panel + javax.swing.JPanel jp = new javax.swing.JPanel(); + panel = jp; + panel.setLayout(new java.awt.GridBagLayout()); + // configure the scrollpane + javax.swing.JScrollPane jsp = new javax.swing.JScrollPane(); + + scroller = jsp; + + jsp.setBorder(null); + + panel.add(jsp); + panel.setPreferredSize(new java.awt.Dimension(Constants.maxHorizontalProgWindow, Constants.maxVerticalProgWindow)); + panel.setMinimumSize(new java.awt.Dimension(Constants.maxHorizontalProgWindow, Constants.maxVerticalProgWindow)); + panel.setOpaque(false); + panel.setBackground(new java.awt.Color(255,255,255)); + + // configure the programming panel within the JScrollPane + ProgWindow jP2 = new ProgWindow(njDirectionsLabel); + jsp.setBackground(new java.awt.Color(255,255,255)); + jP2.setLayout(null); + jP2.setArea(new java.awt.Dimension(ndx*4, ndy*2)); + prog_panel = jP2; + + int p_width = (int)jP2.getPreferredSize().getWidth(); + int p_height = (int)jP2.getPreferredSize().getHeight(); + + jsp.setPreferredSize(new java.awt.Dimension(p_width, p_height)); + jsp.setMinimumSize(new java.awt.Dimension(p_width, p_height)); + jP2.setBackground(new java.awt.Color(255,255,255)); + javax.swing.JViewport viewport = new javax.swing.JViewport(); + viewport.setView(jP2); + jsp.setViewport(viewport); + + + icons_list icon_list = icons_list.Instance(); + wires wire_list = wires.Instance(); + + // add the start icon + + icon_list.addIcon(start_icon); + + int xpos = gridcalculation.calculateXleft(ndx); + int ypos = gridcalculation.calculateY(ndy); + + coord tmp_co = new coord(xpos, ypos); + + coord co = gridcalculation.computeCoord(start_icon, tmp_co); + start_icon.setCoordinate(co); + start_icon.setBounds(co.getX(), co.getY(), start_icon.getPreferredSize().width,start_icon.getPreferredSize().height); + start_icon.setProgWindow(jP2); + start_icon.setScroller(jsp); + start_icon.setEventMonitor(this); + jP2.add(start_icon); + jP2.addIcon(start_icon); + jP2.setStartIcon(start_icon); + + // add the end icon + icon_list.addIcon(end_icon); + + // finish up the end icon construction + xpos = ndx*2; + ypos = ndy; + + // update the y coordinate of start_ic now that all members have been read + + tmp_co = new coord(xpos, ypos); + co = new coord(); + co = gridcalculation.computeCoord(start_icon, tmp_co); + end_icon.setCoordinate(co); + end_icon.setBounds(co.getX(), co.getY(), end_icon.getPreferredSize().width, end_icon.getPreferredSize().height); + end_icon.setEventMonitor(this); + jP2.addIcon(end_icon); + jP2.setEndIcon(end_icon); + + jP2.add(end_icon); + + // add this ending icon as the starting icon's first member + start_icon.setParentIcon(null); + end_icon.setParentIcon(start_icon); // will be the beginning icon --> instanceof startIcon + end_icon.getParentIcon().addMember(end_icon, start_icon); + + // connect the two initial starting and ending icons + start_icon.setRightNeighbour(end_icon); + end_icon.setLeftNeighbour(start_icon); + + Wire tmp_wire = new Wire(); + tmp_wire.setLeftIcon(start_icon); + tmp_wire.setRightIcon(end_icon); + start_icon.setRightWire(tmp_wire); + end_icon.setLeftWire(tmp_wire); + + wire_list.addWire(tmp_wire); + jP2.addWire(tmp_wire); + + jP2.resizeProgWindow(jsp); + + // assign the event monitor body window + ev_win = njPanel17; + + // complete the members + for(int i=0; i 0) + { + left = ics.get(i-1); + if(left instanceof loopIcon) + { + left = left.getEndIcon(); + } + else if(left instanceof branchIcon) + { + left = left.getEndBranch(); + } + } + else + { + left = start_icon; + } + Icon right = end_icon; + + if(tmp_icon instanceof branchIcon) + { + jP2.insertRecursiveBranchLoopIcon(tmp_icon, right, left, jsp); + } + else if(tmp_icon instanceof loopIcon) + { + jP2.insertRecursiveBranchLoopIcon(tmp_icon, right, left, jsp); + } + else + { + // then set the coordinate + xpos = gridcalculation.midPoint(left.getCoordinate(), right.getCoordinate()); + ypos = left.getCoordinate().getY()+(left.getHeight()/2); + tmp_co = new coord(xpos, ypos); + co = gridcalculation.computeCoord(tmp_icon, tmp_co); + tmp_icon.setCoordinate(co); + tmp_icon.setBounds(co.getX(), co.getY(), tmp_icon.getWidth(), tmp_icon.getHeight()); + jP2.insertObjectIcon(tmp_icon, right, left, jsp); + } + } + return jp; + } + + // for reinsertion, need to place the panel, jscrollpane and progwindow + + /** + * Get the programming window displaying this Event monitor body + * @return The programming window + */ + public monitorEventWindow getEventMonitorWindow() + { + return ev_win; + } + + /** + * Returns the panel this task's member are on, not the individual task's icon itself + * @return The programming window + */ + public ProgWindow getProgWindow() + { + return prog_panel; + } + /** + * Returns the scroll pane of the programming window + * @return Programming window's scroller + */ + public javax.swing.JScrollPane getScroller() + { + return scroller; + } + /** + * Returns the panel on top of the programming window + * @return Programming window's parent panel + */ + public javax.swing.JPanel getPanel() + { + return panel; + } + + + /** + * Alters the id of the event this icon is representing + * @param i New task id + */ + public void setNumId(int i) + { + num_id = i; + } + + /** + * Returns the id of the event this icon is representing + * @return task id + */ + public int getNumId() + { + return num_id; + } + + + /** + * Sets the major elements of this event + * @param type The type (global or local) + * @param aux The auxiliary related to this event + */ + public void setEventElements(String type, auxiliary aux) + { + this.type = type; + this.aux_point = aux; + } + + /** + * Alters the level of this event monitor. Only a function with equal or lower level can be called from this event monitor + * (To avoid recursion in function calls through an event monitor call) + * @param l The level of the event monitor + */ + public void setLevel(int l) + { + level = l; + } + + /** + * Returns the level of the event monitor representing + * @return event monitor level + */ + public int getLevel() + { + return level; + } + + /** + * Returns this event's type + * @return event type + */ + public String getType() + { + return type; + } + + /** + * Returns this event's auxiliary points + * @return event auxiliary point + */ + public auxiliary getAuxPoint() + { + return aux_point; + } + + /** + * Returns this monitor's events + * @param n The new list of monitored events + */ + public void setMonitoredEvents(java.util.Vector n) + { + tobe_monitored = n; + } + + /** + * Returns this monitor's events + * @return event this monitor's events + */ + public java.util.Vector getMonitoredEvents() + { + return tobe_monitored; + } + + /** + * Sets the name of this event monitor + * @param n New event monitor name + */ + public void setName(String n) + { + name = n; + } + /** + * Returns this event monitor's name + * @return event monitor name + */ + public String getName() + { + return name; + } + + /** + * Returns the list of icons this event contains + * @return Set of icons + */ + public java.util.Vector getMembers() + { + ics = start_icon.getMembers(); + return ics; + } + /** + * Sets the members of this event monitor icon + * @param nics Set of icons + */ + public void setMembers(java.util.Vector nics) + { + ics = nics; + for(int i=0; i GlobalEvents; // the members, each being an event + private java.util.Vector LocalEvents; // the members, each being an event + + private java.awt.Dimension area; // the area of the panel + + // the four temporary variables needed for the construction of a ProgWindow + private TitlePanelLabel jDirectionsLabel; + + private javax.swing.JFrame jFrame; + private javax.swing.JPanel GlobalPane; + private javax.swing.JPanel LocalPane; + private javax.swing.JSeparator line; + + // the tabbed window manager + private TabbedWindowManager twm; + + private auxiliary current_aux; + + /** + * Creates a new instance of eventWindow + * @param jf The frame + * @param jPanel13 Panel on top of programming window + * @param njDirectionsLabel Real time direction palette + * @param varw The variable window + */ + public monitorEventWindow(javax.swing.JFrame jf, javax.swing.JPanel jPanel13, + TitlePanelLabel njDirectionsLabel, VarWindow varw) + { + super(); + super.setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.PAGE_AXIS)); + jFrame = jf; + GlobalEvents = new java.util.Vector(); + LocalEvents = new java.util.Vector(); + twm = TabbedWindowManager.Instance(jPanel13, varw, this); + jDirectionsLabel = njDirectionsLabel; + + GlobalPane = new javax.swing.JPanel(); + GlobalPane.setLayout(new javax.swing.BoxLayout(GlobalPane, javax.swing.BoxLayout.PAGE_AXIS)); + LocalPane = new javax.swing.JPanel(); + LocalPane.setLayout(new javax.swing.BoxLayout(LocalPane, javax.swing.BoxLayout.PAGE_AXIS)); + + GlobalPane.setOpaque(false); + LocalPane.setOpaque(false); + + line = new javax.swing.JSeparator(); + line.setForeground(new java.awt.Color(0, 0, 0)); + line.setAlignmentX(0.5f); + line.setAlignmentY(0.5f); + line.setPreferredSize(new java.awt.Dimension(0, 1)); + line.setMaximumSize(new java.awt.Dimension(Integer.MAX_VALUE, 1)); + + add(GlobalPane); + + add(javax.swing.Box.createVerticalStrut(2)); + add(line); + add(javax.swing.Box.createVerticalStrut(2)); + + add(LocalPane); + + setBackground(new java.awt.Color(247, 247, 247)); + } + + /** + * To paint this event monitor window + * @param g Graphics + */ + protected void paintComponent(java.awt.Graphics g) + { + // update the radio buttons texts + int lim = GlobalPane.getComponentCount(); + for(int i=0; i New + */ + public void reset() + { + GlobalPane.removeAll(); + LocalPane.removeAll(); + GlobalEvents = new java.util.Vector(); + LocalEvents = new java.util.Vector(); + + refreshContainer(); + } + + /** + * Insert a new event monitor radio button onto this event monitor window + * @param evt The event monitor radio button to be inserted + */ + public void insertEvent(monitorEvent evt) + { + javax.swing.JRadioButton tskrb = new javax.swing.JRadioButton(evt.getName()); + tskrb.setBackground(new java.awt.Color(247, 247, 247)); + tskrb.setActionCommand(Integer.toString(evt.getNumId())); + tskrb.addActionListener(this); + radiobuttons.Instance().getButtonGroup().add(tskrb); + + String type = evt.getType(); + if(type.compareTo("Local") == 0) + { + LocalEvents.addElement(evt); + LocalPane.add(tskrb); + if(evt.getAuxPoint().getNumId() != current_aux.getNumId()) + { + tskrb.setVisible(false); + } + } + else if(type.compareTo("Global") == 0) + { + GlobalEvents.addElement(evt); + GlobalPane.add(tskrb); + } + + // to set up the component pop up menu + javax.swing.JPopupMenu jpm = new javax.swing.JPopupMenu(); + javax.swing.JMenuItem jm = new javax.swing.JMenuItem(); + jm = new javax.swing.JMenuItem("Delete Event"); + final int num_id = evt.getNumId(); + final monitorEvent evt_tmp = evt; + + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + deleteEventPerformed(evt_tmp, num_id); + } + }); + jpm.add(jm); + jm = new javax.swing.JMenuItem("Edit Event"); + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + renameEventPerformed(num_id); + } + }); + jpm.add(jm); + jm = new javax.swing.JMenuItem("Event Properties"); + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent e) { + javax.swing.JOptionPane.showMessageDialog(null, + evt_tmp.getHelpMsg(), + evt_tmp.getHelpTitle(), + javax.swing.JOptionPane.INFORMATION_MESSAGE); + } + }); + jpm.add(jm); + + tskrb.setComponentPopupMenu(jpm); + + javax.swing.JPanel jp = evt.setUpAllIcons(jDirectionsLabel, this); + twm.addPanel(jp, evt.getNumId()); + + refreshContainer(); + } + + // to edit some attributes of this event monitor + private void renameEventPerformed(int num_id) + { + monitorEventDialog me_dialog = new monitorEventDialog(jFrame, (monitorEvent)aux_list.Instance().getAuxiliaries().get(num_id), 1); + me_dialog.pack(); + me_dialog.setLocationRelativeTo(jFrame); + me_dialog.setVisible(true); + + String tmpName = aux_list.Instance().getAuxiliaries().get(num_id).getName(); + String eventName = me_dialog.getEventMonitorName(); + + monitorEvent tmp = (monitorEvent)aux_list.Instance().getAuxiliaries().get(num_id); + if(eventName.compareTo("") != 0 && eventName.compareTo(tmpName) != 0) // not the current value and not an empty string + { + // change the names for this event monitor and all of its associated event begin and stop icons + + tmp.setName(eventName); + + java.util.Vector ics = (icons_list.Instance()).getIcons(); + for(int i=1; i ics = icon_list.getIcons(); + for(int i=1; i enum_ab = radiobuttons.Instance().getButtonGroup().getElements(); + while(enum_ab.hasMoreElements()) + { + javax.swing.JRadioButton jrb = (javax.swing.JRadioButton)enum_ab.nextElement(); + if(jrb.getActionCommand().compareTo("1") == 0) + { + jrb.setSelected(true); + // break; + } + } + } + deleteEvent(to_be_deleted, num_id); + UndoRedo.update_state(); + } + } + + // to determine whether the to-be-deleted event monitor window is currently-selected + private Boolean isEventSelected(int id_del) + { + String rad_butt_command = new String(); + java.util.Enumeration enum_ab = radiobuttons.Instance().getButtonGroup().getElements(); + javax.swing.JRadioButton jrb; + int sel_id = 1; + while(enum_ab.hasMoreElements()) + { + jrb = (javax.swing.JRadioButton)enum_ab.nextElement(); + if(jrb.isSelected() == true) + { + rad_butt_command = jrb.getActionCommand(); + sel_id = Integer.parseInt(rad_butt_command); + break; + } + } + + return (sel_id == id_del); + } + + /** + * Delete a selected event monitor radio button + * @param to_delete The event monitor to be deleted + * @param num_id Event id + */ + public void deleteEvent(monitorEvent to_delete, int num_id) + { + aux_list func_list = aux_list.Instance(); + monitorEvent tmp = (monitorEvent)aux_list.Instance().getAuxiliaries().get(num_id); + func_list.delAuxiliary(num_id); + + int del_pos = 0; + String type = to_delete.getType(); + + if(type.compareTo("Local") == 0) + { + for(int i=0; i widest) +// { +// widest = (int)jrb.getPreferredSize().getWidth(); +// } +// } +// +// lim = LocalPane.getComponentCount(); +// for(int i=0; i widest) +// { +// widest = (int)jrb.getPreferredSize().getWidth(); +// } +// } +// +// if(widest < 120) +// { +// widest = 120; +// } +// +// height_local += 5; +// height_global += 5; +// +// LocalPane.setPreferredSize(new java.awt.Dimension(widest, height_local)); +// LocalPane.setMinimumSize(new java.awt.Dimension(widest, height_local)); +// GlobalPane.setPreferredSize(new java.awt.Dimension(widest, height_global)); +// GlobalPane.setMinimumSize(new java.awt.Dimension(widest, height_global)); +// line.setPreferredSize(new java.awt.Dimension(widest, 1)); +// } +} diff --git a/src/funsoftware/functs/ComboBoxRenderer.java b/src/funsoftware/functs/ComboBoxRenderer.java new file mode 100644 index 0000000..8b59043 --- /dev/null +++ b/src/funsoftware/functs/ComboBoxRenderer.java @@ -0,0 +1,60 @@ +/* + * ComboBoxRenderer.java + * + * Created on 4 January 2006, 18:06 + * + */ + +package funsoftware.functs; + +/** + * For the function combo box's renderer + * @author Thomas Legowo + */ +public class ComboBoxRenderer extends javax.swing.JLabel implements javax.swing.ListCellRenderer{ + + /** Creates a new instance of ComboBoxRenderer */ + public ComboBoxRenderer(){ + setOpaque(true); + setHorizontalAlignment(CENTER); + setVerticalAlignment(CENTER); + } + + /** + * This method finds the text corresponding + * to the selected value and returns the label, set up + * to display the text and image. + * @param list list + * @param value value + * @param index index + * @param isSelected whether it is selected + * @param cellHasFocus focus + * @return The selected component + */ + public java.awt.Component getListCellRendererComponent(javax.swing.JList list, + Object value, + int index, + boolean isSelected, + boolean cellHasFocus) + { + if (isSelected) + { + setBackground(list.getSelectionBackground()); + setForeground(list.getSelectionForeground()); + } else + { + setBackground(list.getBackground()); + setForeground(list.getForeground()); + } + if(value != null && value instanceof javax.swing.JMenuItem) + { + javax.swing.JMenuItem label = (javax.swing.JMenuItem) value; + setText(label.getText()); + } + else + { + setText(""); + } + return this; + } +} diff --git a/src/funsoftware/functs/FunctionCombo.java b/src/funsoftware/functs/FunctionCombo.java new file mode 100644 index 0000000..0cbf1c3 --- /dev/null +++ b/src/funsoftware/functs/FunctionCombo.java @@ -0,0 +1,56 @@ +/* + * FunctionCombo.java + * + * Created on 3 October 2005, 23:30 + * + */ + +package funsoftware.functs; + +/** + * This class handles the jComboBox that displays available functions that can be reused + * @author Thomas Legowo + */ +public class FunctionCombo extends javax.swing.JComboBox{ + + // for singleton design pattern + private static FunctionCombo instance = null; + + /** Creates a new instance of FunctionCombo */ + protected FunctionCombo() { + setPreferredSize(new java.awt.Dimension(200, 20)); + ComboBoxRenderer renderer= new ComboBoxRenderer(); + renderer.setPreferredSize(new java.awt.Dimension(200, 20)); + this.setRenderer(renderer); + setMaximumRowCount(5); + addItem(" "); + } + + /** + * To ensure only one instance of this combo box is used and to provide global access to this class, use singleton design pattern + * @return Instance of this function combo box + */ + public static FunctionCombo Instance() + { + if(instance == null) + { + instance = new FunctionCombo(); + } + return instance; + } + + /** + * To reset this function combo + */ + public void reset() + { + int total = getItemCount(); + if(total > 1) + { + for(int i=1; i Functions; // the members, each being a function icon + private java.awt.Dimension area; // the area of the panel + + // the four temporary variables needed for the construction of a ProgWindow + private TitlePanelLabel jDirectionsLabel; + + private javax.swing.JFrame jFrame; + + // the tabbed window manager + private TabbedWindowManager twm; + + /** + * Creates a new instance of FunctionWindow + * @param jf The frame + * @param jPanel13 Panel on top of programming window + * @param njDirectionsLabel Real time direction palette + * @param varw Variable window + * @param evw Event window + */ + public FunctionWindow(javax.swing.JFrame jf, javax.swing.JPanel jPanel13, + TitlePanelLabel njDirectionsLabel, VarWindow varw, monitorEventWindow evw) + { + super(); + super.setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS)); + jFrame = jf; + Functions = new java.util.Vector(); + twm = TabbedWindowManager.Instance(jPanel13, varw, evw); + jDirectionsLabel = njDirectionsLabel; + setBackground(new java.awt.Color(247, 247, 247)); + } + + /** + * To paint this function window + * @param g Graphics + */ + protected void paintComponent(java.awt.Graphics g) + { + // update the radio buttons texts + int lim = getComponentCount(); + for(int i=0; i New + */ + public void reset() + { + removeAll(); + Functions = new java.util.Vector(); + + refreshContainer(); + } + + /** + * Insert a new function button onto this function window + * @param func A function icon + */ + public void insertFunction(function func) + { + javax.swing.JRadioButton funcby = new javax.swing.JRadioButton(func.getName()); + funcby.setBackground(new java.awt.Color(247, 247, 247)); + funcby.setActionCommand(Integer.toString(func.getNumId())); + funcby.addActionListener(this); + Functions.addElement(func); + radiobuttons.Instance().getButtonGroup().add(funcby); + add(funcby); + + // to set up the component pop up menu + javax.swing.JPopupMenu jpm = new javax.swing.JPopupMenu(); + javax.swing.JMenuItem jm = new javax.swing.JMenuItem(); + jm = new javax.swing.JMenuItem("Delete Function"); + final int num_id = func.getNumId(); + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + deleteFunctionPerformed(num_id); + } + }); + jpm.add(jm); + + jm = new javax.swing.JMenuItem("Rename Function"); + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + renameFunctionPerformed(num_id); + } + }); + jpm.add(jm); + + jm = new javax.swing.JMenuItem("View Level"); + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + viewLevelPerformed(num_id); + } + }); + jpm.add(jm); + + funcby.setComponentPopupMenu(jpm); + + javax.swing.JPanel jp = func.setUpAllIcons(jDirectionsLabel, this); + twm.addPanel(jp, func.getNumId()); + + refreshContainer(); + } + + // the action handler for the radio button's pop up menu for renaming functions + private void renameFunctionPerformed(int num_id) + { + FunctionNameDialog func_dialog = new FunctionNameDialog(jFrame, aux_list.Instance().getAuxiliaries().get(num_id).getName(), 1); + func_dialog.pack(); + func_dialog.setLocationRelativeTo(jFrame); + func_dialog.setVisible(true); + + String tmpName = aux_list.Instance().getAuxiliaries().get(num_id).getName(); + String[] functionName = func_dialog.getUserInput(); + if(functionName != null && functionName[0].compareTo("") != 0 && functionName[0].compareTo(tmpName) != 0) + { + // change the names for this function and all of its associated function begin and stop icons + function tmp = (function)aux_list.Instance().getAuxiliaries().get(num_id); + tmp.setName(functionName[0]); + + java.util.Vector ics = (icons_list.Instance()).getIcons(); + for(int i=1; i ics = icon_list.getIcons(); + for(int i=1; i enum_ab = radiobuttons.Instance().getButtonGroup().getElements(); + while(enum_ab.hasMoreElements() == true) + { + javax.swing.JRadioButton jrb = (javax.swing.JRadioButton)enum_ab.nextElement(); + if(jrb.getActionCommand().compareTo("1") == 0) + { + jrb.setSelected(true); + break; + } + } + } + + deleteFunction(num_id); + + UndoRedo.update_state(); + } + } + + // the action handler for the radio button's pop up menu + private void viewLevelPerformed(int num_id) + { + function tmp = (function)aux_list.Instance().getAuxiliaries().get(num_id); + int level = tmp.getLevel(); + javax.swing.JOptionPane.showMessageDialog(null, + "Level: " + level, + "Function Level", + javax.swing.JOptionPane.INFORMATION_MESSAGE); + } + + // to determine whether the to-be-deleted function is the currently-selected function + private Boolean isFunctionSelected(int id_del) + { + String rad_butt_command = new String(); + java.util.Enumeration enum_ab = radiobuttons.Instance().getButtonGroup().getElements(); + javax.swing.JRadioButton jrb; + int sel_id = 1; + while(enum_ab.hasMoreElements()) + { + jrb = (javax.swing.JRadioButton)enum_ab.nextElement(); + if(jrb.isSelected() == true) + { + rad_butt_command = jrb.getActionCommand(); + sel_id = Integer.parseInt(rad_butt_command); + break; + } + } + + return (sel_id == id_del); + } + + + /** + * Delete a function button and all function icons representing that function on this function window based on the given num_id + * @param num_id Function id + */ + public void deleteFunction(int num_id) + { + int del_pos = 0; + for(int i=0; i ics; + + // a vector that is there to preserve the positions of the icons + private java.util.Vector backup_coord; + private ProgWindow prog_panel; + private javax.swing.JScrollPane scroller; + private javax.swing.JPanel panel; + + // the function window + private FunctionWindow funcwin; + + // each function cannot have a return value, but it can have argument(s) + private java.util.Vector arguments; + + // the level of the function + private int level; // the level starts from 1 + + /** Creates a new instance of function */ + public function() + { + super(); + num_id = 0; // not assigned originally, this id will be assigned by the function_list (called from ProgWindow class) + name = "func"; + ics = new java.util.Vector(); + backup_coord = new java.util.Vector(); + start_icon = (new startFunctionIcon()).Clone(); + end_icon = (new endFunctionIcon()).Clone(); + arguments = new java.util.Vector(); + list_var = new local_var_list(); + level = 1; // by default + } + + /** + * Sets up the beginning, ending and the member icons to be together. Programming window and its connected panels are also set up here + * @param njDirectionsLabel The real time direction label + * @param njPanel17 The function window + * @return The panel on top of the programming window to be + */ + public javax.swing.JPanel setUpAllIcons(TitlePanelLabel njDirectionsLabel, FunctionWindow njPanel17) + { + int ndx = Constants.gridDistanceX; + int ndy = Constants.gridDistanceY; + // configure the parent panel + javax.swing.JPanel jp = new javax.swing.JPanel(); + panel = jp; + panel.setBackground(new java.awt.Color(255,255,255)); + jp.setLayout(new java.awt.GridBagLayout()); + + // configure the scrollpane + javax.swing.JScrollPane jsp = new javax.swing.JScrollPane(); + scroller = jsp; + jsp.setBackground(new java.awt.Color(255,255,255)); + jsp.setBorder(null); + jp.add(jsp); + jp.setPreferredSize(new java.awt.Dimension(Constants.maxHorizontalProgWindow, Constants.maxVerticalProgWindow)); + jp.setMinimumSize(new java.awt.Dimension(Constants.maxHorizontalProgWindow, Constants.maxVerticalProgWindow)); + jp.setOpaque(false); + + // configure the programming panel within the JScrollPane + ProgWindow jP2 = new ProgWindow(njDirectionsLabel); + jP2.setLayout(null); + jP2.setArea(new java.awt.Dimension(ndx*4, ndy*2)); + prog_panel = jP2; + + int p_width = (int)jP2.getPreferredSize().getWidth(); + int p_height = (int)jP2.getPreferredSize().getHeight(); + + jsp.setPreferredSize(new java.awt.Dimension(p_width, p_height)); + jsp.setMinimumSize(new java.awt.Dimension(p_width, p_height)); + jP2.setBackground(new java.awt.Color(255,255,255)); + javax.swing.JViewport viewport = new javax.swing.JViewport(); + viewport.setView(jP2); + jsp.setViewport(viewport); + + icons_list icon_list = icons_list.Instance(); + wires wire_list = wires.Instance(); + + // add the start icon + + icon_list.addIcon(start_icon); + + int xpos = gridcalculation.calculateXleft(ndx); + int ypos = gridcalculation.calculateY(ndy); + + coord tmp_co = new coord(xpos, ypos); + + coord co = gridcalculation.computeCoord(start_icon, tmp_co); + start_icon.setCoordinate(co); + start_icon.setBounds(co.getX(), co.getY(), start_icon.getPreferredSize().width,start_icon.getPreferredSize().height); + start_icon.setProgWindow(jP2); + start_icon.setScroller(jsp); + start_icon.setFunction(this); + jP2.add(start_icon); + jP2.addIcon(start_icon); + jP2.setStartIcon(start_icon); + + // add the end icon + icon_list.addIcon(end_icon); + + // finish up the end icon construction + xpos = ndx * 2; + ypos = ndy; + + // update the y coordinate of start_ic now that all members have been read + + tmp_co = new coord(xpos, ypos); + co = new coord(); + co = gridcalculation.computeCoord(start_icon, tmp_co); + end_icon.setCoordinate(co); + end_icon.setBounds(co.getX(), co.getY(), end_icon.getPreferredSize().width, end_icon.getPreferredSize().height); + end_icon.setFunction(this); + jP2.addIcon(end_icon); + jP2.setEndIcon(end_icon); + + jP2.add(end_icon); + + // add this ending icon as the starting icon's first member + start_icon.setParentIcon(null); + end_icon.setParentIcon(start_icon); // will be the beginning icon --> instanceof startIcon + end_icon.getParentIcon().addMember(end_icon, start_icon); + + // connect the two initial starting and ending icons + start_icon.setRightNeighbour(end_icon); + end_icon.setLeftNeighbour(start_icon); + + Wire tmp_wire = new Wire(); + tmp_wire.setLeftIcon(start_icon); + tmp_wire.setRightIcon(end_icon); + start_icon.setRightWire(tmp_wire); + end_icon.setLeftWire(tmp_wire); + + wire_list.addWire(tmp_wire); + jP2.addWire(tmp_wire); + + jP2.resizeProgWindow(jsp); + + // assign the function window + funcwin = njPanel17; + + // complete the members + for(int i=0; i 0) + { + left = ics.get(i-1); + if(left instanceof loopIcon) + { + left = left.getEndIcon(); + } + else if(left instanceof branchIcon) + { + left = left.getEndBranch(); + } + } + else + { + left = start_icon; + } + Icon right = end_icon; + + if(tmp_icon instanceof branchIcon) + { + jP2.insertRecursiveBranchLoopIcon(tmp_icon, right, left, jsp); + } + else if(tmp_icon instanceof loopIcon) + { + jP2.insertRecursiveBranchLoopIcon(tmp_icon, right, left, jsp); + } + else + { + // then set the coordinate + xpos = gridcalculation.midPoint(left.getCoordinate(), right.getCoordinate()); + ypos = left.getCoordinate().getY()+(left.getHeight()/2); + tmp_co = new coord(xpos, ypos); + co = gridcalculation.computeCoord(tmp_icon, tmp_co); + tmp_icon.setCoordinate(co); + tmp_icon.setBounds(co.getX(), co.getY(), tmp_icon.getWidth(), tmp_icon.getHeight()); + jP2.insertObjectIcon(tmp_icon, right, left, jsp); + } + } + return jp; + } + + // for the function icon + /** + * Returns the function window + * @return The function window + */ + public FunctionWindow getFunctionWindow() + { + return funcwin; + } + + // for reinsertion, need to place the panel, jscrollpane and progwindow + + /** + * Returns the panel this function's member are on, not the individual function's icon itself + * @return The programming window + */ + public ProgWindow getProgWindow() + { + return prog_panel; + } + /** + * Returns the scroll pane of the programming window + * @return Programming window's scroller + */ + public javax.swing.JScrollPane getScroller() + { + return scroller; + } + /** + * Returns the panel on top of the programming window + * @return Programming window's parent panel + */ + public javax.swing.JPanel getPanel() + { + return panel; + } + + /** + * Alters the level of this function. A function with equal or lower level cannot be called from this function + * @param l The level of the function + */ + public void setLevel(int l) + { + level = l; + } + + /** + * Returns the level of the function representing + * @return function level + */ + public int getLevel() + { + return level; + } + + + /** + * Alters the id of this function + * @param i New function id + */ + public void setNumId(int i) + { + num_id = i; + } + + /** + * Returns the id of this function + * @return function id + */ + public int getNumId() + { + return num_id; + } + + /** + * Sets the name of this function + * @param n New function name + */ + public void setName(String n) + { + name = n; + } + /** + * Returns this function icon's name + * @return function name + */ + public String getName() + { + return name; + } + + /** + * Returns the list of icons this function contains + * @return Set of icons + */ + public java.util.Vector getMembers() + { + ics = start_icon.getMembers(); + return ics; + } + /** + * Sets the members of this function + * @param nics Set of icons + */ + public void setMembers(java.util.Vector nics) + { + ics = nics; + for(int i=0; i tmp_list_var = list_var.getVariables(); + for(int i=1; i getVariables() + { + return list_var.getVariables(); + } + + /** + * To set the list of the local variables list manager that this function owns + * @param lvl The local variable list manager + */ + public void setLocalVarList(local_var_list lvl) + { + list_var = lvl; + } + + /** + * To return the list of the local variables list manager that this function owns + * @return Local variable list + */ + public local_var_list getLocalVarList() + { + return list_var; + } + + /** + * To add an argument onto the list + * @param nv Argument + */ + public void addArgument(variable nv) + { + arguments.addElement(nv); + } + + /** + * To delete an argument from this function's argument list + * @param nv Argument to be deleted + */ + public void delArgument(variable nv) + { + int del_pos = 0; + for(int i=0; i getArguments() + { + return arguments; + } + + /** + * To return an individual local variable that this auxiliary structure has + * @param name The name of the variable + * @return The variable to be returned + */ + public variable getVariable(String name) + { + variable tmp_var = list_var.getVariable(name); + return tmp_var; + } +} diff --git a/src/funsoftware/gri/GridDialog.java b/src/funsoftware/gri/GridDialog.java new file mode 100644 index 0000000..01e6542 --- /dev/null +++ b/src/funsoftware/gri/GridDialog.java @@ -0,0 +1,267 @@ +/* + * GridDialog.java + * + * Created on 20 September 2005, 21:24 + * + */ + +package funsoftware.gri; + +/** + * This dialog class caters for the dialog window that prompts the user for the size of grid segment's width and height + * @author Thomas Legowo + */ +public class GridDialog extends javax.swing.JDialog implements java.awt.event.ActionListener, + java.beans.PropertyChangeListener{ + // private variables + private javax.swing.JTextField gridWidth; + private javax.swing.JTextField gridHeight; + + private javax.swing.JPanel jp_top; + private javax.swing.JPanel jp_bottom; + private javax.swing.JLabel jl; + java.awt.GridBagConstraints gridBagConstraints; + + private String msg_top; + private String msg_bottom; + private String guide_top; + private String guide_bottom; + + private String button1; + private String button2; + private String button3; + + private javax.swing.JOptionPane optionPane; + + // the current distanceX and distanceY + private int distanceX; + private int distanceY; + + // return values + private int[] ret_vals; + + /** + * Creates a new instance of GridDialog + * @param frame The fUNSoftWare window + * @param input1 Current horizontal distance + * @param input2 Current vertical distance + */ + public GridDialog(java.awt.Frame frame, int input1, int input2) { + super(frame, true); + setTitle("Set Grid Sizes"); + + // default values + distanceX = 50; + distanceY = 55; + + ret_vals = new int[2]; // width and height respectively + ret_vals[0] = input1; + ret_vals[1] = input2; + + gridWidth = new javax.swing.JTextField(Integer.toString(input1), 8); + gridHeight = new javax.swing.JTextField(Integer.toString(input2), 8); + + msg_top = "Grid Width"; + msg_bottom = "Grid Height"; + guide_top = "Min 44"; + guide_bottom = "Min 50"; + + button1 = "Enter"; + button2 = "Cancel"; + button3 = "Defaults"; + + jp_top = new javax.swing.JPanel(); + jp_top.setLayout(new java.awt.GridBagLayout()); + jl = new javax.swing.JLabel(msg_top); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_top.add(jl, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 8, 5, 5); + jp_top.add(gridWidth, gridBagConstraints); + + jl = new javax.swing.JLabel(guide_top); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_top.add(jl, gridBagConstraints); + + jp_bottom = new javax.swing.JPanel(); + jp_bottom.setLayout(new java.awt.GridBagLayout()); + jl = new javax.swing.JLabel(msg_bottom); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_bottom.add(jl, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_bottom.add(gridHeight, gridBagConstraints); + + jl = new javax.swing.JLabel(guide_bottom); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_bottom.add(jl, gridBagConstraints); + + Object[] array = {jp_top, jp_bottom}; + Object[] options = {button1, button2, button3}; + + optionPane = new javax.swing.JOptionPane(array, + javax.swing.JOptionPane.QUESTION_MESSAGE, + javax.swing.JOptionPane.OK_OPTION, + null, + options, + options[0]); + + setContentPane(optionPane); + + setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); + addWindowListener(new java.awt.event.WindowAdapter() { + public void windowClosing(java.awt.event.WindowEvent we) { + /* + * Instead of directly closing the window, + * we're going to change the JOptionPane's + * value property. + */ + optionPane.setValue(new Integer( + javax.swing.JOptionPane.CLOSED_OPTION)); + } + }); + + //Ensure the text field always gets the first focus. + addComponentListener(new java.awt.event.ComponentAdapter() { + public void componentShown(java.awt.event.ComponentEvent ce) { + gridWidth.requestFocusInWindow(); + } + }); + + // Register an event handler that puts the text into the option pane. + gridWidth.addActionListener(this); + gridHeight.addActionListener(this); + + // Register an event handler that reacts to option pane state changes. + optionPane.addPropertyChangeListener(this); + } + + + /** + * This method handles events for the text field. + * @param e ActionEvent + */ + public void actionPerformed(java.awt.event.ActionEvent e) { + optionPane.setValue(button1); + } + + /** + * This method reacts to state changes in the option pane. + * @param e PropertyChangeEvent + */ + public void propertyChange(java.beans.PropertyChangeEvent e) { + String prop = e.getPropertyName(); + + if (isVisible() + && (e.getSource() == optionPane) + && (javax.swing.JOptionPane.VALUE_PROPERTY.equals(prop) || + javax.swing.JOptionPane.INPUT_VALUE_PROPERTY.equals(prop))) + { + Object value = optionPane.getValue(); + + if (value == javax.swing.JOptionPane.UNINITIALIZED_VALUE) + { + //ignore reset + return; + } + //Reset the JOptionPane's value. + //If not done, then if the user + //presses the same button next time, no + //property change event will be fired. + optionPane.setValue(javax.swing.JOptionPane.UNINITIALIZED_VALUE); + + if (button1.equals(value)) + { + if(gridWidth.getText().compareTo("") == 0 || gridHeight.getText().compareTo("") == 0) + { + javax.swing.JOptionPane.showMessageDialog( + GridDialog.this, + "Please enter values for both fields,\nclick cancel to close the window", + "Field empty", + javax.swing.JOptionPane.ERROR_MESSAGE); + } + else + { + int tmp1 = ret_vals[0]; + int tmp2 = ret_vals[1]; + ret_vals[0] = Integer.parseInt(gridWidth.getText()); + ret_vals[1] = Integer.parseInt(gridHeight.getText()); + // do the checking + + if (ret_vals[0] >= 44 && ret_vals[1] >= 50) + { + // we're done; clear and dismiss the dialog + clearAndHide(); + } + else if(ret_vals[0] < 44) + { + // input for grid width was invalid + gridWidth.selectAll(); + javax.swing.JOptionPane.showMessageDialog( + GridDialog.this, + "Sorry, minimum value for grid width is 44", + "Try again", + javax.swing.JOptionPane.ERROR_MESSAGE); + ret_vals[0] = tmp1; + gridWidth.requestFocusInWindow(); + } + else if(ret_vals[1] < 50) + { + // input for grid height was invalid + gridHeight.selectAll(); + javax.swing.JOptionPane.showMessageDialog( + GridDialog.this, + "Sorry, minimum value for grid height is 50", + "Try again", + javax.swing.JOptionPane.ERROR_MESSAGE); + ret_vals[1] = tmp2; + gridHeight.requestFocusInWindow(); + } + } + } + else if(button3.equals(value)) + { + gridWidth.setText(Integer.toString(distanceX)); + gridHeight.setText(Integer.toString(distanceY)); + } + else + { + clearAndHide(); + } + } + } + + /** + * Return the user input of grid sizes + * @return User input + */ + public int[] getUserInput() { + return ret_vals; + } + + + /** This method clears the dialog and hides it. */ + public void clearAndHide() { + gridWidth.setText(null); + gridHeight.setText(null); + setVisible(false); + } +} diff --git a/src/funsoftware/gri/coord.java b/src/funsoftware/gri/coord.java new file mode 100644 index 0000000..4436b80 --- /dev/null +++ b/src/funsoftware/gri/coord.java @@ -0,0 +1,70 @@ +/* + * coord.java + * + * Created on 18 July 2005, 20:32 + */ + +package funsoftware.gri; + +/** + * This class defines a coordinate (X and Y), to be used by icons and wires + * @author Thomas Legowo + * + * + */ +public class coord { + + private int x; + private int y; + + /** Creates a new instance of coord */ + public coord() { + } + + /** + * Creates a new instance of coord + * @param nx X coordinate + * @param ny Y coordinate + */ + public coord(int nx, int ny) + { + x = nx; + y = ny; + } + + /** + * Get X coordinate + * @return X coordinate + */ + public int getX() + { + return x; + } + + /** + * Get Y coordinate + * @return Y coordinate + */ + public int getY() + { + return y; + } + + /** + * Set the x coordinate + * @param nx New x coordinate + */ + public void setX(int nx) + { + x = nx; + } + + /** + * Set the y coordinate + * @param ny New y coordinate + */ + public void setY(int ny) + { + y = ny; + } +} diff --git a/src/funsoftware/gri/gridcalculation.java b/src/funsoftware/gri/gridcalculation.java new file mode 100644 index 0000000..7e798f0 --- /dev/null +++ b/src/funsoftware/gri/gridcalculation.java @@ -0,0 +1,119 @@ +/* + * gridcalculation.java + * + * Created on 14 July 2005, 13:21 + */ + +package funsoftware.gri; + +import funsoftware.ic.*; +import funsoftware.consts.*; + +/** + * This class is used only to calculate the required grid position after the user had click on any pixel of the programming window + * in the fUNSoftWare program. + * The calculations will return either the X position or Y position of a grid intersection. + * @author Thomas Legowo + */ +public class gridcalculation { + + /** Creates a new instance of gridcalculation */ + /** Also need to know the distances between grid intersections */ + public gridcalculation() { + } + + // the four calculations methods (2 for X coordinates (left and right) and 2 for Y coordinates (top and bottom)) + // they require the X and the Y positions of the mouse click + // the half_icon argument is the half size of the icon, + // for example a motor icon would have 16 as its half size + /** + * Calculates the closest left X coordinate to the clicked coordinate + * @param clickedX X coordinate of user click + * @return X coordinate + */ + public static int calculateXleft(int clickedX) + { + int dx = Constants.gridDistanceX; + int x = (clickedX/dx) * dx; + return x; + } + + /** + * Calculates the closest right X coordinate to the clicked coordinate + * @param clickedX X coordinate of user click + * @return X coordinate + */ + public static int calculateXright(int clickedX) + { + int dx = Constants.gridDistanceX; + int x = (clickedX/dx) * dx + dx; + return x; + } + + // Unlike the X coordinate, the Y coordinate will always be the closest one to the mouse click coordinate + /** + * Calculates the closest Y coordinate to the clicked coordinate + * @param clickedY Y coordinate of user click + * @return Y coordinate + */ + public static int calculateY(int clickedY) + { + int dy = Constants.gridDistanceY; + int y; + // always check for two possibilities, either the Y coordinate top of the desired one, or + // Y coordinate bottom of the desired one + int ytop; + int ybottom; + ytop = (clickedY/dy) * dy; + ybottom = (clickedY/dy) * dy + dy; + + int tempY1; // difference between clickedY and ytop + int tempY2; // difference between clickedY and ybottom + + tempY1 = Math.abs(clickedY-ytop); + tempY2 = Math.abs(clickedY-ybottom); + + if(tempY1 > tempY2) + { + y = ybottom; + } + else + { + y = ytop; + } + return y; + } + + /** + * Calculates the mid point in terms of a grid intersection in between two existing icon coordinates + * @param left Left coordinate + * @param right Right coordinate + * @return X coordinate of the mid point + */ + public static int midPoint(coord left, coord right) + { + int ret_val; + int x_left = left.getX(); + int x_right = right.getX(); + ret_val = calculateXright(x_left+(x_right - x_left)/2); + return ret_val; + } + + /** + * Given a grid intersection and an icon, compute the required coordinate of that icon that resides on the intersection + * @param icon Icon + * @param grid_inter Grid intersection coordinate + * @return Coordinate + */ + public static coord computeCoord(Icon icon, coord grid_inter) + { + int x = grid_inter.getX(); + int y = grid_inter.getY(); + + x = x - (icon.getWidth()/2); + y = y - (icon.getHeight()/2); + + coord co = new coord(x,y); + return co; + } +} diff --git a/src/funsoftware/ic/ArithComparatorDialog.java b/src/funsoftware/ic/ArithComparatorDialog.java new file mode 100644 index 0000000..fbe225b --- /dev/null +++ b/src/funsoftware/ic/ArithComparatorDialog.java @@ -0,0 +1,421 @@ +/* + * ArithComparatorDialog.java + * + * Created on 7 February 2006, 17:27 + * + */ + +package funsoftware.ic; + +import funsoftware.struct.*; +import funsoftware.events.*; +import funsoftware.var.*; +import funsoftware.consts.*; + +/** + * This class ask for an arithmetic expression input from the user + * @author Thomas Legowo + */ +public class ArithComparatorDialog extends javax.swing.JDialog{ + + // private variables + private java.awt.GridBagConstraints gridBagConstraints; + + private javax.swing.JComboBox operand_left; + private javax.swing.JComboBox operator; + private javax.swing.JComboBox operand_right; + private javax.swing.JComboBox left_variables; + private javax.swing.JComboBox right_variables; + private javax.swing.JTextField right_constant; + private javax.swing.JTextField left_constant; + + private javax.swing.JButton button1; + private javax.swing.JButton button2; + + private javax.swing.JPanel jp; + private javax.swing.JPanel jp_top; + private javax.swing.JPanel jp_bottom; + + private auxiliary current_aux; + + private java.awt.Frame frame; + private NestedOperation NO; + + /** + * Creates a new instance of ArithComparatorDialog + * @param frame The frame + * @param aux The auxiliary this operation is on + * @param newNO The nested operation for the arithmetic expression + */ + public ArithComparatorDialog(java.awt.Frame frame, auxiliary aux, NestedOperation newNO) { + super(frame, true); + this.frame = frame; + + NO = new NestedOperation(); + setTitle("Branch Arithmetic Expression"); + + if(aux instanceof monitorEvent) + { + monitorEvent e = (monitorEvent)aux; + current_aux = e.getAuxPoint(); + + if (null == current_aux){ + // then e is global, not local + current_aux = aux; + } + } + else + { + current_aux = aux; + } + + operand_left = new javax.swing.JComboBox(); + operand_left.addItem("Constant"); + operand_left.addItem("Variable"); + operand_right = new javax.swing.JComboBox(); + operand_right.addItem("Constant"); + operand_right.addItem("Variable"); + + left_variables = new javax.swing.JComboBox(); + right_variables = new javax.swing.JComboBox(); + + // do the global variables + java.util.Vector vv = var_list.Instance().getVariables(); + for(int i=1; i"); + operator.addItem(">="); + operator.addItem("<"); + operator.addItem("<="); + operator.addItem("=="); + operator.addItem("!="); + + left_constant = new javax.swing.JTextField("", 8); + left_constant.setFont(new java.awt.Font("Tahoma", 0, 12)); + left_constant.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + right_constant = new javax.swing.JTextField("", 8); + right_constant.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + right_constant.setFont(new java.awt.Font("Tahoma", 0, 12)); + + jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp_top = new javax.swing.JPanel(); + jp_top.setLayout(new java.awt.GridBagLayout()); + jp_bottom = new javax.swing.JPanel(); + jp_bottom.setLayout(new java.awt.GridBagLayout()); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_top.add(operand_left, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_top.add(operator, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_top.add(operand_right, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_top.add(left_constant, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_top.add(left_variables, gridBagConstraints); + left_variables.setVisible(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 1; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_top.add(right_constant, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 1; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_top.add(right_variables, gridBagConstraints); + right_variables.setVisible(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp.add(jp_top, gridBagConstraints); + + button1 = new javax.swing.JButton("Enter"); + button1.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + button1MouseClicked(); + } + }); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_bottom.add(button1, gridBagConstraints); + + button2 = new javax.swing.JButton("Cancel"); + button2.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + button2MouseClicked(); + } + }); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_bottom.add(button2, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp.add(jp_bottom, gridBagConstraints); + + current_aux = aux; + + setContentPane(jp); + + setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); + + addWindowListener(new java.awt.event.WindowAdapter() { + public void windowClosing(java.awt.event.WindowEvent we) { + /* + * Instead of directly closing the window, + * we're going to change the JOptionPane's + * value property. + */ + } + }); + + //Ensure the combo box always gets the first focus. + addComponentListener(new java.awt.event.ComponentAdapter() { + public void componentShown(java.awt.event.ComponentEvent ce) { + } + }); + + operand_left.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + changeOperand(1); + } + }); + operand_right.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + changeOperand(2); + } + }); + + + // for edit mode + if(newNO != null) + { + // sets the operator + operator.setSelectedItem(newNO.getOperator().getOperator()); + + // sets the first operand + Operand op = newNO.getOperand1(); + if(op instanceof variable) + { + operand_left.setSelectedItem("Variable"); + variable tmp_v = (variable)op; + + left_variables.setSelectedItem(tmp_v.getName()); + } + else if(op instanceof constant) + { + operand_left.setSelectedItem("Constant"); + constant tmp_c = (constant)op; + left_constant.setText(Integer.toString(tmp_c.getValue())); + } + + // sets the second operand + op = newNO.getOperand2(); + if(op instanceof variable) + { + operand_right.setSelectedItem("Variable"); + variable tmp_v = (variable)op; + right_variables.setSelectedItem(tmp_v.getName()); + } + else if(op instanceof constant) + { + operand_right.setSelectedItem("Constant"); + constant tmp_c = (constant)op; + right_constant.setText(Integer.toString(tmp_c.getValue())); + } + } + } + + // The handler for the changing operand type, constant or variable + private void changeOperand(int type) + { + String selected = new String(); + if(type == 1) + { + selected = (String)operand_left.getSelectedItem(); + if(selected.compareTo("Constant") == 0) + { + left_constant.setVisible(true); + left_variables.setVisible(false); + } + else if(selected.compareTo("Variable") == 0) + { + left_variables.setVisible(true); + left_constant.setVisible(false); + } + } + else if(type == 2) + { + selected = (String)operand_right.getSelectedItem(); + if(selected.compareTo("Constant") == 0) + { + right_constant.setVisible(true); + right_variables.setVisible(false); + } + else if(selected.compareTo("Variable") == 0) + { + right_variables.setVisible(true); + right_constant.setVisible(false); + } + } + pack(); + setLocationRelativeTo(frame); + } + + // The handler for the button1 -- Ok + private void button1MouseClicked() + { + int to_close = 0; // zero means can close, 1 means can't close + + // sets the operator + Operator Ot = new Operator(); + Ot.setOperator((String)operator.getSelectedItem()); + NO.setOperator(Ot); + + variable tmp_var; + + // sets the left operand + String selected = (String)operand_left.getSelectedItem(); + if(selected.compareTo("Variable") == 0) + { + selected = (String)left_variables.getSelectedItem(); + tmp_var = var_list.Instance().getVariable(selected); + + if(tmp_var == null) + { + tmp_var = current_aux.getVariable(selected); + } + NO.setOperand1(tmp_var); + } + else if(selected.compareTo("Constant") == 0) + { + try + { + constant c = new constant(); + c.setValue(Integer.parseInt(left_constant.getText())); + NO.setOperand1(c); + } + catch(RuntimeException re) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the constant in Operand1 is invalid.\nPlease enter numbers only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + left_constant.requestFocusInWindow(); + to_close = 1; + } + } + + if(to_close == 0) + { + // sets the right operand + selected = (String)operand_right.getSelectedItem(); + if(selected.compareTo("Variable") == 0) + { + selected = (String)right_variables.getSelectedItem(); + tmp_var = var_list.Instance().getVariable(selected); + + if(tmp_var == null) + { + tmp_var = current_aux.getVariable(selected); + } + NO.setOperand2(tmp_var); + } + else if(selected.compareTo("Constant") == 0) + { + try + { + constant c = new constant(); + c.setValue(Integer.parseInt(right_constant.getText())); + NO.setOperand2(c); + } + catch(RuntimeException re) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the constant in Operand2 is invalid.\nPlease enter numbers only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + right_constant.requestFocusInWindow(); + to_close = 1; + } + } + } + + if(to_close == 0) + { + setVisible(false); + } + } + + + /** + * To return the NestedOperation + * @return NestedOperation configured by the user + */ + public NestedOperation getExpression() + { + return NO; + } + + + // The handler for the button2 -- Cancel + private void button2MouseClicked() + { + NO = null; + setVisible(false); + } +} diff --git a/src/funsoftware/ic/ComparatorDialog.java b/src/funsoftware/ic/ComparatorDialog.java new file mode 100644 index 0000000..d21087c --- /dev/null +++ b/src/funsoftware/ic/ComparatorDialog.java @@ -0,0 +1,276 @@ +/* + * ComparatorDialog.java + * + * Created on 18 February 2006, 16:48 + * + */ + +package funsoftware.ic; + +import funsoftware.ic.bran.*; + +/** + * To display the dialog that asks the user for a comparator for an expression + * @author Thomas Legowo + */ +public class ComparatorDialog extends javax.swing.JDialog{ + + // private variables + private java.awt.GridBagConstraints gridBagConstraints; + + private javax.swing.JComboBox comparator; + + private javax.swing.JLabel msg1; + private javax.swing.JLabel msg2; + private javax.swing.JLabel comparator_display; + private javax.swing.JLabel guide1; + + private javax.swing.JButton button1; + private javax.swing.JButton button2; + + private javax.swing.JPanel jp; + private javax.swing.JPanel jp_top; + private javax.swing.JPanel jp_bottom; + + private int ret_val; + + private String[] array_of_comparator; + + /** + * Creates a new instance of ComparatorDialog + * @param type The type of whether edit or set + * @param icon The icon this comparator is in reference to + * @param frame The frame + */ + public ComparatorDialog(java.awt.Frame frame, int type, Icon icon) { + super(frame, true); + setTitle("Set The Comparator"); + + ret_val = type; + + array_of_comparator = new String[6]; + array_of_comparator[0] = ">"; + array_of_comparator[1] = ">="; + array_of_comparator[2] = "<"; + array_of_comparator[3] = "<="; + array_of_comparator[4] = "=="; + array_of_comparator[5] = "!="; + + + comparator = new javax.swing.JComboBox(); + comparator.addItem(array_of_comparator[0]); + comparator.addItem(array_of_comparator[1]); + comparator.addItem(array_of_comparator[2]); + comparator.addItem(array_of_comparator[3]); + comparator.addItem(array_of_comparator[4]); + comparator.addItem(array_of_comparator[5]); + + comparator.setSelectedItem(array_of_comparator[type-1]); + + if(icon instanceof branchIcon) + { + msg1 = new javax.swing.JLabel("Top Comparator"); + msg2 = new javax.swing.JLabel("Bottom Comparator"); + if(type == 1) + { + comparator_display = new javax.swing.JLabel(array_of_comparator[3]); + } + else if(type == 2) + { + comparator_display = new javax.swing.JLabel(array_of_comparator[2]); + } + else if(type == 3) + { + comparator_display = new javax.swing.JLabel(array_of_comparator[1]); + } + else if(type == 4) + { + comparator_display = new javax.swing.JLabel(array_of_comparator[0]); + } + else if(type == 5) + { + comparator_display = new javax.swing.JLabel(array_of_comparator[5]); + } + else if(type == 6) + { + comparator_display = new javax.swing.JLabel(array_of_comparator[4]); + } + } + else + { + msg1 = new javax.swing.JLabel("Comparator"); + } + + guide1 = new javax.swing.JLabel("Select 1"); + + jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp_top = new javax.swing.JPanel(); + jp_top.setLayout(new java.awt.GridBagLayout()); + jp_bottom = new javax.swing.JPanel(); + jp_bottom.setLayout(new java.awt.GridBagLayout()); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_top.add(msg1, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_top.add(comparator, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_top.add(guide1, gridBagConstraints); + + if(icon instanceof branchIcon) + { + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_top.add(msg2, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 1; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_top.add(comparator_display, gridBagConstraints); + } + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp.add(jp_top, gridBagConstraints); + + button1 = new javax.swing.JButton("Select"); + button1.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + button1MouseClicked(); + } + }); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_bottom.add(button1, gridBagConstraints); + + button2 = new javax.swing.JButton("Cancel"); + button2.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + button2MouseClicked(); + } + }); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_bottom.add(button2, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp.add(jp_bottom, gridBagConstraints); + + setContentPane(jp); + + setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); + + if(icon instanceof branchIcon) + { + comparator.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + changeComparator(); + } + }); + } + } + + // to handle from a change of state in the comparator JComboBox + private void changeComparator() + { + String select = (String)comparator.getSelectedItem(); + + if(select.compareTo(array_of_comparator[0]) == 0) + { + comparator_display.setText(array_of_comparator[3]); + } + else if(select.compareTo(array_of_comparator[1]) == 0) + { + comparator_display.setText(array_of_comparator[2]); + } + else if(select.compareTo(array_of_comparator[2]) == 0) + { + comparator_display.setText(array_of_comparator[1]); + } + else if(select.compareTo(array_of_comparator[3]) == 0) + { + comparator_display.setText(array_of_comparator[0]); + } + else if(select.compareTo(array_of_comparator[4]) == 0) + { + comparator_display.setText(array_of_comparator[5]); + } + else if(select.compareTo(array_of_comparator[5]) == 0) + { + comparator_display.setText(array_of_comparator[4]); + } + repaint(); + } + + /** + * To return the comparator type selected + * @return The comparator selected + */ + public int getComparator() + { + return ret_val; + } + + // The handler for "Select" buttons + private void button1MouseClicked() + { + String selected = (String)comparator.getSelectedItem(); + + if(selected.compareTo(">") == 0) + { + ret_val = 1; + } + else if(selected.compareTo(">=") == 0) + { + ret_val = 2; + } + else if(selected.compareTo("<") == 0) + { + ret_val = 3; + } + else if(selected.compareTo("<=") == 0) + { + ret_val = 4; + } + else if(selected.compareTo("==") == 0) + { + ret_val = 5; + } + else if(selected.compareTo("!=") == 0) + { + ret_val = 6; + } + setVisible(false); + } + + // The handler for "Cancel" buttons + private void button2MouseClicked() + { + setVisible(false); + } +} diff --git a/src/funsoftware/ic/Icon.java b/src/funsoftware/ic/Icon.java new file mode 100644 index 0000000..5449e34 --- /dev/null +++ b/src/funsoftware/ic/Icon.java @@ -0,0 +1,986 @@ +/* + * Icon.java + * + * Created on 14 July 2005, 19:47 + */ + +package funsoftware.ic; + +import funsoftware.gri.*; +import funsoftware.wr.*; +import funsoftware.functs.*; +import funsoftware.tasks.*; +import funsoftware.struct.*; +import funsoftware.events.*; +import funsoftware.ic.func.*; +import funsoftware.ic.tsk.*; +import funsoftware.ic.ev.*; +import funsoftware.var.*; + +/** + * This class represent an icon and its main and auxiliary attributes + * Other icons would simply extend this class and implement most of this method + * @author Thomas Legowo * + * + */ +public class Icon extends javax.swing.JPanel { + + // private attributes or variables + + private String id; // icon's id, the id is a unique identifier, it will be a number that is preceeded by the + // letter I + private int width; // the width of the icon + private int height; // the height of the icon + private javax.swing.ImageIcon ic; // the image of this icon + private coord co; // the coordinate of this icon + + private int vertical_size; // the vertical size an icon takes up. For a repeat branch, it depends on the icons inside it + // e.g. a branch or a test icon initially takes up a vertical size of 3 + + private Icon parent_icon; // the parent icon of this icon + // for a branch(or test) icon, the join icons and all icons within them point to the branch icon + // as their parent, the branch icon itself however, points to the other icon that is higher + // up in the hierarchy + // THE SAME will apply to the loop icons + + private auxiliary aux; // the auxiliary this icon is operating in + + /** Creates a new instance of Icon */ + public Icon() + { + } + + /** + * Creates a new instance of Icon + * @param filepath The source file of this icon's image + */ + public Icon(String filepath) { + // when initialising the id, the checking of whether the id is unique is done outside this class + // that check will go through the icons class containing all active icons on the programming window + ic = new javax.swing.ImageIcon(getClass().getResource(filepath)); + vertical_size = 0; // for all icons, the vertical size is 0, only loops and branches have different sizes and + // they will need to invoke the method setVerticalSize(int) + parent_icon = null; // null only for starting and ending icon where parent icon will not be initialised + aux = new auxiliary(); + } + + /** + * Sets the id of this icon + * @param nid New id + */ + public void setId(String nid) + { + id = nid; + } + + /** + * Returns the id of this icon without the letter "I" + * @return Id + */ + public int getId() + { + int ii = Integer.parseInt(id.substring(1)); // get rid of the I from the id + return ii; + } + + /** + * Returns the full id with the letter "I" + * @return Full Id + */ + public String getFullId() + { + return id; + } + + /** + * Set width of this icon + * @param nwidth New width + */ + public void setWidth(int nwidth) + { + width = nwidth; + } + + /** + * Set height of this icon + * @param nheight New height + */ + public void setHeight(int nheight) + { + height = nheight; + } + + /** + * Get the width of this icon + * @return Width + */ + public int getWidth() + { + return width; + } + + /** + * Get the height of this icon + * @return Height + */ + public int getHeight() + { + return height; + } + + /** + * Set the coordinate of this icon + * @param nco New coordinate + */ + public void setCoordinate(coord nco) + { + co = nco; + } + + + /** + * Return the coordinate of this icon + * @return Coordinate + */ + public coord getCoordinate() + { + return co; + } + + // ---- VERTICAL SIZES --> ONLY the BRANCH ICONS have the 2 TOP and 2 BOTTOM vertical sizes !!!! + + /** + * For branch and loop icons: Return the vertical size + * @return Vertical size + */ + public int getVerticalSize() + { + return vertical_size; + } + + /** + * For branch and loop icons: Set the vertical size + * @param nvs New vertical size + */ + public void setVerticalSize(int nvs) + { + vertical_size = nvs; + } + + /** + * Get the top part of branch top's vertical size + * @return Top part of branch top's vertical size + */ + public int getTopTopVerticalSize() + { + return 0; + } + + /** + * Get the top part of branch bottom's vertical size + * @return Top part of branch bottom's vertical size + */ + public int getTopBottomVerticalSize() + { + return 0; + } + + /** + * Get the bottom part of branch top's vertical size + * @return Bottom part of branch top's vertical size + */ + public int getBottomTopVerticalSize() + { + return 0; + } + + /** + * Get the bottom part of branch bottom's vertical size + * @return Bottom part of branch bottom's vertical size + */ + public int getBottomBottomVerticalSize() + { + return 0; + } + + /** + * Set the top part of branch top's vertical size + * @param ns New vertical size + */ + public void setTopTopVerticalSize(int ns) + { + + } + + /** + * Set the top part of branch bottom's vertical size + * @param ns New vertical size + */ + public void setTopBottomVerticalSize(int ns) + { + + } + + /** + * Set the bottom part of branch top's vertical size + * @param ns New vertical size + */ + public void setBottomTopVerticalSize(int ns) + { + + } + + /** + * Set the bottom part of branch bottom's vertical size + * @param ns New vertical size + */ + public void setBottomBottomVerticalSize(int ns) + { + + } + + // the methods for vertical repositioning of a repeat + /** + * Set top part of a loop icon's vertical size + * @param nvs New vertical size + */ + public void setTopVerticalSize(int nvs) + { + + } + + /** + * Set bottom part of a loop icon's vertical size + * @param nvs New vertical size + */ + public void setBottomVerticalSize(int nvs) + { + + } + + /** + * Get top part of loop's vertical size + * @return Top part of loop's vertical size + */ + public int getTopVerticalSize() + { + return 0; + } + + /** + * Get bottom part of loop's vertical size + * @return Bottom part of loop's vertical size + */ + public int getBottomVerticalSize() + { + return 0; + } + + // ---------------------- + + // dealing with the parent icons + /** + * Get the parent icon of this icon + * @return Parent icon + */ + public Icon getParentIcon() + { + return parent_icon; + } + + /** + * Set the parent icon of this icon + * @param npi New parent icon + */ + public void setParentIcon(Icon npi) + { + parent_icon = npi; + } + + /** + * Get the image of this icon + * @return Image of this icon + */ + public javax.swing.ImageIcon getImage() + { + return ic; + } + + /** + * Set the image of this icon + */ + public void setImage() + { + + } + + /** + * Set the left neighbour of this icon + * @param nicon New neighbour + */ + public void setLeftNeighbour(Icon nicon) + { + + } + + /** + * Set the right neighbour of this icon + * @param nicon New neighbour + */ + public void setRightNeighbour(Icon nicon) + { + + } + + /** + * Set the left wire of this icon + * @param nwire New wire + */ + public void setLeftWire(Wire nwire) + { + + } + + /** + * Set the right wire of this icon + * @param nwire New wire + */ + public void setRightWire(Wire nwire) + { + + } + + /** + * Get left icon neighbour of this icon + * @return Left icon + */ + public Icon getLeftNeighbour() + { + return null; + } + + /** + * Get right icon neighbour of this icon + * @return Right icon + */ + public Icon getRightNeighbour() + { + return null; + } + + /** + * Get the left wire of this icon + * @return Left wire + */ + public Wire getLeftWire() + { + return null; + } + + /** + * Get the right wire of this icon + * @return Right wire + */ + public Wire getRightWire() + { + return null; + } + + // extra methods for the branching icons + /** + * For joinEndBranchIcon : Get left top neighbour of this icon + * @return Left neighbour top + */ + public Icon getLeftNeighbourTop() + { + return null; + } + + /** + * For joinEndBranchIcon : Get left bottom neighbour of this icon + * @return Left neighbour bottom + */ + public Icon getLeftNeighbourBottom() + { + return null; + } + + /** + * For branch icons : Get right top neighbour of this icon + * @return Right top neighbour + */ + public Icon getRightNeighbourTop() + { + return null; + } + + /** + * For branch icons : Get right bottom neighbour of this icon + * @return Right bottom neighbour + */ + public Icon getRightNeighbourBottom() + { + return null; + } + + /** + * For joinEndBranchIcon : Get left top wire of this icon + * @return Left top wire + */ + public Wire getLeftWireTop() + { + return null; + } + + /** + * For joinEndBranchIcon : Get left bottom wire of this icon + * @return Left bottom wire + */ + public Wire getLeftWireBottom() + { + return null; + } + + /** + * For branch icons : Get right top wire of this icon + * @return Right top wire + */ + public Wire getRightWireTop() + { + return null; + } + + /** + * For branch icons : Get right bottom wire of this icon + * @return Right bottom wire + */ + public Wire getRightWireBottom() + { + return null; + } + + /** + * For joinEndBranchIcon : Set the left neighbour top of this icon + * @param nicon Left neighbour top + */ + public void setLeftNeighbourTop(Icon nicon) + { + + } + + /** + * For joinEndBranchIcon : Set the left neighbour bottom of this icon + * @param nicon Left neighbour bottom + */ + public void setLeftNeighbourBottom(Icon nicon) + { + + } + + /** + * For branch icons : Set the right neighbour top of this icon + * @param nicon Right neighbour top + */ + public void setRightNeighbourTop(Icon nicon) + { + + } + + /** + * For branch icons : Set the right neighbour bottom of this icon + * @param nicon Right neighbour bottom + */ + public void setRightNeighbourBottom(Icon nicon) + { + + } + + /** + * For joinEndBranchIcon : Set left wire top of this icon + * @param nwire Left wire top + */ + public void setLeftWireTop(Wire nwire) + { + + } + + /** + * For joinEndBranchIcon : Set left wire bottom of this icon + * @param nwire Left wire bottom + */ + public void setLeftWireBottom(Wire nwire) + { + + } + + /** + * For branch icons : Set right wire top of this icon + * @param nwire Right wire top + */ + public void setRightWireTop(Wire nwire) + { + + } + + /** + * For branch icons : Set right wire bottom of this icon + * @param nwire Right wire bottom + */ + public void setRightWireBottom(Wire nwire) + { + + } + + // methods for the joinLoopIcon + /** + * For joinLoopIcon : Get the loop icon (bottom of this icon visually) + * @return Bottom neighbour + */ + public Icon getBottomNeighbour() + { + return null; + } + + /** + * For joinLoopIcon : Set the loop icon (bottom of this icon visually) + * @param nicon New bottom neighbour + */ + public void setBottomNeighbour(Icon nicon) + { + + } + + // methods for joinEndBranchIcon + /** + * For joinEndBranchIcon : Get branch icon of this icon + * @return Branch icon + */ + public Icon getBranchIcon() + { + return null; + } + + /** + * For joinEndBranchIcon : Set branch icon of this icon + * @param nicon Branch icon + */ + public void setBranchIcon(Icon nicon) + { + + } + + // methods for the branch or test icon + /** + * For branch icons : Get end branch icon of this icon + * @return End branch icon + */ + public Icon getEndBranch() + { + return null; + } + + /** + * For branch icons : Set end branch icon of this icon + * @param neb New end branch icon + */ + public void setEndBranch(Icon neb) + { + + } + + // method for test/branch icons to deal with its members + + /** + * For branch icons : Determine whether a member of this icon is in top or bottom part of this icon + * @param icon Member icon + * @return Determiner + */ + public int determineMember(Icon icon) + { + return 0; + } + /** + * For branch icons : Get the members in the top part of this branch icon + * @return Set of icons + */ + public java.util.Vector getIfMembers() + { + return null; + } + + /** + * For branch icons : Get the members in the bottom part of this branch icon + * @return Set of icons + */ + public java.util.Vector getElseMembers() + { + return null; + } + + /** + * For branch icons : Get the icon with the tallest vertical size in top of branch's top part + * @return Tallest member in top part of branch's top part + */ + public Icon tallestIfMemberTop() + { + return null; + } + + /** + * For branch icons : Get the icon with the tallest vertical size in bottom of branch's top part + * @return Tallest member in bottom part of branch's top part + */ + public Icon tallestIfMemberBottom() + { + return null; + } + + /** + * For branch icons : Get the icon with the tallest vertical size in top of branch's bottom part + * @return Tallest member in top part of branch's bottom part + */ + public Icon tallestElseMemberTop() + { + return null; + } + + /** + * For branch icons : Get the icon with the tallest vertical size in bottom of branch's bottom part + * @return Tallest member in bottom part of branch's bottom part + */ + public Icon tallestElseMemberBottom() + { + return null; + } + + // now methods for the loopIcons that deals with its members and neighbours + + /** + * Special for loopIcons : To set left neighbour + */ + public void setLeftNeighbour() + { + + } + + /** + * Special for loopIcons : To set right neighbour + */ + public void setRightNeighbour() + { + + } + + /** + * For loop icons : Get begin icon of this icon + * @return Begin icon + */ + public Icon getBeginIcon() + { + return null; + } + + /** + * For loop icons : Get end icon of this icon + * @return End icon + */ + public Icon getEndIcon() + { + return null; + } + + /** + * For loop icons : Set the begin icon of this icon + * @param nicon New begin icon + */ + public void setBeginIcon(Icon nicon) + { + + } + + /** + * For loop icons : Set the end icon of this icon + * @param nicon New end icon + */ + public void setEndIcon(Icon nicon) + { + + } + + /** + * For startIcon and loop icons : Get members of this icon + * @return Set of icons + */ + public java.util.Vector getMembers() + { + return null; + } + + // methods by the repeat Icons needed for the automatic vertical repositioning + /** + * For loop icons : Get the member with the tallest vertical size in the bottom part of this icon + * @return Icon + */ + public Icon tallestBottomMember() + { + return null; + } + + /** + * For loop icons : Get the member with the tallest vertical size in the top part of this icon + * @return Icon + */ + public Icon tallestTopMember() + { + return null; + } + + // common methods for repeat and branches + + /** + * To add a new member icon to this icon + * @param new_icon Icon to be added + * @param right_icon Icon to the right of the to be added icon + */ + public void addMember(Icon new_icon, Icon right_icon) + { + + } + + // to delete a particular member + /** + * To delete a particular member of this icon + * @param icon Icon to be deleted + */ + public void delMember(Icon icon) + { + + } + + // to delete all members + /** + * To delete all member icons within thi sicon + */ + public void delAllMembers() + { + + } + + /** + * Turns off mouse listerners for this icon + */ + public void turnoffListeners() + { + + } + + + /** + * Turns on mouse listerners for this icon + */ + public void turnonListeners() + { + + } + + /** + * Get the help title of this icon + * @return Help title + */ + public String getHelpTitle() + { + return null; + } + + /** + * Get help message of this icon + * @return Help message + */ + public String getHelpMsg() + { + return null; + } + + /** + * Get the description of this icon + * @return Help Description + */ + public String getHelpDesc() + { + return null; + } + + /** + * Get help picture of this icon + * @return Help picture + */ + public javax.swing.Icon getHelpIcon() + { + return null; + } + + /** + * To clone this icon + * @return New instance of this icon + */ + public Icon Clone() + { + return null; + } + + /** + * To copy this icon + * @return New instance of this icon with its attributes set + */ + public Icon Copy() + { + return null; + } + + /** + * Set the auxiliary that this arithmetic operation icon is in + * @param a Auxiliary to be set + */ + public void setAux(auxiliary a) + { + aux = a; + } + + /** + * Get the auxiliary that this arithmetic operation icon is in + * @return Auxiliary (function or task) + */ + public auxiliary getAux() + { + if(aux instanceof monitorEvent) + { + monitorEvent tmp = (monitorEvent)aux; + aux = tmp.getAuxPoint(); + if(aux == null) + { + return new auxiliary(); + } + } + return aux; + } + + /** + * Algorithm translation for the Translator object to create a text representation of this icon + * @param id_separator To separate ids + * @param id_att_separator To separate id with attribute + * @param att_boundary_begin To start attributes + * @param att_boundary_end To end attributes + * @param att_value_connector To separate attributes and its values + * @param att_separator To separate attributes + * @return Translation + */ + public String getTranslation(String id_separator, String id_att_separator, + String att_boundary_begin, String att_boundary_end, String att_value_connector, String att_separator) + { + return null; + } + + // for the NQCCode + /** + * Returns a string format of the NQCCode representation of this object + * @param indentation Indentation + * @return The NQC Code + */ + public String getNQCCode(String indentation) + { + return null; + } + + // for subroutine icons + /** + * For subroutine icons : Get the subroutine id of this icon + * @return Subroutine id + */ + public int getNumId() + { + return 0; + } + + /** + * For function icons, to set the function this icon is pointing to + * @param f The function + */ + public void setFunction(function f) + { + } + + /** + * For task icons, to set the task this icon is pointing to + * @param t The task + */ + public void setTask(task t) + { + } + + /** + * For event icons, to set the event this icon is pointing to + * @param ev The event + */ + public void setEventMonitor(monitorEvent ev) + { + } + + /** + * To return a panel prompting users to input a variable into one of the icon's attributes + * @return The label of the panel + */ + public javax.swing.JLabel getVarLabel() + { + return null; + } + + /** + * Find the current auxiliary this icon is on + * @return The auxiliary + */ + public auxiliary findCurrentAux() + { + Icon parent = this.getParentIcon(); + auxiliary ret = new auxiliary(); + while(true) + { + if(parent instanceof startFunctionIcon) + { + startFunctionIcon sfi = (startFunctionIcon)parent; + ret = sfi.getFunction(); + break; + } + else if(parent instanceof startTaskIcon) + { + startTaskIcon sti = (startTaskIcon)parent; + ret = sti.getTask(); + break; + } + else if(parent instanceof startEventIcon) + { + startEventIcon sti = (startEventIcon)parent; + ret = sti.getEventMonitor().getAuxPoint(); + if(ret == null) + { + ret = new auxiliary(); + } + break; + } + else + { + parent = parent.getParentIcon(); + } + } + return ret; + } + + /** + * To indicate whether this icon uses a variable + * @param var The variable used + * @return True or false + */ + public Boolean useAVariable(variable var) + { + return false; + } +} diff --git a/src/funsoftware/ic/PicButton.java b/src/funsoftware/ic/PicButton.java new file mode 100644 index 0000000..356b2e3 --- /dev/null +++ b/src/funsoftware/ic/PicButton.java @@ -0,0 +1,26 @@ +/* + * PicButton.java + * + * Created on 2 August 2005, 15:59 + */ + +package funsoftware.ic; + +/** + * This class is for the little buttons constructing the larger button for each icon + * @author Thomas Legowo + */ +public class PicButton extends javax.swing.JLabel{ + + /** + * Creates a new instance of PicButton + * @param nic The image icon + */ + public PicButton(javax.swing.ImageIcon nic) { + super(); + super.setPreferredSize(new java.awt.Dimension(nic.getImage().getWidth(this), nic.getImage().getHeight(this))); + setOpaque(true); + setIcon(nic); + setBackground(new java.awt.Color(255, 255, 255)); + } +} diff --git a/src/funsoftware/ic/VarInputDialog.java b/src/funsoftware/ic/VarInputDialog.java new file mode 100644 index 0000000..05f5bc4 --- /dev/null +++ b/src/funsoftware/ic/VarInputDialog.java @@ -0,0 +1,188 @@ +/* + * VarInputDialog.java + * + * Created on 23 January 2006, 11:27 + * + */ + +package funsoftware.ic; + +import funsoftware.var.*; +import funsoftware.consts.*; +import funsoftware.struct.*; + +/** + * This dialog displays a panel asking for variable input into an icon's attribute + * @author Thomas Legowo + */ +public class VarInputDialog extends javax.swing.JDialog{ + + // private variable + private javax.swing.JPanel big_panel; + private javax.swing.JPanel jp_bottom; + private javax.swing.JButton button; + private javax.swing.JComboBox jcb; + private java.awt.GridBagConstraints gridBagConstraints; + + private variable ret_val; + private auxiliary current_aux; + + /** + * Creates a new instance of FunctionNameDialog + * @param frame The frame + * @param icon The icon + * @param current_aux The auxiliary the icon is on + */ + public VarInputDialog(java.awt.Frame frame, Icon icon, auxiliary current_aux) { + super(frame, true); + ret_val = new variable(); + this.current_aux = current_aux; + setTitle("Set Variable to Use"); + + big_panel = new javax.swing.JPanel(); + big_panel.setLayout(new java.awt.GridBagLayout()); + jp_bottom = new javax.swing.JPanel(); + jp_bottom.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JPanel jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jcb = new javax.swing.JComboBox(); + java.awt.GridBagConstraints gridBagConstraints; + + java.util.Vector vars = var_list.Instance().getVariables(); + for(int i=1; i 3) + { + jcb.addItem(tmp_var.getName()); + } + } + } + + vars = current_aux.getVariables(); + for(int i=1; i" for greater than + + /** + * Creates a new instance of BcelciusSensorIcon + */ + public BcelciusSensorIcon() { + } + + /** + * Creates a new instance of BcelciusSensorIcon + * @param filepath The source file of the BCelciusSensorIcon icon + */ + public BcelciusSensorIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); + super.setHeight(super.getImage().getImage().getHeight(this)); + port = 1; + temperature = 300; + identifier = 3; + var_temperature = null; + type = 1; + setImage(); + } + + /** + * Helps provide the transparent background + * @param g Graphic + */ + protected void paintComponent(java.awt.Graphics g) + { + super.paintComponent(g); + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/branches/celcius/celcius_field.gif")); + g.drawImage(ii.getImage(), 14, 24, this); + } + + /** + * To return the input port this temperature sensor is connected to + * @return Input port + */ + public int getPort() + { + return port; + } + + /** + * To get the value of temperature reading from the sensor + * @return Temperature value + */ + public int getTemperatureValue() + { + return temperature; + } + + /** + * To set the port attribute + * @param nport New port + */ + public void setPort(int nport) + { + port = nport; + } + + /** + * To set the temperature value attribute of this icon + * @param nt New temperature value + */ + public void setTemperatureValue(int nt) + { + temperature = nt; + } + + /** + * To set the temperature value attribute of this icon + * @param var The temperature variable + */ + public void setVarTemperature(variable var) + { + var_temperature = var; + } + + /** + * Sets the new comparator type to this icon + * @param nct New comparator type + */ + public void setComparatorType(int nct) + { + type = nct; + } + + /** + * Gets the comparator type to this icon + * @return Comparator type + */ + public int getComparatorType() + { + return type; + } + + /** + * To set the image of this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + javax.swing.ImageIcon nic; + PicButton pic; + + javax.swing.JPanel jp, jp2; + + jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp.setPreferredSize(new java.awt.Dimension(40, 24)); + + // add le stuffs into le jp + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/branches/celcius/top.gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + // displays the comparator according to its type + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/branches/comparator/comp"+type+".gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(jp, gridBagConstraints); + + jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp.setPreferredSize(new java.awt.Dimension(40, 16)); + + // do the panel within jp + jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(14, 16)); + + javax.swing.JLabel portLabel = new javax.swing.JLabel(Integer.toString(port)); + portLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + portLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(portLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(jp2, gridBagConstraints); + + // ---------- the light value panel + + jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(26, 16)); + + javax.swing.JLabel temperatureLabel; + if(var_temperature == null) + { + temperatureLabel = new javax.swing.JLabel(Integer.toString(temperature)); + } + else + { + temperatureLabel = new javax.swing.JLabel("V"); + } + temperatureLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + temperatureLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + temperatureLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(temperatureLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(jp2, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(jp, gridBagConstraints); + + jp.setOpaque(false); + setOpaque(false); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * To change the value of the port attribute + * @param evt Mouse event + */ + public void changePort(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField = new javax.swing.JTextField(Integer.toString(port)); + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(14,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + javax.swing.JPanel jp; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditModePort(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + + /** + * To change the temperature attribute of this icon + * @param evt Mouse event + */ + public void changeTemperatureValue(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField; + if(var_temperature != null) + { + textField = new javax.swing.JTextField("v"); + } + else + { + textField = new javax.swing.JTextField(Integer.toString(temperature)); + } + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(26,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + javax.swing.JPanel jp; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditModeTemperature(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the comparator type of this icon + * @param evt Mouse event + */ + public void changeComparator(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + ComparatorDialog c_dialog = new ComparatorDialog(null, type, this); + c_dialog.pack(); + c_dialog.setLocationRelativeTo(this); + c_dialog.setVisible(true); + + type = c_dialog.getComparator(); + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + jp.remove(1); + // displays the comparator according to its type + javax.swing.ImageIcon nic = new javax.swing.ImageIcon(getClass().getResource("/icons/branches/comparator/comp"+type+".gif")); + PicButton pic = new PicButton(nic); + java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + // set the states for undo and redo + UndoRedo.update_state(); + + repaint(); + validate(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To stop edit mode for port text field of this icon + */ + public void stopEditModePort() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + jp.removeAll(); + + // parse the port number + int tmp_port = port; // current port number + try + { + port = Integer.parseInt(text); + if(port > 3 || port <= 0) // maximum of 3 input ports + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the input port is invalid.\nIt can be either 1, 2 or 3.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + port = tmp_port; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the input port is invalid.\nPlease enter numbers only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_port != port) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JLabel portLabel = new javax.swing.JLabel(Integer.toString(port)); + portLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + portLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(portLabel, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + } + + /** + * Stop the edit mode of the light value on this branch icon + */ + public void stopEditModeTemperature() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + + String text = textField.getText(); + jp.removeAll(); + + // parse the light sensor value + int tmp_temp = temperature; + try + { + if(text.compareTo("v") == 0 || text.compareTo("V") == 0) + { + if(var_list.Instance().isDefinedVariables() == true || findCurrentAux().getLocalVarList().isEmpty() == false) + { + VarInputDialog vid = new VarInputDialog(null, this, findCurrentAux()); + vid.pack(); + vid.setLocationRelativeTo(this); + vid.setVisible(true); + + if(vid.getUserInput() != null) + { + var_temperature = vid.getUserInput(); + } + } + else + { + javax.swing.JOptionPane.showMessageDialog(null, + "You have not defined any global variables or local variables to this function or task yet.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + } + else + { + temperature = Integer.parseInt(text); + var_temperature = null; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the temperature sensor threshold is invalid.\nPlease enter numbers only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_temp != temperature || var_temperature != null) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JLabel temperatureLabel; + if(var_temperature == null) + { + temperatureLabel = new javax.swing.JLabel(Integer.toString(temperature)); + } + else + { + temperatureLabel = new javax.swing.JLabel("V"); + } + temperatureLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + temperatureLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + temperatureLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(temperatureLabel, gridBagConstraints); + jp.setOpaque(false); + + repaint(); + validate(); + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + java.awt.event.MouseListener[] ml = jp.getMouseListeners(); + for(int i=0; i port + sp2 = sp[0].split(att_value_connector); + port = Integer.parseInt(sp2[1]); + + // do the second one --> temperature + sp2 = sp[1].split(att_value_connector); + if(sp2[1].substring(0,1).compareTo("V") == 0) // must be a variable + { + var_temperature = var_list.Instance().getVariable(sp2[1].substring(2)); + if(var_temperature == null) // must be local, not global + { + var_temperature = getAux().getVariable(sp2[1].substring(2)); + } + } + else + { + temperature = Integer.parseInt(sp2[1]); + } + // do the third one --> comparator + sp2 = sp[2].split(att_value_connector); + type = Integer.parseInt(sp2[1]); + } + + /** + * To display an input panel to ask for a variable to be used + * @return The label for the input panel + */ + public javax.swing.JLabel getVarLabel() + { + return new javax.swing.JLabel("Temperature Value Threshold"); + } + + /** + * To indicate whether this icon uses a variable + * @param var Variable to be checked + * @return True or false + */ + public Boolean useAVariable(variable var) + { + if(var_temperature != null) + { + if(var_temperature.getType() == var.getType() && var_temperature.getName().compareTo(var.getName()) == 0) + { + return true; + } + } + return false; + } +} diff --git a/src/funsoftware/ic/bran/BlightSensorIcon.java b/src/funsoftware/ic/bran/BlightSensorIcon.java new file mode 100644 index 0000000..c446e0a --- /dev/null +++ b/src/funsoftware/ic/bran/BlightSensorIcon.java @@ -0,0 +1,879 @@ +/* + * BlightSensorIcon.java + * + * Created on 6 September 2005, 21:58 + * + */ + +package funsoftware.ic.bran; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.st.*; +import funsoftware.var.*; +import funsoftware.consts.*; + +/** + * This class is for the Branch Light Sensor Icon of the fUNSoftWare + * @author Thomas Legowo + */ +public class BlightSensorIcon extends branchIcon{ + + // the local variables + + private int port; // with default value being 1, port is the value of the input port of this light sensor + private int light_sensor_value; // default value being 55, minimum is 1 and maximum is 100 + private variable var_light_sensor_value; // alternative to light_sensor_value + + // for algorithm representation, represent a branch light sensor icon with an identifier of 2 + private int identifier; + + private int type; // originally type 1, ">" for greater than + + /** + * Creates a new instance of BlightSensorIcon + */ + public BlightSensorIcon() { + } + + /** + * Creates a new instance of BlightSensorIcon + * @param filepath The source file of this icon's graphic + */ + public BlightSensorIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); + super.setHeight(super.getImage().getImage().getHeight(this)); + port = 1; + light_sensor_value = 55; + identifier = 2; + var_light_sensor_value = null; + type = 1; + setImage(); + } + + /** + * Helps provide the transparent background + * @param g Graphics + */ + protected void paintComponent(java.awt.Graphics g) + { + super.paintComponent(g); + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/branches/light/light_field.gif")); + g.drawImage(ii.getImage(), 14, 24, this); + } + + /** + * Return the port this light sensor is operating in + * @return Port + */ + public int getPort() + { + return port; + } + + /** + * Return the light sensor value threshold of this branch light sensor icon + * @return Light sensor value + */ + public int getLightSensorValue() + { + return light_sensor_value; + } + + /** + * Set the input port of this icon + * @param nport New port value + */ + public void setPort(int nport) + { + port = nport; + } + + /** + * Set the light sensor value of this icon + * @param nlsv New light sensor value + */ + public void setLightSensorValue(int nlsv) + { + light_sensor_value = nlsv; + } + + /** + * Set the light sensor value of this icon + * @param var The light sensor variable + */ + public void setVarLight(variable var) + { + var_light_sensor_value = var; + } + + /** + * Sets the new comparator type to this icon + * @param nct New comparator type + */ + public void setComparatorType(int nct) + { + type = nct; + } + + /** + * Gets the comparator type to this icon + * @return Comparator type + */ + public int getComparatorType() + { + return type; + } + + /** + * Set the image of this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + javax.swing.ImageIcon nic; + PicButton pic; + + javax.swing.JPanel jp, jp2; + + jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp.setPreferredSize(new java.awt.Dimension(40, 24)); + + // add le stuffs into le jp + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/branches/light/top.gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + // displays the comparator according to its type + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/branches/comparator/comp"+type+".gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(jp, gridBagConstraints); + + jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp.setPreferredSize(new java.awt.Dimension(40, 16)); + + // do the panel within jp + jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(14, 16)); + + javax.swing.JLabel portLabel = new javax.swing.JLabel(Integer.toString(port)); + portLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + portLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(portLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(jp2, gridBagConstraints); + + // ---------- the light value panel + + jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(26, 16)); + + javax.swing.JLabel lightLabel; + if(var_light_sensor_value == null) + { + lightLabel = new javax.swing.JLabel(Integer.toString(light_sensor_value)); + } + else + { + lightLabel = new javax.swing.JLabel("V"); + } + lightLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + lightLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + lightLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(lightLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(jp2, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(jp, gridBagConstraints); + + jp.setOpaque(false); + setOpaque(false); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * To change the port value of this icon + * @param evt Mouse event + */ + public void changePort(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField = new javax.swing.JTextField(Integer.toString(port)); + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(14,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + javax.swing.JPanel jp; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditModePort(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the light sensor value threshold of this icon + * @param evt Mouse event + */ + public void changeLightSensorValue(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField; + if(var_light_sensor_value != null) + { + textField = new javax.swing.JTextField("v"); + } + else + { + textField = new javax.swing.JTextField(Integer.toString(light_sensor_value)); + } + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(26,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditModeLight(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the comparator type of this icon + * @param evt Mouse event + */ + public void changeComparator(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + ComparatorDialog c_dialog = new ComparatorDialog(null, type, this); + c_dialog.pack(); + c_dialog.setLocationRelativeTo(this); + c_dialog.setVisible(true); + + type = c_dialog.getComparator(); + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + jp.remove(1); + // displays the comparator according to its type + javax.swing.ImageIcon nic = new javax.swing.ImageIcon(getClass().getResource("/icons/branches/comparator/comp"+type+".gif")); + PicButton pic = new PicButton(nic); + java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + // set the states for undo and redo + UndoRedo.update_state(); + + repaint(); + validate(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * Stop the edit mode of the port value on this branch icon + */ + public void stopEditModePort() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + jp.removeAll(); + + // parse the port number + int tmp_port = port; // current port number + try{ + port = Integer.parseInt(text); + if(port > 3 || port <= 0) // maximum of 3 input ports + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the input port is invalid.\nIt can be either 1, 2 or 3.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + port = tmp_port; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the input port is invalid.\nPlease enter numbers only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_port != port) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JLabel portLabel = new javax.swing.JLabel(Integer.toString(port)); + portLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + portLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(portLabel, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + } + + + /** + * Stop the edit mode of the light value on this branch icon + */ + public void stopEditModeLight() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + jp.removeAll(); + + int tmp_light = light_sensor_value; // current port number + try + { + if(text.compareTo("v") == 0 || text.compareTo("V") == 0) + { + if(var_list.Instance().isDefinedVariables() == true || findCurrentAux().getLocalVarList().isEmpty() == false) + { + VarInputDialog vid = new VarInputDialog(null, this, findCurrentAux()); + vid.pack(); + vid.setLocationRelativeTo(this); + vid.setVisible(true); + + if(vid.getUserInput() != null) + { + var_light_sensor_value = vid.getUserInput(); + } + } + else + { + javax.swing.JOptionPane.showMessageDialog(null, + "You have not defined any global variables or local variables to this function or task yet.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + } + else + { + light_sensor_value = Integer.parseInt(text); + if(light_sensor_value > 100 || light_sensor_value < 1) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the light sensor threshold is invalid.\nMinimum value is 1 and maximum value is 100.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + light_sensor_value = tmp_light; + } + else + { + var_light_sensor_value = null; + } + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the light sensor threshold is invalid.\nPlease enter numbers only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_light != light_sensor_value || var_light_sensor_value != null) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JLabel lightLabel; + if(var_light_sensor_value == null) + { + lightLabel = new javax.swing.JLabel(Integer.toString(light_sensor_value)); + } + else + { + lightLabel = new javax.swing.JLabel("V"); + } + lightLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + lightLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + lightLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(lightLabel, gridBagConstraints); + jp.setOpaque(false); + + repaint(); + validate(); + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + java.awt.event.MouseListener[] ml = jp.getMouseListeners(); + for(int i=0; i port + sp2 = sp[0].split(att_value_connector); + port = Integer.parseInt(sp2[1]); + + // do the second one --> light_sensor_value + sp2 = sp[1].split(att_value_connector); + + if(sp2[1].substring(0,1).compareTo("V") == 0) // must be a variable + { + var_light_sensor_value = var_list.Instance().getVariable(sp2[1].substring(2)); + if(var_light_sensor_value == null) // must be local, not global + { + var_light_sensor_value = getAux().getVariable(sp2[1].substring(2)); + } + } + else + { + light_sensor_value = Integer.parseInt(sp2[1]); + } + // do the third one --> comparator + sp2 = sp[2].split(att_value_connector); + type = Integer.parseInt(sp2[1]); + } + + /** + * To display an input panel to ask for a variable to be used + * @return The label of the panel + */ + public javax.swing.JLabel getVarLabel() + { + return new javax.swing.JLabel("Light Value Threshold"); + } + + /** + * To indicate whether this icon uses a variable + * @param var Variable to be checked + * @return True or false + */ + public Boolean useAVariable(variable var) + { + if(var_light_sensor_value != null) + { + if(var_light_sensor_value.getType() == var.getType() && var_light_sensor_value.getName().compareTo(var.getName()) == 0) + { + return true; + } + } + return false; + } +} diff --git a/src/funsoftware/ic/bran/BrandomIcon.java b/src/funsoftware/ic/bran/BrandomIcon.java new file mode 100644 index 0000000..e5ef797 --- /dev/null +++ b/src/funsoftware/ic/bran/BrandomIcon.java @@ -0,0 +1,176 @@ +/* + * BrandomIcon.java + * + * Created on 30 January 2006, 16:56 + * + */ + +package funsoftware.ic.bran; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.st.*; + +/** + * This icon handles a branch that takes a path depending on the a random number. (Branch randomly) + * @author Thomas Legowo + */ +public class BrandomIcon extends branchIcon{ + + // for algorithm representation, represent a branch random icon with an identifier of 6 + private int identifier; + + /** + * Creates a new instance of BrandomIcon + */ + public BrandomIcon() { + } + + /** + * Creates a new instance of BrandomIcon + * @param filepath The source file of this icon's graphic + */ + public BrandomIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); + super.setHeight(super.getImage().getImage().getHeight(this)); + identifier = 6; + setImage(); + } + + /** + * Set the image of this icon + */ + public void setImage() + { + removeAll(); + setLayout(new java.awt.GridBagLayout()); + javax.swing.ImageIcon nic; + PicButton pic; + + // add le stuffs into le jp + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/branches/random/random.gif")); + pic = new PicButton(nic); + add(pic); + + setOpaque(false); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + + /** + * Get help title of this icon + * @return Help title + */ + public String getHelpTitle() + { + String s = "Branch Random Icon"; + return s; + } + + /** + * Get help message of this icon + * @return Help message + */ + public String getHelpMsg() + { + String s = "DETAILS:"; + s+="This icon has no attributes"; + return s; + } + + /** + * Get help description of this icon + * @return Help description + */ + public String getHelpDesc() + { + String s = "This icon acts as a branch.\nIt chooses one between two paths\ndepending on a random number\n"; + return s; + } + + /** + * Get help picture of this icon + * @return Help picture + */ + public javax.swing.Icon getHelpIcon() + { + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/helps/BrandomIcon.gif")); + return ii; + } + + /** + * To clone this icon + * @return New instance of this icon + */ + public BrandomIcon Clone() + { + return new BrandomIcon("/icons/branches/random/random.gif"); + } + + /** + * To copy this icon + * @return New instance of this icon with its attributes set + */ + public Icon Copy() + { + BrandomIcon newWTI = Clone(); + newWTI.setImage(); + return newWTI; + } + + /** + * Algorithm translation for the Translator object to create a text representation of this icon + * @param id_separator To separate ids + * @param id_att_separator To separate id with attribute + * @param att_boundary_begin To start attributes + * @param att_boundary_end To end attributes + * @param att_value_connector To separate attributes and its values + * @param att_separator To separate attributes + * @return Translation + */ + public String getTranslation(String id_separator, String id_att_separator, + String att_boundary_begin, String att_boundary_end, String att_value_connector, String att_separator) + { + String algo = new String(); + algo += "\n"; // to begin with + algo += "branch"; + algo += id_separator; + algo += identifier; + algo += id_separator; + algo += getId(); + algo += id_att_separator; + algo += att_boundary_begin; + algo += att_boundary_end; + return algo; + } + + /** + * Returns a string format of the NQCCode representation of this object + * @param indentation Indentation + * @return The NQC Code + */ + public String getNQCCode(String indentation) + { + String NQCCode = new String(); + String input_port = new String(); + + NQCCode += indentation; + NQCCode += "// random branch \n"; + NQCCode += indentation; + NQCCode += "if(Random(1) == 1)\n"; + return NQCCode; + } + + /** + * Set its own attributes given a string from a text representation of it + * @param att Attributes + * @param att_value_connector Attribute connector + * @param att_separator Attribute separator + */ + public void setAttributes(String att, String att_value_connector, String att_separator) + { + } + +} diff --git a/src/funsoftware/ic/bran/BrotationSensorIcon.java b/src/funsoftware/ic/bran/BrotationSensorIcon.java new file mode 100644 index 0000000..43e0a81 --- /dev/null +++ b/src/funsoftware/ic/bran/BrotationSensorIcon.java @@ -0,0 +1,866 @@ +/* + * BrotationSensorIcon.java + * + * Created on 24 September 2005, 11:55 + * + */ + +package funsoftware.ic.bran; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.st.*; +import funsoftware.var.*; +import funsoftware.consts.*; + +/** + * This class is for the Branch Rotational Sensor Icon of the fUNSoftWare + * @author Thomas Legowo + */ +public class BrotationSensorIcon extends branchIcon{ + + // the local variables + private int port; // with default value being 1, port is the value of the input port of this rotational sensor + private int angle_value; // default value being 16 (1 rotation) + private variable var_angle_value; // alternative to angle_value + + // for algorithm representation, represent this branch rotation sensor icon with an identifier of 4 + private int identifier; + + private int type; // originally typed 1, ">" for greater than + + /** Creates a new instance of BrotationSensorIcon */ + public BrotationSensorIcon() { + } + + /** + * Creates a new instance of BrotationSensorIcon + * @param filepath Source file for this icon + */ + public BrotationSensorIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); + super.setHeight(super.getImage().getImage().getHeight(this)); + port = 1; + angle_value = 16; + identifier = 4; + var_angle_value = null; + type = 1; + setImage(); + } + + /** + * Helps provide the transparent background + * @param g Graphic + */ + protected void paintComponent(java.awt.Graphics g) + { + super.paintComponent(g); + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/branches/rotation/rotation_field.gif")); + g.drawImage(ii.getImage(), 14, 24, this); + } + + // return the port this rotation sensor is operating in + /** + * Get the port value of this icon + * @return Port value + */ + public int getPort() + { + return port; + } + + /** + * Get the angular value of this icon + * @return Angular value + */ + public int getAngleValue() + { + return angle_value; + } + + /** + * To set the prot value of this icon + * @param nport New port value + */ + public void setPort(int nport) + { + port = nport; + } + + /** + * To set the angular value of this branch rotational sensor icon + * @param nlsv New angle value + */ + public void setAngleValue(int nlsv) + { + angle_value = nlsv; + } + + /** + * To set the angular value of this branch rotational sensor icon + * @param var The angle value variable + */ + public void setVarAngle(variable var) + { + var_angle_value = var; + } + + /** + * Sets the new comparator type to this icon + * @param nct New comparator type + */ + public void setComparatorType(int nct) + { + type = nct; + } + + /** + * Gets the comparator type to this icon + * @return Comparator type + */ + public int getComparatorType() + { + return type; + } + + /** + * To set the image of this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + javax.swing.ImageIcon nic; + PicButton pic; + + javax.swing.JPanel jp, jp2; + + jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp.setPreferredSize(new java.awt.Dimension(40, 24)); + + // add le stuffs into le jp + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/branches/rotation/rotationtop.gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + // displays the comparator according to its type + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/branches/comparator/comp"+type+".gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(jp, gridBagConstraints); + + jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp.setPreferredSize(new java.awt.Dimension(40, 16)); + + // do the panel within jp + jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(14, 16)); + + javax.swing.JLabel portLabel = new javax.swing.JLabel(Integer.toString(port)); + portLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + portLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(portLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(jp2, gridBagConstraints); + + // ---------- the light value panel + + jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(26, 16)); + + javax.swing.JLabel angleLabel; + if(var_angle_value == null) + { + angleLabel = new javax.swing.JLabel(Integer.toString(angle_value)); + } + else + { + angleLabel = new javax.swing.JLabel("V"); + } + angleLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + angleLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + angleLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(angleLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(jp2, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(jp, gridBagConstraints); + + jp.setOpaque(false); + setOpaque(false); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * To change the port value of this icon + * @param evt Mouse event + */ + public void changePort(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField = new javax.swing.JTextField(Integer.toString(port)); + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(14,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + javax.swing.JPanel jp; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditModePort(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + // to change the angle value comparator + + /** + * To change the angular value of this branch rotational sensor icon + * @param evt Mouse event + */ + public void changeAngleValue(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField; + if(var_angle_value != null) + { + textField = new javax.swing.JTextField("v"); + } + else + { + textField = new javax.swing.JTextField(Integer.toString(angle_value)); + } + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(26,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditModeAngle(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the comparator type of this icon + * @param evt Mouse event + */ + public void changeComparator(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + ComparatorDialog c_dialog = new ComparatorDialog(null, type, this); + c_dialog.pack(); + c_dialog.setLocationRelativeTo(this); + c_dialog.setVisible(true); + + type = c_dialog.getComparator(); + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + jp.remove(1); + // displays the comparator according to its type + javax.swing.ImageIcon nic = new javax.swing.ImageIcon(getClass().getResource("/icons/branches/comparator/comp"+type+".gif")); + PicButton pic = new PicButton(nic); + java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + // set the states for undo and redo + UndoRedo.update_state(); + + repaint(); + validate(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + // this method is to stop the edit mode of the port value on this branch icon + /** + * Stop the edit mode in port value of this icon + */ + public void stopEditModePort() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + jp.removeAll(); + + // parse the port number + int tmp_port = port; // current port number + try{ + port = Integer.parseInt(text); + if(port > 3 || port < 1) // maximum of 3 input ports + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the input port is invalid.\nIt can be either 1, 2 or 3.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + port = tmp_port; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the input port is invalid.\nPlease enter numbers only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_port != port) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JLabel portLabel = new javax.swing.JLabel(Integer.toString(port)); + portLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + portLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(portLabel, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + } + + /** + * this method is to stop the edit mode of the angle value on this branch icon + */ + public void stopEditModeAngle() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + jp.removeAll(); + + // parse the angle sensor value + int tmp_angle = angle_value; // current port number + try + { + if(text.compareTo("v") == 0 || text.compareTo("V") == 0) + { + if(var_list.Instance().isDefinedVariables() == true || findCurrentAux().getLocalVarList().isEmpty() == false) + { + VarInputDialog vid = new VarInputDialog(null, this, findCurrentAux()); + vid.pack(); + vid.setLocationRelativeTo(this); + vid.setVisible(true); + + if(vid.getUserInput() != null) + { + var_angle_value = vid.getUserInput(); + } + } + else + { + javax.swing.JOptionPane.showMessageDialog(null, + "You have not defined any global variables or local variables to this function or task yet.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + } + else + { + angle_value = Integer.parseInt(text); + var_angle_value = null; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the rotational sensor threshold is invalid.\nPlease enter numbers only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_angle != angle_value || var_angle_value != null) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JLabel angleLabel; + if(var_angle_value == null) + { + angleLabel = new javax.swing.JLabel(Integer.toString(angle_value)); + } + else + { + angleLabel = new javax.swing.JLabel("V"); + } + angleLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + angleLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + angleLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(angleLabel, gridBagConstraints); + jp.setOpaque(false); + + repaint(); + validate(); + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + java.awt.event.MouseListener[] ml = jp.getMouseListeners(); + for(int i=0; i port + sp2 = sp[0].split(att_value_connector); + port = Integer.parseInt(sp2[1]); + + // do the second one --> angle_sensor_value + sp2 = sp[1].split(att_value_connector); + if(sp2[1].substring(0,1).compareTo("V") == 0) // must be a variable + { + var_angle_value = var_list.Instance().getVariable(sp2[1].substring(2)); + if(var_angle_value == null) // must be local, not global + { + var_angle_value = getAux().getVariable(sp2[1].substring(2)); + } + } + else + { + angle_value = Integer.parseInt(sp2[1]); + } + // do the third one --> comparator + sp2 = sp[2].split(att_value_connector); + type = Integer.parseInt(sp2[1]); + } + + /** + * To display an input panel to ask for a variable to be used + * @return The label of the panel + */ + public javax.swing.JLabel getVarLabel() + { + return new javax.swing.JLabel("Rotational Value Threshold"); + } + + /** + * To indicate whether this icon uses a variable + * @param var Variable to be checked + * @return True or false + */ + public Boolean useAVariable(variable var) + { + if(var_angle_value != null) + { + if(var_angle_value.getType() == var.getType() && var_angle_value.getName().compareTo(var.getName()) == 0) + { + return true; + } + } + return false; + } +} diff --git a/src/funsoftware/ic/bran/BtimerIcon.java b/src/funsoftware/ic/bran/BtimerIcon.java new file mode 100644 index 0000000..9de7da9 --- /dev/null +++ b/src/funsoftware/ic/bran/BtimerIcon.java @@ -0,0 +1,870 @@ +/* + * BtimerIcon.java + * + * Created on 17 December 2005, 18:58 + * + */ + +package funsoftware.ic.bran; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.st.*; +import funsoftware.var.*; +import funsoftware.consts.*; + +/** + * This class represents the branch that tests whether the timer is of a certain value + * @author Thomas Legowo + */ +public class BtimerIcon extends branchIcon{ + + // the local variables + + private int timer_number; // with default value being 0, timer number can be 0 to 3 (4 timers in the RCX bot) + private int timer_value; // default value being 50, minimum is 1, unit is in 100ms. + private variable var_timer_value; // alternative to timer_value + + // for algorithm representation, represent a branch timer icon with an identifier of 5 + private int identifier; + + private int type; // originally typed 1, ">" for greater than + + /** + * Creates a new instance of BtimerIcon + */ + public BtimerIcon() { + } + + /** + * Creates a new instance of BtimerIcon + * @param filepath The source file of this icon's graphic + */ + public BtimerIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); + super.setHeight(super.getImage().getImage().getHeight(this)); + timer_number = 0; + timer_value = 50; + identifier = 5; + var_timer_value = null; + type = 1; + setImage(); + } + + /** + * Helps provide the transparent background + * @param g Graphic + */ + protected void paintComponent(java.awt.Graphics g) + { + super.paintComponent(g); + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/branches/timer/timer_field.gif")); + g.drawImage(ii.getImage(), 14, 24, this); + } + + + /** + * Return the timer number is operating in + * @return Timer number + */ + public int getTimer() + { + return timer_number; + } + + /** + * Return the light sensor value threshold of this branch timer icon + * @return Timer value + */ + public int getTimerValue() + { + return timer_value; + } + + /** + * Set the timer number + * @param ntimer New Timer number + */ + public void setTimer(int ntimer) + { + timer_number = ntimer; + } + + /** + * Set the timer value of this icon + * @param ntv New timer value + */ + public void setTimerValue(int ntv) + { + timer_value = ntv; + } + + /** + * Set the timer value of this icon + * @param var The timer value variable + */ + public void setVarTimerVal(variable var) + { + var_timer_value = var; + } + + /** + * Sets the new comparator type to this icon + * @param nct New comparator type + */ + public void setComparatorType(int nct) + { + type = nct; + } + + /** + * Gets the comparator type to this icon + * @return Comparator type + */ + public int getComparatorType() + { + return type; + } + + /** + * Set the image of this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + javax.swing.ImageIcon nic; + PicButton pic; + + javax.swing.JPanel jp, jp2; + + jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp.setPreferredSize(new java.awt.Dimension(40, 24)); + + // add le stuffs into le jp + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/branches/timer/top.gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + // displays the comparator according to its type + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/branches/comparator/comp"+type+".gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(jp, gridBagConstraints); + + jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp.setPreferredSize(new java.awt.Dimension(40, 16)); + + // do the panel within jp + jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(14, 16)); + + javax.swing.JLabel timerNumberLabel = new javax.swing.JLabel(Integer.toString(timer_number)); + timerNumberLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + timerNumberLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + timerNumberLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(timerNumberLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(jp2, gridBagConstraints); + + // ---------- the light value panel + + jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(26, 16)); + + javax.swing.JLabel timerValueLabel; + if(var_timer_value == null) + { + timerValueLabel = new javax.swing.JLabel(Integer.toString(timer_value)); + } + else + { + timerValueLabel = new javax.swing.JLabel("V"); + } + timerValueLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + timerValueLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + timerValueLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(timerValueLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(jp2, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(jp, gridBagConstraints); + + jp.setOpaque(false); + setOpaque(false); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * To change the port value of this icon + * @param evt Mouse event + */ + public void changeTimerNumber(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField = new javax.swing.JTextField(Integer.toString(timer_number)); + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(14,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + javax.swing.JPanel jp; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditModeTimerNumber(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the timer value threshold of this icon + * @param evt Mouse event + */ + public void changeTimerValue(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField; + if(var_timer_value != null) + { + textField = new javax.swing.JTextField("v"); + } + else + { + textField = new javax.swing.JTextField(Integer.toString(timer_value)); + } + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(26,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditModeTimerValue(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the comparator type of this icon + * @param evt Mouse event + */ + public void changeComparator(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + ComparatorDialog c_dialog = new ComparatorDialog(null, type, this); + c_dialog.pack(); + c_dialog.setLocationRelativeTo(this); + c_dialog.setVisible(true); + + type = c_dialog.getComparator(); + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + jp.remove(1); + // displays the comparator according to its type + javax.swing.ImageIcon nic = new javax.swing.ImageIcon(getClass().getResource("/icons/branches/comparator/comp"+type+".gif")); + PicButton pic = new PicButton(nic); + java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + // set the states for undo and redo + UndoRedo.update_state(); + + repaint(); + validate(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * Stop the edit mode of the timer number on this branch icon + */ + public void stopEditModeTimerNumber() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + jp.removeAll(); + + // parse the port number + int tmp_timer_number = timer_number; // current port number + try{ + timer_number = Integer.parseInt(text); + if(timer_number > 3 || timer_number < 0) // values between 0 to 3 only + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the timer number is invalid.\nIt can only be either between 0 and 3.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + timer_number = tmp_timer_number; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the timer number is invalid.\nPlease enter numbers only (0 to 3).\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_timer_number != timer_number) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JLabel timerNumberLabel = new javax.swing.JLabel(Integer.toString(timer_number)); + timerNumberLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + timerNumberLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + timerNumberLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(timerNumberLabel, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + } + + + /** + * Stop the edit mode of the timer value on this branch icon + */ + public void stopEditModeTimerValue() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + jp.removeAll(); + + // parse the light sensor value + int tmp_timer_value = timer_value; // current port number + try + { + if(text.compareTo("v") == 0 || text.compareTo("V") == 0) + { + if(var_list.Instance().isDefinedVariables() == true || findCurrentAux().getLocalVarList().isEmpty() == false) + { + VarInputDialog vid = new VarInputDialog(null, this, findCurrentAux()); + vid.pack(); + vid.setLocationRelativeTo(this); + vid.setVisible(true); + + if(vid.getUserInput() != null) + { + var_timer_value = vid.getUserInput(); + } + } + else + { + javax.swing.JOptionPane.showMessageDialog(null, + "You have not defined any global variables or local variables to this function or task yet.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + } + else + { + timer_value = Integer.parseInt(text); + if(timer_value < 1) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the timer threshold is invalid.\nMinimum value is 1.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + timer_value = tmp_timer_value; + } + else + { + var_timer_value = null; + } + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the timer threshold is invalid.\nPlease enter numbers only (Greater than 1).\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_timer_value != timer_value || var_timer_value != null) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JLabel timerValueLabel; + if(var_timer_value == null) + { + timerValueLabel = new javax.swing.JLabel(Integer.toString(timer_value)); + } + else + { + timerValueLabel = new javax.swing.JLabel("V"); + } + timerValueLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + timerValueLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + timerValueLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(timerValueLabel, gridBagConstraints); + jp.setOpaque(false); + + repaint(); + validate(); + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + java.awt.event.MouseListener[] ml = jp.getMouseListeners(); + for(int i=0; i port + sp2 = sp[0].split(att_value_connector); + timer_number = Integer.parseInt(sp2[1]); + + // do the second one --> timer_value + sp2 = sp[1].split(att_value_connector); + if(sp2[1].substring(0,1).compareTo("V") == 0) // must be a variable + { + var_timer_value = var_list.Instance().getVariable(sp2[1].substring(2)); + if(var_timer_value == null) // must be local, not global + { + var_timer_value = getAux().getVariable(sp2[1].substring(2)); + } + } + else + { + timer_value = Integer.parseInt(sp2[1]); + } + // do the third one --> comparator + sp2 = sp[2].split(att_value_connector); + type = Integer.parseInt(sp2[1]); + } + + /** + * To display an input panel to ask for a variable to be used + * @return The label of the panel + */ + public javax.swing.JLabel getVarLabel() + { + return new javax.swing.JLabel("Timer Value Threshold"); + } + + /** + * To indicate whether this icon uses a variable + * @param var Variable to be checked + * @return True or false + */ + public Boolean useAVariable(variable var) + { + if(var_timer_value != null) + { + if(var_timer_value.getType() == var.getType() && var_timer_value.getName().compareTo(var.getName()) == 0) + { + return true; + } + } + return false; + } +} diff --git a/src/funsoftware/ic/bran/BtouchSensorIcon.java b/src/funsoftware/ic/bran/BtouchSensorIcon.java new file mode 100644 index 0000000..5bbce1d --- /dev/null +++ b/src/funsoftware/ic/bran/BtouchSensorIcon.java @@ -0,0 +1,509 @@ +/* + * BtouchSensorIcon.java + * + * Created on 3 August 2005, 21:11 + */ + +package funsoftware.ic.bran; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.st.*; + +/** + * This class is for the Branch Touch Sensor Icon of the fUNSoftWare + * @author Thomas Legowo + * + */ +public class BtouchSensorIcon extends branchIcon{ + + private int port; // with default value being 1, port is the value of the input port of this touch sensor + + // for algorithm representation, represent a branch touch sensor icon with an identifier of 1 + private int identifier; + + private int type; // originally typed 1, "Y" for sensor touched + + /** Creates a new instance of BtouchSensorIcon */ + public BtouchSensorIcon() { + } + + /** + * Creates a new instance of BtouchSensorIcon + * @param filepath The source file of the BtouchSensorIcon icon + */ + public BtouchSensorIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); // for startIcon the size of the icon is 26x61 + port = 1; + identifier = 1; + type = 1; + setImage(); + } + + /** + * Get the port value of this icon + * @return Port value + */ + public int getPort() + { + return port; + } + + /** + * Set the port value of this icon + * @param nport New port value + */ + public void setPort(int nport) + { + port = nport; + } + + /** + * Sets the new comparator type to this icon + * @param nct New comparator type + */ + public void setComparatorType(int nct) + { + type = nct; + } + + /** + * Gets the comparator type to this icon + * @return Comparator type + */ + public int getComparatorType() + { + return type; + } + + /** + * To set the image of this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + javax.swing.ImageIcon nic; + + javax.swing.JPanel jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp.setPreferredSize(new java.awt.Dimension(40, 24)); + + // add le stuffs into le jp + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/branches/touch/touch_if_top.gif")); + PicButton pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + // displays the comparator according to its type + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/branches/touch/comp"+type+".gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(jp, gridBagConstraints); + + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(40, 16)); + + javax.swing.JPanel jp3 = new javax.swing.JPanel(); + jp3.setLayout(new java.awt.GridBagLayout()); + jp3.setPreferredSize(new java.awt.Dimension(15, 16)); + + javax.swing.JLabel portLabel = new javax.swing.JLabel(Integer.toString(port)); + portLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + portLabel.setPreferredSize(new java.awt.Dimension(15, 16)); + portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp3.add(portLabel, gridBagConstraints); + jp3.setOpaque(false); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(jp3, gridBagConstraints); + + jp3 = new javax.swing.JPanel(); + jp3.setLayout(new java.awt.GridBagLayout()); + jp3.setPreferredSize(new java.awt.Dimension(25, 16)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp2.add(jp3, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(jp2, gridBagConstraints); + + jp3.setOpaque(false); + jp2.setOpaque(false); + setOpaque(false); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * To change the port value of this icon + * @param evt Mouse event + */ + public void changePort(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField = new javax.swing.JTextField(Integer.toString(port)); + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(15,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + java.awt.GridBagConstraints gridBagConstraints; + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditMode(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the comparator type of this icon + * @param evt Mouse event + */ + public void changeComparator(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.ImageIcon nic = new javax.swing.ImageIcon(); + if(type == 2) + { + type = 1; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/branches/touch/comp1.gif")); + } + else if(type == 1) + { + type = 2; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/branches/touch/comp2.gif")); + } + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + jp.remove(1); + // displays the comparator according to its type + PicButton pic = new PicButton(nic); + java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + // set the states for undo and redo + UndoRedo.update_state(); + + repaint(); + validate(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * Stop edit mode of this icon + */ + public void stopEditMode() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + + // parse the unit of the time, second will be taken as default should the user does not indicate + // the unit + int tmp_port = port; // current port number + try{ + port = Integer.parseInt(text); + if(port > 3 || port <= 0) // maximum of 3 input ports + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the input port is invalid.\nIt can be either 1, 2 or 3.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + port = tmp_port; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the input port is invalid.\nPlease enter numbers only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_port != port) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + java.awt.GridBagConstraints gridBagConstraints; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JLabel portLabel = new javax.swing.JLabel(Integer.toString(port)); + portLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + portLabel.setPreferredSize(new java.awt.Dimension(15, 16)); + portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(portLabel, gridBagConstraints); + + repaint(); + validate(); + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + java.awt.event.MouseListener[] ml = jp.getMouseListeners(); + for(int i=0; i port + sp2 = sp[0].split(att_value_connector); + port = Integer.parseInt(sp2[1]); + + // do the second one --> comparator + sp2 = sp[1].split(att_value_connector); + type = Integer.parseInt(sp2[1]); + } +} diff --git a/src/funsoftware/ic/bran/branchIcon.java b/src/funsoftware/ic/bran/branchIcon.java new file mode 100644 index 0000000..a0a9f62 --- /dev/null +++ b/src/funsoftware/ic/bran/branchIcon.java @@ -0,0 +1,567 @@ +/* + * branchIcon.java + * + * Created on 5 September 2005, 01:08 + * + */ + +package funsoftware.ic.bran; + +import funsoftware.ic.*; +import funsoftware.ic.loo.*; +import funsoftware.wr.*; + +/** + * This method is a branch type of icons. + * All kinds of branchIcon extends Icon + * @author Thomas Legowo + */ +public class branchIcon extends Icon{ + + // the private attributes + private Icon rightNeighbourTop; + private Icon rightNeighbourBottom; + + private Icon rightNeighbour; // since a branch is regarded as one entity, the right Neighbour + // is the right neighbour of its end branch + private Icon leftNeighbour; + + // need to point at the end of the branch + private Icon endBranch; + + private Wire leftWire; + // branches + private Wire rightWireTop; + private Wire rightWireBottom; + + // variables for the icon's vertical repositioning + private int toptopVerticalSize; + private int topbottomVerticalSize; + + private int bottomtopVerticalSize; + private int bottombottomVerticalSize; + + private java.util.Vector if_members; // the icons enclosed within this branch + private java.util.Vector else_members; // the icons enclosed within this branch + + /** Creates a new instance of branchIcon */ + public branchIcon() { + } + + /** + * Creates a new instance of branchIcon + * @param filepath Source file for the image of this branch typed icon + */ + public branchIcon(String filepath) { + super(filepath); + toptopVerticalSize = 0; // initial value = 0 + topbottomVerticalSize = 0; // initial value = 0 + bottomtopVerticalSize = 0; // initial value = 0 + bottombottomVerticalSize = 0; // initial value = 0 + if_members = new java.util.Vector(); + else_members = new java.util.Vector(); + } + + // The get and set methods + + /** + * Gets right neighbour top + * @return Right neighbour top + */ + public Icon getRightNeighbourTop() + { + return rightNeighbourTop; + } + + /** + * Gets the right neighbour bottom + * @return Right neighbour bottom + */ + public Icon getRightNeighbourBottom() + { + return rightNeighbourBottom; + } + + /** + * Gets the right neighbour of this icon + * @return Right neighbour + */ + public Icon getRightNeighbour() + { + return rightNeighbour; + } + + /** + * Gets the left neighbour of this icon + * @return Left neighbour + */ + public Icon getLeftNeighbour() + { + return leftNeighbour; + } + + /** + * Gets the left wire of this icon + * @return Left wire + */ + public Wire getLeftWire() + { + return leftWire; + } + + /** + * Gets the right wire top of this icon + * @return Right wire top + */ + public Wire getRightWireTop() + { + return rightWireTop; + } + + /** + * Gets the right wire bottom of this icon + * @return Right wire bottom + */ + public Wire getRightWireBottom() + { + return rightWireBottom; + } + + /** + * Sets the right neighbour icon top + * @param nicon New right neighbour icon top + */ + public void setRightNeighbourTop(Icon nicon) + { + rightNeighbourTop = nicon; + } + + /** + * Sets the right neighbour icon bottom + * @param nicon New right neighbour icon bottom + */ + public void setRightNeighbourBottom(Icon nicon) + { + rightNeighbourBottom = nicon; + } + + /** + * Sets the right neighbour of this icon + * @param nicon Right neighbour + */ + public void setRightNeighbour(Icon nicon) + { + rightNeighbour = nicon; + } + + /** + * Sets the left neighbour of this icon + * @param nicon Left neighbour + */ + public void setLeftNeighbour(Icon nicon) + { + leftNeighbour = nicon; + } + + /** + * Sets the left wire of this icon + * @param nwire New left wire + */ + public void setLeftWire(Wire nwire) + { + leftWire = nwire; + } + + /** + * Sets the right wire top of this icon + * @param nwire New right wire top + */ + public void setRightWireTop(Wire nwire) + { + rightWireTop = nwire; + } + + /** + * Sets the right wire bottom of this icon + * @param nwire New right wire bottom + */ + public void setRightWireBottom(Wire nwire) + { + rightWireBottom = nwire; + } + + // dealing with the joinEndBranchIcon of this icon + /** + * Gets the endbranch icon of this branch icon + * @return End branch icon + */ + public Icon getEndBranch() + { + return endBranch; + } + + /** + * Sets the end branch icon of this branch icon + * @param neb New end branch + */ + public void setEndBranch(Icon neb) + { + endBranch = neb; + } + + // the top and bottom vertical size methods + /** + * Gets the top of the branch's top part vertical size + * @return Top of the branch's top part vertical size + */ + public int getTopTopVerticalSize() + { + return toptopVerticalSize; + } + + /** + * Gets the bottom of the branch's top part vertical size + * @return Bottom of the branch's top part vertical size + */ + public int getTopBottomVerticalSize() + { + return topbottomVerticalSize; + } + + /** + * Gets the top of the branch's bottom part vertical size + * @return Top of the branch's bottom part vertical size + */ + public int getBottomTopVerticalSize() + { + return bottomtopVerticalSize; + } + + /** + * Gets the bottom of the branch's bottom part vertical size + * @return Bottom of the branch's bottom part vertical size + */ + public int getBottomBottomVerticalSize() + { + return bottombottomVerticalSize; + } + + /** + * Sets the top of the branch's top part vertical size + * @param ns Vertical size + */ + public void setTopTopVerticalSize(int ns) + { + toptopVerticalSize = ns; + } + + /** + * Sets the bottom of the branch's top part vertical size + * @param ns Vertical size + */ + public void setTopBottomVerticalSize(int ns) + { + topbottomVerticalSize = ns; + } + + /** + * Sets the top of the branch's bottom part vertical size + * @param ns Vertical size + */ + public void setBottomTopVerticalSize(int ns) + { + bottomtopVerticalSize = ns; + } + + /** + * Sets the bottom of the branch's bottom part vertical size + * @param ns Vertical size + */ + public void setBottomBottomVerticalSize(int ns) + { + bottombottomVerticalSize = ns; + } + + // this function will never return null (if icon does not exist) since the methods that called this method would + // have checked whether this icon exists in one of the branches anyway + /** + * Determines whether an icon is in the if part of else part of this branch + * @param icon Icon + * @return Value = 0 -> icon in if part, Value = 1 -> icon in else part + */ + public int determineMember(Icon icon) + { + int ret_val = 0; + Icon tmp_ic; + // do the if_branch first + for(int i=0; i getIfMembers() + { + return if_members; + } + + /** + * Get icons in the bottom(else) part of the branch + * @return Set of icons + */ + public java.util.Vector getElseMembers() + { + return else_members; + } + + /** + * Add a new member into this branch icon + * @param new_icon New icon + * @param right_icon Icon to the right of the new icon + */ + public void addMember(Icon new_icon, Icon right_icon) + { + int ypos = new_icon.getCoordinate().getY(); + int yb = new_icon.getParentIcon().getCoordinate().getY(); + if(ypos > yb) // add element to else + { + addToVect(new_icon, right_icon, 1); + } + else // add element to if + { + addToVect(new_icon, right_icon, 0); + } + } + + /** + * Delete an icon off the membership list of this branch icon + * @param icon Icon + */ + public void delMember(Icon icon) + { + int ypos = icon.getCoordinate().getY(); + int yb = icon.getParentIcon().getCoordinate().getY(); + + if(ypos > yb) // delete element from else + { + for(int i=0; i(); + else_members = new java.util.Vector(); + } + + // type = 0, add to if, type = 1, add to else + private void addToVect(Icon new_icon, Icon right_icon, int type) + { + int found=0; + if(type == 0) + { + for(int i=0; i tallestIfMember and tallestElseMember are to be used only to determine + // whether it is appropriate to collapse a branch inward + // similar to the ones in repeat, but need to do it twice for if and else part of the branch + /** + * Gets the icon with the greatest TopBottom vertical size + * @return Icon with the greatest TopBottom vertical size + */ + public Icon tallestIfMemberBottom() + { + Icon ret_ic = new Icon(); + int max_ver = -1; + for(int i = 0; imax_ver) + { + max_ver = vert; + ret_ic = tmp_ic; + } + } + return ret_ic; + } + + /** + * Gets the icon with the greatest TopTop vertical size + * @return Icon with the greatest TopTop vertical size + */ + public Icon tallestIfMemberTop() + { + Icon ret_ic = new Icon(); + int max_ver = -1; + for(int i = 0; imax_ver) + { + max_ver = vert; + ret_ic = tmp_ic; + } + } + return ret_ic; + } + + /** + * Gets the icon with the greatest BottomTop vertical size + * @return Icon with the greatest BottomTop vertical size + */ + public Icon tallestElseMemberTop() + { + Icon ret_ic = new Icon(); + int max_ver = -1; + // now iterate through the else branch + for(int i = 0; imax_ver) + { + max_ver = vert; + ret_ic = tmp_ic; + } + } + return ret_ic; + } + + /** + * Gets the icon with the greatest BottomBottom vertical size + * @return Icon with the greatest BottomBottom vertical size + */ + public Icon tallestElseMemberBottom() + { + Icon ret_ic = new Icon(); + int max_ver = -1; + // now iterate through the else branch + for(int i = 0; imax_ver) + { + max_ver = vert; + ret_ic = tmp_ic; + } + } + return ret_ic; + } + + +} diff --git a/src/funsoftware/ic/ev/ChooseEventDialog.java b/src/funsoftware/ic/ev/ChooseEventDialog.java new file mode 100644 index 0000000..9e45d78 --- /dev/null +++ b/src/funsoftware/ic/ev/ChooseEventDialog.java @@ -0,0 +1,268 @@ +/* + * ChooseEventDialog.java + * + * Created on 3 February 2006, 09:26 + * + */ + +package funsoftware.ic.ev; + +import funsoftware.events.*; +import funsoftware.functs.*; +import funsoftware.struct.*; +import funsoftware.consts.*; + +/** + * This class is a dialog window prompting user for a event to be selected as the event-monitor-to-start. + * An instance of this class will be created as soon as users insert a start event icon onto the programming window + * @author Thomas Legowo + */ +public class ChooseEventDialog extends javax.swing.JDialog{ + + // private variables + private javax.swing.JComboBox events; + private javax.swing.JLabel instead_of_events; + + java.awt.GridBagConstraints gridBagConstraints; + + private javax.swing.JPanel jp_top; + private javax.swing.JPanel jp; + private javax.swing.JLabel jl; + private javax.swing.JButton button; + + private String msg_top; + private String guide_top; + + // return value + private monitorEvent ret_val; + + /** + * Creates a new instance of ChooseEventDialog + * @param frame The frame + * @param tobe_compared The auxiliary of the event + */ + public ChooseEventDialog(java.awt.Frame frame, auxiliary tobe_compared) + { + super(frame, true); + setTitle("Set Event"); + + ret_val = null; + + events = new javax.swing.JComboBox(); + + // input the tasks + java.util.Vector al = aux_list.Instance().getAuxiliaries(); + + if(tobe_compared instanceof function) + { + function tmp_func = (function)tobe_compared; + int level = tmp_func.getLevel(); + for(int i=1; i ret; + + /** + * Creates a new instance of monitorEventDialog + * @param frame The frame + * @param input1 The event + * @param edit_or_set To determine whether this is to initialize an event or to edit it + */ + public monitorEventDialog(java.awt.Frame frame, monitorEvent input1, int edit_or_set) { + super(frame, true); + this.frame = frame; + this.input1 = input1; + + ret = new java.util.Vector(); + + if(edit_or_set == 0) + { + setTitle("Set Event Monitor Properties"); + } + else + { + setTitle("Edit Event Monitor Properties"); + } + + if(input1 != null) + { + event_name = input1.getName(); + auxiliary aux_point = input1.getAuxPoint(); + } + else + { + event_name = ""; + } + eventName = new javax.swing.JTextField(event_name, 12); + + evMonitorLevel = new javax.swing.JTextField("", 10); + + msg_level = "Level"; + guide_level = "Values (minimum = 1)"; + + type = new javax.swing.JComboBox(); + type.addItem("Global"); + type.addItem("Local"); + + auxiliary_combo = new javax.swing.JComboBox(); + java.util.Vector auxs = aux_list.Instance().getAuxiliaries(); + for(int i=1; i input_list = input1.getMonitoredEvents(); + for(int i=0; i ev_list = event_number_tracker.Instance().getEvents(); + for(int i=1; i(); + + // check the validity for the input name first + if(eventName.getText().compareTo(event_name) == 0 && eventName.getText().compareTo("") != 0) // must be valid already + { + event_name = eventName.getText(); + int check = checkEvMonitorLevel(); + if(check == 0) + { + checkEventsMonitored(); + } + } + else + { + String tmp = eventName.getText(); + if(tmp.compareTo("") == 0) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Please input at least 1 character.", + "Input Invalid", javax.swing.JOptionPane.WARNING_MESSAGE); + } + else + { + if(aux_list.Instance().checkName(tmp) == 0) + { + event_name = eventName.getText(); + int check = checkEvMonitorLevel(); + if(check == 0) + { + checkEventsMonitored(); + } + } + else if(aux_list.Instance().checkName(tmp) == 1) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value is invalid.\nThe name has been used.\nPlease Try Again.", + "Input Invalid", javax.swing.JOptionPane.WARNING_MESSAGE); + } + else if(aux_list.Instance().checkName(tmp) == 2) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value is invalid.\nPlease enter string and numbers only.\nFirst character has to be a letter.\nPlease Try Again.", + "Input Invalid", javax.swing.JOptionPane.WARNING_MESSAGE); + } + } + } + } + + /** + * Check whether the value entered by the user is valid (i.e. Integer and greater than 1) + */ + private int checkEvMonitorLevel() + { + try + { + int level = Integer.parseInt(evMonitorLevel.getText()); + + if(level < 1) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for event monitor level is invalid.\nPlease enter numbers greater than one only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + evMonitorLevel.requestFocusInWindow(); + return 1; + } + else + { + ret_level = Integer.parseInt(evMonitorLevel.getText()); + return 0; + } + } + catch(RuntimeException re) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for event monitor level is invalid.\nPlease enter numbers greater than one only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + evMonitorLevel.requestFocusInWindow(); + return 1; + } + } + + /** + * Check and fills in the events to be monitored list + */ + private void checkEventsMonitored() + { + int lim = events.getComponentCount(); + int can_close = 0; + if(lim == 0) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Please enter at least one event to be monitored.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + can_close = 1; + } + else + { + for(int i=0; i getEventsMonitored() { + return ret; + } + + /** This method clears the dialog and hides it. */ + public void clearAndHide() { + eventName.setText(null); + setVisible(false); + } + + +} diff --git a/src/funsoftware/ic/ev/startEvent.java b/src/funsoftware/ic/ev/startEvent.java new file mode 100644 index 0000000..63db4ee --- /dev/null +++ b/src/funsoftware/ic/ev/startEvent.java @@ -0,0 +1,322 @@ +/* + * startEvent.java + * + * Created on 1 February 2006, 13:07 + * + */ + +package funsoftware.ic.ev; + +import funsoftware.ic.obj.*; +import funsoftware.inter.*; +import funsoftware.ic.*; +import funsoftware.ic.others.*; +import funsoftware.ic.tsk.*; +import funsoftware.ic.func.*; +import funsoftware.consts.*; +import funsoftware.struct.*; +import funsoftware.events.*; +import funsoftware.comp.*; + +/** + * This class represents an icon that starts a specified event + * @author Thomas Legowo + */ +public class startEvent extends objectIcon{ + + // private variables + private int num_id; // id of the event to be started as given by the eventWindow class + private String name; // name of this event as given by the user + // for algorithm representation, represent a start event icon with an identifier of 15 + private int identifier; + + // the eventmonitor this icon is starting + private monitorEvent the_event; + + /** Creates a new instance of startEvent */ + public startEvent() { + } + + /** + * Creates a new instance of startEvent + * @param filepath The filepath of the icon's image + */ + public startEvent(String filepath) { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); + identifier = 15; + name = ""; + setImage(); + } + + /** + * Alters the id of the event this icon is representing + * @param i New event id + */ + public void setNumId(int i) + { + num_id = i; + } + + /** + * Returns the id of the event this icon is representing + * @return event id + */ + public int getNumId() + { + return num_id; + } + + /** + * To set the event monitor this icon is pointing to + * @param ev The event monitor this icon is pointing to + */ + public void setEventMonitor(monitorEvent ev) + { + the_event = ev; + num_id = the_event.getNumId(); + name = the_event.getName(); + } + + /** + * Returns the event monitor this icon is connected to + * @return The event monitor this icon is connected to + */ + public monitorEvent getEventMonitor() + { + return the_event; + } + + /** + * To set the name of this icon + * @param n The name of the event this icon is pointing to + */ + public void setName(String n) + { + name = n; + } + + /** + * Returns this event icon's name + * @return event name + */ + public String getName() + { + return name; + } + + /** + * To set the image of this event icon + */ + public void setImage() + { + removeAll(); + setLayout(new java.awt.GridBagLayout()); + java.awt.GridBagConstraints gridBagConstraints; + + // creating the top panel + javax.swing.ImageIcon nic; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/events/start/start_top.gif")); + PicButton pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(pic, gridBagConstraints); + + javax.swing.JLabel nameLabel = new javax.swing.JLabel(name); + nameLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + nameLabel.setPreferredSize(new java.awt.Dimension(40, 16)); + nameLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + setOpaque(false); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(nameLabel, gridBagConstraints); + + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * To clone this icon + * @return New instance of this icon + */ + public startEvent Clone() + { + return new startEvent("/icons/events/start/start.gif"); + } + + /** + * To copy this icon + * @return New instance of this icon with its attributes set + */ + public Icon Copy() + { + startEvent newBTI = Clone(); + newBTI.setNumId(num_id); + newBTI.setEventMonitor(the_event); + newBTI.setName(name); + newBTI.setImage(); + return newBTI; + } + + /** + * Get the help title of this start event icon + * @return Help title + */ + public String getHelpTitle() + { + String s = "Start Event Monitor Icon"; + return s; + } + + /** + * Get help message of this start event icon + * @return Help message + */ + public String getHelpMsg() + { + String s = "DETAILS:"; + s+="\n\nThe event started: "; + java.util.Vector al = aux_list.Instance().getAuxiliaries(); + s+=al.get(num_id).getName(); + + return s; + } + + /** + * Get the description of this icon + * @return Help Description + */ + public String getHelpDesc() + { + String s = "This icon calls and starts\nto monitor a specified event."; + return s; + } + + /** + * Get help picture of this icon + * @return Help picture + */ + public javax.swing.Icon getHelpIcon() + { + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/helps/startEvent.gif")); + return ii; + } + + + /** + * Algorithm translation for the Translator object to create a text representation of this icon + * @param id_separator To separate ids + * @param id_att_separator To separate id with attribute + * @param att_boundary_begin To start attributes + * @param att_boundary_end To end attributes + * @param att_value_connector To separate attributes and its values + * @param att_separator To separate attributes + * @return Translation + */ + public String getTranslation(String id_separator, String id_att_separator, + String att_boundary_begin, String att_boundary_end, String att_value_connector, String att_separator) + { + String algo = new String(); + algo += "\n"; // to begin with + algo += "object"; + algo += id_separator; + algo += identifier; + algo += id_att_separator; + algo += att_boundary_begin; + algo += "name"+att_value_connector; + algo += name; + algo += att_boundary_end; + return algo; + } + + /** + * Returns a string format of the NQCCode representation of this object + * @return The NQC Code + * @param num_indent The number of indentation + * @param indentation Indentation + */ + public String getNQCCode(String indentation, int num_indent) + { + String NQCCode = new String(); + NQCCode += the_event.getNQCEventHeader(indentation); + NQCCode += Translator.getBodyNQCCode(the_event.getBeginIcon(), num_indent+1); + return NQCCode; + } + + /** + * Set its own attributes given a string from a text representation of it + * @param att Attributes + * @param att_value_connector Attribute connector + * @param att_separator Attribute separator + */ + public void setAttributes(String att, String att_value_connector, String att_separator) + { + String[] sp = att.split(att_separator); + String[] sp2 = new String[2]; + + // do the first one --> event name + sp2 = sp[0].split(att_value_connector); + name = sp2[1]; + } + + /** + * Programming window where this function icon is on + * @return Programming window + */ + public ProgWindow getIndividualProgWindow() + { + Icon parent = new Icon(); + ProgWindow ret_val = new ProgWindow(); + while(true) + { + if(parent instanceof startIcon) + { + if(parent instanceof startFunctionIcon) + { + ret_val = ((startFunctionIcon)parent).getProgWindow(); + } + else if(parent instanceof startTaskIcon) + { + ret_val = ((startTaskIcon)parent).getProgWindow(); + } + else if(parent instanceof startEventIcon) + { + ret_val = ((startEventIcon)parent).getProgWindow(); + } + break; + } + else + { + parent = this.getParentIcon(); + } + } + return ret_val; + } + + /** + * Returns scroll pane of the individual programming window + * @return Scroll Pane + */ + public javax.swing.JScrollPane getIndividualScroller() + { + Icon parent = new Icon(); + javax.swing.JScrollPane ret_val = new javax.swing.JScrollPane(); + while(true) + { + if(parent instanceof startIcon) + { + ret_val = ((startIcon)parent).getScroller(); + break; + } + else + { + parent = this.getParentIcon(); + } + } + + return ret_val; + } +} diff --git a/src/funsoftware/ic/ev/startEventIcon.java b/src/funsoftware/ic/ev/startEventIcon.java new file mode 100644 index 0000000..055eed8 --- /dev/null +++ b/src/funsoftware/ic/ev/startEventIcon.java @@ -0,0 +1,95 @@ +/* + * startEventIcon.java + * + * Created on 2 February 2006, 10:30 + * + */ + +package funsoftware.ic.ev; + +import funsoftware.ic.*; +import funsoftware.inter.*; +import funsoftware.ic.others.*; +import funsoftware.ic.PicButton; +import funsoftware.events.*; + +/** + * To indicate a start on a sequence of icons to be executed during an event procedure + * @author Thomas Legowo + */ +public class startEventIcon extends startIcon{ + + private monitorEvent ev; + + /** Creates a new instance of beginEventIcon */ + public startEventIcon() { + } + + /** + * Creates a new instance of beginEventIcon + * @param filepath Source file of the icon's image + */ + public startEventIcon(String filepath) + { + super(filepath); + } + + /** + * Sets the event monitor this starting event icon is associated to + * @param ev the event monitor + */ + public void setEventMonitor(monitorEvent ev) + { + this.ev = ev; + } + + /** + * To return the event monitor + * @return The event monitor + */ + public monitorEvent getEventMonitor() + { + return ev; + } + + /** + * To clone this icon + * @return New instance of this icon + */ + public startEventIcon Clone() + { + return new startEventIcon("/icons/closures/argument.gif"); + } + + /** + * Algorithm translation for the Translator object to create a text representation of this icon + * @param id_separator To separate ids + * @param id_att_separator To separate id with attribute + * @param att_boundary_begin To start attributes + * @param att_boundary_end To end attributes + * @param att_value_connector To separate attributes and its values + * @param att_separator To separate attributes + * @return Translation + */ + public String getTranslation(String id_separator, String id_att_separator, + String att_boundary_begin, String att_boundary_end, String att_value_connector, String att_separator) + { + String algo = new String(); + algo += "\nstartmonitorevent"; + algo += id_separator; + algo += ev.getNumId(); + return algo; + } + + /** + * Returns a string format of the NQCCode representation of this object + * @param indentation Indentation + * @return The NQC Code + */ + public String getNQCCode(String indentation) + { + String NQCCode = new String(); + NQCCode += "\n"+indentation+"{\n"; + return NQCCode; + } +} diff --git a/src/funsoftware/ic/func/ChooseFunctionDialog.java b/src/funsoftware/ic/func/ChooseFunctionDialog.java new file mode 100644 index 0000000..0f516c1 --- /dev/null +++ b/src/funsoftware/ic/func/ChooseFunctionDialog.java @@ -0,0 +1,188 @@ +/* + * ChooseFunctionDialog.java + * + * Created on 8 January 2006, 21:16 + * + */ + +package funsoftware.ic.func; + +import funsoftware.consts.*; +import funsoftware.struct.*; +import funsoftware.functs.*; + +/** + * This class is a dialog window prompting user for a function to be called + * An instance of this class will be created as soon as users insert a function icon onto the programming window + * @author Thomas Legowo + */ +public class ChooseFunctionDialog extends javax.swing.JDialog{ + + // private variables + private javax.swing.JComboBox functions; + + java.awt.GridBagConstraints gridBagConstraints; + + private javax.swing.JPanel jp_top; + private javax.swing.JPanel jp; + private javax.swing.JLabel jl; + private javax.swing.JButton button; + + private String msg_top; + private String guide_top; + + // return value + private int ret_val; + + /** + * Creates a new instance of ChooseFunctionDialog + * @param frame The frame + * @param f The function + */ + public ChooseFunctionDialog(java.awt.Frame frame, function f) { + super(frame, true); + setTitle("Set Function"); + + ret_val = 1; // default num_id of the selected function + + functions = new javax.swing.JComboBox(); + + // input the tasks + java.util.Vector al = aux_list.Instance().getAuxiliaries(); + for(int i=1; i ret_val; + + /** + * Creates a new instance of FunctionArgumentDialog + * @param frame The frame + * @param fu The function + * @param current_aux Current auxiliary + * @param fic The function icon + */ + public FunctionArgumentDialog(java.awt.Frame frame, function fu, auxiliary current_aux, functionIcon fic) { + super(frame, true); + this.frame = frame; + this.current_aux = current_aux; + ret_val = new java.util.Vector(); + + setTitle("Set Function Call and Arguments"); + + jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + arguments = new javax.swing.JPanel(); + arguments.setLayout(new javax.swing.BoxLayout(arguments, javax.swing.BoxLayout.Y_AXIS)); + jp_bottom = new javax.swing.JPanel(); + jp_bottom.setLayout(new java.awt.GridBagLayout()); + + // put in the arguments display first + int total = fu.getArguments().size(); + for(int i=0; i list_var = current_aux.getVariables(); + if(list_var.size() > 1) + { + jcb.addItem("Variable"); + for(int i2=1; i2(); + + for(int i=0; i getUserInput() { + return ret_val; + } + + /** + * This method reacts to state changes in the combo box containing the types of an operand. + * @param row The position of the arguments + * @param e PropertyChangeEvent + */ + public void typeOperAction(java.awt.event.ActionEvent e, int row) { + String selected = new String(); + + javax.swing.JPanel tmp = (javax.swing.JPanel)arguments.getComponent(row); + javax.swing.JTextField jtf = (javax.swing.JTextField)tmp.getComponent(1); + javax.swing.JComboBox selection = (javax.swing.JComboBox)tmp.getComponent(2); + selected = (String)selection.getSelectedItem(); + javax.swing.JComboBox jcb = (javax.swing.JComboBox)tmp.getComponent(3); + if(selected.compareTo("Constant") == 0) + { + jtf.setVisible(true); + jcb.setVisible(false); + } + else if(selected.compareTo("Variable") == 0) + { + jcb.setVisible(true); + jtf.setVisible(false); + } + pack(); + setLocationRelativeTo(frame); + repaint(); + } +} diff --git a/src/funsoftware/ic/func/FunctionNameDialog.java b/src/funsoftware/ic/func/FunctionNameDialog.java new file mode 100644 index 0000000..0bb79c0 --- /dev/null +++ b/src/funsoftware/ic/func/FunctionNameDialog.java @@ -0,0 +1,472 @@ +/* + * FunctionNameDialog.java + * + * Created on 30 December 2005, 16:52 + * + */ + +package funsoftware.ic.func; + +import funsoftware.consts.*; +import funsoftware.struct.*; +import funsoftware.var.*; + +/** + * This class acts as a pop up window prompting the user for a name and arguments for the newly-to-be introduced function. + * The pop up window also asks for a level to be set on the function. + * This class also ensures that the inserted name is unique and the variables indicated as arguments exist and are valid. + * @author Thomas Legowo + */ +public class FunctionNameDialog extends javax.swing.JDialog{ + + // private variables + private javax.swing.JTextField functionName; + private javax.swing.JTextField functionLevel; + + java.awt.GridBagConstraints gridBagConstraints; + + private javax.swing.JPanel jp; + private javax.swing.JPanel jp_top; + private javax.swing.JPanel arguments; + private javax.swing.JPanel middle; + private javax.swing.JPanel jp_bottom; + private javax.swing.JLabel jl; + private javax.swing.JButton button; + + + private String msg_top; + private String guide_top; + + private String msg_middle; // for the function levels + private String guide_middle; + + // return values + private String[] ret_val; + private local_var_list arg_list; + private String input; + + /** + * Creates a new instance of FunctionNameDialog + * @param frame The frame + * @param input1 The name of the function + * @param type Whether to set or edit the function + */ + public FunctionNameDialog(java.awt.Frame frame, String input1, int type) { + super(frame, true); + if(type == 0) + { + setTitle("Set Function Name and Arguments"); + } + else + { + setTitle("Edit Function Name"); + } + + arg_list = new local_var_list(); + ret_val = new String[2]; + input = input1; + + functionName = new javax.swing.JTextField(input1, 10); + functionLevel = new javax.swing.JTextField("", 10); + + msg_top = "Name"; + guide_top = "At least 1 character"; + + msg_middle = "Level"; + guide_middle = "Values (minimum = 1)"; + + arguments = new javax.swing.JPanel(); + arguments.setLayout(new javax.swing.BoxLayout(arguments, javax.swing.BoxLayout.Y_AXIS)); + + jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp_top = new javax.swing.JPanel(); + jp_top.setLayout(new java.awt.GridBagLayout()); + + jl = new javax.swing.JLabel(msg_top); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_top.add(jl, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 8, 5, 5); + jp_top.add(functionName, gridBagConstraints); + + jl = new javax.swing.JLabel(guide_top); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_top.add(jl, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp.add(jp_top, gridBagConstraints); + + if(type == 0) + { + jp_top = new javax.swing.JPanel(); + jp_top.setLayout(new java.awt.GridBagLayout()); + + jl = new javax.swing.JLabel(msg_middle); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_top.add(jl, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 8, 5, 5); + jp_top.add(functionLevel, gridBagConstraints); + + jl = new javax.swing.JLabel(guide_middle); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_top.add(jl, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp.add(jp_top, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 2; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp.add(arguments, gridBagConstraints); + } + else + { + // for the sake of it to get rid of function level changes + functionLevel.setText("1"); + } + + jp_bottom = new javax.swing.JPanel(); + jp_bottom.setLayout(new java.awt.GridBagLayout()); + + if(type == 0) + { + middle = new javax.swing.JPanel(); + middle.setLayout(new java.awt.GridBagLayout()); + button = new javax.swing.JButton("Add Argument"); + button.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + addMouseClicked(evt); + } + }); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + middle.add(button, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 3; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp.add(middle, gridBagConstraints); + } + + + button = new javax.swing.JButton("Enter"); + button.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + buttonMouseClicked(evt); + } + }); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_bottom.add(button, gridBagConstraints); + + button = new javax.swing.JButton("Cancel"); + button.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + cancelMouseClicked(evt); + } + }); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp_bottom.add(button, gridBagConstraints); + + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 4; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp.add(jp_bottom, gridBagConstraints); + + + setContentPane(jp); + + setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); + + addWindowListener(new java.awt.event.WindowAdapter() { + public void windowClosing(java.awt.event.WindowEvent we) { + /* + * Instead of directly closing the window, + * we're going to change the JOptionPane's + * value property. + */ + } + }); + + //Ensure the text field always gets the first focus. + addComponentListener(new java.awt.event.ComponentAdapter() { + public void componentShown(java.awt.event.ComponentEvent ce) { + functionName.requestFocusInWindow(); + } + }); + } + + // to handle for mouse click + private void buttonMouseClicked(java.awt.event.MouseEvent e) + { + // clear the arguments textfields first + int size = arguments.getComponentCount(); + int check=0; + for(int i=0; i All arguments are local variables so their name must not clash with existing local variables within + // the function + + int size = arguments.getComponentCount(); + String to_check; + int check=0; // not zero means error encountered + + ret_val[0] = functionName.getText(); + try + { + int level = Integer.parseInt(functionLevel.getText()); + + if(level < 1) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for function level is invalid.\nPlease enter numbers greater than one only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + functionLevel.requestFocusInWindow(); + check = 1; + } + else + { + ret_val[1] = functionLevel.getText(); + check = 0; + } + } + catch(RuntimeException re) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for function level is invalid.\nPlease enter numbers greater than one only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + functionLevel.requestFocusInWindow(); + check = 1; + } + + if(check == 0) + { + for(int i=0; i arguments; // values to be passed on to this function call, can either be a constant or a variable + + // the function this icon is representing + private function the_function; + + /** Creates a new instance of functionIcon */ + public functionIcon() { + } + + /** + * Creates a new instance of functionIcon + * @param filepath Source file of this icon's image + */ + public functionIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); + num_id = 0; // not assigned originally, this id will be assigned by the function_list (called from ProgWindow class) + name = ""; + the_function = new function(); + arguments = new java.util.Vector(); + setImage(); + } + + /** + * Helps provide the transparent background + * @param g Graphics + */ + protected void paintComponent(java.awt.Graphics g) + { + super.paintComponent(g); + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/function/nameField.gif")); + g.drawImage(ii.getImage(), 2, 18, this); + } + + /** + * Alters the id of the function this icon is representing + * @param i New function id + */ + public void setNumId(int i) + { + num_id = i; + } + + /** + * Returns the id of the function this icon is representing + * @return function id + */ + public int getNumId() + { + return num_id; + } + + /** + * Sets the name of this function + * @param n New function name + */ + public void setName(String n) + { + name = n; + } + /** + * Returns this function icon's name + * @return function name + */ + public String getName() + { + return name; + } + + /** + * To set the function this function icon is pointing to + * @param fu The function this function icon is pointing to + */ + public void setFunction(function fu) + { + the_function = fu; + num_id = the_function.getNumId(); + name = the_function.getName(); + } + + /** + * Returns this function icon's function + * @return function name + */ + public function getFunction() + { + return the_function; + } + + // for arguments in function call + + /** + * Returns this function icon's arguments + * @return function arguments + */ + public java.util.Vector getArguments() + { + return arguments; + } + + /** + * To set the arguments this function icon has + * @param op The list of operands (arguments) + */ + public void setArguments(java.util.Vector op) + { + arguments = op; + } + /** + * To set the image of this function icon + */ + public void setImage() + { + removeAll(); // remove all first + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + javax.swing.ImageIcon nic; + PicButton pic; + javax.swing.JPanel jp = new javax.swing.JPanel(); + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + + // start the top most panel + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/function/functiontop.gif")); + pic = new PicButton(nic); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(pic); + + jp = new javax.swing.JPanel(); + jp.setPreferredSize(new java.awt.Dimension(40, 16)); + jp.setLayout(new java.awt.GridBagLayout()); + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/function/bottomleft.gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + + javax.swing.JLabel nameLabel = new javax.swing.JLabel(name); + nameLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + nameLabel.setPreferredSize(new java.awt.Dimension(36, 16)); + nameLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp.setOpaque(false); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(nameLabel, gridBagConstraints); + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/function/bottomright.gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(jp, gridBagConstraints); + + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/function/functionbottom.gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 2; + add(pic, gridBagConstraints); + + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + + /** + * Get the help title of this function icon + * @return Help title + */ + public String getHelpTitle() + { + String s = "Function Icon"; + return s; + } + + /** + * Get help message of this function icon + * @return Help message + */ + public String getHelpMsg() + { + String s = "DETAILS:"; + s+="\n\nName: "; + s+=name; + if(arguments.size() > 0) // there exist at least one argument + { + s+="\nArguments:"; + for(int i=0; i 0) // there exist at least one argument + { + for(int i=0; i name + sp2 = sp[0].split(att_value_connector); + name = sp2[1]; + + // do the next ones + if(att.indexOf(att_separator) != -1) // there are arguments + { + att = att.substring(att.indexOf(att_separator)+1); + while(att.compareTo("") != 0) // more arguments to go + { + sp = att.split(id_att_separator); + sp2 = sp[0].split(att_value_connector); + if(sp2[1].compareTo("c") == 0) + { + att = att.substring(att.indexOf(id_att_separator)+2); + sp = att.split(att_value_connector); + tmp = sp[1].substring(0, sp[1].indexOf(att_boundary_end)); + int value = Integer.parseInt(tmp); + constant c = new constant(); + c.setValue(value); + arguments.addElement(c); + } + else if(sp2[1].compareTo("v") == 0) + { + att = att.substring(att.indexOf(id_att_separator)+2); + sp = att.split(att_value_connector); + tmp = sp[1].substring(0, sp[1].indexOf(att_boundary_end)); + variable v = a.getVariable(tmp); + arguments.addElement(v); + } + + if(att.indexOf(att_separator) != -1) + { + att = att.substring(att.indexOf(att_separator)+1); + } + else + { + break; + } + } + } + // the num id of the function this icon is associated to will be set later + } + + // for this function's icon itself + /** + * Programming window where this function icon is on + * @return Programming window + */ + public ProgWindow getIndividualProgWindow() + { + Icon parent = this.getParentIcon(); + ProgWindow ret_val = new ProgWindow(); + while(true) + { + if(parent instanceof startFunctionIcon) + { + ret_val = ((startFunctionIcon)parent).getProgWindow(); + break; + } + else if(parent instanceof startTaskIcon) + { + ret_val = ((startTaskIcon)parent).getProgWindow(); + break; + } + else if(parent instanceof startEventIcon) + { + ret_val = ((startEventIcon)parent).getProgWindow(); + break; + } + else + { + parent = parent.getParentIcon(); + } + } + return ret_val; + } + + /** + * Returns scroll pane of the individual programming window + * @return Scroll Pane + */ + public javax.swing.JScrollPane getIndividualScroller() + { + Icon parent = this.getParentIcon(); + javax.swing.JScrollPane ret_val = new javax.swing.JScrollPane(); + while(true) + { + if(parent instanceof startIcon) + { + ret_val = ((startIcon)parent).getScroller(); + break; + } + else + { + parent = parent.getParentIcon(); + } + } + + return ret_val; + } +} diff --git a/src/funsoftware/ic/func/startFunctionIcon.java b/src/funsoftware/ic/func/startFunctionIcon.java new file mode 100644 index 0000000..9c1c44f --- /dev/null +++ b/src/funsoftware/ic/func/startFunctionIcon.java @@ -0,0 +1,98 @@ +/* + * startFunctionIcon.java + * + * Created on 29 December 2005 + */ + +package funsoftware.ic.func; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.inter.*; +import funsoftware.ic.others.*; +import funsoftware.ic.PicButton; +import funsoftware.functs.*; + +/** + * This class is a subclass from startIcon.java + * This class defines a starting icon of a function + * @author Thomas Legowo + */ +public class startFunctionIcon extends startIcon{ + + private function func; + + /** Creates a new instance of startFunctionIcon */ + public startFunctionIcon() { + } + + /** + * Creates a new instance of startFunctionIcon + * @param filepath Source file of the icon's image + */ + public startFunctionIcon(String filepath) + { + super(filepath); + } + + /** + * Sets the function this starting function icon is associated to + * @param fu the function + */ + public void setFunction(function fu) + { + func = fu; + } + + /** + * Gets the function this starting function icon is associated to + * @return The function this starting function icon is associated to + */ + public function getFunction() + { + return func; + } + + /** + * To clone this icon + * @return New instance of this icon + */ + public startFunctionIcon Clone() + { + return new startFunctionIcon("/icons/closures/argument.gif"); + } + + /** + * Algorithm translation for the Translator object to create a text representation of this icon + * @param id_separator To separate ids + * @param id_att_separator To separate id with attribute + * @param att_boundary_begin To start attributes + * @param att_boundary_end To end attributes + * @param att_value_connector To separate attributes and its values + * @param att_separator To separate attributes + * @return Translation + */ + public String getTranslation(String id_separator, String id_att_separator, + String att_boundary_begin, String att_boundary_end, String att_value_connector, String att_separator) + { + String algo = new String(); + algo += "\nstartfunction"; + algo += id_separator; + algo += func.getNumId(); + return algo; + } + + /** + * Returns a string format of the NQCCode representation of this object + * @param indentation Indentation + * @return The NQC Code + */ + public String getNQCCode(String indentation) + { + String NQCCode = new String(); + NQCCode += "\n{\n"; + NQCCode += func.getNQCLocalVar(); + NQCCode += "\n"; + return NQCCode; + } +} diff --git a/src/funsoftware/ic/loo/arithmeticLoopIcon.java b/src/funsoftware/ic/loo/arithmeticLoopIcon.java new file mode 100644 index 0000000..047d557 --- /dev/null +++ b/src/funsoftware/ic/loo/arithmeticLoopIcon.java @@ -0,0 +1,366 @@ +/* + * arithmeticLoopIcon.java + * + * Created on 1 February 2006, 13:37 + * + */ + +package funsoftware.ic.loo; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.st.*; +import funsoftware.var.*; +import funsoftware.events.*; +import funsoftware.consts.*; +import funsoftware.struct.*; + + +/** + * This icon loops until a condition is met. The condition uses variables and constants instead of a sensor's reading. + * @author Thomas Legowo + */ +public class arithmeticLoopIcon extends loopIcon{ + + // the local variables + private NestedOperation NO; + + // for algorithm representation, this infinite loop icon has an identifier of 8 + private int identifier; + + /** Creates a new instance of arithmeticLoopIcon */ + public arithmeticLoopIcon() { + } + + /** + * Creates a new instance of arithmeticLoopIcon + * @param filepath The source file of this icon's image + */ + public arithmeticLoopIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); + super.setHeight(super.getImage().getImage().getHeight(this)); + identifier = 8; + NO = new NestedOperation(); + setImage(); + } + + /** + * To set the expression + * @param nno The nested operation of the expression + */ + public void setExpression(NestedOperation nno) + { + NO = nno; + } + + /** + * To get the expression + * @return The nested operation of the expression + */ + public NestedOperation getExpression() + { + return NO; + } + + /** + * Sets the images and labels for this icon + */ + public void setImage() + { + removeAll(); + setLayout(new java.awt.GridBagLayout()); + + // creating the top panel + javax.swing.ImageIcon nic; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/loops/arithmetic/arithmetic.gif")); + PicButton pic = new PicButton(nic); + add(pic); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * Get the help title of this arithmetic icon + * @return Help title + */ + public String getHelpTitle() + { + String s = "Arithmetic Repeat Icon"; + return s; + } + + /** + * Get help message of this arithmetic loop icon + * @return Help message + */ + public String getHelpMsg() + { + String s = "DETAILS:\n\n"; + s += "Expression: "; + Operand tmp_op = NO.getOperand1(); + if(tmp_op instanceof constant) + { + constant c = (constant) tmp_op; + s += c.getValue(); + } + else if(tmp_op instanceof variable) + { + variable v = (variable) tmp_op; + s += v.getName(); + } + s += " "; + s += NO.getOperator().getOperator()+" "; + + tmp_op = NO.getOperand2(); + if(tmp_op instanceof constant) + { + constant c = (constant) tmp_op; + s += c.getValue(); + } + else if(tmp_op instanceof variable) + { + variable v = (variable) tmp_op; + s += v.getName(); + } + return s; + } + + /** + * Get the description of this icon + * @return Help Description + */ + public String getHelpDesc() + { + String s = "This icon repeats a sequence of icons\nas long as the provided arithmetic expression\nis satisfied."; + return s; + } + + /** + * Get help picture of this icon + * @return Help picture + */ + public javax.swing.Icon getHelpIcon() + { + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/helps/arithmeticLoopIcon.gif")); + return ii; + } + + /** + * To clone this icon + * @return New instance of this icon + */ + public arithmeticLoopIcon Clone() + { + return new arithmeticLoopIcon("/icons/loops/arithmetic/arithmetic.gif"); + } + + /** + * To copy this icon + * @return New instance of this icon with its attributes set + */ + public Icon Copy() + { + arithmeticLoopIcon newRI = Clone(); + newRI.setExpression(NO); + newRI.setImage(); + return newRI; + } + + /** + * Algorithm translation for the Translator object to create a text representation of this icon + * @param id_separator To separate ids + * @param id_att_separator To separate id with attribute + * @param att_boundary_begin To start attributes + * @param att_boundary_end To end attributes + * @param att_value_connector To separate attributes and its values + * @param att_separator To separate attributes + * @return Translation + */ + public String getTranslation(String id_separator, String id_att_separator, + String att_boundary_begin, String att_boundary_end, String att_value_connector, String att_separator) + { + String algo = new String(); + algo += "\n"; // to begin with + algo += "loop"; + algo += id_separator; + algo += identifier; + algo += id_separator; + algo += getId(); + algo += id_att_separator; + algo += att_boundary_begin; + algo += NO.getAOTranslation(id_separator, id_att_separator, att_boundary_begin, att_boundary_end, att_value_connector, att_separator); + algo += att_boundary_end; + return algo; + } + + /** + * Returns a string format of the NQCCode representation of this object + * @param indentation Indentation + * @return The NQC Code + */ + public String getNQCCode(String indentation) + { + String NQCCode = new String(); + NQCCode += indentation; + NQCCode += "// arithmetic loop\n"; + NQCCode += indentation+"while("; + + Operand tmp_op = NO.getOperand1(); + if(tmp_op instanceof constant) + { + constant c = (constant) tmp_op; + NQCCode += c.getValue(); + } + else if(tmp_op instanceof variable) + { + variable v = (variable) tmp_op; + NQCCode += v.getName(); + } + NQCCode += " "; + NQCCode += NO.getOperator().getOperator()+" "; + + tmp_op = NO.getOperand2(); + if(tmp_op instanceof constant) + { + constant c = (constant) tmp_op; + NQCCode += c.getValue(); + } + else if(tmp_op instanceof variable) + { + variable v = (variable) tmp_op; + NQCCode += v.getName(); + } + NQCCode += ")\n"; + + return NQCCode; + } + + /** + * Set its own attributes given a string from a text representation of it + * @param id_att_separator The id and attribute separator + * @param att Attributes + * @param att_value_connector Attribute connector + * @param att_separator Attribute separator + */ + public void setAttributes(String att, String att_value_connector, String att_separator, String id_att_separator) + { + String[] sp = att.split(id_att_separator); + String[] sp2 = sp[1].split(att_value_connector); + auxiliary tmp_aux; + + String type = sp2[1]; + String value; + + att = att.substring(att.indexOf(id_att_separator)+2); + att = att.substring(att.indexOf(att_value_connector)+1); + + sp = att.split(id_att_separator); + sp2 = sp[1].split(att_value_connector); + sp = sp2[1].split(att_separator); + value = sp[0].substring(0, sp[0].length()-1); + + if(type.compareTo("v") == 0) // a variable + { + variable v = var_list.Instance().getVariable(value); + if(v == null) // must be local, not global + { + tmp_aux = getAux(); + if(tmp_aux instanceof monitorEvent) + { + monitorEvent ev = (monitorEvent)tmp_aux; + v = ev.getAuxPoint().getVariable(value); + } + else + { + v = tmp_aux.getVariable(value); + } + } + NO.setOperand1(v); + } + else if(type.compareTo("c") == 0) // a constant + { + constant c = new constant(); + c.setValue(Integer.parseInt(value)); + NO.setOperand1(c); + } + + att = att.substring(att.indexOf(id_att_separator)+2); + att = att.substring(att.indexOf(att_separator)+1); + + sp = att.split(att_value_connector); + sp2 = sp[1].split(id_att_separator); + + type = sp2[0]; + + sp = att.split(id_att_separator); + sp2 = sp[1].split(att_value_connector); + sp = sp2[1].split(att_separator); + value = sp[0].substring(0, sp[0].length()-1); + + if(type.compareTo("v") == 0) // a variable + { + variable v = var_list.Instance().getVariable(value); + if(v == null) // must be local, not global + { + tmp_aux = getAux(); + if(tmp_aux instanceof monitorEvent) + { + monitorEvent ev = (monitorEvent)tmp_aux; + v = ev.getAuxPoint().getVariable(value); + } + else + { + v = tmp_aux.getVariable(value); + } + } + NO.setOperand2(v); + } + else if(type.compareTo("c") == 0) // a constant + { + constant c = new constant(); + c.setValue(Integer.parseInt(value)); + NO.setOperand2(c); + } + + att = att.substring(att.indexOf(id_att_separator)+2); + att = att.substring(att.indexOf(att_separator)+1); + + sp = att.split(id_att_separator); + sp2 = sp[1].split(att_value_connector); + value = sp2[1].substring(0, sp2[1].length()-3); + + Operator opt = new Operator(); + opt.setOperator(value); + NO.setOperator(opt); + } + + /** + * To indicate whether this icon uses variable(s) in its expression + * @param var The variable to be searched + * @return True or false + */ + public Boolean useAVariable(variable var) + { + if(NO != null) + { + if(NO.getOperand1() instanceof variable) + { + variable tmp_v = (variable)NO.getOperand1(); + if(tmp_v.getType() == var.getType() && tmp_v.getName() == var.getName()) + { + return true; + } + } + if(NO.getOperand2() instanceof variable) + { + variable tmp_v = (variable)NO.getOperand2(); + if(tmp_v.getType() == var.getType() && tmp_v.getName() == var.getName()) + { + return true; + } + } + } + return false; + } +} diff --git a/src/funsoftware/ic/loo/celciusSensorLoopIcon.java b/src/funsoftware/ic/loo/celciusSensorLoopIcon.java new file mode 100644 index 0000000..dffe85a --- /dev/null +++ b/src/funsoftware/ic/loo/celciusSensorLoopIcon.java @@ -0,0 +1,870 @@ +/* + * celciusSensorLoopIcon.java + * + * Created on 17 December 2005, 19:00 + */ + +package funsoftware.ic.loo; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.st.*; +import funsoftware.var.*; +import funsoftware.consts.*; + +/** + * This class represents a loop that continues to loop unless the value from the temperature sensor is less than or greater + * than a specified treshold value. + * @author Thomas Legowo + */ +public class celciusSensorLoopIcon extends loopIcon { + + private int port; // with default value being 1, port is the value of the input port of this temperature sensor + private int temperature; // default value being 30 + private variable var_temperature; // alternative to temperature + private int type; // if type = 1 it means "greater than" + + // for algorithm representation, this celcius sensor loop icon has an identifier of 5 + private int identifier; + + /** Creates a new instance of celciusSensorLoopIcon */ + public celciusSensorLoopIcon() { + } + + /** + * Creates a new instance of infiniteLoopIcon + * @param filepath The source file of this icon's image + */ + public celciusSensorLoopIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); + super.setHeight(super.getImage().getImage().getHeight(this)); + identifier = 5; + port = 1; + temperature = 300; + type = 1; + var_temperature = null; + setImage(); + } + + /** + * Helps provide the transparent background + * @param g Graphic + */ + protected void paintComponent(java.awt.Graphics g) + { + super.paintComponent(g); + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/loops/celcius/celcius_field.gif")); + g.drawImage(ii.getImage(), 14, 24, this); + } + + /** + * Returns the port this temperature sensor is operating in + * @return Port value + */ + public int getPort() + { + return port; + } + + /** + * Gets the temperature sensor value threshold + * @return Temperature sensor value threshold + */ + public int getTemperature() + { + return temperature; + } + + /** + * Returns the type whether it is greater than or less than + * @return Comparison type (< or >) + */ + public int getType() + { + return type; + } + + /** + * Sets the port of the sensor + * @param nport New port value + */ + public void setPort(int nport) + { + port = nport; + } + + /** + * Sets the temperature sensor value threshold of the sensor + * @param nt The new temperatur + */ + public void setTemperature(int nt) + { + temperature = nt; + } + + /** + * Sets the comparison type of the loop icon + * @param nt New type + */ + public void setType(int nt) + { + type = nt; + } + + /** + * To set the temperature value attribute of this icon + * @param var The temperature variable + */ + public void setVarTemperature(variable var) + { + var_temperature = var; + } + + /** + * Sets the image of this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + javax.swing.ImageIcon nic; + PicButton pic; + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + javax.swing.JPanel jp3 = new javax.swing.JPanel(); + + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(40, 24)); + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/loops/celcius/topcelcius.gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(pic, gridBagConstraints); + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/loops/celcius/comp"+type+".gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp2.add(pic, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(jp2, gridBagConstraints); + + jp3 = new javax.swing.JPanel(); + jp3.setLayout(new java.awt.GridBagLayout()); + jp3.setPreferredSize(new java.awt.Dimension(40, 16)); + + jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(14, 16)); + + javax.swing.JLabel portLabel = new javax.swing.JLabel(Integer.toString(port)); + portLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + portLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(portLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp3.add(jp2, gridBagConstraints); + + jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(26, 16)); + + javax.swing.JLabel temperatureLabel; + if(var_temperature == null) + { + temperatureLabel = new javax.swing.JLabel(Integer.toString(temperature)); + } + else + { + temperatureLabel = new javax.swing.JLabel("V"); + } + temperatureLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + temperatureLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + temperatureLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(temperatureLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp3.add(jp2, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + jp3.setOpaque(false); + add(jp3, gridBagConstraints); + setOpaque(false); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * To change the port of the sensor + * @param evt MouseEvent + */ + public void changePort(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField = new javax.swing.JTextField(Integer.toString(port)); + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(14,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditModePort(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the temperature sensor value threshold + * @param evt MouseEvent + */ + public void changeTemperature(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField; + if(var_temperature != null) + { + textField = new javax.swing.JTextField("v"); + } + else + { + textField = new javax.swing.JTextField(Integer.toString(temperature)); + } + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(25,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + jp.setOpaque(false); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditModeTemperature(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the comparator of this loop's ending case (either less than or greater than) + * @param evt MouseEvent + */ + public void changeComparator(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + ComparatorDialog c_dialog = new ComparatorDialog(null, type, this); + c_dialog.pack(); + c_dialog.setLocationRelativeTo(this); + c_dialog.setVisible(true); + + type = c_dialog.getComparator(); + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + jp.remove(1); + // displays the comparator according to its type + javax.swing.ImageIcon nic = new javax.swing.ImageIcon(getClass().getResource("/icons/loops/celcius/comp"+type+".gif")); + PicButton pic = new PicButton(nic); + java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + // set the states for undo and redo + UndoRedo.update_state(); + + repaint(); + validate(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * Stop the edit mode on port value of this icon + */ + public void stopEditModePort() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + jp.removeAll(); + + // parse the input port + int tmp_port = port; // current port number + try + { + port = Integer.parseInt(text); + if(port > 3 || port < 1) // 3 ports + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the input port is invalid.\nIt can be either 1, 2 or 3.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + port = tmp_port; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the input port is invalid.\nPlease enter numbers only (1 to 3).\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_port != port) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(14, 16)); + + javax.swing.JLabel portLabel = new javax.swing.JLabel(Integer.toString(port)); + portLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + portLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(portLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(jp2, gridBagConstraints); + + repaint(); + validate(); + } + + /** + * Stops the edit mode for the temperature sensor value threshold + */ + public void stopEditModeTemperature() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + jp.removeAll(); + + // parse the timer value + int tmp_temp = temperature; // current timer value + try + { + if(text.compareTo("v") == 0 || text.compareTo("V") == 0) + { + if(var_list.Instance().isDefinedVariables() == true || findCurrentAux().getLocalVarList().isEmpty() == false) + { + VarInputDialog vid = new VarInputDialog(null, this, findCurrentAux()); + vid.pack(); + vid.setLocationRelativeTo(this); + vid.setVisible(true); + + if(vid.getUserInput() != null) + { + var_temperature = vid.getUserInput(); + } + } + else + { + javax.swing.JOptionPane.showMessageDialog(null, + "You have not defined any global variables or local variables to this function or task yet.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + } + else + { + temperature = Integer.parseInt(text); + var_temperature = null; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the temperature sensor threshold is invalid.\nPlease enter numbers only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_temp != temperature || var_temperature != null) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(26, 16)); + + javax.swing.JLabel temperatureLabel; + if(var_temperature == null) + { + temperatureLabel = new javax.swing.JLabel(Integer.toString(temperature)); + } + else + { + temperatureLabel = new javax.swing.JLabel("V"); + } + temperatureLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + temperatureLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + temperatureLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(temperatureLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(jp2, gridBagConstraints); + + repaint(); + validate(); + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + java.awt.event.MouseListener[] ml = jp.getMouseListeners(); + for(int i=0; i port + sp2 = sp[0].split(att_value_connector); + port = Integer.parseInt(sp2[1]); + + // do the second one --> light_sensor_value + sp2 = sp[1].split(att_value_connector); + if(sp2[1].substring(0,1).compareTo("V") == 0) // must be a variable + { + var_temperature = var_list.Instance().getVariable(sp2[1].substring(2)); + if(var_temperature == null) // must be local, not global + { + var_temperature = getAux().getVariable(sp2[1].substring(2)); + } + } + else + { + temperature = Integer.parseInt(sp2[1]); + } + + // do the first one --> type + sp2 = sp[2].split(att_value_connector); + type = Integer.parseInt(sp2[1]); + } + /** + * To display an input panel to ask for a variable to be used + * @return The label of the panel + */ + public javax.swing.JLabel getVarLabel() + { + return new javax.swing.JLabel("Temperature Value Threshold"); + } + + /** + * To indicate whether this icon uses a variable + * @param var Variable to be checked + * @return True or false + */ + public Boolean useAVariable(variable var) + { + if(var_temperature != null) + { + if(var_temperature.getType() == var.getType() && var_temperature.getName().compareTo(var.getName()) == 0) + { + return true; + } + } + return false; + } +} diff --git a/src/funsoftware/ic/loo/infiniteLoopIcon.java b/src/funsoftware/ic/loo/infiniteLoopIcon.java new file mode 100644 index 0000000..30e9a74 --- /dev/null +++ b/src/funsoftware/ic/loo/infiniteLoopIcon.java @@ -0,0 +1,168 @@ +/* + * infiniteLoopIcon.java + * + * Created on 23 September 2005, 18:55 + * + */ + +package funsoftware.ic.loo; + +import funsoftware.ic.*; +import funsoftware.wr.*; + +/** + * This class is for the loop icon that repeats infinitely + * @author Thomas Legowo + * + */ +public class infiniteLoopIcon extends loopIcon { + + // for algorithm representation, this infinite loop icon has an identifier of 3 + private int identifier; + + /** Creates a new instance of infiniteLoopIcon */ + public infiniteLoopIcon() { + } + + /** + * Creates a new instance of infiniteLoopIcon + * @param filepath The source file of this icon's image + */ + public infiniteLoopIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); + super.setHeight(super.getImage().getImage().getHeight(this)); + identifier = 3; + setImage(); + } + + /** + * Sets the images and labels for this icon + */ + public void setImage() + { + removeAll(); + setLayout(new java.awt.GridBagLayout()); + + // creating the top panel + javax.swing.ImageIcon nic; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/loops/infiniteloop/infinite_rep.gif")); + PicButton pic = new PicButton(nic); + add(pic); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * Get the help title of this infinite loop icon + * @return Help title + */ + public String getHelpTitle() + { + String s = "Infinite Repeat Icon"; + return s; + } + + /** + * Get help message of this infinite loop icon + * @return Help message + */ + public String getHelpMsg() + { + String s = "DETAILS:"; + s+="\n\nRepeat: "; + s+=" infinitely"; + return s; + } + + /** + * Get the description of this icon + * @return Help Description + */ + public String getHelpDesc() + { + String s = ""; + return s; + } + + /** + * Get help picture of this icon + * @return Help picture + */ + public javax.swing.Icon getHelpIcon() + { + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/helps/infiniteLoopIcon.gif")); + return ii; + } + + /** + * To clone this icon + * @return New instance of this icon + */ + public infiniteLoopIcon Clone() + { + return new infiniteLoopIcon("/icons/loops/infiniteloop/infinite_rep.gif"); + } + + /** + * To copy this icon + * @return New instance of this icon with its attributes set + */ + public Icon Copy() + { + infiniteLoopIcon newRI = Clone(); + newRI.setImage(); + return newRI; + } + + /** + * Algorithm translation for the Translator object to create a text representation of this icon + * @param id_separator To separate ids + * @param id_att_separator To separate id with attribute + * @param att_boundary_begin To start attributes + * @param att_boundary_end To end attributes + * @param att_value_connector To separate attributes and its values + * @param att_separator To separate attributes + * @return Translation + */ + public String getTranslation(String id_separator, String id_att_separator, + String att_boundary_begin, String att_boundary_end, String att_value_connector, String att_separator) + { + String algo = new String(); + algo += "\n"; // to begin with + algo += "loop"; + algo += id_separator; + algo += identifier; + algo += id_separator; + algo += getId(); + algo += id_att_separator; + algo += att_boundary_begin; + algo += att_boundary_end; + return algo; + } + + /** + * Returns a string format of the NQCCode representation of this object + * @param indentation Indentation + * @return The NQC Code + */ + public String getNQCCode(String indentation) + { + String NQCCode = new String(); + NQCCode += indentation; + NQCCode += "// infinite loop\n"; + NQCCode += indentation+"while(true)\n"; + return NQCCode; + } + + /** + * Set its own attributes given a string from a text representation of it + * @param att Attributes + * @param att_value_connector Attribute connector + * @param att_separator Attribute separator + */ + public void setAttributes(String att, String att_value_connector, String att_separator) + { + } + +} diff --git a/src/funsoftware/ic/loo/lightSensorLoopIcon.java b/src/funsoftware/ic/loo/lightSensorLoopIcon.java new file mode 100644 index 0000000..ab48aed --- /dev/null +++ b/src/funsoftware/ic/loo/lightSensorLoopIcon.java @@ -0,0 +1,881 @@ +/* + * lightSensorLoopIcon.java + * + * Created on 6 September 2005, 22:01 + * + */ + +package funsoftware.ic.loo; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.st.*; +import funsoftware.var.*; +import funsoftware.consts.*; + +/** + * This class is for the "Repeat" icon that repeats until the light sensor read a value greater than the specified treshold value. + * @author Thomas Legowo + */ +public class lightSensorLoopIcon extends loopIcon{ + + private int port; // with default value being 1, port is the value of the input port of this light sensor + private int light_sensor_value; // default value being 55, minimum is 1 and maximum is 100 + private variable var_light_sensor_value; // alternative to light_sensor_value + + private int type; // if type = 1 it means "greater than" + + // for algorithm representation, represent a loop light sensor icon with an identifier of 2 + private int identifier; + + /** Creates a new instance of lightSensorLoopIcon */ + public lightSensorLoopIcon() { + } + + /** + * Creates a new instance of lightSensorLoopIcon + * @param filepath Source file for the icon's image + */ + public lightSensorLoopIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); + super.setHeight(super.getImage().getImage().getHeight(this)); + port = 1; + light_sensor_value = 55; // loop until the value read from the RCX's light sensor exceeded 55 by default + type = 1; + identifier = 2; + var_light_sensor_value = null; + setImage(); + } + + /** + * Helps provide the transparent background + * @param g Graphic + */ + protected void paintComponent(java.awt.Graphics g) + { + super.paintComponent(g); + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/loops/lightrep/light_field.gif")); + g.drawImage(ii.getImage(), 14, 24, this); + } + + /** + * Returns the port this light sensor is operating in + * @return Port value + */ + public int getPort() + { + return port; + } + + /** + * Gets the light sensor value threshold + * @return Light sensor value threshold + */ + public int getLightSensorValue() + { + return light_sensor_value; + } + + /** + * Returns the type whether it is greater than or less than + * @return Comparison type (< or >) + */ + public int getType() + { + return type; + } + + /** + * Sets the port of the sensor + * @param nport New port value + */ + public void setPort(int nport) + { + port = nport; + } + + /** + * Sets the light sensor value threshold of the sensor + * @param nlsv New light sensor value threshold + */ + public void setLightSensorValue(int nlsv) + { + light_sensor_value = nlsv; + } + + /** + * Set the light sensor value of this icon + * @param var The light value variable + */ + public void setVarLight(variable var) + { + var_light_sensor_value = var; + } + + /** + * Sets the comparison type of the loop icon + * @param nt New type + */ + public void setType(int nt) + { + type = nt; + } + + /** + * Sets the image of this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + javax.swing.ImageIcon nic; + PicButton pic; + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + javax.swing.JPanel jp3 = new javax.swing.JPanel(); + + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(40, 24)); + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/loops/lightrep/toploop.gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(pic, gridBagConstraints); + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/loops/lightrep/comp"+type+".gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp2.add(pic, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(jp2, gridBagConstraints); + + jp3 = new javax.swing.JPanel(); + jp3.setLayout(new java.awt.GridBagLayout()); + jp3.setPreferredSize(new java.awt.Dimension(40, 16)); + + jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(14, 16)); + + javax.swing.JLabel portLabel = new javax.swing.JLabel(Integer.toString(port)); + portLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + portLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(portLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp3.add(jp2, gridBagConstraints); + + jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(26, 16)); + + javax.swing.JLabel lightLabel; + if(var_light_sensor_value == null) + { + lightLabel = new javax.swing.JLabel(Integer.toString(light_sensor_value)); + } + else + { + lightLabel = new javax.swing.JLabel("V"); + } + lightLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + lightLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + lightLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(lightLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp3.add(jp2, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + jp3.setOpaque(false); + add(jp3, gridBagConstraints); + setOpaque(false); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * To change the port of the sensor + * @param evt MouseEvent + */ + public void changePort(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField = new javax.swing.JTextField(Integer.toString(port)); + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(14,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditModePort(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the light sensor value threshold + * @param evt MouseEvent + */ + public void changeLightSensorValue(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField; + if(var_light_sensor_value != null) + { + textField = new javax.swing.JTextField("v"); + } + else + { + textField = new javax.swing.JTextField(Integer.toString(light_sensor_value)); + } + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(25,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + jp.setOpaque(false); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditModeLightSensorValue(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the comparator of this loop's ending case (either less than or greater than) + * @param evt MouseEvent + */ + public void changeComparator(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + ComparatorDialog c_dialog = new ComparatorDialog(null, type, this); + c_dialog.pack(); + c_dialog.setLocationRelativeTo(this); + c_dialog.setVisible(true); + + type = c_dialog.getComparator(); + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + jp.remove(1); + // displays the comparator according to its type + javax.swing.ImageIcon nic = new javax.swing.ImageIcon(getClass().getResource("/icons/loops/lightrep/comp"+type+".gif")); + PicButton pic = new PicButton(nic); + java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + // set the states for undo and redo + UndoRedo.update_state(); + + repaint(); + validate(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * Stop the edit mode on port value of this icon + */ + public void stopEditModePort() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + jp.removeAll(); + + // parse the port number + int tmp_port = port; // current port number + try{ + port = Integer.parseInt(text); + if(port > 3 || port <= 0) // maximum of 3 input ports + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the input port is invalid.\nIt can be either 1, 2 or 3.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + port = tmp_port; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the input port is invalid.\nPlease enter numbers only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_port != port) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(14, 16)); + + javax.swing.JLabel portLabel = new javax.swing.JLabel(Integer.toString(port)); + portLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + portLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(portLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(jp2, gridBagConstraints); + + repaint(); + validate(); + } + + /** + * Stops the edit mode for the light sensor value threshold + */ + public void stopEditModeLightSensorValue() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + jp.removeAll(); + + // parse the light sensor value + int tmp_light = light_sensor_value; // current port number + try + { + if(text.compareTo("v") == 0 || text.compareTo("V") == 0) + { + if(var_list.Instance().isDefinedVariables() == true || findCurrentAux().getLocalVarList().isEmpty() == false) + { + VarInputDialog vid = new VarInputDialog(null, this, findCurrentAux()); + vid.pack(); + vid.setLocationRelativeTo(this); + vid.setVisible(true); + + if(vid.getUserInput() != null) + { + var_light_sensor_value = vid.getUserInput(); + } + } + else + { + javax.swing.JOptionPane.showMessageDialog(null, + "You have not defined any global variables or local variables to this function or task yet.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + } + else + { + light_sensor_value = Integer.parseInt(text); + if(light_sensor_value > 100 || light_sensor_value < 1) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the light sensor threshold is invalid.\nMinimum value is 1 and maximum value is 100.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + light_sensor_value = tmp_light; + } + else + { + var_light_sensor_value = null; + } + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the light sensor threshold is invalid.\nPlease enter numbers only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_light != light_sensor_value || var_light_sensor_value != null) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(26, 16)); + + javax.swing.JLabel lightLabel; + if(var_light_sensor_value == null) + { + lightLabel = new javax.swing.JLabel(Integer.toString(light_sensor_value)); + } + else + { + lightLabel = new javax.swing.JLabel("V"); + } + lightLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + lightLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + lightLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(lightLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(jp2, gridBagConstraints); + + repaint(); + validate(); + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + java.awt.event.MouseListener[] ml = jp.getMouseListeners(); + for(int i=0; i port + sp2 = sp[0].split(att_value_connector); + port = Integer.parseInt(sp2[1]); + + // do the second one --> light_sensor_value + sp2 = sp[1].split(att_value_connector); + if(sp2[1].substring(0,1).compareTo("V") == 0) // must be a variable + { + var_light_sensor_value = var_list.Instance().getVariable(sp2[1].substring(2)); + if(var_light_sensor_value == null) // must be local, not global + { + var_light_sensor_value = getAux().getVariable(sp2[1].substring(2)); + } + } + else + { + light_sensor_value = Integer.parseInt(sp2[1]); + } + + // do the first one --> type + sp2 = sp[2].split(att_value_connector); + type = Integer.parseInt(sp2[1]); + } + + /** + * To display an input panel to ask for a variable to be used + * @return The label of the panel + */ + public javax.swing.JLabel getVarLabel() + { + return new javax.swing.JLabel("Light Value Threshold"); + } + + /** + * To indicate whether this icon uses a variable + * @param var Variable to be checked + * @return True or false + */ + public Boolean useAVariable(variable var) + { + if(var_light_sensor_value != null) + { + if(var_light_sensor_value.getType() == var.getType() && var_light_sensor_value.getName().compareTo(var.getName()) == 0) + { + return true; + } + } + return false; + } +} diff --git a/src/funsoftware/ic/loo/loopIcon.java b/src/funsoftware/ic/loo/loopIcon.java new file mode 100644 index 0000000..bf89ebf --- /dev/null +++ b/src/funsoftware/ic/loo/loopIcon.java @@ -0,0 +1,329 @@ +/* + * loopIcon.java + * + * Created on 5 September 2005, 10:43 + * + */ + +package funsoftware.ic.loo; + +import funsoftware.ic.*; +import funsoftware.ic.bran.*; +import funsoftware.wr.*; + +/** + * This class is the superclass for all kind of repeat or loop icons + * @author Thomas Legowo + */ +public class loopIcon extends Icon{ + + // the private attributes + + private Wire leftWire; + private Wire rightWire; + + private Icon beginIcon; // the joinLoop icon that starts the loop segment + private Icon endIcon; // the joinLoop icon that ends the loop segment + + private Icon leftNeighbour; + private Icon rightNeighbour; + + private java.util.Vector members; // the icons enclosed within this repeat segment + + // variables for the icon's vertical repositioning + private int topVerticalSize; + + private int bottomVerticalSize; + + /** Creates a new instance of loopIcon */ + public loopIcon() { + } + + /** + * Creates a new instance of loopIcon + * @param filepath Source file of this icon's image + */ + public loopIcon(String filepath) { + super(filepath); + members = new java.util.Vector(); + topVerticalSize = 0; + bottomVerticalSize = 0; + } + + // the set and get methods for the neighbouring wires + + /** + * Gets left wire of this icon + * @return Left wire + */ + public Wire getLeftWire() + { + return leftWire; + } + + /** + * Gets right wire of this icon + * @return Right wire + */ + public Wire getRightWire() + { + return rightWire; + } + + /** + * Gets the begin icon of the segment of icons enclosed by this loop icon + * @return Begin icon + */ + public Icon getBeginIcon() + { + return beginIcon; + } + + /** + * Gets the end icon of the segment of icons enclosed by this loop icon + * @return End icon + */ + public Icon getEndIcon() + { + return endIcon; + } + + /** + * Gets left neighbour of this icon + * @return Left neighbour + */ + public Icon getLeftNeighbour() + { + return leftNeighbour; + } + + /** + * Gets right neighbour of this icon + * @return Right neighbour + */ + public Icon getRightNeighbour() + { + return rightNeighbour; + } + + /** + * Sets left wire of this icon + * @param nwire New left wire + */ + public void setLeftWire(Wire nwire) + { + leftWire = nwire; + } + + /** + * Sets right wire of this icon + * @param nwire New right wire + */ + public void setRightWire(Wire nwire) + { + rightWire = nwire; + } + + /** + * Sets the begin icon of this loop icon + * @param nicon New begin icon + */ + public void setBeginIcon(Icon nicon) + { + beginIcon = nicon; + } + + /** + * Sets the end icon of this loop icon + * @param nicon New end icon + */ + public void setEndIcon(Icon nicon) + { + endIcon = nicon; + } + + /** + * Ensure its left neighbour of this icon is the left of begin icon + */ + public void setLeftNeighbour() + { + leftNeighbour = beginIcon.getLeftNeighbour(); + } + + /** + * Ensure its right neighbour of this icon is the right of begin icon + */ + public void setRightNeighbour() + { + rightNeighbour = endIcon.getRightNeighbour(); + } + + // dealing with the elements within the loop + /** + * Gets the members of this loop icon + * @return Set of icons + */ + public java.util.Vector getMembers() + { + return members; + } + + // the repositioning variables + /** + * Sets the top part of the icon's vertical size + * @param nvs New top part of vertical size + */ + public void setTopVerticalSize(int nvs) + { + topVerticalSize = nvs; + } + + /** + * Sets the bottom part of the icon's vertical size + * @param nvs New bottom part of vertical size + */ + public void setBottomVerticalSize(int nvs) + { + bottomVerticalSize = nvs; + } + + /** + * Gets the top part of the icon's vertical size + * @return Top part of the vertical size + */ + public int getTopVerticalSize() + { + return topVerticalSize; + } + + /** + * Gets the bottom part of the icon's vertical size + * @return Bottom part of the vertical size + */ + public int getBottomVerticalSize() + { + return bottomVerticalSize; + } + + + /** + * Adds a new icon to this icon member list + * @param new_icon New icon + * @param right_icon Right icon of the new icon + */ + public void addMember(Icon new_icon, Icon right_icon) + { + int found = 0; + for(int i=0; i(); + } + + // a method to determine the tallest bottom member, needed to maintain uniform vertical distance between the icons, branches and repeats + // NOTE: this method if called by the addMember or delMember compared to when it is called by ProgWindow.expandBranchVertical + // will not differ in terms of performance since those method will be called whenever an icon is added or deleted anyway + // -- + // since this method will be invoked after the latest icon is added to the members vector, that latest icon must be excluded + // from the calculation + /** + * Gets the icon with greatest bottom vertical size + * @return Icon with greatest bottom vertical size + */ + public Icon tallestBottomMember() + { + Icon ret_ic = new Icon(); + int max_ver = -1; + for(int i = 0; imax_ver) + { + max_ver = vert; + ret_ic = tmp_ic; + } + } + return ret_ic; + } + + // the opposite method of the previous method + /** + * Gets the icon with greatest top vertical size + * @return Icon with greatest top vertical size + */ + public Icon tallestTopMember() + { + Icon ret_ic = new Icon(); + int max_ver = -1; + for(int i = 0; imax_ver) + { + max_ver = vert; + ret_ic = tmp_ic; + } + } + return ret_ic; + } +} diff --git a/src/funsoftware/ic/loo/repeatIcon.java b/src/funsoftware/ic/loo/repeatIcon.java new file mode 100644 index 0000000..e962509 --- /dev/null +++ b/src/funsoftware/ic/loo/repeatIcon.java @@ -0,0 +1,465 @@ +/* + * repeatIcon.java + * + * Created on 24 July 2005, 11:41 + */ + +package funsoftware.ic.loo; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.st.*; +import funsoftware.var.*; +import funsoftware.consts.*; + +/** + * This class is for the "Repeat" icon that repeats a certain loop by a specified number of times + * @author Thomas Legowo + * + */ +public class repeatIcon extends loopIcon{ + + private int num_loop; // the number of loops this 'repeat' icon is to perform, default value is one + private variable var_num_loop; // alternative to num_loop + + // for algorithm representation, this repeat icon has an identifier of 1 + private int identifier; + + /** Creates a new instance of repeatIcon */ + public repeatIcon() { + } + + /** + * Creates a new instance of repeatIcon + * @param filepath Source file for this icon's image + */ + public repeatIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); + super.setHeight(super.getImage().getImage().getHeight(this)); + num_loop = 1; + identifier = 1; + var_num_loop = null; + setImage(); + } + + /** + * Gets the number of loop + * @return Number of loop + */ + public int getNumLoop() + { + return num_loop; + } + + + /** + * Sets the number of loops of this "repeat icon" + * @param nloop New number of loops + */ + public void setNumLoop(int nloop) + { + num_loop = nloop; + } + + /** + * Sets the number of loops of this "repeat icon" + * @param var The number of loop variable + */ + public void setVarNumLoop(variable var) + { + var_num_loop = var; + } + + /** + * Sets the images and labels for this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + javax.swing.ImageIcon nic; + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/loops/repeat/toploop.gif")); + PicButton pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(pic, gridBagConstraints); + + javax.swing.JLabel repeatLabel; + if(var_num_loop == null) + { + repeatLabel = new javax.swing.JLabel(Integer.toString(num_loop)); + } + else + { + repeatLabel = new javax.swing.JLabel("V"); + } + repeatLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + repeatLabel.setPreferredSize(new java.awt.Dimension(40, 16)); + repeatLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(repeatLabel, gridBagConstraints); + + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * Changes the number of loops + * @param evt MouseEvent + */ + public void changeNumLoops(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField; + if(var_num_loop != null) + { + textField = new javax.swing.JTextField("v"); + } + else + { + textField = new javax.swing.JTextField(Integer.toString(num_loop)); + } + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(40,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + removeAll(); + setLayout(new java.awt.GridBagLayout()); + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/loops/repeat/toploop.gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(pic, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(textField, gridBagConstraints); + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditMode(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + + } + + // method called by changeNumLoops + /** + * Handles click that stops edit mode + */ + public void stopEditMode() + { + javax.swing.JTextField textField = (javax.swing.JTextField)getComponent(1); + String text = textField.getText(); + removeAll(); + + // set the number of loops + int tmp_num_loop = num_loop; // current number of loops + try + { + if(text.compareTo("v") == 0 || text.compareTo("V") == 0) + { + if(var_list.Instance().isDefinedVariables() == true || findCurrentAux().getLocalVarList().isEmpty() == false) + { + VarInputDialog vid = new VarInputDialog(null, this, findCurrentAux()); + vid.pack(); + vid.setLocationRelativeTo(this); + vid.setVisible(true); + + if(vid.getUserInput() != null) + { + var_num_loop = vid.getUserInput(); + } + } + else + { + javax.swing.JOptionPane.showMessageDialog(null, + "You have not defined any global variables or local variables to this function or task yet.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + } + else + { + num_loop = Integer.parseInt(text); + if(num_loop < 0) // cannot be negative or zero, looping 0 times is for debugging purposes + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the repeat's value is invalid.\nMinimum value is zero.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + num_loop = tmp_num_loop; + } + else + { + var_num_loop = null; + } + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the repeat's value is invalid.\nPlease enter numbers only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + + // set the states for undo and redo + if(tmp_num_loop != num_loop || var_num_loop != null) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // reset the icon's graphics + setImage(); + + repaint(); + validate(); + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + java.awt.event.MouseListener[] ml = getMouseListeners(); + for(int i=0; i num_loop + sp2 = sp[0].split(att_value_connector); + if(sp2[1].substring(0,1).compareTo("V") == 0) // must be a variable + { + var_num_loop = var_list.Instance().getVariable(sp2[1].substring(2)); + if(var_num_loop == null) // must be local, not global + { + var_num_loop = getAux().getVariable(sp2[1].substring(2)); + } + } + else + { + num_loop = Integer.parseInt(sp2[1]); + } + } + + /** + * To display an input panel to ask for a variable to be used + * @return The label of the panel + */ + public javax.swing.JLabel getVarLabel() + { + return new javax.swing.JLabel("Number of Repeat"); + } + + /** + * To indicate whether this icon uses a variable + * @param var Variable to be checked + * @return True or false + */ + public Boolean useAVariable(variable var) + { + if(var_num_loop != null) + { + if(var_num_loop.getType() == var.getType() && var_num_loop.getName().compareTo(var.getName()) == 0) + { + return true; + } + } + return false; + } +} diff --git a/src/funsoftware/ic/loo/rotationSensorLoopIcon.java b/src/funsoftware/ic/loo/rotationSensorLoopIcon.java new file mode 100644 index 0000000..ded462b --- /dev/null +++ b/src/funsoftware/ic/loo/rotationSensorLoopIcon.java @@ -0,0 +1,870 @@ +/* + * rotationSensorLoopIcon.java + * + * Created on 17 December 2005, 18:59 + * + */ + +package funsoftware.ic.loo; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.st.*; +import funsoftware.var.*; +import funsoftware.consts.*; + +/** + * This icon is a loop that continues unless the value from the rotational sensor is less or greater than a specified treshold value + * @author Thomas Legowo + */ +public class rotationSensorLoopIcon extends loopIcon { + + private int port; // with default value being 1, port is the value of the input port of this rotation sensor + private int angle_value; // default value being 16 (1 rotation) + private variable var_angle_value; // alternative to angle_value + + private int type; // default = 0 means "less than", if type = 1 it means "greater than" + + // for algorithm representation, this rotation sensor loop icon has an identifier of 6 + private int identifier; + + /** Creates a new instance of rotationSensorLoopIcon */ + public rotationSensorLoopIcon() { + } + + /** + * Creates a new instance of infiniteLoopIcon + * @param filepath The source file of this icon's image + */ + public rotationSensorLoopIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); + super.setHeight(super.getImage().getImage().getHeight(this)); + identifier = 6; + port = 1; + angle_value = 16; + type = 1; + var_angle_value = null; + setImage(); + } + + /** + * Helps provide the transparent background + * @param g Graphic + */ + protected void paintComponent(java.awt.Graphics g) + { + super.paintComponent(g); + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/loops/rotation/rotation_field.gif")); + g.drawImage(ii.getImage(), 14, 24, this); + } + + /** + * Returns the port this rotation sensor is operating in + * @return Port value + */ + public int getPort() + { + return port; + } + + /** + * Gets the rotation sensor value threshold + * @return angle value threshold + */ + public int getAngleValue() + { + return angle_value; + } + + /** + * Returns the type whether it is greater than or less than + * @return Comparison type (< or >) + */ + public int getType() + { + return type; + } + + /** + * Sets the port of the sensor + * @param nport New port value + */ + public void setPort(int nport) + { + port = nport; + } + + /** + * Sets the rotation sensor angle value threshold of the sensor + * @param na The angle value + */ + public void setAngleValue(int na) + { + angle_value = na; + } + + /** + * Sets the comparison type of the loop icon + * @param nt New type + */ + public void setType(int nt) + { + type = nt; + } + + /** + * To set the angular value of this branch rotational sensor icon + * @param var The angle value variable + */ + public void setVarAngle(variable var) + { + var_angle_value = var; + } + + /** + * Sets the image of this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + javax.swing.ImageIcon nic; + PicButton pic; + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + javax.swing.JPanel jp3 = new javax.swing.JPanel(); + + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(40, 24)); + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/loops/rotation/toprotation.gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(pic, gridBagConstraints); + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/loops/rotation/comp"+type+".gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp2.add(pic, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(jp2, gridBagConstraints); + + jp3 = new javax.swing.JPanel(); + jp3.setLayout(new java.awt.GridBagLayout()); + jp3.setPreferredSize(new java.awt.Dimension(40, 16)); + + jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(14, 16)); + + javax.swing.JLabel portLabel = new javax.swing.JLabel(Integer.toString(port)); + portLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + portLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(portLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp3.add(jp2, gridBagConstraints); + + jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(26, 16)); + + javax.swing.JLabel angleLabel; + if(var_angle_value == null) + { + angleLabel = new javax.swing.JLabel(Integer.toString(angle_value)); + } + else + { + angleLabel = new javax.swing.JLabel("V"); + } + angleLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + angleLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + angleLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(angleLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp3.add(jp2, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + jp3.setOpaque(false); + add(jp3, gridBagConstraints); + setOpaque(false); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * To change the port of the sensor + * @param evt MouseEvent + */ + public void changePort(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField = new javax.swing.JTextField(Integer.toString(port)); + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(14,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditModePort(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the angle sensor value threshold + * @param evt MouseEvent + */ + public void changeAngleSensorValue(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField; + if(var_angle_value != null) + { + textField = new javax.swing.JTextField("v"); + } + else + { + textField = new javax.swing.JTextField(Integer.toString(angle_value)); + } + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(25,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + jp.setOpaque(false); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditModeAngleSensorValue(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the comparator of this loop's ending case (either less than or greater than) + * @param evt MouseEvent + */ + public void changeComparator(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + ComparatorDialog c_dialog = new ComparatorDialog(null, type, this); + c_dialog.pack(); + c_dialog.setLocationRelativeTo(this); + c_dialog.setVisible(true); + + type = c_dialog.getComparator(); + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + jp.remove(1); + // displays the comparator according to its type + javax.swing.ImageIcon nic = new javax.swing.ImageIcon(getClass().getResource("/icons/loops/rotation/comp"+type+".gif")); + PicButton pic = new PicButton(nic); + java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + // set the states for undo and redo + UndoRedo.update_state(); + + repaint(); + validate(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * Stop the edit mode on port value of this icon + */ + public void stopEditModePort() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + jp.removeAll(); + + // parse the input port + int tmp_port = port; // current port number + try + { + port = Integer.parseInt(text); + if(port > 3 || port < 1) // 3 ports + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the input port is invalid.\nIt can be either 1, 2 or 3.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + port = tmp_port; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the input port is invalid.\nPlease enter numbers only (1 to 3).\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_port != port) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(14, 16)); + + javax.swing.JLabel portLabel = new javax.swing.JLabel(Integer.toString(port)); + portLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + portLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(portLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(jp2, gridBagConstraints); + + repaint(); + validate(); + } + + /** + * Stops the edit mode for the angle sensor value threshold + */ + public void stopEditModeAngleSensorValue() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + jp.removeAll(); + + // parse the timer value + int tmp_angle = angle_value; // current timer value + try + { + if(text.compareTo("v") == 0 || text.compareTo("V") == 0) + { + if(var_list.Instance().isDefinedVariables() == true || findCurrentAux().getLocalVarList().isEmpty() == false) + { + VarInputDialog vid = new VarInputDialog(null, this, findCurrentAux()); + vid.pack(); + vid.setLocationRelativeTo(this); + vid.setVisible(true); + + if(vid.getUserInput() != null) + { + var_angle_value = vid.getUserInput(); + } + } + else + { + javax.swing.JOptionPane.showMessageDialog(null, + "You have not defined any global variables or local variables to this function or task yet.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + } + else + { + angle_value = Integer.parseInt(text); + var_angle_value = null; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the rotational sensor threshold is invalid.\nPlease enter numbers only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_angle != angle_value || var_angle_value != null) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(26, 16)); + + javax.swing.JLabel angleLabel; + if(var_angle_value == null) + { + angleLabel = new javax.swing.JLabel(Integer.toString(angle_value)); + } + else + { + angleLabel = new javax.swing.JLabel("V"); + } + angleLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + angleLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + angleLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(angleLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(jp2, gridBagConstraints); + + repaint(); + validate(); + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + java.awt.event.MouseListener[] ml = jp.getMouseListeners(); + for(int i=0; i port + sp2 = sp[0].split(att_value_connector); + port = Integer.parseInt(sp2[1]); + + // do the second one --> angle_sensor_value + sp2 = sp[1].split(att_value_connector); + if(sp2[1].substring(0,1).compareTo("V") == 0) // must be a variable + { + var_angle_value = var_list.Instance().getVariable(sp2[1].substring(2)); + if(var_angle_value == null) // must be local, not global + { + var_angle_value = getAux().getVariable(sp2[1].substring(2)); + } + } + else + { + angle_value = Integer.parseInt(sp2[1]); + } + + // do the first one --> type + sp2 = sp[2].split(att_value_connector); + type = Integer.parseInt(sp2[1]); + } + + /** + * To display an input panel to ask for a variable to be used + * @return The label of the panel + */ + public javax.swing.JLabel getVarLabel() + { + return new javax.swing.JLabel("Rotational Value Threshold"); + } + + /** + * To indicate whether this icon uses a variable + * @param var Variable to be checked + * @return True or false + */ + public Boolean useAVariable(variable var) + { + if(var_angle_value != null) + { + if(var_angle_value.getType() == var.getType() && var_angle_value.getName().compareTo(var.getName()) == 0) + { + return true; + } + } + return false; + } +} diff --git a/src/funsoftware/ic/loo/timerLoopIcon.java b/src/funsoftware/ic/loo/timerLoopIcon.java new file mode 100644 index 0000000..f433f5d --- /dev/null +++ b/src/funsoftware/ic/loo/timerLoopIcon.java @@ -0,0 +1,872 @@ +/* + * timerLoopIcon.java + * + * Created on 17 December 2005, 19:01 + * + */ + +package funsoftware.ic.loo; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.st.*; +import funsoftware.var.*; +import funsoftware.consts.*; + +/** + * This class represents a loop that continues to loop unless the value of the specified timer is less than or greater than a treshold value + * @author Thomas Legowo + */ +public class timerLoopIcon extends loopIcon { + + private int timer_number; // with default value being 0, can be between 0 and 3 + private int timer_value; // default value being 50, minimum is 1, unit is in 100ms. + private variable var_timer_value; // alternative to timer_value + private int type; // if type = 1 it means "greater than" + + // for algorithm representation, this timer loop icon has an identifier of 4 + private int identifier; + + /** Creates a new instance of timerLoopIcon */ + public timerLoopIcon() { + } + + /** + * Creates a new instance of infiniteLoopIcon + * @param filepath The source file of this icon's image + */ + public timerLoopIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); + super.setHeight(super.getImage().getImage().getHeight(this)); + identifier = 4; + timer_number = 0; + timer_value = 50; + type = 1; + var_timer_value = null; + setImage(); + } + + /** + * Helps provide the transparent background + * @param g Graphic + */ + protected void paintComponent(java.awt.Graphics g) + { + super.paintComponent(g); + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/loops/timer/timer_field.gif")); + g.drawImage(ii.getImage(), 14, 24, this); + } + + /** + * Returns the timer number of this loop + * @return Timer number + */ + public int getTimerNumber() + { + return timer_number; + } + + /** + * Gets the timer value threshold + * @return timer value threshold + */ + public int getTimerValue() + { + return timer_value; + } + + /** + * Returns the type whether it is greater than or less than + * @return Comparison type (< or >) + */ + public int getType() + { + return type; + } + + /** + * Sets the number of the timer + * @param ntn The new timer number + */ + public void setTimerNumber(int ntn) + { + timer_number = ntn; + } + + /** + * Sets the timer value threshold of the sensor + * @param ntv The new timer value + */ + public void setTimerValue(int ntv) + { + timer_value = ntv; + } + + /** + * Sets the comparison type of the loop icon + * @param nt New type + */ + public void setType(int nt) + { + type = nt; + } + + /** + * Set the timer value of this icon + * @param var The timer value variable + */ + public void setVarTimerVal(variable var) + { + var_timer_value = var; + } + + /** + * Sets the image of this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + javax.swing.ImageIcon nic; + PicButton pic; + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + javax.swing.JPanel jp3 = new javax.swing.JPanel(); + + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(40, 24)); + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/loops/timer/toploop.gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(pic, gridBagConstraints); + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/loops/timer/comp"+type+".gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp2.add(pic, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(jp2, gridBagConstraints); + + jp3 = new javax.swing.JPanel(); + jp3.setLayout(new java.awt.GridBagLayout()); + jp3.setPreferredSize(new java.awt.Dimension(40, 16)); + + jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(14, 16)); + + javax.swing.JLabel timerNumberLabel = new javax.swing.JLabel(Integer.toString(timer_number)); + timerNumberLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + timerNumberLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + timerNumberLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(timerNumberLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp3.add(jp2, gridBagConstraints); + + jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(26, 16)); + + javax.swing.JLabel timerValueLabel; + if(var_timer_value == null) + { + timerValueLabel = new javax.swing.JLabel(Integer.toString(timer_value)); + } + else + { + timerValueLabel = new javax.swing.JLabel("V"); + } + timerValueLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + timerValueLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + timerValueLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(timerValueLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp3.add(jp2, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + jp3.setOpaque(false); + add(jp3, gridBagConstraints); + setOpaque(false); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * To change the timer number of the sensor + * @param evt MouseEvent + */ + public void changeTimerNumber(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField = new javax.swing.JTextField(Integer.toString(timer_number)); + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(14,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditModeTimerNumber(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the timer value threshold + * @param evt MouseEvent + */ + public void changeTimerValue(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField; + if(var_timer_value != null) + { + textField = new javax.swing.JTextField("v"); + } + else + { + textField = new javax.swing.JTextField(Integer.toString(timer_value)); + } + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(25,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + jp.setOpaque(false); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditModeTimerValue(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the comparator of this loop's ending case (either less than or greater than) + * @param evt MouseEvent + */ + public void changeComparator(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + ComparatorDialog c_dialog = new ComparatorDialog(null, type, this); + c_dialog.pack(); + c_dialog.setLocationRelativeTo(this); + c_dialog.setVisible(true); + + type = c_dialog.getComparator(); + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + jp.remove(1); + // displays the comparator according to its type + javax.swing.ImageIcon nic = new javax.swing.ImageIcon(getClass().getResource("/icons/loops/timer/comp"+type+".gif")); + PicButton pic = new PicButton(nic); + java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + // set the states for undo and redo + UndoRedo.update_state(); + + repaint(); + validate(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * Stop the edit mode on timer number of this icon + */ + public void stopEditModeTimerNumber() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + jp.removeAll(); + + // parse the timer number + int tmp_timer_number = timer_number; // current port number + try + { + timer_number = Integer.parseInt(text); + if(timer_number > 3 || timer_number < 0) // maximum of 4 timers + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the timer number is invalid.\nIt can only be either between 0 and 3.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + timer_number = tmp_timer_number; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the timer number is invalid.\nPlease enter numbers only (0 to 3).\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_timer_number != timer_number) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(14, 16)); + + javax.swing.JLabel timerNumberLabel = new javax.swing.JLabel(Integer.toString(timer_number)); + timerNumberLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + timerNumberLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + timerNumberLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(timerNumberLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(jp2, gridBagConstraints); + + repaint(); + validate(); + } + + /** + * Stops the edit mode for the timer value threshold + */ + public void stopEditModeTimerValue() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + jp.removeAll(); + + // parse the timer value + int tmp_timer_value = timer_value; // current timer value + try + { + if(text.compareTo("v") == 0 || text.compareTo("V") == 0) + { + if(var_list.Instance().isDefinedVariables() == true || findCurrentAux().getLocalVarList().isEmpty() == false) + { + VarInputDialog vid = new VarInputDialog(null, this, findCurrentAux()); + vid.pack(); + vid.setLocationRelativeTo(this); + vid.setVisible(true); + + if(vid.getUserInput() != null) + { + var_timer_value = vid.getUserInput(); + } + } + else + { + javax.swing.JOptionPane.showMessageDialog(null, + "You have not defined any global variables or local variables to this function or task yet.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + } + else + { + timer_value = Integer.parseInt(text); + if(timer_value < 1) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the timer threshold is invalid.\nMinimum value is 1.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + timer_value = tmp_timer_value; + } + else + { + var_timer_value = null; + } + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the timer threshold is invalid.\nPlease enter numbers only (Greater than 1).\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_timer_value != timer_value || var_timer_value != null) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(26, 16)); + + javax.swing.JLabel timerValueLabel; + if(var_timer_value == null) + { + timerValueLabel = new javax.swing.JLabel(Integer.toString(timer_value)); + } + else + { + timerValueLabel = new javax.swing.JLabel("V"); + } + timerValueLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + timerValueLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + timerValueLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(timerValueLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(jp2, gridBagConstraints); + + repaint(); + validate(); + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + java.awt.event.MouseListener[] ml = jp.getMouseListeners(); + for(int i=0; i port + sp2 = sp[0].split(att_value_connector); + timer_number = Integer.parseInt(sp2[1]); + + // do the second one --> timer_value + sp2 = sp[1].split(att_value_connector); + if(sp2[1].substring(0,1).compareTo("V") == 0) // must be a variable + { + var_timer_value = var_list.Instance().getVariable(sp2[1].substring(2)); + if(var_timer_value == null) // must be local, not global + { + var_timer_value = getAux().getVariable(sp2[1].substring(2)); + } + } + else + { + timer_value = Integer.parseInt(sp2[1]); + } + + // do the first one --> type + sp2 = sp[2].split(att_value_connector); + type = Integer.parseInt(sp2[1]); + } + + /** + * To display an input panel to ask for a variable to be used + * @return The label of the panel + */ + public javax.swing.JLabel getVarLabel() + { + return new javax.swing.JLabel("Timer Value Threshold"); + } + + /** + * To indicate whether this icon uses a variable + * @param var Variable to be checked + * @return True or false + */ + public Boolean useAVariable(variable var) + { + if(var_timer_value != null) + { + if(var_timer_value.getType() == var.getType() && var_timer_value.getName().compareTo(var.getName()) == 0) + { + return true; + } + } + return false; + } +} diff --git a/src/funsoftware/ic/loo/touchSensorLoopIcon.java b/src/funsoftware/ic/loo/touchSensorLoopIcon.java new file mode 100644 index 0000000..5d0748f --- /dev/null +++ b/src/funsoftware/ic/loo/touchSensorLoopIcon.java @@ -0,0 +1,526 @@ +/* + * touchSensorLoopIcon.java + * + * Created on 30 January 2006, 10:00 + * + */ + +package funsoftware.ic.loo; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.st.*; + +/** + * This icon loops a set of icons if the specified touch sensor is touched + * @author Thomas Legowo + */ +public class touchSensorLoopIcon extends loopIcon{ + + private int port; // with default value being 1, port is the value of the input port of this touch sensor + private int type; // default = 0 means "Not touched", if type = 1 it means "Touched" + + // for algorithm representation, this touch sensor loop icon has an identifier of 7 + private int identifier; + + /** Creates a new instance of touchSensorLoopIcon */ + public touchSensorLoopIcon() { + } + + /** + * Creates a new instance of touchSensorLoopIcon + * @param filepath The source file of this icon's image + */ + public touchSensorLoopIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); + super.setHeight(super.getImage().getImage().getHeight(this)); + identifier = 7; + port = 1; + type = 1; + setImage(); + } + + /** + * Returns the port this touch sensor is operating in + * @return Port value + */ + public int getPort() + { + return port; + } + + /** + * Returns the type whether it is greater than or less than + * @return Comparison type (Y or N) + */ + public int getType() + { + return type; + } + + /** + * Sets the port of the sensor + * @param nport New port value + */ + public void setPort(int nport) + { + port = nport; + } + + /** + * Sets the comparison type of the loop icon + * @param nt New type + */ + public void setType(int nt) + { + type = nt; + } + + /** + * Sets the image of this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + javax.swing.ImageIcon nic; + PicButton pic; + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + javax.swing.JPanel jp3 = new javax.swing.JPanel(); + javax.swing.JPanel jp4 = new javax.swing.JPanel(); + + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(29, 40)); + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/loops/touch/toptouch.gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(pic, gridBagConstraints); + + jp4.setLayout(new java.awt.GridBagLayout()); + jp4.setPreferredSize(new java.awt.Dimension(29, 16)); + + jp3.setLayout(new java.awt.GridBagLayout()); + jp3.setPreferredSize(new java.awt.Dimension(14, 16)); + + javax.swing.JLabel portLabel = new javax.swing.JLabel(Integer.toString(port)); + portLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + portLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp3.setOpaque(false); + jp4.setOpaque(false); + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp3.add(portLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp4.add(jp3, gridBagConstraints); + + jp3 = new javax.swing.JPanel(); + jp3.setPreferredSize(new java.awt.Dimension(15, 16)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp4.add(jp3, gridBagConstraints); + jp3.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + jp2.add(jp4, gridBagConstraints); + + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(jp2, gridBagConstraints); + + if(type == 0) + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/loops/touch/signal0.gif")); + } + else if(type == 1) + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/loops/touch/signal1.gif")); + } + + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + add(pic, gridBagConstraints); + + setOpaque(false); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * To change the port of the sensor + * @param evt MouseEvent + */ + public void changePort(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField = new javax.swing.JTextField(Integer.toString(port)); + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(14,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditModePort(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * Stop the edit mode on port value of this icon + */ + public void stopEditModePort() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + jp.removeAll(); + + // parse the input port + int tmp_port = port; // current port number + try + { + port = Integer.parseInt(text); + if(port > 3 || port < 1) // 3 ports + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the input port is invalid.\nIt can be either 1, 2 or 3.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + port = tmp_port; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the input port is invalid.\nPlease enter numbers only (1 to 3).\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_port != port) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(0); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + + jp.setLayout(new java.awt.GridBagLayout()); + jp.setPreferredSize(new java.awt.Dimension(14, 16)); + + javax.swing.JLabel portLabel = new javax.swing.JLabel(Integer.toString(port)); + portLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + portLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(portLabel, gridBagConstraints); + + repaint(); + validate(); + } + + /** + * To change the comparator of this loop's ending case (either less than or greater than) + * @param evt MouseEvent + */ + public void changeComparator(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.ImageIcon nic = new javax.swing.ImageIcon(); + if(type == 0) + { + type = 1; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/loops/touch/signal1.gif")); + } + else if(type == 1) + { + type = 0; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/loops/touch/signal0.gif")); + } + + PicButton picpic = (PicButton)getComponent(1); + picpic.setIcon(nic); + + // set the states for undo and redo + UndoRedo.update_state(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + jp = (javax.swing.JPanel)jp.getComponent(1); + java.awt.event.MouseListener[] ml = jp.getMouseListeners(); + for(int i=0; i port + sp2 = sp[0].split(att_value_connector); + port = Integer.parseInt(sp2[1]); + + // do the first one --> type + sp2 = sp[1].split(att_value_connector); + type = Integer.parseInt(sp2[1]); + } + +} diff --git a/src/funsoftware/ic/obj/beepIcon.java b/src/funsoftware/ic/obj/beepIcon.java new file mode 100644 index 0000000..cc7b26b --- /dev/null +++ b/src/funsoftware/ic/obj/beepIcon.java @@ -0,0 +1,362 @@ +/* + * beepIcon.java + * + * Created on 26 August 2005, 18:34 + */ + +package funsoftware.ic.obj; + +import funsoftware.ic.*; +import funsoftware.st.*; + +/** + * This class handles the icon that manages the robot when it comes to making the beeping sound + * @author Thomas Legowo + * + */ +public class beepIcon extends objectIcon{ + + private int sound_type; // ranging from 1 to 6 + + // for algorithm representation, represent a beep icon with an identifier of 5 + private int identifier; + private double zoom_scale; + /** Creates a new instance of beepIcon */ + public beepIcon() { + } + + /** + * Creates a new instance of beepIcon + * @param filepath The source file of this icon's image + */ + public beepIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); + sound_type = 6; // initially is 6 + identifier = 5; + zoom_scale = 1; + setImage(); + } + + // now methods dealing with the other attribute of this beep icon + /** + * Gets the sound type + * @return Sound type + */ + public int getSoundType() + { + return sound_type; + } + + /** + * Sets the sound type + * @param nst Sound type + */ + public void setSoundType(int nst) + { + sound_type = nst; + } + + /** + * To set the image of this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + javax.swing.ImageIcon nic; + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/beeps/topbeep.gif")); + PicButton pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(pic, gridBagConstraints); + + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(40, 16)); + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/beeps/bottomleftbeep.gif")); + pic = new PicButton(nic); + + jp2.add(pic); + + javax.swing.JLabel beepLabel = new javax.swing.JLabel(Integer.toString(sound_type)); + beepLabel.setFont(new java.awt.Font("Tahoma", 1, 10)); + beepLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + beepLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + setOpaque(false); + + jp2.add(beepLabel); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(jp2, gridBagConstraints); + + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * To change the sound type + * @param evt MouseEvent + */ + public void changeSoundType(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + // the text field to edit the beep sound + javax.swing.JTextField textField = new javax.swing.JTextField(Integer.toString(sound_type)); + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(14,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + + removeAll(); + setLayout(new java.awt.GridBagLayout()); + + javax.swing.ImageIcon nic; + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/beeps/topbeep.gif")); + PicButton pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(pic, gridBagConstraints); + + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(40, 16)); + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/beeps/bottomleftbeep.gif")); + pic = new PicButton(nic); + + jp2.add(pic); + jp2.setOpaque(false); + setOpaque(false); + + jp2.add(textField); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(jp2, gridBagConstraints); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditMode(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To handle click that stops edit mode + */ + public void stopEditMode() + { + javax.swing.JPanel panel = (javax.swing.JPanel)getComponent(1); + javax.swing.JTextField textField = (javax.swing.JTextField)panel.getComponent(1); + String text = textField.getText(); + removeAll(); + + // set the number of loops + int tmp_st = sound_type; + try + { + sound_type = Integer.parseInt(text); + if(sound_type > 6 || sound_type < 1) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the beep's sound type is invalid.\nPermitted value is between 1 to 6.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + sound_type = tmp_st; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the beep's sound type is invalid.\nPlease enter numbers (1 to 6) only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + + // set the states for undo and redo + if(tmp_st != sound_type) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // reset the icon's graphics + setImage(); + + repaint(); + validate(); + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + java.awt.event.MouseListener[] ml = getMouseListeners(); + for(int i=0; i sound type + sp2 = sp[0].split(att_value_connector); + sound_type = Integer.parseInt(sp2[1]); + } +} diff --git a/src/funsoftware/ic/obj/clearSensorIcon.java b/src/funsoftware/ic/obj/clearSensorIcon.java new file mode 100644 index 0000000..3412df4 --- /dev/null +++ b/src/funsoftware/ic/obj/clearSensorIcon.java @@ -0,0 +1,567 @@ +/* + * ClearSensorIcon.java + * + * Created on 16 December 2005, 16:10 + */ + +package funsoftware.ic.obj; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.st.*; + +/** + * This class represents an icon that can be used to clear the values of sensors connected to the RCX input ports + * @author Thomas Legowo + */ +public class clearSensorIcon extends objectIcon{ + + private int input1; // if input1 = 0, then all sensors connected to this input 1 would not be cleared + private int input2; + private int input3; + + // for algorithm representation, represent a stop motor icon with an identifier of 7 + private int identifier; + + /** Creates a new instance of ClearSensorIcon */ + public clearSensorIcon() { + } + + /** + * Creates a new instance of clearsensorIcon + * @param filepath The source file of this icon's image + */ + public clearSensorIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); // for startIcon the size of the icon is 26x61 + input1 = 1; + input2 = 1; + input3 = 1; + identifier = 7; + setImage(); + } + + + // to get the status of the input sensors + /** + * Gets the status of input 1 + * @return input1 status + */ + public int input1Status() + { + return input1; + } + + /** + * Gets the status of input 2 + * @return input2 status + */ + public int input2Status() + { + return input2; + } + + /** + * Gets the status of input 3 + * @return input3 status + */ + public int input3Status() + { + return input3; + } + + + // methods for the input ports, these methods also change the graphical representation of the clear sensor icon's attributes + // the little boxes with the numbers '1', '2' and '3' will change in background colour depending on whether + // the sensors connected to the ports are to be cleared + /** + * Clear input1 + */ + public void turninput1on() + { + input1 = 1; + } + /** + * Don't clear input1 + */ + public void turninput1off() + { + input1 = 0; + } + /** + * Clear input2 + */ + public void turninput2on() + { + input2 = 1; + } + /** + * Don't clear input2 + */ + public void turninput2off() + { + input2 = 0; + } + /** + * Clear input3 + */ + public void turninput3on() + { + input3 = 1; + } + /** + * Don't clear input3 + */ + public void turninput3off() + { + input3 = 0; + } + + + /** + * Sets the image of this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + + // creating the top panel + javax.swing.JPanel jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp.setPreferredSize(new java.awt.Dimension(40, 30)); + javax.swing.ImageIcon nic; + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/sensors/top.gif")); + PicButton pic = new PicButton(nic); + jp.add(pic); + + // creating the bottom panel + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(40, 10)); + if(input1 == 0) + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/sensors/input1_off.gif")); + } + else + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/sensors/input1_clear.gif")); + } + pic = new PicButton(nic); + jp2.add(pic); + + if(input2 == 0) + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/sensors/input2_off.gif")); + } + else + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/sensors/input2_clear.gif")); + } + pic = new PicButton(nic); + jp2.add(pic); + + if(input3 == 0) + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/sensors/input3_off.gif")); + } + else + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/sensors/input3_clear.gif")); + } + pic = new PicButton(nic); + jp2.add(pic); + + // joining the top and bottom panels + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(jp, gridBagConstraints); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(jp2, gridBagConstraints); + + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + // the handlers method + /** + * Change the status of input port 1 + * @param evt MouseEvent + */ + public void changeInput1(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.ImageIcon nic; + if(input1 == 0) // not cleared yet + { + input1 = 1; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/sensors/input1_clear.gif")); + } + else + { + input1 = 0; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/sensors/input1_off.gif")); + } + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(1); + PicButton picpic = (PicButton) jp.getComponent(0); + picpic.setIcon(nic); + + // set the states for undo and redo + UndoRedo.update_state(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + /** + * Change the status of input port 2 + * @param evt MouseEvent + */ + public void changeInput2(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.ImageIcon nic; + if(input2 == 0) // not cleared yet + { + input2 = 1; // now it is cleared + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/sensors/input2_clear.gif")); + } + else + { + input2 = 0; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/sensors/input2_off.gif")); + } + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(1); + PicButton picpic = (PicButton) jp.getComponent(1); + picpic.setIcon(nic); + + // set the states for undo and redo + UndoRedo.update_state(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + /** + * Change the status of input port 3 + * @param evt MouseEvent + */ + public void changeInput3(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.ImageIcon nic; + if(input3 == 0) // not cleared yet + { + input3 = 1; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/sensors/input3_clear.gif")); + } + else + { + input3 = 0; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/sensors/input3_off.gif")); + } + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(1); + PicButton picpic = (PicButton) jp.getComponent(2); + picpic.setIcon(nic); + + // set the states for undo and redo + UndoRedo.update_state(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(1); + PicButton pic = (PicButton) jp.getComponent(0); + java.awt.event.MouseListener[] ml = pic.getMouseListeners(); + for(int i=0; i input1 + sp2 = sp[0].split(att_value_connector); + input1 = Integer.parseInt(sp2[1]); + + // do the second one --> input2 + sp2 = sp[1].split(att_value_connector); + input2 = Integer.parseInt(sp2[1]); + + // do the third one --> input3 + sp2 = sp[2].split(att_value_connector); + input3 = Integer.parseInt(sp2[1]); + } +} diff --git a/src/funsoftware/ic/obj/clearTimerIcon.java b/src/funsoftware/ic/obj/clearTimerIcon.java new file mode 100644 index 0000000..fbcae6a --- /dev/null +++ b/src/funsoftware/ic/obj/clearTimerIcon.java @@ -0,0 +1,367 @@ +/* + * clearTimerIcon.java + * + * Created on 16 December 2005, 17:00 + */ + +package funsoftware.ic.obj; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.st.*; + +/** + * This class represents the clear timer process + * @author Thomas Legowo + */ +public class clearTimerIcon extends objectIcon{ + + private int timer; // 0 to 3 + + // for algorithm representation, represent a cleartimer icon with an identifier of 8 + private int identifier; + + /** Creates a new instance of clearTimerIcon */ + public clearTimerIcon() { + } + + /** + * Creates a new instance of clearTimerIcon + * @param filepath The source file of this icon's image + */ + public clearTimerIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); + timer = 0; + identifier = 8; + setImage(); + } + + /** + * Helps provide the transparent background + * @param g Graphic + */ + protected void paintComponent(java.awt.Graphics g) + { + super.paintComponent(g); + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/timers/cleart/timer_field.gif")); + g.drawImage(ii.getImage(), 26, 24, this); + } + + // now methods dealing with the other attribute of this clear timer icon + /** + * Gets the timer type + * @return Timer type + */ + public int getTimer() + { + return timer; + } + + /** + * Sets the timer type + * @param nt The new timer + */ + public void setTimer(int nt) + { + timer = nt; + } + + /** + * To set the image of this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + javax.swing.ImageIcon nic; + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/timers/cleart/top.gif")); + PicButton pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(pic, gridBagConstraints); + + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(40, 16)); + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/timers/cleart/bottomleft.gif")); + pic = new PicButton(nic); + + jp2.add(pic); + + javax.swing.JLabel timerLabel = new javax.swing.JLabel(Integer.toString(timer)); + timerLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + timerLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + timerLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + + jp2.add(timerLabel); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(jp2, gridBagConstraints); + + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * To change the timer type + * @param evt MouseEvent + */ + public void changeTimer(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + // the text field to edit the timer type + javax.swing.JTextField textField = new javax.swing.JTextField(Integer.toString(timer)); + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(14,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + java.awt.GridBagConstraints gridBagConstraints; + + removeAll(); + setLayout(new java.awt.GridBagLayout()); + + javax.swing.ImageIcon nic; + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/timers/cleart/top.gif")); + PicButton pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(pic, gridBagConstraints); + + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(40, 16)); + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/timers/cleart/bottomleft.gif")); + pic = new PicButton(nic); + jp2.setOpaque(false); + jp2.add(pic); + + jp2.add(textField); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(jp2, gridBagConstraints); + + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditMode(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To handle click that stops edit mode + */ + public void stopEditMode() + { + javax.swing.JPanel panel = (javax.swing.JPanel)getComponent(1); + javax.swing.JTextField textField = (javax.swing.JTextField)panel.getComponent(1); + String text = textField.getText(); + removeAll(); + + // set the number of loops + int tmp_st = timer; + try + { + timer = Integer.parseInt(text); + if(timer > 3 || timer < 0) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the timer type is invalid.\nPermitted value is between 0 to 3.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + timer = tmp_st; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the timer type is invalid.\nPlease enter numbers (0 to 3) only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + + // set the states for undo and redo + if(tmp_st != timer) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // reset the icon's graphics + setImage(); + + repaint(); + validate(); + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + java.awt.event.MouseListener[] ml = getMouseListeners(); + for(int i=0; i sound type + sp2 = sp[0].split(att_value_connector); + timer = Integer.parseInt(sp2[1]); + } +} \ No newline at end of file diff --git a/src/funsoftware/ic/obj/directionalMotorIcon.java b/src/funsoftware/ic/obj/directionalMotorIcon.java new file mode 100644 index 0000000..fd54478 --- /dev/null +++ b/src/funsoftware/ic/obj/directionalMotorIcon.java @@ -0,0 +1,581 @@ +/* + * directionalMotor.java + * + * Created on 4 September 2005, 18:36 + */ + +package funsoftware.ic.obj; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.st.*; + +/** + * This method will flip the direction of all motors that are connected in the specified port. + * @author Thomas Legowo + * + */ +public class directionalMotorIcon extends objectIcon{ + + // other private attributes + + private int portA; // 0 if direction of motor in portA is not changed, 1 implies that the direction is changed + private int portB; + private int portC; + + // for algorithm representation, represent a directional motor icon with an identifier of 3 + private int identifier; + + /** Creates a new instance of directionalMotor */ + public directionalMotorIcon() { + } + + /** + * Creates a new instance of directionalMotor + * @param filepath The source file of this icon's image + */ + public directionalMotorIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); // for startIcon the size of the icon is 26x61 + portA = 1; + portB = 1; // by default, all motors in all ports are to be changed in direction + portC = 1; + identifier = 3; + setImage(); + } + + + // to get the status of individual port + /** + * Get port A status + * @return Port A status + */ + public int portAStatus() + { + return portA; + } + + /** + * Get port B status + * @return Port B status + */ + public int portBStatus() + { + return portB; + } + + /** + * Get port C status + * @return Port C status + */ + public int portCStatus() + { + return portC; + } + + + // methods for the ports, these methods also change the graphical representation of the motor icon's attributes + // the little boxes with the letters 'A', 'B' or 'C' will change in background colour depending on whether + // the port is turned on + /** + * Turn port A on + */ + public void turnPortAon() + { + portA = 1; + } + /** + * Turn port A off + */ + public void turnPortAoff() + { + portA = 0; + } + /** + * Turn port B on + */ + public void turnPortBon() + { + portB = 1; + } + /** + * Turn port B off + */ + public void turnPortBoff() + { + portB = 0; + } + /** + * Turn port C on + */ + public void turnPortCon() + { + portC = 1; + } + /** + * Turn port C off + */ + public void turnPortCoff() + { + portC = 0; + } + + + /** + * Set the image of this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + + // creating the top panel + javax.swing.JPanel jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp.setPreferredSize(new java.awt.Dimension(40, 30)); + javax.swing.ImageIcon nic; + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/directional/topdir.gif")); + PicButton pic = new PicButton(nic); + jp.add(pic); + + // creating the bottom panel + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(40, 10)); + if(portA == 0) + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/directional/A_norm.gif")); + } + else + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/directional/A_rev.gif")); + } + pic = new PicButton(nic); + jp2.add(pic); + + if(portB == 0) + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/directional/B_norm.gif")); + } + else + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/directional/B_rev.gif")); + } + pic = new PicButton(nic); + jp2.add(pic); + + if(portC == 0) + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/directional/C_norm.gif")); + } + else + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/directional/C_rev.gif")); + } + pic = new PicButton(nic); + jp2.add(pic); + + // joining the top and bottom panels + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(jp, gridBagConstraints); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(jp2, gridBagConstraints); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + // the handlers method + /** + * To change the status of port A + * @param evt MouseEvent + */ + public void changeA(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.ImageIcon nic; + if(portA == 0) // not turned off yet + { + portA = 1; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/directional/A_rev.gif")); + } + else + { + portA = 0; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/directional/A_norm.gif")); + } + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(1); + PicButton picpic = (PicButton) jp.getComponent(0); + picpic.setIcon(nic); + + // set the states for undo and redo + UndoRedo.update_state(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + /** + * To change the status of port B + * @param evt MouseEvent + */ + public void changeB(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.ImageIcon nic; + if(portB == 0) // not turned off yet + { + portB = 1; // now it is turned off + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/directional/B_rev.gif")); + } + else + { + portB = 0; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/directional/B_norm.gif")); + } + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(1); + PicButton picpic = (PicButton) jp.getComponent(1); + picpic.setIcon(nic); + + // set the states for undo and redo + UndoRedo.update_state(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + /** + * To change the status of port C + * @param evt MouseEvent + */ + public void changeC(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.ImageIcon nic; + if(portC == 0) // not turned off yet + { + portC = 1; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/directional/C_rev.gif")); + } + else + { + portC = 0; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/directional/C_norm.gif")); + } + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(1); + PicButton picpic = (PicButton) jp.getComponent(2); + picpic.setIcon(nic); + + // set the states for undo and redo + UndoRedo.update_state(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(1); + PicButton pic = (PicButton) jp.getComponent(0); + java.awt.event.MouseListener[] ml = pic.getMouseListeners(); + for(int i=0; i portA + sp2 = sp[0].split(att_value_connector); + portA = Integer.parseInt(sp2[1]); + + // do the second one --> portB + sp2 = sp[1].split(att_value_connector); + portB = Integer.parseInt(sp2[1]); + + // do the third one --> portC + sp2 = sp[2].split(att_value_connector); + portC = Integer.parseInt(sp2[1]); + } + +} diff --git a/src/funsoftware/ic/obj/floatMotorIcon.java b/src/funsoftware/ic/obj/floatMotorIcon.java new file mode 100644 index 0000000..b9bcdf1 --- /dev/null +++ b/src/funsoftware/ic/obj/floatMotorIcon.java @@ -0,0 +1,582 @@ +/* + * floatMotorIcon.java + * + * Created on 31 January 2006, 09:49 + * + */ + +package funsoftware.ic.obj; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.st.*; + +/** + * Float motor means to turn off the motors, but without applying the brakes on them. + * @author Thomas Legowo + */ +public class floatMotorIcon extends objectIcon{ + + // other private attributes + + private int portA; // 0 if port A is not floated, 1 if port A is floated + private int portB; + private int portC; + + // for algorithm representation, represent a stop motor icon with an identifier of 13 + private int identifier; + + /** Creates a new instance of floatMotorIcon */ + public floatMotorIcon() + { + } + + /** + * Creates a new instance of floatMotorIcon + * @param filepath Source file of this icon's image + */ + public floatMotorIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); + identifier = 13; + portA = 1; + portB = 1; + portC = 1; + setImage(); + } + + // to get the status of individual port + /** + * Gets the status of port A + * @return Port A status + */ + public int portAStatus() + { + return portA; + } + + /** + * Gets the status of port B + * @return Port B status + */ + public int portBStatus() + { + return portB; + } + + /** + * Gets the status of port C + * @return Port C status + */ + public int portCStatus() + { + return portC; + } + + + // methods for the ports, these methods also change the graphical representation of the float motor icon's attributes + // the little boxes with the letters 'A', 'B' or 'C' will change in background colour depending on whether + // the port is turned floated + /** + * Floats output port A + */ + public void floatPortA() + { + portA = 1; + } + /** + * Turns output port A off + */ + public void turnPortAoff() + { + portA = 0; + } + /** + * Floats output port B + */ + public void floatPortB() + { + portB = 1; + } + /** + * Turns output port B off + */ + public void turnPortBoff() + { + portB = 0; + } + /** + * Floats output port C + */ + public void floatPortC() + { + portC = 1; + } + /** + * Turns output port C off + */ + public void turnPortCoff() + { + portC = 0; + } + + + /** + * Sets the image of this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + + // creating the top panel + javax.swing.JPanel jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp.setPreferredSize(new java.awt.Dimension(40, 30)); + javax.swing.ImageIcon nic; + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/floatmotor/topfloat.gif")); + PicButton pic = new PicButton(nic); + jp.add(pic); + + // creating the bottom panel + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(40, 10)); + if(portA == 0) + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/floatmotor/Anofloat.gif")); + } + else + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/floatmotor/Afloat.gif")); + } + pic = new PicButton(nic); + jp2.add(pic); + + if(portB == 0) + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/floatmotor/Bnofloat.gif")); + } + else + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/floatmotor/Bfloat.gif")); + } + pic = new PicButton(nic); + jp2.add(pic); + + if(portC == 0) + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/floatmotor/Cnofloat.gif")); + } + else + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/floatmotor/Cfloat.gif")); + } + pic = new PicButton(nic); + jp2.add(pic); + + // joining the top and bottom panels + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(jp, gridBagConstraints); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(jp2, gridBagConstraints); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + // the handlers method + /** + * Change the status of output port A + * @param evt MouseEvent + */ + public void changeA(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.ImageIcon nic; + if(portA == 0) // not turned off yet + { + portA = 1; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/floatmotor/Afloat.gif")); + } + else + { + portA = 0; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/floatmotor/Anofloat.gif")); + } + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(1); + PicButton picpic = (PicButton) jp.getComponent(0); + picpic.setIcon(nic); + + // set the states for undo and redo + UndoRedo.update_state(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + /** + * Change the status of output port B + * @param evt MouseEvent + */ + public void changeB(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.ImageIcon nic; + if(portB == 0) // not turned off yet + { + portB = 1; // now it is turned off + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/floatmotor/Bfloat.gif")); + } + else + { + portB = 0; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/floatmotor/Bnofloat.gif")); + } + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(1); + PicButton picpic = (PicButton) jp.getComponent(1); + picpic.setIcon(nic); + + // set the states for undo and redo + UndoRedo.update_state(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + /** + * Change the status of output port C + * @param evt MouseEvent + */ + public void changeC(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.ImageIcon nic; + if(portC == 0) // not turned off yet + { + portC = 1; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/floatmotor/Cfloat.gif")); + } + else + { + portC = 0; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/floatmotor/Cnofloat.gif")); + } + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(1); + PicButton picpic = (PicButton) jp.getComponent(2); + picpic.setIcon(nic); + + // set the states for undo and redo + UndoRedo.update_state(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(1); + PicButton pic = (PicButton) jp.getComponent(0); + java.awt.event.MouseListener[] ml = pic.getMouseListeners(); + for(int i=0; i portA + sp2 = sp[0].split(att_value_connector); + portA = Integer.parseInt(sp2[1]); + + // do the second one --> portB + sp2 = sp[1].split(att_value_connector); + portB = Integer.parseInt(sp2[1]); + + // do the third one --> portC + sp2 = sp[2].split(att_value_connector); + portC = Integer.parseInt(sp2[1]); + } + +} diff --git a/src/funsoftware/ic/obj/lampIcon.java b/src/funsoftware/ic/obj/lampIcon.java new file mode 100644 index 0000000..b3f7e20 --- /dev/null +++ b/src/funsoftware/ic/obj/lampIcon.java @@ -0,0 +1,957 @@ +/* + * lampIcon.java + * + * Created on 26 August 2005, 18:35 + */ + +package funsoftware.ic.obj; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.st.*; +import funsoftware.struct.*; +import funsoftware.var.*; +import funsoftware.consts.*; + +/** + * A subclass of Icon that manages the lamp of the RCX robot + * @author Thomas Legowo + */ +public class lampIcon extends objectIcon{ + + private int power; // the power level of this lamp, from 1 to 8, no zero power allowed default power = 8 + private variable var_power; + + private int portA; // 0 if port A is not used by this lamp, 1 otherwise + private int portB; + private int portC; + + // for algorithm representation, represent a lamp icon with an identifier of 6 + private int identifier; + + /** Creates a new instance of lampIcon */ + public lampIcon() { + } + + /** + * Creates a new instance of lampIcon + * @param filepath Source file for this icon's image + */ + public lampIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); // for startIcon the size of the icon is 26x61 + power = 8; + identifier = 6; + portA = 1; + portB = 1; + portC = 1; + var_power = null; + setImage(); + } + + /** + * Helps provide the transparent background + * @param g Graphic + */ + protected void paintComponent(java.awt.Graphics g) + { + super.paintComponent(g); + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/lamps/power_field.gif")); + g.drawImage(ii.getImage(), 25, 0, this); + } + + + // now methods dealing with the attributes + + /** + * Returns the power of this lamp + * @return Lamp's power + */ + public int getPower() + { + return power; + } + + /** + * Sets the power level of this lamp + * @param npow New power level + */ + public void setPower(int npow) + { + power = npow; + } + + /** + * Sets the power level of this lamp icon (variable not constant) + * @param vp The new power variable + */ + public void setVarPower(variable vp) + { + var_power = vp; + } + + // to get the status of individual port + /** + * Gets port A status + * @return Port A status + */ + public int portAStatus() + { + return portA; + } + + /** + * Gets port B status + * @return Port B status + */ + public int portBStatus() + { + return portB; + } + + /** + * Gets port C status + * @return Port C status + */ + public int portCStatus() + { + return portC; + } + + /** + * Turn port A on + */ + public void turnPortAon() + { + portA = 1; + } + /** + * Turn port A off + */ + public void turnPortAoff() + { + portA = 0; + } + /** + * Turn port B on + */ + public void turnPortBon() + { + portB = 1; + } + /** + * Turn port B off + */ + public void turnPortBoff() + { + portB = 0; + } + /** + * Turn port C on + */ + public void turnPortCon() + { + portC = 1; + } + /** + * Turn port C off + */ + public void turnPortCoff() + { + portC = 0; + } + + /** + * to set the images of this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + + // creating the top panel + javax.swing.JPanel jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp.setPreferredSize(new java.awt.Dimension(40, 29)); + javax.swing.ImageIcon nic; + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/lamps/symbol.gif")); + PicButton pic = new PicButton(nic); + jp.add(pic); + + javax.swing.JPanel jp4 = new javax.swing.JPanel(); + jp4.setLayout(new java.awt.GridBagLayout()); + jp4.setPreferredSize(new java.awt.Dimension(15, 29)); + + + javax.swing.JPanel dummy = new javax.swing.JPanel(); + dummy.setPreferredSize(new java.awt.Dimension(15, 2)); + dummy.setOpaque(false); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp4.add(dummy, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + + javax.swing.JLabel powerLabel; + + if(var_power == null) + { + powerLabel = new javax.swing.JLabel(Integer.toString(power)); + } + else + { + powerLabel = new javax.swing.JLabel("V"); + } + + powerLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + powerLabel.setPreferredSize(new java.awt.Dimension(15, 16)); + powerLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp4.add(powerLabel, gridBagConstraints); + + + dummy = new javax.swing.JPanel(); + dummy.setPreferredSize(new java.awt.Dimension(15, 11)); + dummy.setOpaque(false); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 2; + jp4.add(dummy, gridBagConstraints); + jp4.setOpaque(false); + jp.setOpaque(false); + + jp.add(jp4); + + // creating the bottom panel + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(40, 11)); + if(portA == 0) + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/lamps/A_off.gif")); + } + else + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/lamps/A_on.gif")); + } + pic = new PicButton(nic); + jp2.add(pic); + + if(portB == 0) + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/lamps/B_off.gif")); + } + else + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/lamps/B_on.gif")); + } + pic = new PicButton(nic); + jp2.add(pic); + + if(portC == 0) + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/lamps/C_off.gif")); + } + else + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/lamps/C_on.gif")); + } + pic = new PicButton(nic); + jp2.add(pic); + + + // joining the top and bottom panels + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(jp, gridBagConstraints); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(jp2, gridBagConstraints); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * To stop the editing mode i.e. replace the textfield with the appropriate label + */ + public void stopEditMode() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + jp = (javax.swing.JPanel) jp.getComponent(1); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(1); + String text = textField.getText(); + + jp.removeAll(); + + int tmp_pow = power; + try + { + if(text.compareTo("v") == 0 || text.compareTo("V") == 0) + { + if(var_list.Instance().isDefinedVariables() == true || findCurrentAux().getLocalVarList().isEmpty() == false) + { + VarInputDialog vid = new VarInputDialog(null, this, findCurrentAux()); + vid.pack(); + vid.setLocationRelativeTo(this); + vid.setVisible(true); + + if(vid.getUserInput() != null) + { + var_power = vid.getUserInput(); + } + } + else + { + javax.swing.JOptionPane.showMessageDialog(null, + "You have not defined any global variables or local variables to this function or task yet.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + } + else + { + power = Integer.parseInt(text); + + if(power > 8 || power < 1) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the lamp's power level is invalid.\nPermitted value is between 1 to 8.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + power = tmp_pow; + } + else + { + var_power = null; + } + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the lamp's power level is invalid.\nPlease enter numbers (1 to 8) only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + + // set the states for undo and redo + if(tmp_pow != power) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + else if(var_power != null) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JPanel dummy = new javax.swing.JPanel(); + dummy.setPreferredSize(new java.awt.Dimension(15, 2)); + dummy.setOpaque(false); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(dummy, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + + javax.swing.JLabel powerLabel; + if(var_power == null) + { + powerLabel = new javax.swing.JLabel(Integer.toString(power)); + } + else + { + powerLabel = new javax.swing.JLabel("V"); + } + + powerLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + powerLabel.setPreferredSize(new java.awt.Dimension(15, 16)); + powerLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + jp.add(powerLabel, gridBagConstraints); + + dummy = new javax.swing.JPanel(); + dummy.setPreferredSize(new java.awt.Dimension(15, 11)); + dummy.setOpaque(false); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 2; + jp.add(dummy, gridBagConstraints); + + repaint(); + validate(); + } + + + /** + * Method to receive input from a user to change the power level of this lamp + * @param evt MouseEvent + */ + public void changePowerLevel(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField; + if(var_power != null) + { + textField = new javax.swing.JTextField("v"); + } + else + { + textField = new javax.swing.JTextField(Integer.toString(power)); + } + + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(0); + jp = (javax.swing.JPanel) jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + textField.setPreferredSize(new java.awt.Dimension(15,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.JPanel dummy = new javax.swing.JPanel(); + dummy.setPreferredSize(new java.awt.Dimension(15, 2)); + dummy.setOpaque(false); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(dummy, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + jp.add(textField, gridBagConstraints); + + dummy = new javax.swing.JPanel(); + dummy.setPreferredSize(new java.awt.Dimension(15, 11)); + dummy.setOpaque(false); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 2; + jp.add(dummy, gridBagConstraints); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + + //stop edit mode (Enter-key) + stopEditMode(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the status of port A + * @param evt MouseEvent + */ + public void changeA(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.ImageIcon nic; + if(portA == 0) // off + { + portA = 1; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/lamps/A_on.gif")); + } + else + { + portA = 0; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/lamps/A_off.gif")); + } + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(1); + PicButton picpic = (PicButton) jp.getComponent(0); + picpic.setIcon(nic); + + // set the states for undo and redo + UndoRedo.update_state(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the status of port B + * @param evt MouseEvent + */ + public void changeB(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.ImageIcon nic; + if(portB == 0) // off + { + portB = 1; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/lamps/B_on.gif")); + } + else + { + portB = 0; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/lamps/B_off.gif")); + } + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(1); + PicButton picpic = (PicButton) jp.getComponent(1); + picpic.setIcon(nic); + + // set the states for undo and redo + UndoRedo.update_state(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the status of port C + * @param evt MouseEvent + */ + public void changeC(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.ImageIcon nic; + if(portC == 0) // off + { + portC = 1; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/lamps/C_on.gif")); + } + else + { + portC = 0; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/lamps/C_off.gif")); + } + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(1); + PicButton picpic = (PicButton) jp.getComponent(2); + picpic.setIcon(nic); + + // set the states for undo and redo + UndoRedo.update_state(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(0); + jp = (javax.swing.JPanel) jp.getComponent(1); + java.awt.event.MouseListener[] ml = jp.getMouseListeners(); + for(int i=0; i power + sp2 = sp[0].split(att_value_connector); + if(sp2[1].substring(0,1).compareTo("V") == 0) // must be a variable + { + var_power = var_list.Instance().getVariable(sp2[1].substring(2)); + if(var_power == null) // must be local, not global + { + var_power = getAux().getVariable(sp2[1].substring(2)); + } + } + else + { + power = Integer.parseInt(sp2[1]); + } + + // do the second one --> portA + sp2 = sp[1].split(att_value_connector); + portA = Integer.parseInt(sp2[1]); + + // do the third one --> portB + sp2 = sp[2].split(att_value_connector); + portB = Integer.parseInt(sp2[1]); + + // do the fourth one --> portC + sp2 = sp[3].split(att_value_connector); + portC = Integer.parseInt(sp2[1]); + } + + /** + * To display an input panel to ask for a variable to be used + * @return The label of the panel + */ + public javax.swing.JLabel getVarLabel() + { + return new javax.swing.JLabel("Lamp Power"); + } + + /** + * To indicate whether this icon uses a variable + * @param var Variable to be checked + * @return True or false + */ + public Boolean useAVariable(variable var) + { + if(var_power != null) + { + if(var_power.getType() == var.getType() && var_power.getName().compareTo(var.getName()) == 0) + { + return true; + } + } + return false; + } +} diff --git a/src/funsoftware/ic/obj/motorIcon.java b/src/funsoftware/ic/obj/motorIcon.java new file mode 100644 index 0000000..f967ebe --- /dev/null +++ b/src/funsoftware/ic/obj/motorIcon.java @@ -0,0 +1,1083 @@ +/* + * motorIcon.java + * + * Created on 22 July 2005, 11:30 + */ + +package funsoftware.ic.obj; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.gri.*; +import funsoftware.st.*; +import funsoftware.struct.*; +import funsoftware.var.*; +import funsoftware.consts.*; + +/** + * This is a subclass of icon handling a motor icon + * @author Thomas Legowo + */ +public class motorIcon extends objectIcon{ + + // other private attributes + + private int power; // the power level of this motor, from 1 to 8, no zero power allowed, zero for stop motor + // default power being one = 8 (full power) + private variable var_power; + + private int direction; // the direction of the motor (0 for FORWARD(CLOCKWISE) or 1 BACKWARD for (ANTICLOCKWISE)), 2 + // for stop motor + private int portA; // 0 if port A is not used by this motor, 1 otherwise + private int portB; + private int portC; + + // for algorithm representation, represent a motor icon with an identifier of 1 + private int identifier; + + /** Creates a new instance of motorIcon */ + public motorIcon() { + } + + /** + * Creates a new instance of motorIcon + * @param filepath Source file of this icon's image + * @param dir Direction of the motor + */ + public motorIcon(String filepath, int dir) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); + power = 8; + direction = dir; + identifier = 1; + portA = 1; + portB = 1; + portC = 1; + var_power = null; + setImage(); + } + + /** + * Helps provide the transparent background + * @param g Graphic + */ + protected void paintComponent(java.awt.Graphics g) + { + super.paintComponent(g); + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/movemotor/power_field.gif")); + g.drawImage(ii.getImage(), 26, 0, this); + } + + + /** + * Returns the power of this motor + * @return Power level of this motor + */ + public int getPower() + { + return power; + } + + /** + * Returns the direction of this motor's spin + * @return Motor's direction + */ + public int getDirection() + { + return direction; + } + + /** + * Sets the power level of this motor + * @param npow New power level + */ + public void setPower(int npow) + { + power = npow; + } + + /** + * Sets the power level of this motor (variable not constant) + * @param vp The power variable + */ + public void setVarPower(variable vp) + { + var_power = vp; + } + + /** + * Sets the direction of this motor's spin + * @param ndir New direction + */ + public void setDirection(int ndir) + { + direction = ndir; + } + + // to get the status of individual port + /** + * Gets the status of port A + * @return Port A status + */ + public int portAStatus() + { + return portA; + } + + /** + * Gets the status of port B + * @return Port B status + */ + public int portBStatus() + { + return portB; + } + + /** + * Gets the status of port C + * @return Port C status + */ + public int portCStatus() + { + return portC; + } + + + // methods for the ports, these methods also change the graphical representation of the motor icon's attributes + // the little boxes with the letters 'A', 'B' or 'C' will change in background colour depending on whether + // the port is turned on + /** + * Turn port A on + */ + public void turnPortAon() + { + portA = 1; + } + /** + * Turn port A off + */ + public void turnPortAoff() + { + portA = 0; + } + /** + * Turn port B on + */ + public void turnPortBon() + { + portB = 1; + } + /** + * Turn port B off + */ + public void turnPortBoff() + { + portB = 0; + } + /** + * Turn port C on + */ + public void turnPortCon() + { + portC = 1; + } + /** + * Turn port C off + */ + public void turnPortCoff() + { + portC = 0; + } + + /** + * To set the images of this icon (for move motor icon there are 5 elements --> direction, power level and output ports) + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + + // creating the top panel + javax.swing.JPanel jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp.setPreferredSize(new java.awt.Dimension(40, 29)); + javax.swing.ImageIcon nic; + if(direction == 0) + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/movemotor/forward.gif")); + } + else + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/movemotor/backward.gif")); + } + PicButton pic = new PicButton(nic); + jp.add(pic); + + javax.swing.JPanel jp4 = new javax.swing.JPanel(); + jp4.setLayout(new java.awt.GridBagLayout()); + jp4.setPreferredSize(new java.awt.Dimension(14, 29)); + + + javax.swing.JPanel dummy = new javax.swing.JPanel(); + dummy.setPreferredSize(new java.awt.Dimension(14, 7)); + dummy.setOpaque(false); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp4.add(dummy, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + + javax.swing.JLabel powerLabel; + if(var_power == null) + { + powerLabel = new javax.swing.JLabel(Integer.toString(power)); + } + else + { + powerLabel = new javax.swing.JLabel("V"); + } + + powerLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + powerLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + powerLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp4.add(powerLabel, gridBagConstraints); + + + dummy = new javax.swing.JPanel(); + dummy.setPreferredSize(new java.awt.Dimension(14, 6)); + dummy.setOpaque(false); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 2; + jp4.add(dummy, gridBagConstraints); + jp4.setOpaque(false); + jp.setOpaque(false); + + jp.add(jp4); + + // creating the bottom panel + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(40, 11)); + if(portA == 0) + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/movemotor/A_off.gif")); + } + else + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/movemotor/A_on.gif")); + } + pic = new PicButton(nic); + jp2.add(pic); + + if(portB == 0) + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/movemotor/B_off.gif")); + } + else + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/movemotor/B_on.gif")); + } + pic = new PicButton(nic); + jp2.add(pic); + + if(portC == 0) + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/movemotor/C_off.gif")); + } + else + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/movemotor/C_on.gif")); + } + pic = new PicButton(nic); + jp2.add(pic); + + + // joining the top and bottom panels + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(jp, gridBagConstraints); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(jp2, gridBagConstraints); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + + // Following are the methods that responds to the mouse events + /** + * Changes the direction of the motor + * @param evt MouseEvent + */ + public void changeDirection(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.ImageIcon nic; + if(direction == 0) // forward + { + direction = 1; // becomes backward + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/movemotor/backward.gif")); + } + else + { + direction = 0; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/movemotor/forward.gif")); + } + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(0); + PicButton picpic = (PicButton) jp.getComponent(0); + picpic.setIcon(nic); + + // set the states for undo and redo + UndoRedo.update_state(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + /** + * Changes the power level of the motor + * @param evt MouseEvent + */ + public void changePowerLevel(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + // prompt the user for new power level of this motor icon + // get the value of the current power first + javax.swing.JTextField textField; + if(var_power != null) + { + textField = new javax.swing.JTextField("v"); + } + else + { + textField = new javax.swing.JTextField(Integer.toString(power)); + } + + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(0); + jp = (javax.swing.JPanel) jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + textField.setPreferredSize(new java.awt.Dimension(14,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.JPanel dummy = new javax.swing.JPanel(); + dummy.setPreferredSize(new java.awt.Dimension(14, 7)); + dummy.setOpaque(false); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(dummy, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + jp.add(textField, gridBagConstraints); + + dummy = new javax.swing.JPanel(); + dummy.setPreferredSize(new java.awt.Dimension(14, 6)); + dummy.setOpaque(false); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 2; + jp.add(dummy, gridBagConstraints); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + + //stop edit mode (Enter-key) + stopEditMode(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * Stops the power level edit mode on this motor icon + */ + public void stopEditMode() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + jp = (javax.swing.JPanel) jp.getComponent(1); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(1); + String text = textField.getText(); + + jp.removeAll(); + + int tmp_power = power; // the current power + // assign the power level + try + { + if(text.compareTo("v") == 0 || text.compareTo("V") == 0) + { + if(var_list.Instance().isDefinedVariables() == true || findCurrentAux().getLocalVarList().isEmpty() == false) + { + VarInputDialog vid = new VarInputDialog(null, this, findCurrentAux()); + vid.pack(); + vid.setLocationRelativeTo(this); + vid.setVisible(true); + + if(vid.getUserInput() != null) + { + var_power = vid.getUserInput(); + } + } + else + { + javax.swing.JOptionPane.showMessageDialog(null, + "You have not defined any global variables or local variables to this function or task yet.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + } + else + { + power = Integer.parseInt(text); + if(power > 8 || power < 1) // maximum power is 8 + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the motor's power is invalid.\nPermitted value is between 1 to 8.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + power = tmp_power; + } + else + { + var_power = null; + } + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the motor's power is invalid.\nPlease enter numbers only (1 to 8).\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + + // set the states for undo and redo + if(tmp_power != power) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + else if(var_power != null) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JPanel dummy = new javax.swing.JPanel(); + dummy.setPreferredSize(new java.awt.Dimension(14, 7)); + dummy.setOpaque(false); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(dummy, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + + javax.swing.JLabel powerLabel; + if(var_power == null) + { + powerLabel = new javax.swing.JLabel(Integer.toString(power)); + } + else + { + powerLabel = new javax.swing.JLabel("V"); + } + + powerLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + powerLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + powerLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + jp.add(powerLabel, gridBagConstraints); + + + dummy = new javax.swing.JPanel(); + dummy.setPreferredSize(new java.awt.Dimension(14, 6)); + dummy.setOpaque(false); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 2; + jp.add(dummy, gridBagConstraints); + + repaint(); + validate(); + } + + /** + * To change the status of port A + * @param evt MouseEvent + */ + public void changeA(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.ImageIcon nic = new javax.swing.ImageIcon(); + if(portA == 0) // off + { + portA = 1; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/movemotor/A_on.gif")); + } + else if(portA == 1) + { + portA = 0; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/movemotor/A_off.gif")); + } + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(1); + PicButton picpic = (PicButton) jp.getComponent(0); + picpic.setIcon(nic); + + // set the states for undo and redo + UndoRedo.update_state(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the status of port B + * @param evt MouseEvent + */ + public void changeB(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.ImageIcon nic = new javax.swing.ImageIcon(); + if(portB == 0) // off + { + portB = 1; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/movemotor/B_on.gif")); + } + else if(portB == 1) + { + portB = 0; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/movemotor/B_off.gif")); + } + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(1); + PicButton picpic = (PicButton) jp.getComponent(1); + picpic.setIcon(nic); + + // set the states for undo and redo + UndoRedo.update_state(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the status of port C + * @param evt MouseEvent + */ + public void changeC(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.ImageIcon nic = new javax.swing.ImageIcon(); + if(portC == 0) // off + { + portC = 1; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/movemotor/C_on.gif")); + } + else if(portC == 1) + { + portC = 0; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/movemotor/C_off.gif")); + } + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(1); + PicButton picpic = (PicButton) jp.getComponent(2); + picpic.setIcon(nic); + + // set the states for undo and redo + UndoRedo.update_state(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(0); + PicButton pic = (PicButton) jp.getComponent(0); + java.awt.event.MouseListener[] ml = pic.getMouseListeners(); + for(int i=0; i direction + sp2 = sp[0].split(att_value_connector); + direction = Integer.parseInt(sp2[1]); + + // do the second one --> power + sp2 = sp[1].split(att_value_connector); + + if(sp2[1].substring(0,1).compareTo("V") == 0) // must be a variable + { + var_power = var_list.Instance().getVariable(sp2[1].substring(2)); + if(var_power == null) // must be local, not global + { + var_power = getAux().getVariable(sp2[1].substring(2)); + } + } + else + { + power = Integer.parseInt(sp2[1]); + } + + // do the third one --> portA + sp2 = sp[2].split(att_value_connector); + portA = Integer.parseInt(sp2[1]); + + // do the fourth one --> portB + sp2 = sp[3].split(att_value_connector); + portB = Integer.parseInt(sp2[1]); + + // do the fifth one --> portC + sp2 = sp[4].split(att_value_connector); + portC = Integer.parseInt(sp2[1]); + } + + /** + * To display an input panel to ask for a variable to be used + * @return The label of the panel + */ + public javax.swing.JLabel getVarLabel() + { + return new javax.swing.JLabel("Motor Power"); + } + + /** + * To indicate whether this icon uses a variable + * @param var Variable to be checked + * @return True or false + */ + public Boolean useAVariable(variable var) + { + if(var_power != null) + { + if(var_power.getType() == var.getType() && var_power.getName().compareTo(var.getName()) == 0) + { + return true; + } + } + return false; + } +} diff --git a/src/funsoftware/ic/obj/objectIcon.java b/src/funsoftware/ic/obj/objectIcon.java new file mode 100644 index 0000000..d274be4 --- /dev/null +++ b/src/funsoftware/ic/obj/objectIcon.java @@ -0,0 +1,111 @@ +/* + * objectIcon.java + * + * Created on 28 December 2005, 14:51 + * + */ + +package funsoftware.ic.obj; + +import funsoftware.ic.*; +import funsoftware.wr.*; + +/** + * This method is for object type icons (2 neighbours and 2 enclosing wires) + * @author Thomas Legowo + */ +public class objectIcon extends Icon{ + + // private attributes + private Icon leftNeighbour; + private Icon rightNeighbour; + + private Wire leftWire; + private Wire rightWire; + + /** Creates a new instance of objectIcon */ + public objectIcon() { + } + + /** + * Creates a new instance of objectIcon + * @param filepath Source file for the image of this object typed icon + */ + public objectIcon(String filepath) { + super(filepath); + } + + + // The get and set methods + /** + * Gets left neighbour of this icon + * @return Left neighbour + */ + public Icon getLeftNeighbour() + { + return leftNeighbour; + } + + /** + * Gets right neighbour of this icon + * @return Right neighbour + */ + public Icon getRightNeighbour() + { + return rightNeighbour; + } + + /** + * Gets left wire of this icon + * @return Left wire + */ + public Wire getLeftWire() + { + return leftWire; + } + + /** + * Gets right wire of this icon + * @return Right wire + */ + public Wire getRightWire() + { + return rightWire; + } + + /** + * Sets left neighbour of this icon + * @param nicon New left icon + */ + public void setLeftNeighbour(Icon nicon) + { + leftNeighbour = nicon; + } + + /** + * Sets right neighbour of this icon + * @param nicon New right icon + */ + public void setRightNeighbour(Icon nicon) + { + rightNeighbour = nicon; + } + + /** + * Sets left wire of this icon + * @param nwire New left wire + */ + public void setLeftWire(Wire nwire) + { + leftWire = nwire; + } + + /** + * Sets right wire of this icon + * @param nwire New right wire + */ + public void setRightWire(Wire nwire) + { + rightWire = nwire; + } +} diff --git a/src/funsoftware/ic/obj/playAnyNoteIcon.java b/src/funsoftware/ic/obj/playAnyNoteIcon.java new file mode 100644 index 0000000..91e94f7 --- /dev/null +++ b/src/funsoftware/ic/obj/playAnyNoteIcon.java @@ -0,0 +1,698 @@ +/* + * playAnyNoteIcon.java + * + * Created on 17 December 2005, 18:45 + */ + +package funsoftware.ic.obj; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.st.*; +import funsoftware.var.*; +import funsoftware.consts.*; + +/** + * This class represents the icon that can play notes on the specified frequency and period + * @author Thomas Legowo + */ +public class playAnyNoteIcon extends objectIcon{ + + // other private attributes + + private int duration; // the amount of time this note will be played in (per 10ms) + private int frequency; // 0 frequency of this note + private variable var_frequency; // alternative to frequency + + // for algorithm representation, represent a playanynote icon with an identifier of 9 + private int identifier; + + /** Creates a new instance of playAnyNoteIcon */ + public playAnyNoteIcon() { + } + + /** + * Creates a new instance of playanynote Icon + * @param filepath Source file of this icon's image + */ + public playAnyNoteIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); // for startIcon the size of the icon is 26x61 + duration = 100; + frequency = 33; + identifier = 9; + var_frequency = null; + setImage(); + } + + /** + * Helps to provide the transparent background + * @param g Graphic + */ + protected void paintComponent(java.awt.Graphics g) + { + super.paintComponent(g); + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/notes/free/textField.gif")); + g.drawImage(ii.getImage(), 15, 1, this); + + ii = new javax.swing.ImageIcon(getClass().getResource("/icons/notes/free/textField.gif")); + g.drawImage(ii.getImage(), 15, 23, this); + } + + /** + * Returns the duration + * @return Duration value + */ + public int getDuration() + { + return duration; + } + + /** + * Returns the frequency + * @return Frequency + */ + public int getFrequency() + { + return frequency; + } + + /** + * Sets the duration + * @param ndur Duration + */ + public void setDuration(int ndur) + { + duration = ndur; + } + + /** + * Sets the frequency + * @param nfre Frequency + */ + public void setFrequency(int nfre) + { + frequency = nfre; + } + + /** + * Sets the variable frequency + * @param newv The new frequency variable + */ + public void setVarFrequency(variable newv) + { + var_frequency = newv; + } + + /** + * To set the images and labels of this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + javax.swing.ImageIcon nic; + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/notes/free/left.gif")); + PicButton pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(pic, gridBagConstraints); + + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(25, 40)); + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/notes/free/line.gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(pic, gridBagConstraints); + + javax.swing.JPanel jp3 = new javax.swing.JPanel(); + jp3.setLayout(new java.awt.GridBagLayout()); + jp3.setPreferredSize(new java.awt.Dimension(25, 16)); + + javax.swing.JLabel durationLabel = new javax.swing.JLabel(Integer.toString(duration)); + durationLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + durationLabel.setPreferredSize(new java.awt.Dimension(25, 16)); + durationLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp3.add(durationLabel, gridBagConstraints); + jp3.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + jp2.add(jp3, gridBagConstraints); + + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 2; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/notes/free/middle.gif")); + pic = new PicButton(nic); + jp2.add(pic, gridBagConstraints); + + javax.swing.JLabel frequencyLabel; + if(var_frequency == null) + { + frequencyLabel = new javax.swing.JLabel(Integer.toString(frequency)); + } + else + { + frequencyLabel = new javax.swing.JLabel("V"); + } + frequencyLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + frequencyLabel.setPreferredSize(new java.awt.Dimension(25, 16)); + frequencyLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + jp3 = new javax.swing.JPanel(); + jp3.setLayout(new java.awt.GridBagLayout()); + jp3.setPreferredSize(new java.awt.Dimension(25, 16)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp3.add(frequencyLabel, gridBagConstraints); + jp3.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 3; + jp2.add(jp3, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 4; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/notes/free/line.gif")); + pic = new PicButton(nic); + jp2.add(pic, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + add(jp2, gridBagConstraints); + + jp2.setOpaque(false); + setOpaque(false); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * Change the duration + * @param evt MouseEvent + */ + public void changeDuration(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField = new javax.swing.JTextField(Integer.toString(duration)); + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(25,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.remove(0); + + jp.add(textField); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopDurationEditMode(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + + /** + * Change the frequency + * @param evt MouseEvent + */ + public void changeFrequency(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField; + if(var_frequency != null) + { + textField = new javax.swing.JTextField("v"); + } + else + { + textField = new javax.swing.JTextField(Integer.toString(frequency)); + } + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(25,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(3); + jp.remove(0); + + jp.add(textField); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopFrequencyEditMode(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * This is to handle click that stops edit mode + */ + public void stopDurationEditMode() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + + int tmp_duration = duration; + try + { + duration = Integer.parseInt(text); + if(duration <= 0) // it is pointless to time for 0 or negative values + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the duration is invalid.\nPlease enter value greater than 0.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + duration = tmp_duration; + } + + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the duration is invalid.\nEnter only numbers greater than zero.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_duration != duration) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + + java.awt.GridBagConstraints gridBagConstraints; + + jp.remove(0); + + javax.swing.JLabel durationLabel = new javax.swing.JLabel(Integer.toString(duration)); + durationLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + durationLabel.setPreferredSize(new java.awt.Dimension(25, 16)); + durationLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp.add(durationLabel); + + jp.setOpaque(false); + + repaint(); + validate(); + } + + + /** + * This is to handle click that stops edit mode + */ + public void stopFrequencyEditMode() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(3); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + + int tmp_frequency = frequency; + try + { + if(text.compareTo("v") == 0 || text.compareTo("V") == 0) + { + if(var_list.Instance().isDefinedVariables() == true || findCurrentAux().getLocalVarList().isEmpty() == false) + { + VarInputDialog vid = new VarInputDialog(null, this, findCurrentAux()); + vid.pack(); + vid.setLocationRelativeTo(this); + vid.setVisible(true); + + if(vid.getUserInput() != null) + { + var_frequency = vid.getUserInput(); + } + } + else + { + javax.swing.JOptionPane.showMessageDialog(null, + "You have not defined any global variables or local variables to this function or task yet.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + } + else + { + frequency = Integer.parseInt(text); + if(frequency <= 0) // it is pointless to time for 0 or negative values + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the frequency is invalid.\nPlease enter value greater than 0.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + frequency = tmp_frequency; + } + else + { + var_frequency = null; + } + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the frequency is invalid.\nEnter only numbers greater than zero.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_frequency != frequency || var_frequency != null) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + + java.awt.GridBagConstraints gridBagConstraints; + + jp.remove(0); + + javax.swing.JLabel frequencyLabel; + if(var_frequency == null) + { + frequencyLabel = new javax.swing.JLabel(Integer.toString(frequency)); + } + else + { + frequencyLabel = new javax.swing.JLabel("V"); + } + frequencyLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + frequencyLabel.setPreferredSize(new java.awt.Dimension(25, 16)); + frequencyLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + jp.add(frequencyLabel); + jp.setOpaque(false); + + repaint(); + validate(); + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + java.awt.event.MouseListener[] ml = jp.getMouseListeners(); + for(int i=0; i duration + sp2 = sp[0].split(att_value_connector); + duration = Integer.parseInt(sp2[1]); + + // do the second one --> frequency + sp2 = sp[1].split(att_value_connector); + if(sp2[1].substring(0,1).compareTo("V") == 0) // must be a variable + { + var_frequency = var_list.Instance().getVariable(sp2[1].substring(2)); + if(var_frequency == null) // must be local, not global + { + var_frequency = getAux().getVariable(sp2[1].substring(2)); + } + } + else + { + frequency = Integer.parseInt(sp2[1]); + } + } + + /** + * To display an input panel to ask for a variable to be used + * @return The label of the panel + */ + public javax.swing.JLabel getVarLabel() + { + return new javax.swing.JLabel("Note Frequency"); + } + + /** + * To indicate whether this icon uses a variable + * @param var Variable to be checked + * @return True or false + */ + public Boolean useAVariable(variable var) + { + if(var_frequency != null) + { + if(var_frequency.getType() == var.getType() && var_frequency.getName().compareTo(var.getName()) == 0) + { + return true; + } + } + return false; + } +} diff --git a/src/funsoftware/ic/obj/playSpecificNote.java b/src/funsoftware/ic/obj/playSpecificNote.java new file mode 100644 index 0000000..2317c26 --- /dev/null +++ b/src/funsoftware/ic/obj/playSpecificNote.java @@ -0,0 +1,804 @@ +/* + * playSpecificNote.java + * + * Created on 30 January 2006, 10:00 + * + */ + +package funsoftware.ic.obj; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.st.*; +import funsoftware.consts.*; + +/** + * This icon plays a discrete as indicated by the user + * @author Thomas Legowo + */ +public class playSpecificNote extends objectIcon{ + + // private variables + private String note; // possible notes --> C, C#, D, D#, E, E#, F, F#, G, G#, A, A#, B, B# + + private int duration; // the amount of time this note will be played in (per 10ms) + private int octave; // possible values between 1 and 7 + + // for algorithm representation, represent a playspecificnote icon with an identifier of 14 + private int identifier; + + /** Creates a new instance of playSpecificNote */ + public playSpecificNote() { + } + + /** + * Creates a new instance of playSpecificNote Icon + * @param filepath Source file of this icon's image + */ + public playSpecificNote(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); // for startIcon the size of the icon is 26x61 + duration = 100; + octave = 4; + identifier = 14; + note = "C"; + setImage(); + } + + /** + * Helps provide the transparent background + * @param g Graphic + */ + protected void paintComponent(java.awt.Graphics g) + { + super.paintComponent(g); + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/notes/specific/durationField.gif")); + g.drawImage(ii.getImage(), 0, 24, this); + + ii = new javax.swing.ImageIcon(getClass().getResource("/icons/notes/specific/noteField.gif")); + g.drawImage(ii.getImage(), 20, 8, this); + } + + /** + * Returns the duration + * @return Duration value + */ + public int getDuration() + { + return duration; + } + + /** + * Returns the octave + * @return Octave + */ + public int getOctave() + { + return octave; + } + + /** + * Returns the note + * @return Note + */ + public String getNote() + { + return note; + } + + /** + * Sets the duration + * @param ndur Duration + */ + public void setDuration(int ndur) + { + duration = ndur; + } + + /** + * Sets the octave + * @param no Octave + */ + public void setOctave(int no) + { + octave = no; + } + + /** + * Sets the note + * @param nno New note + */ + public void setNote(String nno) + { + note = nno; + } + + /** + * To set the images and labels of this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + javax.swing.ImageIcon nic; + + javax.swing.JPanel jp1 = new javax.swing.JPanel(); + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + javax.swing.JPanel jp3 = new javax.swing.JPanel(); + + jp1.setLayout(new java.awt.GridBagLayout()); + jp1.setPreferredSize(new java.awt.Dimension(40, 24)); + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/notes/specific/topleft.gif")); + PicButton pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp1.add(pic, gridBagConstraints); + + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(20, 24)); + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/notes/specific/topright.gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(pic, gridBagConstraints); + + jp3.setLayout(new java.awt.GridBagLayout()); + jp3.setPreferredSize(new java.awt.Dimension(20, 16)); + + javax.swing.JLabel noteLabel = new javax.swing.JLabel(note); + noteLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + noteLabel.setPreferredSize(new java.awt.Dimension(20, 16)); + noteLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp3.add(noteLabel, gridBagConstraints); + jp3.setOpaque(false); + jp2.setOpaque(false); + jp1.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + jp2.add(jp3, gridBagConstraints); + + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp1.add(jp2, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(jp1, gridBagConstraints); + + + jp1 = new javax.swing.JPanel(); + jp2 = new javax.swing.JPanel(); + jp3 = new javax.swing.JPanel(); + + jp1.setLayout(new java.awt.GridBagLayout()); + jp1.setPreferredSize(new java.awt.Dimension(40, 16)); + + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(26, 16)); + + javax.swing.JLabel durationLabel = new javax.swing.JLabel(Integer.toString(duration)); + durationLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + durationLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + durationLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(durationLabel, gridBagConstraints); + jp2.setOpaque(false); + jp1.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp1.add(jp2, gridBagConstraints); + + jp3.setLayout(new java.awt.GridBagLayout()); + jp3.setPreferredSize(new java.awt.Dimension(14, 16)); + + javax.swing.JLabel octaveLabel = new javax.swing.JLabel(Integer.toString(octave)); + octaveLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + octaveLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + octaveLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp3.add(octaveLabel, gridBagConstraints); + jp3.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp1.add(jp3, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(jp1, gridBagConstraints); + + setOpaque(false); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * Change the note + * @param evt MouseEvent + */ + public void changeNote(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField = new javax.swing.JTextField(note); + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(20,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.remove(0); + + jp.add(textField); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopNoteEditMode(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + + /** + * Change the duration + * @param evt MouseEvent + */ + public void changeDuration(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField = new javax.swing.JTextField(Integer.toString(duration)); + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(26,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.remove(0); + + jp.add(textField); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopDurationEditMode(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + + /** + * Change the octave + * @param evt MouseEvent + */ + public void changeOctave(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField = new javax.swing.JTextField(Integer.toString(octave)); + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(14,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.remove(0); + + jp.add(textField); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopOctaveEditMode(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * This is to handle click that stops edit mode for note editing + */ + public void stopNoteEditMode() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + + String tmp_note = note; + try + { + note = text; + if(note.compareTo("C") != 0 && note.compareTo("C#") != 0 && note.compareTo("D") != 0 && + note.compareTo("D#") != 0 && note.compareTo("E") != 0 && note.compareTo("F") != 0 && + note.compareTo("F#") != 0 && note.compareTo("G") != 0 && note.compareTo("G#") != 0 && + note.compareTo("A") != 0 && note.compareTo("A#") != 0 && note.compareTo("B") != 0) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the note is invalid.\nPossible values are C, C#, D, D#, E, F, F#, G, G#, A, A#, B.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + note = tmp_note; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the note is invalid.\nPossible values are C, C#, D, D#, E, F, F#, G, G#, A, A#, B.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_note.compareTo(note) != 0) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + + java.awt.GridBagConstraints gridBagConstraints; + + jp.remove(0); + + javax.swing.JLabel noteLabel = new javax.swing.JLabel(note); + noteLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + noteLabel.setPreferredSize(new java.awt.Dimension(20, 16)); + noteLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp.add(noteLabel); + + jp.setOpaque(false); + + repaint(); + validate(); + } + + + /** + * This is to handle click that stops edit mode + */ + public void stopDurationEditMode() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + + int tmp_duration = duration; + try + { + duration = Integer.parseInt(text); + if(duration <= 0) // it is pointless to time for 0 or negative values + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the duration is invalid.\nPlease enter value greater than 0.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + duration = tmp_duration; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the duration is invalid.\nEnter only numbers greater than zero.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_duration != duration) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + + java.awt.GridBagConstraints gridBagConstraints; + + jp.remove(0); + + javax.swing.JLabel durationLabel = new javax.swing.JLabel(Integer.toString(duration)); + durationLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + durationLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + durationLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp.add(durationLabel); + + jp.setOpaque(false); + + repaint(); + validate(); + } + + + /** + * This is to handle click that stops edit mode for octave input + */ + public void stopOctaveEditMode() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + + int tmp_octave = octave; + try + { + octave = Integer.parseInt(text); + if(octave < 1 || octave > 7) // possible values for octave are between 1 and 7 + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the octave is invalid.\nPlease enter a value between 1 and 7.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + octave = tmp_octave; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the octave is invalid.\nEnter only numbers between 1 and 7.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_octave != octave) // only if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + + java.awt.GridBagConstraints gridBagConstraints; + + jp.remove(0); + + javax.swing.JLabel octaveLabel = new javax.swing.JLabel(Integer.toString(octave)); + octaveLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + octaveLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + octaveLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + jp.add(octaveLabel); + jp.setOpaque(false); + + repaint(); + validate(); + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + java.awt.event.MouseListener[] ml = jp.getMouseListeners(); + for(int i=0; i note + sp2 = sp[0].split(att_value_connector); + note = sp2[1]; + // do the second one --> duration + sp2 = sp[1].split(att_value_connector); + duration = Integer.parseInt(sp2[1]); + // do the third one --> octave + sp2 = sp[2].split(att_value_connector); + octave = Integer.parseInt(sp2[1]); + } + + // to find a suitable frequency of a note + private int findFrequency() + { + int frequency; + + int vertical_column = octave-1; + int horizontal_column = 0; + + + if(note.compareTo("C") == 0) + { + horizontal_column = 0; + } + else if(note.compareTo("C#") == 0) + { + horizontal_column = 1; + } + else if(note.compareTo("D") == 0) + { + horizontal_column = 2; + } + else if(note.compareTo("D#") == 0) + { + horizontal_column = 3; + } + else if(note.compareTo("E") == 0) + { + horizontal_column = 4; + } + else if(note.compareTo("F") == 0) + { + horizontal_column = 5; + } + else if(note.compareTo("F#") == 0) + { + horizontal_column = 6; + } + else if(note.compareTo("G") == 0) + { + horizontal_column = 7; + } + else if(note.compareTo("G#") == 0) + { + horizontal_column = 8; + } + else if(note.compareTo("A") == 0) + { + horizontal_column = 9; + } + else if(note.compareTo("A#") == 0) + { + horizontal_column = 10; + } + else if(note.compareTo("B") == 0) + { + horizontal_column = 11; + } + + frequency = Constants.frequencies[vertical_column][horizontal_column]; + + return frequency; + } +} diff --git a/src/funsoftware/ic/obj/returnIcon.java b/src/funsoftware/ic/obj/returnIcon.java new file mode 100644 index 0000000..3a37300 --- /dev/null +++ b/src/funsoftware/ic/obj/returnIcon.java @@ -0,0 +1,163 @@ +/* + * returnIcon.java + * + * Created on 1 February 2006, 13:36 + * + */ + +package funsoftware.ic.obj; + +import funsoftware.ic.*; + +/** + * This icon simply breaks off early from a function. Can be used in event monitor, function or task. + * @author Thomas Legowo + */ +public class returnIcon extends objectIcon{ + + // for algorithm representation, represent a break icon with an identifier of 16 + private int identifier; + + /** Creates a new instance of returnIcon */ + public returnIcon() { + } + + /** + * Creates a new instance of returnIcon + * @param filepath The source file of this icon's image + */ + public returnIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); + identifier = 16; + setImage(); + } + + /** + * To set the image of this icon + */ + public void setImage() + { + removeAll(); + setLayout(new java.awt.GridBagLayout()); + + // creating the top panel + javax.swing.ImageIcon nic; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/structure/return/return.gif")); + PicButton pic = new PicButton(nic); + add(pic); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + + /** + * Get the help title of this return icon + * @return Help title + */ + public String getHelpTitle() + { + String s = "Return Icon"; + return s; + } + + /** + * Get help message of this return icon + * @return Help message + */ + public String getHelpMsg() + { + String s = "DETAILS:"; + s+="This icon has no attributes"; + return s; + } + + /** + * Get the description of this icon + * @return Help Description + */ + public String getHelpDesc() + { + String s = ""; + return s; + } + + /** + * Get help picture of this icon + * @return Help picture + */ + public javax.swing.Icon getHelpIcon() + { + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/helps/returnIcon.gif")); + return ii; + } + + /** + * To clone this icon + * @return New instance of this icon + */ + public returnIcon Clone() + { + return new returnIcon("/icons/structure/return/return.gif"); + } + + /** + * To copy this icon + * @return New instance of this icon with its attributes set + */ + public Icon Copy() + { + returnIcon newRI = Clone(); + newRI.setImage(); + return newRI; + } + + /** + * Algorithm translation for the Translator object to create a text representation of this icon + * @param id_separator To separate ids + * @param id_att_separator To separate id with attribute + * @param att_boundary_begin To start attributes + * @param att_boundary_end To end attributes + * @param att_value_connector To separate attributes and its values + * @param att_separator To separate attributes + * @return Translation + */ + public String getTranslation(String id_separator, String id_att_separator, + String att_boundary_begin, String att_boundary_end, String att_value_connector, String att_separator) + { + String algo = new String(); + algo += "\n"; // to begin with + algo += "object"; + algo += id_separator; + algo += identifier; + algo += id_att_separator; + algo += att_boundary_begin; + algo += att_boundary_end; + return algo; + } + + /** + * Returns a string format of the NQCCode representation of this object + * @param indentation Indentation + * @return The NQC Code + */ + public String getNQCCode(String indentation) + { + String NQCCode = new String(); + + NQCCode += indentation+"// return from this function\n"; + NQCCode += indentation+"return;\n\n"; + return NQCCode; + } + + /** + * Set its own attributes given a string from a text representation of it + * @param att Attributes + * @param att_value_connector Attribute connector + * @param att_separator Attribute separator + */ + public void setAttributes(String att, String att_value_connector, String att_separator) + { + } +} diff --git a/src/funsoftware/ic/obj/stopMotorIcon.java b/src/funsoftware/ic/obj/stopMotorIcon.java new file mode 100644 index 0000000..1880620 --- /dev/null +++ b/src/funsoftware/ic/obj/stopMotorIcon.java @@ -0,0 +1,581 @@ +/* + * motorIcon.java + * + * Created on 22 July 2005, 11:30 + */ + +package funsoftware.ic.obj; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.st.*; + +/** + * This is a subclass of icon handling a stop motor icon, but can also stop any kind of output on the RCX output port. + * @author Thomas Legowo + */ +public class stopMotorIcon extends objectIcon{ + + // other private attributes + + private int portA; // 0 if port A is not turned off yet, 1 if port A is turned off + private int portB; + private int portC; + + // for algorithm representation, represent a stop motor icon with an identifier of 2 + private int identifier; + + /** Creates a new instance of motorIcon */ + public stopMotorIcon() + { + } + + /** + * Creates a new instance of stopmotorIcon + * @param filepath Source file of this icon's image + */ + public stopMotorIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); + identifier = 2; + portA = 1; + portB = 1; + portC = 1; + setImage(); + } + + + // to get the status of individual port + /** + * Gets the status of port A + * @return Port A status + */ + public int portAStatus() + { + return portA; + } + + /** + * Gets the status of port B + * @return Port B status + */ + public int portBStatus() + { + return portB; + } + + /** + * Gets the status of port C + * @return Port C status + */ + public int portCStatus() + { + return portC; + } + + + // methods for the ports, these methods also change the graphical representation of the stop motor icon's attributes + // the little boxes with the letters 'A', 'B' or 'C' will change in background colour depending on whether + // the port is turned on + /** + * Turns output port A on + */ + public void turnPortAon() + { + portA = 1; + } + /** + * Turns output port A off + */ + public void turnPortAoff() + { + portA = 0; + } + /** + * Turns output port B on + */ + public void turnPortBon() + { + portB = 1; + } + /** + * Turns output port B off + */ + public void turnPortBoff() + { + portB = 0; + } + /** + * Turns output port C on + */ + public void turnPortCon() + { + portC = 1; + } + /** + * Turns output port C off + */ + public void turnPortCoff() + { + portC = 0; + } + + + /** + * Sets the image of this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + + // creating the top panel + javax.swing.JPanel jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp.setPreferredSize(new java.awt.Dimension(40, 30)); + javax.swing.ImageIcon nic; + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/stopmotor/topstopmotor.gif")); + PicButton pic = new PicButton(nic); + jp.add(pic); + + // creating the bottom panel + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(40, 10)); + if(portA == 0) + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/stopmotor/A_on.gif")); + } + else + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/stopmotor/A_off.gif")); + } + pic = new PicButton(nic); + jp2.add(pic); + + if(portB == 0) + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/stopmotor/B_on.gif")); + } + else + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/stopmotor/B_off.gif")); + } + pic = new PicButton(nic); + jp2.add(pic); + + if(portC == 0) + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/stopmotor/C_on.gif")); + } + else + { + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/stopmotor/C_off.gif")); + } + pic = new PicButton(nic); + jp2.add(pic); + + // joining the top and bottom panels + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(jp, gridBagConstraints); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(jp2, gridBagConstraints); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + // the handlers method + /** + * Change the status of output port A + * @param evt MouseEvent + */ + public void changeA(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.ImageIcon nic; + if(portA == 0) // not turned off yet + { + portA = 1; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/stopmotor/A_off.gif")); + } + else + { + portA = 0; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/stopmotor/A_on.gif")); + } + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(1); + PicButton picpic = (PicButton) jp.getComponent(0); + picpic.setIcon(nic); + + // set the states for undo and redo + UndoRedo.update_state(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + /** + * Change the status of output port B + * @param evt MouseEvent + */ + public void changeB(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.ImageIcon nic; + if(portB == 0) // not turned off yet + { + portB = 1; // now it is turned off + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/stopmotor/B_off.gif")); + } + else + { + portB = 0; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/stopmotor/B_on.gif")); + } + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(1); + PicButton picpic = (PicButton) jp.getComponent(1); + picpic.setIcon(nic); + + // set the states for undo and redo + UndoRedo.update_state(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + /** + * Change the status of output port C + * @param evt MouseEvent + */ + public void changeC(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.ImageIcon nic; + if(portC == 0) // not turned off yet + { + portC = 1; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/stopmotor/C_off.gif")); + } + else + { + portC = 0; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/motors/stopmotor/C_on.gif")); + } + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(1); + PicButton picpic = (PicButton) jp.getComponent(2); + picpic.setIcon(nic); + + // set the states for undo and redo + UndoRedo.update_state(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + javax.swing.JPanel jp = (javax.swing.JPanel) getComponent(1); + PicButton pic = (PicButton) jp.getComponent(0); + java.awt.event.MouseListener[] ml = pic.getMouseListeners(); + for(int i=0; i portA + sp2 = sp[0].split(att_value_connector); + portA = Integer.parseInt(sp2[1]); + + // do the second one --> portB + sp2 = sp[1].split(att_value_connector); + portB = Integer.parseInt(sp2[1]); + + // do the third one --> portC + sp2 = sp[2].split(att_value_connector); + portC = Integer.parseInt(sp2[1]); + } +} diff --git a/src/funsoftware/ic/obj/timerIcon.java b/src/funsoftware/ic/obj/timerIcon.java new file mode 100644 index 0000000..6a74d7f --- /dev/null +++ b/src/funsoftware/ic/obj/timerIcon.java @@ -0,0 +1,634 @@ +/* + * timerIcon.java + * + * Created on 23 July 2005, 00:09 + */ + +package funsoftware.ic.obj; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.st.*; +import funsoftware.struct.*; +import funsoftware.var.*; +import funsoftware.consts.*; + +/** + * This class is for the timer icon of the fUNSoftWare. + * @author Thomas Legowo + * + */ +public class timerIcon extends objectIcon{ + + // other private attributes + + private int timer; // the amount of time this timer is suppose to count until, default value is 1 second + private int type; // 0 for 's' -- seconds, 1 for 'm' -- minutes, 2 for 'h' -- N hundredths of a second, default is zero being second + + private variable var_timer; + + // for algorithm representation, represent a timer icon with an identifier of 4 + private int identifier; + + /** Creates a new instance of timerIcon */ + public timerIcon() + { + } + + /** + * Creates a new instance of timerIcon + * @param filepath Source file of this icon's image + */ + public timerIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); + timer = 1; + type = 0; + identifier = 4; + var_timer = null; + setImage(); + } + + /** + * Helps provide the transparent background + * @param g Graphic + */ + protected void paintComponent(java.awt.Graphics g) + { + super.paintComponent(g); + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/timers/wait/timer_field.gif")); + g.drawImage(ii.getImage(), 0, 24, this); + } + + /** + * Returns the timer value + * @return Timer value + */ + public int getTimer() + { + return timer; + } + + /** + * Returns the unit of the time -- seconds(type 0), minutes(type 1) or hours(type 2) + * @return Type + */ + public int getType() + { + return type; + } + + /** + * Sets the time of this timer + * @param ntimer Timer + */ + public void setTimer(int ntimer) + { + timer = ntimer; + } + + /** + * Sets the type(or unit) of this timer + * @param ntype New type + */ + public void setType(int ntype) + { + type = ntype; + } + + + /** + * Translating the integer value of the time and its units into string + * @return String representation of timer value + */ + public String returnTime() + { + String unit = new String(); + String time = new String(); + if(type == 0) + { + unit = "s"; + } + else if(type == 1) + { + unit = "m"; + } + else if(type == 2) + { + unit = "h"; + } + + time = Integer.toString(timer); + + time = time.concat(unit); + + return time; + } + + /** + * To set the images and labels of this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + javax.swing.ImageIcon nic; + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/timers/wait/lefttime.gif")); + PicButton pic = new PicButton(nic); + add(pic); + + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(30, 40)); + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/timers/wait/toptime.gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(pic, gridBagConstraints); + + javax.swing.JLabel timerLabel; + if(var_timer == null) + { + timerLabel = new javax.swing.JLabel(returnTime()); + } + else + { + timerLabel = new javax.swing.JLabel("V"); + } + + timerLabel.setBorder(null); + timerLabel.setFont(new java.awt.Font("Tahoma", 0, 11)); + timerLabel.setPreferredSize(new java.awt.Dimension(28, 12)); + timerLabel.setMinimumSize(new java.awt.Dimension(28, 12)); + timerLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + jp2.add(timerLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 2; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/timers/wait/bottomtime.gif")); + pic = new PicButton(nic); + jp2.add(pic, gridBagConstraints); + + add(jp2); + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/timers/wait/rightime.gif")); + pic = new PicButton(nic); + add(pic); + + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * Change the time and its unit or type + * @param evt MouseEvent + */ + public void changeTime(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField; + if(var_timer != null) + { + textField = new javax.swing.JTextField("v"); + } + else + { + textField = new javax.swing.JTextField(returnTime()); + } + textField.setFont(new java.awt.Font("Tahoma", 0, 11)); + textField.setPreferredSize(new java.awt.Dimension(40,14)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + java.awt.GridBagConstraints gridBagConstraints; + + removeAll(); + setLayout(new java.awt.GridBagLayout()); + + javax.swing.ImageIcon nic; + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/timers/wait/fulltoptime.gif")); + PicButton pic = new PicButton(nic); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(pic, gridBagConstraints); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(textField, gridBagConstraints); + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/timers/wait/fullbottomtime.gif")); + pic = new PicButton(nic); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 2; + add(pic, gridBagConstraints); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditMode(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * This is to handle click that stops edit mode + */ + public void stopEditMode() + { + javax.swing.JTextField textField = (javax.swing.JTextField)getComponent(1); + String text = textField.getText(); + removeAll(); + + int tmp_timer = timer; + int tmp_type = type; + + // parse the unit of the time, second will be taken as default should the user does not indicate + // the unit + int i=text.length(); + if(i == 1) + { + try + { + if(text.compareTo("v") == 0 || text.compareTo("V") == 0) + { + if(var_list.Instance().isDefinedVariables() == true || findCurrentAux().getLocalVarList().isEmpty() == false) + { + VarInputDialog vid = new VarInputDialog(null, this, findCurrentAux()); + vid.pack(); + vid.setLocationRelativeTo(this); + vid.setVisible(true); + + if(vid.getUserInput() != null) + { + var_timer = vid.getUserInput(); + type = 2; + } + } + else + { + javax.swing.JOptionPane.showMessageDialog(null, + "You have not defined any global variables or local variables to this function or task yet.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + } + else + { + timer = Integer.parseInt(text.substring(0, i)); + type = 0; + if(timer <= 0) // it is pointless to time for 0 or negative values + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the timer is invalid.\nPlease enter value greater than 0.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + timer = tmp_timer; + type = tmp_type; + } + else + { + var_timer = null; + } + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the timer is invalid.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + } + else if(i > 1) + { + try + { + if((text.substring(i-1)).compareTo("s") == 0) + { + timer = Integer.parseInt(text.substring(0, i-1)); + type = 0; + } + else if((text.substring(i-1)).compareTo("m") == 0) + { + timer = Integer.parseInt(text.substring(0, i-1)); + type = 1; + } + else if((text.substring(i-1)).compareTo("h") == 0) + { + timer = Integer.parseInt(text.substring(0, i-1)); + type = 2; + } + else + { + timer = Integer.parseInt(text.substring(0, i)); + type = 0; + } + + if(timer <= 0) // it is pointless to time for 0 or negative values + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the timer is invalid.\nPlease enter value greater than 0.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + timer = tmp_timer; + type = tmp_type; + } + else + { + var_timer = null; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the timer is invalid.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + } + + // set the states for undo and redo + if(tmp_timer != timer || tmp_type != type) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + else if(var_timer != null) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + setImage(); + repaint(); + validate(); + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + java.awt.event.MouseListener[] ml = getMouseListeners(); + for(int i=0; i seconds, minutes or hours) + + // do the first one --> timer + sp2 = sp[0].split(att_value_connector); + + if(sp2[1].substring(0,1).compareTo("V") == 0) // must be a variable + { + var_timer = var_list.Instance().getVariable(sp2[1].substring(2)); + if(var_timer == null) // must be local, not global + { + var_timer = getAux().getVariable(sp2[1].substring(2)); + } + } + else + { + timer = Integer.parseInt(sp2[1]); + } + + // do the second one --> type + sp2 = sp[1].split(att_value_connector); + type = Integer.parseInt(sp2[1]); + } + + /** + * To display an input panel to ask for a variable to be used + * @return The label of the panel + */ + public javax.swing.JLabel getVarLabel() + { + return new javax.swing.JLabel("Timer (in miliseconds)"); + } + + /** + * To indicate whether this icon uses a variable + * @param var Variable to be checked + * @return True or false + */ + public Boolean useAVariable(variable var) + { + if(var_timer != null) + { + if(var_timer.getType() == var.getType() && var_timer.getName().compareTo(var.getName()) == 0) + { + return true; + } + } + return false; + } +} diff --git a/src/funsoftware/ic/obj/waitCelciusIcon.java b/src/funsoftware/ic/obj/waitCelciusIcon.java new file mode 100644 index 0000000..b911e3f --- /dev/null +++ b/src/funsoftware/ic/obj/waitCelciusIcon.java @@ -0,0 +1,868 @@ +/* + * waitCelciusIcon.java + * + * Created on 1 February 2006, 13:40 + * + */ + +package funsoftware.ic.obj; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.st.*; +import funsoftware.var.*; +import funsoftware.consts.*; + +/** + * This icon waits until the temperature sensor reads a value less than or greater than a specified value. + * @author Thomas Legowo + */ +public class waitCelciusIcon extends objectIcon{ + + // the local variables + private int port; // with default value being 1, port is the value of the input port of this temperature sensor + private int temperature; // default value being 30 + private variable var_temperature; // alternative to temperature + + private int type; // originally typed 1, greater than + + // for algorithm representation, represent a wait temperature celcius sensor icon with an identifier of 19 + private int identifier; + + /** Creates a new instance of waitCelciusIcon */ + public waitCelciusIcon() { + } + + /** + * Creates a new instance of waitCelciusIcon + * @param filepath The source file of this icon's image + */ + public waitCelciusIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); + port = 1; + temperature = 300; + identifier = 19; + var_temperature = null; + type = 1; + setImage(); + } + + /** + * Helps to provide the transparent background + * @param g Graphic + */ + protected void paintComponent(java.awt.Graphics g) + { + super.paintComponent(g); + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/wait/celcius/celciusField.gif")); + g.drawImage(ii.getImage(), 14, 24, this); + } + + /** + * Get the port value of this icon + * @return Port value + */ + public int getPort() + { + return port; + } + + /** + * Set the port value of this icon + * @param nport New port value + */ + public void setPort(int nport) + { + port = nport; + } + + /** + * To get the value of temperature reading from the sensor + * @return Temperature value + */ + public int getTemperatureValue() + { + return temperature; + } + + /** + * To set the temperature value attribute of this icon + * @param nt New temperature value + */ + public void setTemperatureValue(int nt) + { + temperature = nt; + } + + /** + * To set the temperature value attribute of this icon + * @param var Temperature variable + */ + public void setVarTemperature(variable var) + { + var_temperature = var; + } + + /** + * Sets the new comparator type to this icon + * @param nct New comparator type + */ + public void setComparatorType(int nct) + { + type = nct; + } + + /** + * Gets the comparator type to this icon + * @return Comparator type + */ + public int getComparatorType() + { + return type; + } + + /** + * To set the image of this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + javax.swing.ImageIcon nic; + PicButton pic; + + javax.swing.JPanel jp, jp2; + + // add le stuffs into le jp + jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp.setPreferredSize(new java.awt.Dimension(40, 24)); + + // add le stuffs into le jp + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/wait/celcius/top_left.gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + // displays the comparator according to its type + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/wait/celcius/comp"+type+".gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(jp, gridBagConstraints); + + jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp.setPreferredSize(new java.awt.Dimension(40, 16)); + + // do the panel within jp + jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(14, 16)); + + javax.swing.JLabel portLabel = new javax.swing.JLabel(Integer.toString(port)); + portLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + portLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(portLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(jp2, gridBagConstraints); + + // ---------- the light value panel + + jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(26, 16)); + + javax.swing.JLabel temperatureLabel; + if(var_temperature == null) + { + temperatureLabel = new javax.swing.JLabel(Integer.toString(temperature)); + } + else + { + temperatureLabel = new javax.swing.JLabel("V"); + } + temperatureLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + temperatureLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + temperatureLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(temperatureLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(jp2, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(jp, gridBagConstraints); + + jp.setOpaque(false); + setOpaque(false); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * To change the value of the port attribute + * @param evt Mouse event + */ + public void changePort(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField = new javax.swing.JTextField(Integer.toString(port)); + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(14,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + javax.swing.JPanel jp; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditModePort(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + + /** + * To change the temperature attribute of this icon + * @param evt Mouse event + */ + public void changeTemperatureValue(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField; + if(var_temperature != null) + { + textField = new javax.swing.JTextField("v"); + } + else + { + textField = new javax.swing.JTextField(Integer.toString(temperature)); + } + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(26,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + javax.swing.JPanel jp; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditModeTemperature(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the comparator type of this icon + * @param evt Mouse event + */ + public void changeComparator(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + ComparatorDialog c_dialog = new ComparatorDialog(null, type, this); + c_dialog.pack(); + c_dialog.setLocationRelativeTo(this); + c_dialog.setVisible(true); + + type = c_dialog.getComparator(); + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + jp.remove(1); + // displays the comparator according to its type + javax.swing.ImageIcon nic = new javax.swing.ImageIcon(getClass().getResource("/icons/wait/celcius/comp"+type+".gif")); + PicButton pic = new PicButton(nic); + java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + // set the states for undo and redo + UndoRedo.update_state(); + + repaint(); + validate(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To stop edit mode for port text field of this wait icon + */ + public void stopEditModePort() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + jp.removeAll(); + + // parse the port number + int tmp_port = port; // current port number + try + { + port = Integer.parseInt(text); + if(port > 3 || port <= 0) // maximum of 3 input ports + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the input port is invalid.\nIt can be either 1, 2 or 3.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + port = tmp_port; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the input port is invalid.\nPlease enter numbers only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_port != port) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JLabel portLabel = new javax.swing.JLabel(Integer.toString(port)); + portLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + portLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(portLabel, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + } + + /** + * Stop the edit mode of the light value on this branch icon + */ + public void stopEditModeTemperature() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + + String text = textField.getText(); + jp.removeAll(); + + // parse the light sensor value + int tmp_temp = temperature; + try + { + if(text.compareTo("v") == 0 || text.compareTo("V") == 0) + { + if(var_list.Instance().isDefinedVariables() == true || findCurrentAux().getLocalVarList().isEmpty() == false) + { + VarInputDialog vid = new VarInputDialog(null, this, findCurrentAux()); + vid.pack(); + vid.setLocationRelativeTo(this); + vid.setVisible(true); + + if(vid.getUserInput() != null) + { + var_temperature = vid.getUserInput(); + } + } + else + { + javax.swing.JOptionPane.showMessageDialog(null, + "You have not defined any global variables or local variables to this function or task yet.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + } + else + { + temperature = Integer.parseInt(text); + var_temperature = null; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the temperature sensor threshold is invalid.\nPlease enter numbers only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_temp != temperature || var_temperature != null) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JLabel temperatureLabel; + if(var_temperature == null) + { + temperatureLabel = new javax.swing.JLabel(Integer.toString(temperature)); + } + else + { + temperatureLabel = new javax.swing.JLabel("V"); + } + temperatureLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + temperatureLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + temperatureLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(temperatureLabel, gridBagConstraints); + jp.setOpaque(false); + + repaint(); + validate(); + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + java.awt.event.MouseListener[] ml = jp.getMouseListeners(); + for(int i=0; i port + sp2 = sp[0].split(att_value_connector); + port = Integer.parseInt(sp2[1]); + + // do the second one --> light_sensor_value + sp2 = sp[1].split(att_value_connector); + + if(sp2[1].substring(0,1).compareTo("V") == 0) // must be a variable + { + var_temperature = var_list.Instance().getVariable(sp2[1].substring(2)); + if(var_temperature == null) // must be local, not global + { + var_temperature = getAux().getVariable(sp2[1].substring(2)); + } + } + else + { + temperature = Integer.parseInt(sp2[1]); + } + + // do the third one --> comparator + sp2 = sp[2].split(att_value_connector); + type = Integer.parseInt(sp2[1]); + } + + /** + * To display an input panel to ask for a variable to be used + * @return The label of the panel + */ + public javax.swing.JLabel getVarLabel() + { + return new javax.swing.JLabel("Temperature Value Threshold"); + } + + /** + * To indicate whether this icon uses a variable + * @param var Variable to be checked + * @return True or false + */ + public Boolean useAVariable(variable var) + { + if(var_temperature != null) + { + if(var_temperature.getType() == var.getType() && var_temperature.getName().compareTo(var.getName()) == 0) + { + return true; + } + } + return false; + } +} diff --git a/src/funsoftware/ic/obj/waitLightIcon.java b/src/funsoftware/ic/obj/waitLightIcon.java new file mode 100644 index 0000000..fa17a78 --- /dev/null +++ b/src/funsoftware/ic/obj/waitLightIcon.java @@ -0,0 +1,873 @@ +/* + * waitLightIcon.java + * + * Created on 1 February 2006, 13:40 + * + */ + +package funsoftware.ic.obj; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.st.*; +import funsoftware.var.*; +import funsoftware.consts.*; + +/** + * This icon waits until the light sensor reads a value less than or greater than a specified value. + * @author Thomas Legowo + */ +public class waitLightIcon extends objectIcon{ + + // the local variables + + private int port; // with default value being 1, port is the value of the input port of this light sensor + private int light_sensor_value; // default value being 55, minimum is 1 and maximum is 100 + private variable var_light_sensor_value; // alternative to light_sensor_value + + private int type; // originally typed 1, greater than + + // for algorithm representation, represent a wait for light sensor icon with an identifier of 18 + private int identifier; + + /** Creates a new instance of waitLightIcon */ + public waitLightIcon() { + } + + /** + * Creates a new instance of waitLightIcon + * @param filepath The source file of this icon's image + */ + public waitLightIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); + port = 1; + light_sensor_value = 55; + identifier = 18; + var_light_sensor_value = null; + type = 1; + setImage(); + } + + /** + * Helps provide the transparent background + * @param g Graphic + */ + protected void paintComponent(java.awt.Graphics g) + { + super.paintComponent(g); + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/wait/light/lightField.gif")); + g.drawImage(ii.getImage(), 14, 24, this); + } + + /** + * Get the port value of this icon + * @return Port value + */ + public int getPort() + { + return port; + } + + /** + * Set the port value of this icon + * @param nport New port value + */ + public void setPort(int nport) + { + port = nport; + } + + /** + * Return the light sensor value threshold of this branch light sensor icon + * @return Light sensor value + */ + public int getLightSensorValue() + { + return light_sensor_value; + } + + /** + * Set the light sensor value of this icon + * @param nlsv New light sensor value + */ + public void setLightSensorValue(int nlsv) + { + light_sensor_value = nlsv; + } + + /** + * Set the light sensor value of this icon + * @param var The new light value variable + */ + public void setVarLight(variable var) + { + var_light_sensor_value = var; + } + + /** + * Sets the new comparator type to this icon + * @param nct New comparator type + */ + public void setComparatorType(int nct) + { + type = nct; + } + + /** + * Gets the comparator type to this icon + * @return Comparator type + */ + public int getComparatorType() + { + return type; + } + + /** + * To set the image of this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + javax.swing.ImageIcon nic; + PicButton pic; + + javax.swing.JPanel jp, jp2; + + jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp.setPreferredSize(new java.awt.Dimension(40, 24)); + + // add le stuffs into le jp + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/wait/light/top_left.gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + // displays the comparator according to its type + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/wait/light/comp"+type+".gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(jp, gridBagConstraints); + + jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp.setPreferredSize(new java.awt.Dimension(40, 16)); + + // do the panel within jp + jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(14, 16)); + + javax.swing.JLabel portLabel = new javax.swing.JLabel(Integer.toString(port)); + portLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + portLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(portLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(jp2, gridBagConstraints); + + // ---------- the light value panel + + jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(26, 16)); + + javax.swing.JLabel lightLabel; + if(var_light_sensor_value == null) + { + lightLabel = new javax.swing.JLabel(Integer.toString(light_sensor_value)); + } + else + { + lightLabel = new javax.swing.JLabel("V"); + } + lightLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + lightLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + lightLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(lightLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(jp2, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(jp, gridBagConstraints); + + jp.setOpaque(false); + setOpaque(false); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * To change the port value of this icon + * @param evt Mouse event + */ + public void changePort(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField = new javax.swing.JTextField(Integer.toString(port)); + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(14,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + javax.swing.JPanel jp; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditModePort(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the light sensor value threshold of this icon + * @param evt Mouse event + */ + public void changeLightSensorValue(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField; + if(var_light_sensor_value != null) + { + textField = new javax.swing.JTextField("v"); + } + else + { + textField = new javax.swing.JTextField(Integer.toString(light_sensor_value)); + } + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(26,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditModeLight(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + + /** + * Stop the edit mode of the port value on this wait icon + */ + public void stopEditModePort() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + jp.removeAll(); + + // parse the port number + int tmp_port = port; // current port number + try{ + port = Integer.parseInt(text); + if(port > 3 || port <= 0) // maximum of 3 input ports + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the input port is invalid.\nIt can be either 1, 2 or 3.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + port = tmp_port; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the input port is invalid.\nPlease enter numbers only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_port != port) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JLabel portLabel = new javax.swing.JLabel(Integer.toString(port)); + portLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + portLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(portLabel, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + } + + /** + * To change the comparator type of this icon + * @param evt Mouse event + */ + public void changeComparator(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + ComparatorDialog c_dialog = new ComparatorDialog(null, type, this); + c_dialog.pack(); + c_dialog.setLocationRelativeTo(this); + c_dialog.setVisible(true); + + type = c_dialog.getComparator(); + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + jp.remove(1); + // displays the comparator according to its type + javax.swing.ImageIcon nic = new javax.swing.ImageIcon(getClass().getResource("/icons/wait/light/comp"+type+".gif")); + PicButton pic = new PicButton(nic); + java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + // set the states for undo and redo + UndoRedo.update_state(); + + repaint(); + validate(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * Stop the edit mode of the light value on this branch icon + */ + public void stopEditModeLight() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + jp.removeAll(); + + int tmp_light = light_sensor_value; // current port number + try + { + if(text.compareTo("v") == 0 || text.compareTo("V") == 0) + { + if(var_list.Instance().isDefinedVariables() == true || findCurrentAux().getLocalVarList().isEmpty() == false) + { + VarInputDialog vid = new VarInputDialog(null, this, findCurrentAux()); + vid.pack(); + vid.setLocationRelativeTo(this); + vid.setVisible(true); + + if(vid.getUserInput() != null) + { + var_light_sensor_value = vid.getUserInput(); + } + } + else + { + javax.swing.JOptionPane.showMessageDialog(null, + "You have not defined any global variables or local variables to this function or task yet.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + } + else + { + light_sensor_value = Integer.parseInt(text); + if(light_sensor_value > 100 || light_sensor_value < 1) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the light sensor threshold is invalid.\nMinimum value is 1 and maximum value is 100.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + light_sensor_value = tmp_light; + } + else + { + var_light_sensor_value = null; + } + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the light sensor threshold is invalid.\nPlease enter numbers only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_light != light_sensor_value || var_light_sensor_value != null) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JLabel lightLabel; + if(var_light_sensor_value == null) + { + lightLabel = new javax.swing.JLabel(Integer.toString(light_sensor_value)); + } + else + { + lightLabel = new javax.swing.JLabel("V"); + } + lightLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + lightLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + lightLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(lightLabel, gridBagConstraints); + jp.setOpaque(false); + + repaint(); + validate(); + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + java.awt.event.MouseListener[] ml = jp.getMouseListeners(); + for(int i=0; i port + sp2 = sp[0].split(att_value_connector); + port = Integer.parseInt(sp2[1]); + + // do the second one --> light_sensor_value + sp2 = sp[1].split(att_value_connector); + + if(sp2[1].substring(0,1).compareTo("V") == 0) // must be a variable + { + var_light_sensor_value = var_list.Instance().getVariable(sp2[1].substring(2)); + if(var_light_sensor_value == null) // must be local, not global + { + var_light_sensor_value = getAux().getVariable(sp2[1].substring(2)); + } + } + else + { + light_sensor_value = Integer.parseInt(sp2[1]); + } + + // do the third one --> comparator + sp2 = sp[2].split(att_value_connector); + type = Integer.parseInt(sp2[1]); + } + + /** + * To display an input panel to ask for a variable to be used + * @return The label of the panel + */ + public javax.swing.JLabel getVarLabel() + { + return new javax.swing.JLabel("Light Value Threshold"); + } + + /** + * To indicate whether this icon uses a variable + * @param var Variable to be checked + * @return True or false + */ + public Boolean useAVariable(variable var) + { + if(var_light_sensor_value != null) + { + if(var_light_sensor_value.getType() == var.getType() && var_light_sensor_value.getName().compareTo(var.getName()) == 0) + { + return true; + } + } + return false; + } +} diff --git a/src/funsoftware/ic/obj/waitRotationalIcon.java b/src/funsoftware/ic/obj/waitRotationalIcon.java new file mode 100644 index 0000000..df03d1e --- /dev/null +++ b/src/funsoftware/ic/obj/waitRotationalIcon.java @@ -0,0 +1,861 @@ +/* + * waitRotationalIcon.java + * + * Created on 1 February 2006, 13:41 + * + */ + +package funsoftware.ic.obj; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.st.*; +import funsoftware.var.*; +import funsoftware.consts.*; + +/** + * This icon waits until the rotational sensor reads a value less than or greater than a specified value. + * @author Thomas Legowo + */ +public class waitRotationalIcon extends objectIcon{ + + // the local variables + private int port; // with default value being 1, port is the value of the input port of this rotational sensor + private int angle_value; // default value being 16 (1 rotation) + private variable var_angle_value; // alternative to angle_value + + private int type; // originally typed 1, greater than + + // for algorithm representation, represent this wait rotation sensor icon with an identifier of 20 + private int identifier; + + /** Creates a new instance of waitRotationalIcon */ + public waitRotationalIcon() { + } + + /** + * Creates a new instance of waitRotationalIcon + * @param filepath The source file of this icon's image + */ + public waitRotationalIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); + port = 1; + angle_value = 16; + identifier = 20; + var_angle_value = null; + type = 1; + setImage(); + } + + /** + * Helps provide the transparent background + * @param g Graphic + */ + protected void paintComponent(java.awt.Graphics g) + { + super.paintComponent(g); + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/wait/rotate/rotateField.gif")); + g.drawImage(ii.getImage(), 14, 24, this); + } + + /** + * Get the port value of this icon + * @return Port value + */ + public int getPort() + { + return port; + } + + /** + * Set the port value of this icon + * @param nport New port value + */ + public void setPort(int nport) + { + port = nport; + } + + /** + * Get the angular value of this icon + * @return Angular value + */ + public int getAngleValue() + { + return angle_value; + } + + /** + * To set the angular value of this wait rotational sensor icon + * @param nlsv New angle value + */ + public void setAngleValue(int nlsv) + { + angle_value = nlsv; + } + + /** + * To set the angular value of this wait rotational sensor icon + * @param var The angle value variable + */ + public void setVarAngle(variable var) + { + var_angle_value = var; + } + + /** + * Sets the new comparator type to this icon + * @param nct New comparator type + */ + public void setComparatorType(int nct) + { + type = nct; + } + + /** + * Gets the comparator type to this icon + * @return Comparator type + */ + public int getComparatorType() + { + return type; + } + + /** + * To set the image of this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + javax.swing.ImageIcon nic; + PicButton pic; + + javax.swing.JPanel jp, jp2; + + // add le stuffs into le jp + jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp.setPreferredSize(new java.awt.Dimension(40, 24)); + + // add le stuffs into le jp + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/wait/rotate/top_left.gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + // displays the comparator according to its type + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/wait/rotate/comp"+type+".gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(jp, gridBagConstraints); + + jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp.setPreferredSize(new java.awt.Dimension(40, 16)); + + // do the panel within jp + jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(14, 16)); + + javax.swing.JLabel portLabel = new javax.swing.JLabel(Integer.toString(port)); + portLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + portLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(portLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(jp2, gridBagConstraints); + + // ---------- the light value panel + + jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(26, 16)); + + javax.swing.JLabel angleLabel; + if(var_angle_value == null) + { + angleLabel = new javax.swing.JLabel(Integer.toString(angle_value)); + } + else + { + angleLabel = new javax.swing.JLabel("V"); + } + angleLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + angleLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + angleLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(angleLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(jp2, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(jp, gridBagConstraints); + + jp.setOpaque(false); + setOpaque(false); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * To change the port value of this icon + * @param evt Mouse event + */ + public void changePort(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField = new javax.swing.JTextField(Integer.toString(port)); + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(14,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + javax.swing.JPanel jp; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditModePort(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the angular value of this wait rotational sensor icon + * @param evt Mouse event + */ + public void changeAngleValue(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField; + if(var_angle_value != null) + { + textField = new javax.swing.JTextField("v"); + } + else + { + textField = new javax.swing.JTextField(Integer.toString(angle_value)); + } + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(26,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditModeAngle(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the comparator type of this icon + * @param evt Mouse event + */ + public void changeComparator(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + ComparatorDialog c_dialog = new ComparatorDialog(null, type, this); + c_dialog.pack(); + c_dialog.setLocationRelativeTo(this); + c_dialog.setVisible(true); + + type = c_dialog.getComparator(); + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + jp.remove(1); + // displays the comparator according to its type + javax.swing.ImageIcon nic = new javax.swing.ImageIcon(getClass().getResource("/icons/wait/rotate/comp"+type+".gif")); + PicButton pic = new PicButton(nic); + java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + // set the states for undo and redo + UndoRedo.update_state(); + + repaint(); + validate(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * Stop the edit mode in port value of this icon + */ + public void stopEditModePort() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + jp.removeAll(); + + // parse the port number + int tmp_port = port; // current port number + try{ + port = Integer.parseInt(text); + if(port > 3 || port < 1) // maximum of 3 input ports + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the input port is invalid.\nIt can be either 1, 2 or 3.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + port = tmp_port; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the input port is invalid.\nPlease enter numbers only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_port != port) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JLabel portLabel = new javax.swing.JLabel(Integer.toString(port)); + portLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + portLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(portLabel, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + } + + /** + * This method is to stop the edit mode of the angle value on this wait icon + */ + public void stopEditModeAngle() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + jp.removeAll(); + + // parse the angle sensor value + int tmp_angle = angle_value; // current port number + try + { + if(text.compareTo("v") == 0 || text.compareTo("V") == 0) + { + if(var_list.Instance().isDefinedVariables() == true || findCurrentAux().getLocalVarList().isEmpty() == false) + { + VarInputDialog vid = new VarInputDialog(null, this, findCurrentAux()); + vid.pack(); + vid.setLocationRelativeTo(this); + vid.setVisible(true); + + if(vid.getUserInput() != null) + { + var_angle_value = vid.getUserInput(); + } + } + else + { + javax.swing.JOptionPane.showMessageDialog(null, + "You have not defined any global variables or local variables to this function or task yet.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + } + else + { + angle_value = Integer.parseInt(text); + var_angle_value = null; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the rotational sensor threshold is invalid.\nPlease enter numbers greater than 1 only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_angle != angle_value || var_angle_value != null) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JLabel angleLabel; + if(var_angle_value == null) + { + angleLabel = new javax.swing.JLabel(Integer.toString(angle_value)); + } + else + { + angleLabel = new javax.swing.JLabel("V"); + } + angleLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + angleLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + angleLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(angleLabel, gridBagConstraints); + jp.setOpaque(false); + + repaint(); + validate(); + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + java.awt.event.MouseListener[] ml = jp.getMouseListeners(); + for(int i=0; i port + sp2 = sp[0].split(att_value_connector); + port = Integer.parseInt(sp2[1]); + + // do the second one --> angle_sensor_value + sp2 = sp[1].split(att_value_connector); + if(sp2[1].substring(0,1).compareTo("V") == 0) // must be a variable + { + var_angle_value = var_list.Instance().getVariable(sp2[1].substring(2)); + if(var_angle_value == null) // must be local, not global + { + var_angle_value = getAux().getVariable(sp2[1].substring(2)); + } + } + else + { + angle_value = Integer.parseInt(sp2[1]); + } + + // do the third one --> comparator + sp2 = sp[2].split(att_value_connector); + type = Integer.parseInt(sp2[1]); + } + + /** + * To display an input panel to ask for a variable to be used + * @return The label of the panel + */ + public javax.swing.JLabel getVarLabel() + { + return new javax.swing.JLabel("Rotational Value Threshold"); + } + + /** + * To indicate whether this icon uses a variable + * @param var Variable to be checked + * @return True or false + */ + public Boolean useAVariable(variable var) + { + if(var_angle_value != null) + { + if(var_angle_value.getType() == var.getType() && var_angle_value.getName().compareTo(var.getName()) == 0) + { + return true; + } + } + return false; + } +} diff --git a/src/funsoftware/ic/obj/waitTimerIcon.java b/src/funsoftware/ic/obj/waitTimerIcon.java new file mode 100644 index 0000000..59ac2e7 --- /dev/null +++ b/src/funsoftware/ic/obj/waitTimerIcon.java @@ -0,0 +1,865 @@ +/* + * waitTimerIcon.java + * + * Created on 1 February 2006, 13:41 + * + */ + +package funsoftware.ic.obj; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.st.*; +import funsoftware.var.*; +import funsoftware.consts.*; + +/** + * This icon waits until the timer reads a value less than or greater than a specified value. + * @author Thomas Legowo + */ +public class waitTimerIcon extends objectIcon{ + + // the local variables + private int timer_number; // with default value being 0, timer number can be 0 to 3 (4 timers in the RCX bot) + private int timer_value; // default value being 100, minimum is 1, unit is in 10ms. + private variable var_timer_value; // alternative to timer_value + + private int type; // originally typed 1, greater than + + // for algorithm representation, represent a wait timer icon with an identifier of 21 + private int identifier; + + /** Creates a new instance of waitTimerIcon */ + public waitTimerIcon() { + } + + /** + * Creates a new instance of waitTimerIcon + * @param filepath The source file of this icon's image + */ + public waitTimerIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); + timer_number = 0; + timer_value = 50; + identifier = 21; + type = 1; + var_timer_value = null; + setImage(); + } + + /** + * Helps provide the transparent background + * @param g Graphic + */ + protected void paintComponent(java.awt.Graphics g) + { + super.paintComponent(g); + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/wait/timer/timerField.gif")); + g.drawImage(ii.getImage(), 14, 24, this); + } + + /** + * Return the timer number is operating in + * @return Timer number + */ + public int getTimer() + { + return timer_number; + } + + /** + * Return the light sensor value threshold of this wait timer icon + * @return Timer value + */ + public int getTimerValue() + { + return timer_value; + } + + /** + * Set the timer number + * @param ntimer New Timer number + */ + public void setTimer(int ntimer) + { + timer_number = ntimer; + } + + /** + * Set the timer value of this icon + * @param ntv New timer value + */ + public void setTimerValue(int ntv) + { + timer_value = ntv; + } + + /** + * Set the timer value of this icon + * @param var The new timer value variable + */ + public void setVarTimerVal(variable var) + { + var_timer_value = var; + } + + /** + * Sets the new comparator type to this icon + * @param nct New comparator type + */ + public void setComparatorType(int nct) + { + type = nct; + } + + /** + * Gets the comparator type to this icon + * @return Comparator type + */ + public int getComparatorType() + { + return type; + } + + /** + * Set the image of this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + javax.swing.ImageIcon nic; + PicButton pic; + + javax.swing.JPanel jp, jp2; + + jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp.setPreferredSize(new java.awt.Dimension(40, 24)); + + // add le stuffs into le jp + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/wait/timer/top_left.gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + // displays the comparator according to its type + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/wait/timer/comp"+type+".gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(jp, gridBagConstraints); + + jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp.setPreferredSize(new java.awt.Dimension(40, 16)); + + // do the panel within jp + jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(14, 16)); + + javax.swing.JLabel timerNumberLabel = new javax.swing.JLabel(Integer.toString(timer_number)); + timerNumberLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + timerNumberLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + timerNumberLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(timerNumberLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(jp2, gridBagConstraints); + + // ---------- the light value panel + + jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(26, 16)); + + javax.swing.JLabel timerValueLabel; + if(var_timer_value == null) + { + timerValueLabel = new javax.swing.JLabel(Integer.toString(timer_value)); + } + else + { + timerValueLabel = new javax.swing.JLabel("V"); + } + timerValueLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + timerValueLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + timerValueLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jp2.setOpaque(false); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(timerValueLabel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(jp2, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(jp, gridBagConstraints); + + jp.setOpaque(false); + setOpaque(false); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * To change the port value of this icon + * @param evt Mouse event + */ + public void changeTimerNumber(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField = new javax.swing.JTextField(Integer.toString(timer_number)); + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(14,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + javax.swing.JPanel jp; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditModeTimerNumber(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the timer value threshold of this icon + * @param evt Mouse event + */ + public void changeTimerValue(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField; + if(var_timer_value != null) + { + textField = new javax.swing.JTextField("v"); + } + else + { + textField = new javax.swing.JTextField(Integer.toString(timer_value)); + } + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(26,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textField.setOpaque(false); + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditModeTimerValue(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the comparator type of this icon + * @param evt Mouse event + */ + public void changeComparator(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + ComparatorDialog c_dialog = new ComparatorDialog(null, type, this); + c_dialog.pack(); + c_dialog.setLocationRelativeTo(this); + c_dialog.setVisible(true); + + type = c_dialog.getComparator(); + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + jp.remove(1); + // displays the comparator according to its type + javax.swing.ImageIcon nic = new javax.swing.ImageIcon(getClass().getResource("/icons/wait/timer/comp"+type+".gif")); + PicButton pic = new PicButton(nic); + java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + // set the states for undo and redo + UndoRedo.update_state(); + + repaint(); + validate(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * Stop the edit mode of the timer number on this wait icon + */ + public void stopEditModeTimerNumber() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + jp.removeAll(); + + // parse the port number + int tmp_timer_number = timer_number; // current port number + try{ + timer_number = Integer.parseInt(text); + if(timer_number > 3 || timer_number < 0) // values between 0 to 3 only + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the timer number is invalid.\nIt can only be either between 0 and 3.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + timer_number = tmp_timer_number; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the timer number is invalid.\nPlease enter numbers only (0 to 3).\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_timer_number != timer_number) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JLabel timerNumberLabel = new javax.swing.JLabel(Integer.toString(timer_number)); + timerNumberLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + timerNumberLabel.setPreferredSize(new java.awt.Dimension(14, 16)); + timerNumberLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(timerNumberLabel, gridBagConstraints); + + jp.setOpaque(false); + + repaint(); + validate(); + } + + + /** + * Stop the edit mode of the timer value on this wait icon + */ + public void stopEditModeTimerValue() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + jp.removeAll(); + + // parse the light sensor value + int tmp_timer_value = timer_value; // current port number + try + { + if(text.compareTo("v") == 0 || text.compareTo("V") == 0) + { + if(var_list.Instance().isDefinedVariables() == true || findCurrentAux().getLocalVarList().isEmpty() == false) + { + VarInputDialog vid = new VarInputDialog(null, this, findCurrentAux()); + vid.pack(); + vid.setLocationRelativeTo(this); + vid.setVisible(true); + + if(vid.getUserInput() != null) + { + var_timer_value = vid.getUserInput(); + } + } + else + { + javax.swing.JOptionPane.showMessageDialog(null, + "You have not defined any global variables or local variables to this function or task yet.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + } + else + { + timer_value = Integer.parseInt(text); + if(timer_value < 1) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the timer threshold is invalid.\nMinimum value is 1.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + timer_value = tmp_timer_value; + } + else + { + var_timer_value = null; + } + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the timer threshold is invalid.\nPlease enter numbers only (Greater than 1).\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_timer_value != timer_value || var_timer_value != null) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + + java.awt.GridBagConstraints gridBagConstraints; + javax.swing.ImageIcon nic; + PicButton pic; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(1); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JLabel timerValueLabel; + if(var_timer_value == null) + { + timerValueLabel = new javax.swing.JLabel(Integer.toString(timer_value)); + } + else + { + timerValueLabel = new javax.swing.JLabel("V"); + } + timerValueLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + timerValueLabel.setPreferredSize(new java.awt.Dimension(26, 16)); + timerValueLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(timerValueLabel, gridBagConstraints); + jp.setOpaque(false); + + repaint(); + validate(); + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + java.awt.event.MouseListener[] ml = jp.getMouseListeners(); + for(int i=0; i port + sp2 = sp[0].split(att_value_connector); + timer_number = Integer.parseInt(sp2[1]); + + // do the second one --> timer_value + sp2 = sp[1].split(att_value_connector); + if(sp2[1].substring(0,1).compareTo("V") == 0) // must be a variable + { + var_timer_value = var_list.Instance().getVariable(sp2[1].substring(2)); + if(var_timer_value == null) // must be local, not global + { + var_timer_value = getAux().getVariable(sp2[1].substring(2)); + } + } + else + { + timer_value = Integer.parseInt(sp2[1]); + } + + // do the third one --> comparator + sp2 = sp[2].split(att_value_connector); + type = Integer.parseInt(sp2[1]); + } + + /** + * To display an input panel to ask for a variable to be used + * @return The label of the panel + */ + public javax.swing.JLabel getVarLabel() + { + return new javax.swing.JLabel("Timer Value Threshold"); + } + + /** + * To indicate whether this icon uses a variable + * @param var Variable to be checked + * @return True or false + */ + public Boolean useAVariable(variable var) + { + if(var_timer_value != null) + { + if(var_timer_value.getType() == var.getType() && var_timer_value.getName().compareTo(var.getName()) == 0) + { + return true; + } + } + return false; + } +} diff --git a/src/funsoftware/ic/obj/waitTouchIcon.java b/src/funsoftware/ic/obj/waitTouchIcon.java new file mode 100644 index 0000000..14a0ffe --- /dev/null +++ b/src/funsoftware/ic/obj/waitTouchIcon.java @@ -0,0 +1,506 @@ +/* + * waitTouchIcon.java + * + * Created on 1 February 2006, 13:39 + * + */ + +package funsoftware.ic.obj; + +import funsoftware.ic.*; +import funsoftware.st.*; + +/** + * This icon waits until the touch sensor is either pushed in or released. + * @author Thomas Legowo + */ +public class waitTouchIcon extends objectIcon{ + + private int port; // with default value being 1, port is the value of the input port of this touch sensor + // for algorithm representation, represent a wait for touch icon with an identifier of 17 + private int identifier; + + private int type; // originally typed 1, "Y" for sensor touched + + /** Creates a new instance of waitTouchIcon */ + public waitTouchIcon() { + } + + /** + * Creates a new instance of waitTouchIcon + * @param filepath The source file of this icon's image + */ + public waitTouchIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); + port = 1; + identifier = 17; + type = 1; + setImage(); + } + + /** + * Get the port value of this icon + * @return Port value + */ + public int getPort() + { + return port; + } + + /** + * Set the port value of this icon + * @param nport New port value + */ + public void setPort(int nport) + { + port = nport; + } + + /** + * Sets the new comparator type to this icon + * @param nct New comparator type + */ + public void setComparatorType(int nct) + { + type = nct; + } + + /** + * Gets the comparator type to this icon + * @return Comparator type + */ + public int getComparatorType() + { + return type; + } + + /** + * To set the image of this icon + */ + public void setImage() + { + removeAll(); + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + javax.swing.ImageIcon nic; + + javax.swing.JPanel jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + jp.setPreferredSize(new java.awt.Dimension(40, 24)); + + // add le stuffs into le jp + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/wait/touch/top_left.gif")); + PicButton pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + // displays the comparator according to its type + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/wait/touch/comp"+type+".gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(jp, gridBagConstraints); + + javax.swing.JPanel jp2 = new javax.swing.JPanel(); + jp2.setLayout(new java.awt.GridBagLayout()); + jp2.setPreferredSize(new java.awt.Dimension(40, 16)); + + javax.swing.JPanel jp3 = new javax.swing.JPanel(); + jp3.setLayout(new java.awt.GridBagLayout()); + jp3.setPreferredSize(new java.awt.Dimension(15, 16)); + + javax.swing.JLabel portLabel = new javax.swing.JLabel(Integer.toString(port)); + portLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + portLabel.setPreferredSize(new java.awt.Dimension(15, 16)); + portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp3.add(portLabel, gridBagConstraints); + jp3.setOpaque(false); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp2.add(jp3, gridBagConstraints); + + jp3 = new javax.swing.JPanel(); + jp3.setLayout(new java.awt.GridBagLayout()); + jp3.setPreferredSize(new java.awt.Dimension(25, 16)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp2.add(jp3, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + add(jp2, gridBagConstraints); + + jp3.setOpaque(false); + jp2.setOpaque(false); + setOpaque(false); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * To change the port value of this icon + * @param evt Mouse event + */ + public void changePort(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.JTextField textField = new javax.swing.JTextField(Integer.toString(port)); + textField.setFont(new java.awt.Font("Tahoma", 1, 11)); + textField.setPreferredSize(new java.awt.Dimension(15,16)); + textField.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + java.awt.GridBagConstraints gridBagConstraints; + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(textField, gridBagConstraints); + + + repaint(); + validate(); + textField.requestFocusInWindow(); + + textField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + //stop edit mode (Enter-key) + stopEditMode(); + } + }); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * To change the comparator type of this icon + * @param evt Mouse event + */ + public void changeComparator(java.awt.event.MouseEvent evt) + { + if(evt.getButton() != 3) // not a right click + { + javax.swing.ImageIcon nic = new javax.swing.ImageIcon(); + if(type == 2) + { + type = 1; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/wait/touch/comp1.gif")); + } + else if(type == 1) + { + type = 2; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/wait/touch/comp2.gif")); + } + + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + jp.remove(1); + // displays the comparator according to its type + PicButton pic = new PicButton(nic); + java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + // set the states for undo and redo + UndoRedo.update_state(); + + repaint(); + validate(); + } + else + { + javax.swing.JPopupMenu jpm = this.getComponentPopupMenu(); + jpm.setInvoker(this); + jpm.pack(); + jpm.show(this, (int)evt.getPoint().getX(), (int)evt.getPoint().getY()); + jpm.setVisible(true); + } + } + + /** + * Stop edit mode of this icon + */ + public void stopEditMode() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + javax.swing.JTextField textField = (javax.swing.JTextField)jp.getComponent(0); + String text = textField.getText(); + + // parse the unit of the time, second will be taken as default should the user does not indicate + // the unit + int tmp_port = port; // current port number + try + { + port = Integer.parseInt(text); + if(port > 3 || port <= 0) // maximum of 3 input ports + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the input port is invalid.\nIt can be either 1, 2 or 3.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + port = tmp_port; + } + } + catch(RuntimeException e) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Input value for the input port is invalid.\nPlease enter numbers only.\nPlease Try Again.", + "Input Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + }; + + // set the states for undo and redo + if(tmp_port != port) // if values are different then store the state for undo and redo (to avoid redundancy) + { + UndoRedo.update_state(); + } + + // put the original stuffs back into the jpanel + java.awt.GridBagConstraints gridBagConstraints; + + jp = (javax.swing.JPanel)getComponent(1); + jp = (javax.swing.JPanel)jp.getComponent(0); + jp.removeAll(); + jp.setLayout(new java.awt.GridBagLayout()); + + javax.swing.JLabel portLabel = new javax.swing.JLabel(Integer.toString(port)); + portLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + portLabel.setPreferredSize(new java.awt.Dimension(15, 16)); + portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(portLabel, gridBagConstraints); + + repaint(); + validate(); + } + + /** + * Turns off the mouse listeners + */ + public void turnoffListeners() + { + javax.swing.JPanel jp = (javax.swing.JPanel)getComponent(0); + java.awt.event.MouseListener[] ml = jp.getMouseListeners(); + for(int i=0; i port + sp2 = sp[0].split(att_value_connector); + port = Integer.parseInt(sp2[1]); + + // do the second one --> comparator + sp2 = sp[1].split(att_value_connector); + type = Integer.parseInt(sp2[1]); + } +} diff --git a/src/funsoftware/ic/others/endIcon.java b/src/funsoftware/ic/others/endIcon.java new file mode 100644 index 0000000..46bc6ec --- /dev/null +++ b/src/funsoftware/ic/others/endIcon.java @@ -0,0 +1,74 @@ +/* + * endIcon.java + * + * Created on 29 December 2005, 16:24 + * + */ + +package funsoftware.ic.others; + +import funsoftware.ic.*; +import funsoftware.wr.*; + +/** + * This class is the superclass for all kind of ending icons of event monitor, tasks and functions + * @author Thomas Legowo + */ +public class endIcon extends Icon{ + + // the private attributes + private Icon leftNeighbour; + private Wire leftWire; + + /** Creates a new instance of endIcon */ + public endIcon() { + } + + /** + * Creates a new instance of endIcon + * @param filepath Source file of this icon + */ + public endIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); + } + + // The get and set methods + /** + * Gets the left icon neighbour of this end icon + * @return Left icon neighbour + */ + public Icon getLeftNeighbour() + { + return leftNeighbour; + } + + /** + * Gets the left wire of this end icon + * @return Left wire + */ + public Wire getLeftWire() + { + return leftWire; + } + + /** + * Sets the left icon neighbour of this end icon + * @param nicon New left icon neighbour + */ + public void setLeftNeighbour(Icon nicon) + { + leftNeighbour = nicon; + } + + /** + * Sets the left wire of this end icon + * @param nwire New left wire + */ + public void setLeftWire(Wire nwire) + { + leftWire = nwire; + } +} diff --git a/src/funsoftware/ic/others/joinEndBranchIcon.java b/src/funsoftware/ic/others/joinEndBranchIcon.java new file mode 100644 index 0000000..5978046 --- /dev/null +++ b/src/funsoftware/ic/others/joinEndBranchIcon.java @@ -0,0 +1,225 @@ +/* + * joinEndBranchIcon.java + * + * Created on 6 August 2005, 11:53 + */ + +package funsoftware.ic.others; + +import funsoftware.ic.*; +import funsoftware.wr.*; + +/** + * This class is for the special icon joinEndBranchIcon that connects a branch icon with its right neighbour. + * @author Thomas Legowo + * + */ +public class joinEndBranchIcon extends Icon{ + + // the private attributes + private Icon leftNeighbourTop; + private Icon leftNeighbourBottom; + private Icon rightNeighbour; + + private Icon branchIcon; // the if icon that this end branch is used for + + private Wire leftWireTop; + private Wire leftWireBottom; + private Wire rightWire; + + /** Creates a new instance of joinEndBranchIcon */ + public joinEndBranchIcon() { + } + + /** + * Creates a new instance of joinEndBranchIcon + * @param filepath Source file of this icon's image + */ + public joinEndBranchIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); // for startIcon the size of the icon is 26x61 + setImage(); + } + + // The get and set methods + /** + * Gets Left neighbour top icon + * @return Left neighbour top icon + */ + public Icon getLeftNeighbourTop() + { + return leftNeighbourTop; + } + + /** + * Gets Left neighbour bottom icon + * @return Left neighbour bottom icon + */ + public Icon getLeftNeighbourBottom() + { + return leftNeighbourBottom; + } + + /** + * Gets the right neighbour icon + * @return Right neighbour icon + */ + public Icon getRightNeighbour() + { + return rightNeighbour; + } + + /** + * Gets the branch icon that this icon is acting as the end branch icon for. + * @return Branch icon + */ + public Icon getBranchIcon() + { + return branchIcon; + } + + /** + * Gets the left wire top + * @return Left wire top + */ + public Wire getLeftWireTop() + { + return leftWireTop; + } + + /** + * Gets the left wire bottom + * @return Left wire bottom + */ + public Wire getLeftWireBottom() + { + return leftWireBottom; + } + + /** + * Gets the right wire + * @return Right wire + */ + public Wire getRightWire() + { + return rightWire; + } + + /** + * Sets the left neighbour top icon of this icon + * @param nicon Left neighbour top icon + */ + public void setLeftNeighbourTop(Icon nicon) + { + leftNeighbourTop = nicon; + } + + /** + * Sets the left neighbour bottom icon of this icon + * @param nicon Left neighbour bottom + */ + public void setLeftNeighbourBottom(Icon nicon) + { + leftNeighbourBottom = nicon; + } + + /** + * Sets the right neighbour icon of this icon + * @param nicon Right neighbour icon + */ + public void setRightNeighbour(Icon nicon) + { + rightNeighbour = nicon; + } + + /** + * Sets the branch icon that this icon is acting as the end branch icon for. + * @param nicon Branch icon + */ + public void setBranchIcon(Icon nicon) + { + branchIcon = nicon; + } + + /** + * Sets the left wire top + * @param nwire Left wire top + */ + public void setLeftWireTop(Wire nwire) + { + leftWireTop = nwire; + } + + /** + * Sets the left wire bottom + * @param nwire Left wire bottom + */ + public void setLeftWireBottom(Wire nwire) + { + leftWireBottom = nwire; + } + + /** + * Sets the right wire + * @param nwire Right wire + */ + public void setRightWire(Wire nwire) + { + rightWire = nwire; + } + + /** + * Set the image of this icon + */ + public void setImage() + { + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + + // creating the top panel + javax.swing.ImageIcon nic; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/other/join.gif")); + PicButton pic = new PicButton(nic); + add(pic); + } + + /** + * To clone this icon + * @return New instance of this icon + */ + public joinEndBranchIcon Clone() + { + return new joinEndBranchIcon("/icons/other/join.gif"); + } + + /** + * Algorithm translation for the Translator object to create a text representation of this icon + * @param id_separator To separate ids + * @param id_att_separator To separate id with attribute + * @param att_boundary_begin To start attributes + * @param att_boundary_end To end attributes + * @param att_value_connector To separate attributes and its values + * @param att_separator To separate attributes + * @return Translation + */ + public String getTranslation(String id_separator, String id_att_separator, + String att_boundary_begin, String att_boundary_end, String att_value_connector, String att_separator) + { + String algo = new String(); + algo += ""; + return algo; + } + + /** + * Returns a string format of the NQCCode representation of this object + * @param indentation Indentation + * @return The NQC Code + */ + public String getNQCCode(String indentation) + { + String NQCCode = ""; + return NQCCode; + } +} diff --git a/src/funsoftware/ic/others/joinIcon.java b/src/funsoftware/ic/others/joinIcon.java new file mode 100644 index 0000000..2548d32 --- /dev/null +++ b/src/funsoftware/ic/others/joinIcon.java @@ -0,0 +1,169 @@ +/* + * joinIcon.java + * + * Created on 13 August 2005, 16:08 + */ + +package funsoftware.ic.others; + +import funsoftware.ic.*; +import funsoftware.wr.*; + +/** + * This icon is used as joints between segment of wires that bend 90 degrees. + * Using this class ensures that the convention of icons enclosed by the other icons on the same y-coordinate is followed. + * @author Thomas Legowo + * + */ +public class joinIcon extends Icon{ + + // the private attributes + private Icon leftNeighbour; + private Icon rightNeighbour; + + private Wire leftWire; + private Wire rightWire; + + private int type; // 0 for being in the IF part, 1 for being in the ELSE part + + /** Creates a new instance of joinIcon */ + public joinIcon() { + } + + /** + * Creates a new instance of joinIcon + * @param filepath Source file of this icon's image + */ + public joinIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); // for startIcon the size of the icon is 26x61 + setImage(); + } + + // The get and set methods + /** + * Gets the left neighbour icon of this icon + * @return Left neighbour icon + */ + public Icon getLeftNeighbour() + { + return leftNeighbour; + } + + /** + * Gets the right neighbour icon of this icon + * @return Right neighbour icon + */ + public Icon getRightNeighbour() + { + return rightNeighbour; + } + + /** + * To get left wire of this join icon + * @return Left wire + */ + public Wire getLeftWire() + { + return leftWire; + } + + /** + * To get right wire of this join icon + * @return Right wire + */ + public Wire getRightWire() + { + return rightWire; + } + + /** + * Sets the left neighbour icon + * @param nicon Left neighbour icon + */ + public void setLeftNeighbour(Icon nicon) + { + leftNeighbour = nicon; + } + + /** + * Sets the right neighbour icon + * @param nicon Right neighbour icon + */ + public void setRightNeighbour(Icon nicon) + { + rightNeighbour = nicon; + } + + /** + * Sets the left wire of this join icon + * @param nwire Left wire + */ + public void setLeftWire(Wire nwire) + { + leftWire = nwire; + } + + /** + * Sets the right wire of this join icon + * @param nwire Right wire + */ + public void setRightWire(Wire nwire) + { + rightWire = nwire; + } + + /** + * Sets the image of this icon + */ + public void setImage() + { + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + + javax.swing.ImageIcon nic; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/other/join.gif")); + PicButton pic = new PicButton(nic); + add(pic); + } + + /** + * To clone this icon + * @return New instance of this icon + */ + public joinIcon Clone() + { + return new joinIcon("/icons/other/join.gif"); + } + + /** + * Algorithm translation for the Translator object to create a text representation of this icon + * @param id_separator To separate ids + * @param id_att_separator To separate id with attribute + * @param att_boundary_begin To start attributes + * @param att_boundary_end To end attributes + * @param att_value_connector To separate attributes and its values + * @param att_separator To separate attributes + * @return Translation + */ + public String getTranslation(String id_separator, String id_att_separator, + String att_boundary_begin, String att_boundary_end, String att_value_connector, String att_separator) + { + String algo = new String(); + algo += ""; + return algo; + } + + /** + * Returns a string format of the NQCCode representation of this object + * @param indentation Indentation + * @return The NQC Code + */ + public String getNQCCode(String indentation) + { + String NQCCode = ""; + return NQCCode; + } +} diff --git a/src/funsoftware/ic/others/joinLoopIcon.java b/src/funsoftware/ic/others/joinLoopIcon.java new file mode 100644 index 0000000..9057f79 --- /dev/null +++ b/src/funsoftware/ic/others/joinLoopIcon.java @@ -0,0 +1,215 @@ +/* + * joinLoopIcon.java + * + * Created on 7 August 2005, 21:28 + */ + +package funsoftware.ic.others; + +import funsoftware.ic.*; +import funsoftware.wr.*; +import funsoftware.gri.*; + +/** + * This is a special class similar to joinIcon.java + * The joinLoopIcon connects current icons horizontally and the loop icon vertically. + * @author Thomas Legowo + * + */ +public class joinLoopIcon extends Icon{ + + // the private attributes + private Icon leftNeighbour; + private Icon rightNeighbour; + private Icon bottomNeighbour; + + private Wire leftWire; + private Wire rightWire; + private Wire bottomWire; + + /** Creates a new instance of joinLoopIcon */ + public joinLoopIcon() { + } + + /** + * Creates a new instance of joinLoopIcon + * @param filepath Source file of this icon's image + */ + public joinLoopIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); // for startIcon the size of the icon is 26x61 + setImage(); + } + + // The get and set methods + /** + * Gets the left neighbour icon of this icon + * @return Left neighbour icon + */ + public Icon getLeftNeighbour() + { + return leftNeighbour; + } + + /** + * Gets the right neighbour icon of this icon + * @return Right neighbour icon + */ + public Icon getRightNeighbour() + { + return rightNeighbour; + } + + /** + * Gets the bottom neighbour icon visually + * @return Bottom neighbour + */ + public Icon getBottomNeighbour() + { + return bottomNeighbour; + } + + /** + * Gets left wire of this icon + * @return Left wire + */ + public Wire getLeftWire() + { + return leftWire; + } + + /** + * Gets right wire of this icon + * @return Right wire + */ + public Wire getRightWire() + { + return rightWire; + } + + /** + * Gets bottom wire of this icon + * @return Bottom wire + */ + public Wire getBottomWire() + { + return bottomWire; + } + + /** + * Sets the left neighbour + * @param nicon New left neighbour + */ + public void setLeftNeighbour(Icon nicon) + { + leftNeighbour = nicon; + } + + /** + * Sets the right neighbour + * @param nicon New right neighbour + */ + public void setRightNeighbour(Icon nicon) + { + rightNeighbour = nicon; + } + + /** + * Sets the bottom neighbour + * @param nicon New bottom neighbour + */ + public void setBottomNeighbour(Icon nicon) + { + bottomNeighbour = nicon; + } + + /** + * Sets the left wire of this icon + * @param nwire New left wire + */ + public void setLeftWire(Wire nwire) + { + leftWire = nwire; + } + + /** + * Sets the right wire of this icon + * @param nwire New right wire + */ + public void setRightWire(Wire nwire) + { + rightWire = nwire; + } + + /** + * Sets the bottom wire of this icon + * @param nwire New bottom wire + */ + public void setBottomWire(Wire nwire) + { + bottomWire = nwire; + } + + /** + * Sets the coordinate of this icon + * @param nco New coordinate + */ + public void setCoordinate(coord nco) + { + super.setCoordinate(nco); + } + + /** + * To set the image of this icon + */ + public void setImage() + { + java.awt.GridBagConstraints gridBagConstraints; + setLayout(new java.awt.GridBagLayout()); + + javax.swing.ImageIcon nic; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/other/joinLoop.gif")); + PicButton pic = new PicButton(nic); + add(pic); + } + + /** + * To clone this icon + * @return New instance of this icon + */ + public joinLoopIcon Clone() + { + return new joinLoopIcon("/icons/other/joinLoop.gif"); + } + + /** + * Algorithm translation for the Translator object to create a text representation of this icon + * @param id_separator To separate ids + * @param id_att_separator To separate id with attribute + * @param att_boundary_begin To start attributes + * @param att_boundary_end To end attributes + * @param att_value_connector To separate attributes and its values + * @param att_separator To separate attributes + * @return Translation + */ + public String getTranslation(String id_separator, String id_att_separator, + String att_boundary_begin, String att_boundary_end, String att_value_connector, String att_separator) + { + String algo = new String(); + algo += ""; + return algo; + } + + /** + * Returns a string format of the NQCCode representation of this object + * @param indentation Indentation + * @return The NQC Code + */ + public String getNQCCode(String indentation) + { + String NQCCode = ""; + return NQCCode; + } +} diff --git a/src/funsoftware/ic/others/startIcon.java b/src/funsoftware/ic/others/startIcon.java new file mode 100644 index 0000000..a8e4932 --- /dev/null +++ b/src/funsoftware/ic/others/startIcon.java @@ -0,0 +1,181 @@ +/* + * startIcon.java + * + * Created on 29 December 2005, 16:24 + */ + +package funsoftware.ic.others; + +import funsoftware.ic.*; +import funsoftware.inter.*; +import funsoftware.wr.*; + +/** + * This class caters for all kind of start icons in event monitors, functions and tasks + * @author Thomas Legowo + */ +public class startIcon extends Icon{ + + // the icons enclosed within this repeat segment + private java.util.Vector members = new java.util.Vector();; + + // for deletions, startIcon needs to know which panel it is on + // due to all its member icons pointing to this startIcon + private ProgWindow prog_panel; + private javax.swing.JScrollPane scroller; + + // the private attributes + private Icon rightNeighbour; + private Wire rightWire; + + /** Creates a new instance of startIcon */ + public startIcon() { + } + + /** + * Creates a new instance of startIcon + * @param filepath Source file of the icon's image + */ + public startIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); + setImage(); + prog_panel = new ProgWindow(); + } + + // for getting and setting the programming window and its scroller + /** + * Gets the programming window this starting icon is associated to + * @return Programming window + */ + public ProgWindow getProgWindow() + { + return prog_panel; + } + + /** + * Sets the programming window this starting icon is associated to + * @param pw New programming window + */ + public void setProgWindow(ProgWindow pw) + { + prog_panel = pw; + } + + /** + * Gets scrollers of the programming window + * @return A scroll pane + */ + public javax.swing.JScrollPane getScroller() + { + return scroller; + } + + /** + * Sets scrollers of the programming window + * @param jsp A scroll pane + */ + public void setScroller(javax.swing.JScrollPane jsp) + { + scroller = jsp; + } + + /** + * Gets right neighbour of this icon + * @return Right neighbour + */ + public Icon getRightNeighbour() + { + return rightNeighbour; + } + + /** + * Gets right wire of this icon + * @return Right wire + */ + public Wire getRightWire() + { + return rightWire; + } + + /** + * Sets right neighbour of this icon + * @param nicon New right icon + */ + public void setRightNeighbour(Icon nicon) + { + rightNeighbour = nicon; + } + + /** + * Sets right wire of this icon + * @param nwire New right wire + */ + public void setRightWire(Wire nwire) + { + rightWire = nwire; + } + + /** + * Get the members of this start icon + * @return Set of icons + */ + public java.util.Vector getMembers() + { + return members; + } + + /** + * Adds a new icon to this icon + * @param new_icon New icon + * @param right_icon Right icon to the new icon + */ + public void addMember(Icon new_icon, Icon right_icon) + { + int found = 0; + for(int i=0; i al = aux_list.Instance().getAuxiliaries(); + for(int i=1; i al = aux_list.Instance().getAuxiliaries(); + s+=al.get(num_id).getName(); + + return s; + } + + /** + * Get the description of this icon + * @return Help Description + */ + public String getHelpDesc() + { + String s = "This icon starts a specified task."; + return s; + } + + /** + * Get help picture of this icon + * @return Help picture + */ + public javax.swing.Icon getHelpIcon() + { + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/helps/beginTaskIcon.gif")); + return ii; + } + + + /** + * Algorithm translation for the Translator object to create a text representation of this icon + * @param id_separator To separate ids + * @param id_att_separator To separate id with attribute + * @param att_boundary_begin To start attributes + * @param att_boundary_end To end attributes + * @param att_value_connector To separate attributes and its values + * @param att_separator To separate attributes + * @return Translation + */ + public String getTranslation(String id_separator, String id_att_separator, + String att_boundary_begin, String att_boundary_end, String att_value_connector, String att_separator) + { + String algo = new String(); + algo += "\n"; // to begin with + algo += "object"; + algo += id_separator; + algo += identifier; + algo += id_att_separator; + algo += att_boundary_begin; + algo += "name"+att_value_connector; + algo += name; + algo += att_boundary_end; + return algo; + } + + /** + * Returns a string format of the NQCCode representation of this object + * @param indentation Indentation + * @return The NQC Code + */ + public String getNQCCode(String indentation) + { + String NQCCode = new String(); + + NQCCode += indentation+"// Start a task \n"; + NQCCode += indentation+"start "; + java.util.Vector al = aux_list.Instance().getAuxiliaries(); + NQCCode+=al.get(num_id).getName(); + NQCCode += ";\n\n"; + return NQCCode; + } + + /** + * Set its own attributes given a string from a text representation of it + * @param att Attributes + * @param att_value_connector Attribute connector + * @param att_separator Attribute separator + */ + public void setAttributes(String att, String att_value_connector, String att_separator) + { + String[] sp = att.split(att_separator); + String[] sp2 = new String[2]; + + // do the first one --> task id + sp2 = sp[0].split(att_value_connector); + name = sp2[1]; + } + + /** + * Programming window where this function icon is on + * @return Programming window + */ + public ProgWindow getIndividualProgWindow() + { + Icon parent = new Icon(); + ProgWindow ret_val = new ProgWindow(); + while(true) + { + if(parent instanceof startIcon) + { + if(parent instanceof startFunctionIcon) + { + ret_val = ((startFunctionIcon)parent).getProgWindow(); + } + else if(parent instanceof startTaskIcon) + { + ret_val = ((startTaskIcon)parent).getProgWindow(); + } + else if(parent instanceof startEventIcon) + { + ret_val = ((startEventIcon)parent).getProgWindow(); + } + break; + } + else + { + parent = this.getParentIcon(); + } + } + return ret_val; + } + + /** + * Returns scroll pane of the individual programming window + * @return Scroll Pane + */ + public javax.swing.JScrollPane getIndividualScroller() + { + Icon parent = new Icon(); + javax.swing.JScrollPane ret_val = new javax.swing.JScrollPane(); + while(true) + { + if(parent instanceof startIcon) + { + ret_val = ((startIcon)parent).getScroller(); + break; + } + else + { + parent = this.getParentIcon(); + } + } + + return ret_val; + } +} diff --git a/src/funsoftware/ic/tsk/endTaskIcon.java b/src/funsoftware/ic/tsk/endTaskIcon.java new file mode 100644 index 0000000..112c8b2 --- /dev/null +++ b/src/funsoftware/ic/tsk/endTaskIcon.java @@ -0,0 +1,101 @@ +/* + * endTaskIcon.java + * + * Created on 29 December 2005 + */ + +package funsoftware.ic.tsk; + +import funsoftware.ic.*; +import funsoftware.ic.others.*; +import funsoftware.ic.PicButton; +import funsoftware.tasks.*; + +/** + * This class is for icon ending a program, the opposite of startTaskIcon.java + * @author Thomas Legowo + */ +public class endTaskIcon extends endIcon{ + + // private variable + private task tsk; + + /** Creates a new instance of endTaskIcon */ + public endTaskIcon() { + } + + /** + * Creates a new instance of endTaskIcon + * @param filepath Source file of this icon + */ + public endTaskIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); + setImage(); + } + + /** + * Sets the task this ending task icon is associated to + * @param tk the task + */ + public void setTask(task tk) + { + tsk = tk; + } + + /** + * to set the image of this icon + */ + public void setImage() + { + PicButton pic = new PicButton(super.getImage()); + setLayout(new java.awt.GridBagLayout()); + add(pic); + setPreferredSize(new java.awt.Dimension(40,40)); + } + + /** + * To clone this icon + * @return New instance of this icon + */ + public endTaskIcon Clone() + { + return new endTaskIcon("/icons/closures/ret_val.gif"); + } + + /** + * Algorithm translation for the Translator object to create a text representation of this icon + * @param id_separator To separate ids + * @param id_att_separator To separate id with attribute + * @param att_boundary_begin To start attributes + * @param att_boundary_end To end attributes + * @param att_value_connector To separate attributes and its values + * @param att_separator To separate attributes + * @return Translation + */ + public String getTranslation(String id_separator, String id_att_separator, + String att_boundary_begin, String att_boundary_end, String att_value_connector, String att_separator) + { + String algo = new String(); + algo += "\nendtask"; + algo += id_separator; + algo += tsk.getNumId(); + algo += "."; + return algo; + } + + /** + * Returns a string format of the NQCCode representation of this object + * @param indentation Indentation + * @return The NQC Code + */ + public String getNQCCode(String indentation) + { + String NQCCode = new String(); + NQCCode += "}"; + NQCCode += "\n\n"; + return NQCCode; + } +} diff --git a/src/funsoftware/ic/tsk/startTaskIcon.java b/src/funsoftware/ic/tsk/startTaskIcon.java new file mode 100644 index 0000000..0ae0611 --- /dev/null +++ b/src/funsoftware/ic/tsk/startTaskIcon.java @@ -0,0 +1,97 @@ +/* + * startTaskIcon.java + * + * Created on 29 December 2005 + */ + +package funsoftware.ic.tsk; + +import funsoftware.ic.*; +import funsoftware.inter.*; +import funsoftware.ic.others.*; +import funsoftware.ic.PicButton; +import funsoftware.tasks.*; + +/** + * This class is a subclass from startIcon.java + * This class defines a starting icon of a task + * @author Thomas Legowo + */ +public class startTaskIcon extends startIcon{ + + private task tsk; + + /** Creates a new instance of startTaskIcon */ + public startTaskIcon() { + } + + /** + * Creates a new instance of startTaskIcon + * @param filepath Source file of the icon's image + */ + public startTaskIcon(String filepath) + { + super(filepath); + } + + /** + * Sets the task this starting task icon is associated to + * @param tk the task + */ + public void setTask(task tk) + { + tsk = tk; + } + + /** + * To return the task + * @return The task + */ + public task getTask() + { + return tsk; + } + + /** + * To clone this icon + * @return New instance of this icon + */ + public startTaskIcon Clone() + { + return new startTaskIcon("/icons/closures/argument.gif"); + } + + /** + * Algorithm translation for the Translator object to create a text representation of this icon + * @param id_separator To separate ids + * @param id_att_separator To separate id with attribute + * @param att_boundary_begin To start attributes + * @param att_boundary_end To end attributes + * @param att_value_connector To separate attributes and its values + * @param att_separator To separate attributes + * @return Translation + */ + public String getTranslation(String id_separator, String id_att_separator, + String att_boundary_begin, String att_boundary_end, String att_value_connector, String att_separator) + { + String algo = new String(); + algo += "\nstarttask"; + algo += id_separator; + algo += tsk.getNumId(); + return algo; + } + + /** + * Returns a string format of the NQCCode representation of this object + * @param indentation Indentation + * @return The NQC Code + */ + public String getNQCCode(String indentation) + { + String NQCCode = new String(); + NQCCode += "\n{\n"; + NQCCode += tsk.getNQCLocalVar(); + NQCCode += "\n"; + return NQCCode; + } +} diff --git a/src/funsoftware/ic/tsk/stopTaskIcon.java b/src/funsoftware/ic/tsk/stopTaskIcon.java new file mode 100644 index 0000000..4189313 --- /dev/null +++ b/src/funsoftware/ic/tsk/stopTaskIcon.java @@ -0,0 +1,366 @@ +/* + * stopTaskIcon.java + * + * Created on 30 December 2005, 16:41 + * + */ + +package funsoftware.ic.tsk; + +import funsoftware.ic.obj.*; +import funsoftware.inter.*; +import funsoftware.ic.*; +import funsoftware.ic.others.*; +import funsoftware.ic.tsk.*; +import funsoftware.ic.ev.*; +import funsoftware.ic.func.*; +import funsoftware.consts.*; +import funsoftware.struct.*; +import funsoftware.tasks.*; + +/** + * This class represents an icon that indicates a currently running task is to be stopped. + * @author Thomas Legowo + */ +public class stopTaskIcon extends objectIcon{ + + // private variables + private int num_id; // id of the task to be stopped as given by the TaskWindow class + private String name; // name of this task as given by the user + // for algorithm representation, represent a stopTask icon with an identifier of 11 + private int identifier; + + // the task this icon is starting + private task the_task; + + /** Creates a new instance of stopTaskIcon */ + public stopTaskIcon() { + } + + /** + * Creates a new instance of stopTaskIcon + * @param filepath The filepath of the icon's image + */ + public stopTaskIcon(String filepath) { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); + identifier = 11; + name = ""; + setImage(); + } + + /** + * Helps provide the transparent background + * @param g Graphic + */ + protected void paintComponent(java.awt.Graphics g) + { + super.paintComponent(g); + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/task/stop/nameField.gif")); + g.drawImage(ii.getImage(), 11, 13, this); + } + + /** + * Alters the id of the task this icon is representing + * @param i New task id + */ + public void setNumId(int i) + { + num_id = i; + } + + /** + * Returns the id of the task this icon is representing + * @return task id + */ + public int getNumId() + { + return num_id; + } + + /** + * To set the task this icon is pointing to + * @param tk The task this icon is pointing to + */ + public void setTask(task tk) + { + the_task = tk; + num_id = the_task.getNumId(); + name = the_task.getName(); + } + + /** + * To set the name of this icon + * @param n The name + */ + public void setName(String n) + { + name = n; + } + + /** + * Returns this task icon's name + * @return task name + */ + public String getName() + { + return name; + } + + /** + * Returns the task this icon is connected to + * @return The task + */ + public task getTask() + { + return the_task; + } + + /** + * To set the image of this task icon + */ + public void setImage() + { + removeAll(); + setLayout(new java.awt.GridBagLayout()); + java.awt.GridBagConstraints gridBagConstraints; + + // creating the top panel + javax.swing.ImageIcon nic; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/task/stop/stopleft.gif")); + PicButton pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + add(pic, gridBagConstraints); + + javax.swing.JPanel jp = new javax.swing.JPanel(); + jp.setPreferredSize(new java.awt.Dimension(28, 40)); + jp.setLayout(new java.awt.GridBagLayout()); + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/task/stop/stoptop.gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + jp.add(pic, gridBagConstraints); + + javax.swing.JLabel nameLabel = new javax.swing.JLabel(name); + nameLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + nameLabel.setPreferredSize(new java.awt.Dimension(28, 14)); + nameLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + jp.setOpaque(false); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + jp.add(nameLabel, gridBagConstraints); + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/task/stop/stopbottom.gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 2; + jp.add(pic, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + add(jp, gridBagConstraints); + + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/task/stop/stopright.gif")); + pic = new PicButton(nic); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 0; + add(pic, gridBagConstraints); + + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + /** + * To clone this icon + * @return New instance of this icon + */ + public stopTaskIcon Clone() + { + return new stopTaskIcon("/icons/task/stop/stopTask.gif"); + } + + /** + * To copy this icon + * @return New instance of this icon with its attributes set + */ + public Icon Copy() + { + stopTaskIcon newBTI = Clone(); + newBTI.setNumId(num_id); + newBTI.setTask(the_task); + newBTI.setName(name); + newBTI.setImage(); + return newBTI; + } + + /** + * Get the help title of this stop task icon + * @return Help title + */ + public String getHelpTitle() + { + String s = "Stop Task Icon"; + return s; + } + + /** + * Get help message of this stop task icon + * @return Help message + */ + public String getHelpMsg() + { + String s = "DETAILS:"; + s+="\n\nThe task started: "; + java.util.Vector al = aux_list.Instance().getAuxiliaries(); + s+=al.get(num_id).getName(); + + return s; + } + + /** + * Get the description of this icon + * @return Help Description + */ + public String getHelpDesc() + { + String s = "This icon stops a specified task."; + return s; + } + + /** + * Get help picture of this icon + * @return Help picture + */ + public javax.swing.Icon getHelpIcon() + { + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/helps/stopTaskIcon.gif")); + return ii; + } + + + /** + * Algorithm translation for the Translator object to create a text representation of this icon + * @param id_separator To separate ids + * @param id_att_separator To separate id with attribute + * @param att_boundary_begin To start attributes + * @param att_boundary_end To end attributes + * @param att_value_connector To separate attributes and its values + * @param att_separator To separate attributes + * @return Translation + */ + public String getTranslation(String id_separator, String id_att_separator, + String att_boundary_begin, String att_boundary_end, String att_value_connector, String att_separator) + { + String algo = new String(); + algo += "\n"; // to begin with + algo += "object"; + algo += id_separator; + algo += identifier; + algo += id_att_separator; + algo += att_boundary_begin; + algo += "name"+att_value_connector; + algo += name; + algo += att_boundary_end; + return algo; + } + + /** + * Returns a string format of the NQCCode representation of this object + * @param indentation Indentation + * @return The NQC Code + */ + public String getNQCCode(String indentation) + { + String NQCCode = new String(); + + NQCCode += indentation+"// Stop a task \n"; + NQCCode += indentation+"stop "; + java.util.Vector al = aux_list.Instance().getAuxiliaries(); + NQCCode+=al.get(num_id).getName(); + NQCCode += ";\n\n"; + return NQCCode; + } + + /** + * Set its own attributes given a string from a text representation of it + * @param att Attributes + * @param att_value_connector Attribute connector + * @param att_separator Attribute separator + */ + public void setAttributes(String att, String att_value_connector, String att_separator) + { + String[] sp = att.split(att_separator); + String[] sp2 = new String[2]; + + // do the first one --> task id + sp2 = sp[0].split(att_value_connector); + name = sp2[1]; + } + + + /** + * Programming window where this function icon is on + * @return Programming window + */ + public ProgWindow getIndividualProgWindow() + { + Icon parent = new Icon(); + ProgWindow ret_val = new ProgWindow(); + while(true) + { + if(parent instanceof startIcon) + { + if(parent instanceof startFunctionIcon) + { + ret_val = ((startFunctionIcon)parent).getProgWindow(); + } + else if(parent instanceof startTaskIcon) + { + ret_val = ((startTaskIcon)parent).getProgWindow(); + } + else if(parent instanceof startEventIcon) + { + ret_val = ((startEventIcon)parent).getProgWindow(); + } + break; + } + else + { + parent = this.getParentIcon(); + } + } + return ret_val; + } + + /** + * Returns scroll pane of the individual programming window + * @return Scroll Pane + */ + public javax.swing.JScrollPane getIndividualScroller() + { + Icon parent = new Icon(); + javax.swing.JScrollPane ret_val = new javax.swing.JScrollPane(); + while(true) + { + if(parent instanceof startIcon) + { + ret_val = ((startIcon)parent).getScroller(); + break; + } + else + { + parent = this.getParentIcon(); + } + } + return ret_val; + } +} diff --git a/src/funsoftware/ic/var/ArithOpIcon.java b/src/funsoftware/ic/var/ArithOpIcon.java new file mode 100644 index 0000000..db70e73 --- /dev/null +++ b/src/funsoftware/ic/var/ArithOpIcon.java @@ -0,0 +1,399 @@ +/* + * ArithOpIcon.java + * + * Created on 22 December 2005, 15:12 + * + */ + +package funsoftware.ic.var; + +import funsoftware.ic.*; +import funsoftware.ic.obj.*; +import funsoftware.var.*; +import funsoftware.struct.*; +import funsoftware.consts.*; +import funsoftware.events.*; + +/** + * This class maintains an icon representing an arithmetic operation. + * @author Thomas Legowo + */ +public class ArithOpIcon extends objectIcon{ + + // the private variables + private int identifier; // identifier of 12 + private ArithmeticOperation AO; + private auxiliary aux; + + /** Creates a new instance of ArithOpIcon */ + public ArithOpIcon() { + } + + /** + * Creates a new instance of ArithOpIcon + * @param filepath The source file of this icon's image + */ + public ArithOpIcon(String filepath) + { + super(filepath); + super.setWidth(super.getImage().getImage().getWidth(this)); // goes vertically + super.setHeight(super.getImage().getImage().getHeight(this)); + identifier = 12; + AO = new ArithmeticOperation(); + setImage(); + } + + /** + * Returns the arithmetic operation this icon is representing + * @return The arithmetic operation this icon is representing + */ + public ArithmeticOperation getAO() + { + return AO; + } + + /** + * Sets the arithmetic operation this icon is representing + * @param AO The arithmetic operation this icon is representing + */ + public void setAO(ArithmeticOperation AO) + { + this.AO = AO; + } + + /** + * Set the auxiliary that this arithmetic operation icon is in + * @param a The auxiliary that this arithmetic operation icon is in + */ + public void setAux(auxiliary a) + { + aux = a; + } + + /** + * Get the auxiliary that this arithmetic operation icon is in + * @return Auxiliary (function or task) + */ + public auxiliary getAux() + { + return aux; + } + + /** + * To set the image of this icon + */ + public void setImage() + { + removeAll(); + setLayout(new java.awt.GridBagLayout()); + + // creating the top panel + javax.swing.ImageIcon nic; + nic = new javax.swing.ImageIcon(getClass().getResource("/icons/arithmetic/opIcon.gif")); + PicButton pic = new PicButton(nic); + add(pic); + setPreferredSize(new java.awt.Dimension(40, 40)); + } + + + /** + * Get the help title of this arithmetic operation icon + * @return Help title + */ + public String getHelpTitle() + { + String s = "Arithmetic Operation Icon"; + return s; + } + + /** + * Get help message of this break icon + * @return Help message + */ + public String getHelpMsg() + { + String s = "Arithmetic Operation:\n"; + s+=AO.getNQCCode(""); + return s; + } + + /** + * Get the description of this icon + * @return Help Description + */ + public String getHelpDesc() + { + String s = ""; + return s; + } + + /** + * Get help picture of this icon + * @return Help picture + */ + public javax.swing.Icon getHelpIcon() + { + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/helps/ArithOpIcon.gif")); + return ii; + } + + /** + * To clone this ArithOpIcon + * @return New instance of this ArithOpIcon + */ + public ArithOpIcon Clone() + { + return new ArithOpIcon("/icons/arithmetic/opIcon.gif"); + } + + /** + * To copy this icon + * @return New instance of this icon with its attributes set + */ + public Icon Copy() + { + ArithOpIcon newAOI = Clone(); + newAOI.setAux(aux); + newAOI.setAO(AO); + newAOI.setImage(); + return newAOI; + } + + /** + * Algorithm translation for the Translator object to create a text representation of this icon + * @param id_separator To separate ids + * @param id_att_separator To separate id with attribute + * @param att_boundary_begin To start attributes + * @param att_boundary_end To end attributes + * @param att_value_connector To separate attributes and its values + * @param att_separator To separate attributes + * @return Translation + */ + public String getTranslation(String id_separator, String id_att_separator, + String att_boundary_begin, String att_boundary_end, String att_value_connector, String att_separator) + { + String algo = new String(); + algo += "\n"; // to begin with + algo += "object"; + algo += id_separator; + algo += identifier; + algo += id_att_separator; + algo += AO.getAOTranslation(id_separator, id_att_separator, att_boundary_begin, att_boundary_end, att_value_connector, att_separator); + return algo; + } + + /** + * Returns a string format of the NQCCode representation of this object + * @param indentation Indentation + * @return The NQC Code + */ + public String getNQCCode(String indentation) + { + String NQCCode = new String(); + NQCCode += indentation; + NQCCode += "// an arithmetic operation\n"; + NQCCode += AO.getNQCCode(indentation); + return NQCCode; + } + + /** + * Set its own attributes given a string from a text representation of it + * @param id_att_separator The id and attribute separator + * @param att Attributes + * @param att_value_connector Attribute connector + * @param att_separator Attribute separator + */ + public void setAttributes(String att, String att_value_connector, String att_separator, String id_att_separator) + { + AO = new ArithmeticOperation(); + + // get the first part, the variable return value + String[] sp = att.split(id_att_separator); + String value; + sp = sp[1].split(att_separator); // skip the res = v + sp = sp[0].split(att_value_connector); + value = sp[1].substring(0, sp[1].length()-1); + att = att.substring(att.indexOf(id_att_separator)+2); + att = att.substring(att.indexOf(att_separator)+1); + variable res = var_list.Instance().getVariable(value); + if(res == null) // must be local, not global + { + if(aux instanceof monitorEvent) + { + monitorEvent ev = (monitorEvent)aux; + res = ev.getAuxPoint().getVariable(value); + } + else + { + res = aux.getVariable(value); + } + } + AO.setVariable(res); + // so the first part is done + + // now do the first operand of AO + sp = att.split(id_att_separator); + sp = sp[0].split(att_value_connector); + if(sp[1].compareTo("v") == 0) // a variable + { + sp = att.split(id_att_separator); + sp = sp[1].split(att_separator); + sp = sp[0].split(att_value_connector); + value = sp[1].substring(0, sp[1].length()-1); + att = att.substring(att.indexOf(id_att_separator)+2); + att = att.substring(att.indexOf(att_separator)+1); + + res = var_list.Instance().getVariable(value); + if(res == null) // must be local, not global + { + if(aux instanceof monitorEvent) + { + monitorEvent ev = (monitorEvent)aux; + res = ev.getAuxPoint().getVariable(value); + } + else + { + res = aux.getVariable(value); + } + } + AO.setOperand1(res); + } + else if(sp[1].compareTo("c") == 0) // a constant + { + constant c = new constant(); + sp = att.split(id_att_separator); + sp = sp[1].split(att_separator); + sp = sp[0].split(att_value_connector); + value = sp[1].substring(0, sp[1].length()-1); + att = att.substring(att.indexOf(id_att_separator)+2); + att = att.substring(att.indexOf(att_separator)+1); + c.setValue(Integer.parseInt(value)); + AO.setOperand1(c); + } + else if(sp[1].compareTo("NO") == 0) // a nested operation + { + NestedOperation NO = new NestedOperation(); + att = att.substring(att.indexOf(id_att_separator)+2); + att = helpSetAtt(att, att_value_connector, att_separator, id_att_separator, NO); + AO.setOperand1(NO); + } + } + + // a helper method for setAttributes + private String helpSetAtt(String att, String att_value_connector, String att_separator, String id_att_separator, NestedOperation the_NO) + { + String[] sp = att.split(id_att_separator); + String value; + variable res; + sp = sp[0].split(att_value_connector); + // do the first operand + if(sp[1].compareTo("v") == 0) // a variable + { + sp = att.split(id_att_separator); + sp = sp[1].split(att_separator); + sp = sp[0].split(att_value_connector); + value = sp[1].substring(0, sp[1].length()-1); + att = att.substring(att.indexOf(id_att_separator)+2); + att = att.substring(att.indexOf(att_separator)+1); + + res = var_list.Instance().getVariable(value); + if(res == null) // must be local, not global + { + if(aux instanceof monitorEvent) + { + monitorEvent ev = (monitorEvent)aux; + res = ev.getAuxPoint().getVariable(value); + } + else + { + res = aux.getVariable(value); + } + } + the_NO.setOperand1(res); + } + else if(sp[1].compareTo("c") == 0) // a constant + { + constant c = new constant(); + sp = att.split(id_att_separator); + sp = sp[1].split(att_separator); + sp = sp[0].split(att_value_connector); + value = sp[1].substring(0, sp[1].length()-1); + att = att.substring(att.indexOf(id_att_separator)+2); + att = att.substring(att.indexOf(att_separator)+1); + c.setValue(Integer.parseInt(value)); + the_NO.setOperand1(c); + } + else if(sp[1].compareTo("NO") == 0) // a nested operation + { + NestedOperation NO = new NestedOperation(); + att = att.substring(att.indexOf(id_att_separator)+2); + att = helpSetAtt(att, att_value_connector, att_separator, id_att_separator, NO); + the_NO.setOperand1(NO); + } + + // do the second operand + sp = att.split(id_att_separator); + sp = sp[0].split(att_value_connector); + + if(sp[1].compareTo("v") == 0) // a variable + { + sp = att.split(id_att_separator); + sp = sp[1].split(att_separator); + sp = sp[0].split(att_value_connector); + value = sp[1].substring(0, sp[1].length()-1); + att = att.substring(att.indexOf(id_att_separator)+2); + att = att.substring(att.indexOf(att_separator)+1); + + res = var_list.Instance().getVariable(value); + if(res == null) // must be local, not global + { + if(aux instanceof monitorEvent) + { + monitorEvent ev = (monitorEvent)aux; + res = ev.getAuxPoint().getVariable(value); + } + else + { + res = aux.getVariable(value); + } + } + the_NO.setOperand2(res); + } + else if(sp[1].compareTo("c") == 0) // a constant + { + constant c = new constant(); + sp = att.split(id_att_separator); + sp = sp[1].split(att_separator); + sp = sp[0].split(att_value_connector); + value = sp[1].substring(0, sp[1].length()-1); + att = att.substring(att.indexOf(id_att_separator)+2); + att = att.substring(att.indexOf(att_separator)+1); + c.setValue(Integer.parseInt(value)); + the_NO.setOperand2(c); + } + else if(sp[1].compareTo("NO") == 0) // a nested operation + { + NestedOperation NO = new NestedOperation(); + att = att.substring(att.indexOf(id_att_separator)+2); + att = helpSetAtt(att, att_value_connector, att_separator, id_att_separator, NO); + the_NO.setOperand2(NO); + } + + // do the operator + sp = att.split(id_att_separator); + sp = sp[0].split(att_value_connector); + if(sp[1].compareTo("o") == 0) + { + Operator O = new Operator(); + sp = att.split(id_att_separator); + sp = sp[1].split(att_separator); + sp = sp[0].split(att_value_connector); + value = sp[1].substring(0, sp[1].length()-2); + O.setOperator(value); + the_NO.setOperator(O); + att = att.substring(att.indexOf(id_att_separator)+2); + att = att.substring(att.indexOf(att_separator)+1); + } + return att; + } +} diff --git a/src/funsoftware/inter/HelpDialog.java b/src/funsoftware/inter/HelpDialog.java new file mode 100644 index 0000000..81b0144 --- /dev/null +++ b/src/funsoftware/inter/HelpDialog.java @@ -0,0 +1,91 @@ +/* + * HelpDialog.java + * + * Created on 14 February 2006, 18:14 + * + */ + +package funsoftware.inter; + +import funsoftware.properties.*; + +/** + * To display a help document + * @author Thomas Legowo + */ +public class HelpDialog extends javax.swing.JDialog{ + // private variables + private javax.swing.JEditorPane help; + private javax.swing.JScrollPane editorScrollPane; + + private javax.swing.JPanel jp; + + java.awt.GridBagConstraints gridBagConstraints; + + private javax.swing.JButton button; + + /** + * Creates a new instance of HelpDialog + * @param frame The frame + */ + public HelpDialog(java.awt.Frame frame) { + super(frame, true); + setTitle(AppProperties.appName + " Documentation"); + + try + { + help = new javax.swing.JEditorPane(getClass().getResource("/readme.txt")); + help.setFont(new java.awt.Font("Verdana", 0, 12)); + help.setEditable(false); + } + catch (java.io.IOException e) + { + System.err.println("Attempted to read a bad readme file."); + } + + editorScrollPane = new javax.swing.JScrollPane(); + javax.swing.JViewport vp = new javax.swing.JViewport(); + vp.setView(help); + editorScrollPane.setViewport(vp); + editorScrollPane.setPreferredSize(new java.awt.Dimension(710, 470)); + editorScrollPane.setMinimumSize(new java.awt.Dimension(710, 470)); + + jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp.add(editorScrollPane, gridBagConstraints); + + button = new javax.swing.JButton("OK"); + button.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + buttonMouseClicked(); + } + }); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); + jp.add(button, gridBagConstraints); + + setContentPane(jp); + + setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); + + addWindowListener(new java.awt.event.WindowAdapter() { + public void windowClosing(java.awt.event.WindowEvent we) { + buttonMouseClicked(); + } + }); + } + + + // to handle for "Ok" button clicked + private void buttonMouseClicked() + { + setVisible(false); + } +} diff --git a/src/funsoftware/inter/ProgWindow.java b/src/funsoftware/inter/ProgWindow.java new file mode 100644 index 0000000..f412601 --- /dev/null +++ b/src/funsoftware/inter/ProgWindow.java @@ -0,0 +1,3322 @@ +/* + * ProgWindow.java + * + * Created on 26 July 2005, 23:00 + */ + +package funsoftware.inter; + +import funsoftware.consts.*; +import funsoftware.pallette.*; +import funsoftware.wr.*; +import funsoftware.ic.*; +import funsoftware.ic.obj.*; +import funsoftware.ic.bran.*; +import funsoftware.ic.loo.*; +import funsoftware.ic.others.*; +import funsoftware.ic.func.*; +import funsoftware.gri.*; +import funsoftware.functs.*; +import funsoftware.ic.ev.*; +import funsoftware.ic.tsk.*; +import funsoftware.ic.func.*; + +/** + * This class will be the panel of the programming window + * @author Thomas Legowo + */ +public class ProgWindow extends javax.swing.JPanel implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener{ + + private wires wire_list; // the wires to be refreshed on the programming window + private icons_list icon_list; // the icons to be refreshed on the programming window + private aux_list func_list; // list of functions + + private java.awt.Dimension area; // the area of the panel + + // list containing wires, icons and errorboxes belonging to this window + private java.util.Vector win_wire; + private java.util.Vector win_icon; + + +// private int gridStatus; // the status of the grid + + private TitlePanelLabel jDirectionsLabel; // the label that provides real time help for the user + + // for the pop up menu + private javax.swing.JPanel jpm; + + // private variables for beginning and end icon of this programming window + private startIcon start_ic; + private endIcon end_ic; + + // for zooming in and out + private double zoom_scale; + + /** Creates a new instance of ProgWindow */ + public ProgWindow() { + } + + /** + * Creates a new instance of ProgWindow + * @param njDirectionsLabel The real time direction label + */ + public ProgWindow(TitlePanelLabel njDirectionsLabel) + { + super(new java.awt.GridBagLayout()); + + area = new java.awt.Dimension(Constants.maxHorizontalProgWindow, Constants.maxVerticalProgWindow); + super.setPreferredSize(area); + + jDirectionsLabel = njDirectionsLabel; + + jpm = new javax.swing.JPanel(); + init_listener(); + + win_wire = new java.util.Vector(); + win_icon = new java.util.Vector(); + + zoom_scale = 1; + + // initialise the icons, wires, error boxes and functions lists + icon_list = icons_list.Instance(); + wire_list = wires.Instance(); + + func_list = aux_list.Instance(); + setBackground(new java.awt.Color(255,255,255)); + } + + /** + * To paint this programming window + * @param g Graphics + */ + protected void paintComponent(java.awt.Graphics g) + { + super.paintComponent(g); + + if(Constants.getGridStatus() == 0) + { + g.setColor(new java.awt.Color(255,255,255)); + } + + // draw the grid + paint_grid(g); + + // draw the wires + for(int i=0; i getWires() + { + return win_wire; + } + + /** + * Reset the wiring list of this programming window + */ + public void resetWires() + { + win_wire = new java.util.Vector(); + } + + // to addIcons to win_icon list + /** + * To add an icon to the icon list of this panel + * @param icon New icon + */ + public void addIcon(Icon icon) + { + win_icon.addElement(icon); + } + // to delete icons + /** + * To delete an icon off the icon list of this panel + * @param icon Deleted icon + */ + public void deleteIcon(Icon icon) + { + for(int i=0; i getIcons() + { + return win_icon; + } + + /** + * Reset the icon list of this programming window + */ + public void resetIcons() + { + win_icon = new java.util.Vector(); + } + + + /** + * Set the start icon of this particular programming window + * @param ic New start icon + */ + public void setStartIcon(startIcon ic) + { + start_ic = ic; + } + /** + * Get the start icon of this programming window + * @return Start icon + */ + public startIcon getStartIcon() + { + return start_ic; + } + /** + * Set the end icon of this programming window + * @param ic End icon + */ + public void setEndIcon(endIcon ic) + { + end_ic = ic; + } + /** + * Get the end icon of this programming window + * @return End icon + */ + public endIcon getEndIcon() + { + return end_ic; + } + + + /** + * Paints the grid of the programming window + * @param g Graphics + */ + public void paint_grid(java.awt.Graphics g) + { + // get the width and height of the panel + int height = (int)area.getHeight(); + int width = (int)area.getWidth(); + + int distanceX = Constants.gridDistanceX; + int distanceY = Constants.gridDistanceY; + if(Constants.getGridStatus() == 1) + { + //start drawing the lines (the grid lines are separated every 50 pixels) + g.setColor(new java.awt.Color(0,0,0,30)); + + for(int i = 0; i < height; i += distanceY) + { + g.drawLine(0, i, width, i); + } + for(int i = 0; i < width; i += distanceX) + { + g.drawLine(i, 0, i, height); + } + } + else if(Constants.getGridStatus() == 0) + { + g.clearRect(0,0, width,height); + } + } + + /** + * Initialise the mouse listeners of this programming window + */ + public void init_listener() + { + addMouseListener(this); + addMouseMotionListener(this); + } + + + // ---------------------------------- + + // AUXILIARY METHODS FOR ICON EDITING -- ADDITION, DELETION and EDITION --> Icons and Wires + + /** + * This method splits up a wire as one icon is introduced in between a pair of icons that that wire is connected to + * @param new_icon Newly added icon + * @param old_icon Already added icon next to it + */ + public void splitWire(Icon new_icon, Icon old_icon) + { + Wire old_wire = old_icon.getLeftWire(); + + // Reconnect the new and old icons with the newer piece of wire and the older piece of wire + + new_icon.setLeftWire(old_wire); + if(new_icon.getParentIcon() instanceof branchIcon) + { + old_wire.setType(1); + } + else if(new_icon.getParentIcon() instanceof loopIcon) + { + old_wire.setType(2); + } + else + { + old_wire.setType(0); + } + + old_wire.setRightIcon(new_icon); + newWire(new_icon, old_icon, old_wire.getType()); + } + + + /** + * Introduces a new wiring between a pair of icons + * @param left_icon Left icon to this piece of wire + * @param right_icon Right icon to this piece of wire + * @param type Type of that wire(for colouring purposes) + */ + public void newWire(Icon left_icon, Icon right_icon, int type) + { + Wire wire = new Wire(); + wire.setLeftIcon(left_icon); + left_icon.setRightWire(wire); + wire.setRightIcon(right_icon); + right_icon.setLeftWire(wire); + wire.setType(type); + wire_list.addWire(wire); + // adding this wire on this window + addWire(wire); + } + + + /** + * This method sets up an icon with its bounds and coordinates in this programming panel + * @param new_icon New icon + * @param xpos X coordinate + * @param ypos Y coordinate + */ + public void setUpIcon(Icon new_icon, int xpos, int ypos) + { + coord co = gridcalculation.computeCoord(new_icon, new coord(xpos, ypos)); + new_icon.setCoordinate(co); + new_icon.setBounds(co.getX(), co.getY(), new_icon.getPreferredSize().width, new_icon.getPreferredSize().height); + } + + + /** + * This method collapse two pieces of wires into one, as an icon is deleted + * @param left_icon Left icon + * @param right_icon Right icon + */ + public void collapseWire(Icon left_icon, Icon right_icon) + { + // get rid of the wire to the right of the deleted icon + deleteWire(right_icon.getLeftWire()); + wire_list.delWire(right_icon.getLeftWire()); + + Wire tmp_wire = left_icon.getRightWire(); + + // update the other icon + + // set the wires and icons new connections + left_icon.setRightWire(tmp_wire); + right_icon.setLeftWire(tmp_wire); + tmp_wire.setLeftIcon(left_icon); + tmp_wire.setRightIcon(right_icon); + } + + /** + * Extends the width of a repeat (simply shift the right end of the branch) + * @param icon Icon + * @param n_shift Number of shift + */ + public void expandRepeatHorizontal(Icon icon, int n_shift) + { + moveIconHorizontal(icon.getEndIcon(), (n_shift*Constants.gridDistanceX)); + } + + /** + * Collapse the repeat + * @param icon Icon + * @param n_shift Number of shift + */ + public void collapseRepeatHorizontal(Icon icon, int n_shift) + { + moveIconHorizontal(icon.getEndIcon(), (n_shift*-Constants.gridDistanceX)); + } + + /** + * Extends the width of a branch, simply shift the right most icons of the branch + * @param icon Icon + * @param n_shift Number of shift + */ + public void expandBranchHorizontal(Icon icon, int n_shift) + { + moveIconHorizontal(icon.getEndBranch(), (n_shift*Constants.gridDistanceX)); + + moveIconHorizontal(icon.getEndBranch().getLeftNeighbourTop(), (n_shift*Constants.gridDistanceX)); + + moveIconHorizontal(icon.getEndBranch().getLeftNeighbourBottom(), (n_shift*Constants.gridDistanceX)); + } + + /** + * Collapse a branch + * @param icon Icon + * @param n_shift Number of shift + */ + public void collapseBranchHorizontal(Icon icon, int n_shift) + { + moveIconHorizontal(icon.getEndBranch(), (n_shift*-Constants.gridDistanceX)); + + moveIconHorizontal(icon.getEndBranch().getLeftNeighbourTop(), (n_shift*-Constants.gridDistanceX)); + + moveIconHorizontal(icon.getEndBranch().getLeftNeighbourBottom(), (n_shift*-Constants.gridDistanceX)); + } + + /** + * Move a part of branch partially number of shift grid intersections + * @param threshold Threshold icon + * @param n_shift Number of shift + */ + public void moveBranchPartial(Icon threshold, int n_shift) + { + Icon parent = threshold.getParentIcon(); + int pos = parent.determineMember(threshold); + java.util.Vector ics = new java.util.Vector(); + if(pos == 0) + { + ics = parent.getIfMembers(); + } + else if(pos == 1) + { + ics = parent.getElseMembers(); + } + + int dist = n_shift*Constants.gridDistanceX; + + int i=0; + for(i=0; i ics = parent.getMembers(); + + int dist = (n_shift*Constants.gridDistanceX); + + int i=0; + for(i=0; i 0) // no more space in the parent + { + if(getFreeSegment(parent, otherb_loc) < n_shift) + { + n_shift = getFreeSegment(parent, otherb_loc); + } + collapseBranchHorizontal(parent, n_shift); + moveBranchPartial(icon, -n_shift); + recursiveShiftIconHorizontalLeft(parent, n_shift); + } + else if(getFreeSegment(parent, otherb_loc) <= 0) + { + moveBranchPartial(icon, -n_shift); + } + } + else if(parent instanceof loopIcon) + { + collapseRepeatHorizontal(parent, n_shift); + moveRepeatPartial(icon, -n_shift); + recursiveShiftIconHorizontalLeft(parent, n_shift); + } + else + { + if(icon instanceof branchIcon) + { + if(icon.getEndBranch().getRightNeighbour() instanceof joinLoopIcon) // the special case + { + repositionIcons(icon.getEndBranch().getRightNeighbour().getBottomNeighbour(), -n_shift); + } + else + { + repositionIcons(icon.getEndBranch().getRightNeighbour(), -n_shift); + } + } + else if(icon instanceof loopIcon) + { + if(icon.getEndIcon().getRightNeighbour() instanceof joinLoopIcon) // the special case + { + repositionIcons(icon.getEndIcon().getRightNeighbour().getBottomNeighbour(), -n_shift); + } + else + { + repositionIcons(icon.getEndIcon().getRightNeighbour(), -n_shift); + } + } + else + { + if(icon.getRightNeighbour() instanceof joinLoopIcon) // the special case + { + repositionIcons(icon.getRightNeighbour().getBottomNeighbour(), -n_shift); + } + else + { + repositionIcons(icon.getRightNeighbour(), -n_shift); + } + } + } + } + + + // the normal updates involving vertical size will be done in the expandRepeatVertical and expandBranchVertical + // for both repeats and branches respectively + /** + * Recursively shift icons vertically according to the newly added icon + * This method also validates the top and bottom vertical size of any of the branches + * @param icon Newly added icon + * @param n_shift Number of shift + */ + public void recursiveShiftIconVerticalDown(Icon icon, int n_shift) + { + Icon parent = icon.getParentIcon(); + // also updates the top and bottom vertical size of any branch icon involved + // need to have methods to return bottom half of a branch icon if section and top half of a branch icon else section + // in the tallestmember function + if(icon instanceof branchIcon) + { + if(parent instanceof loopIcon) + { + // if there are no children within this branch yet, then + // bottomtopVerticalSize + bottombottomVerticalSize = 0 + int b_vsize = icon.getBottomTopVerticalSize() + icon.getBottomBottomVerticalSize() + 1; // always + 1 + int cur_size = parent.getBottomVerticalSize(); + if(cur_size <= b_vsize) + { + n_shift = b_vsize - cur_size + 1; + expandRepeatVertical(parent, n_shift); + int tmp_top = icon.getTopTopVerticalSize()+icon.getTopBottomVerticalSize()+1; + if(tmp_top > parent.getTopVerticalSize()) + { + parent.setTopVerticalSize(tmp_top); + } + recursiveShiftIconVerticalDown(parent, n_shift); + } + } + else if(parent instanceof branchIcon) + { + if(parent.determineMember(icon) == 0) // icon at the top (IF) part + { + int b_vsize = icon.getBottomTopVerticalSize() + icon.getBottomBottomVerticalSize() + 1; // always + 1 + + int cur_tb_vsize = parent.getTopBottomVerticalSize(); + + if(cur_tb_vsize < b_vsize) + { + n_shift = b_vsize - cur_tb_vsize; + expandBranchVertical(parent, n_shift); + parent.setTopBottomVerticalSize(parent.getTopBottomVerticalSize()+n_shift); + parent.setBottomTopVerticalSize(parent.getBottomTopVerticalSize()+n_shift); + } + + n_shift = Math.abs((icon.getTopTopVerticalSize()+icon.getTopBottomVerticalSize()+1)-parent.getTopTopVerticalSize()); + + if(parent.getTopTopVerticalSize() < (icon.getTopTopVerticalSize() + icon.getTopBottomVerticalSize() + 1)) + { + parent.setTopTopVerticalSize(parent.getTopTopVerticalSize()+n_shift); + } + recursiveShiftIconVerticalDown(parent, n_shift); + } + else if(parent.determineMember(icon) == 1) // icon at the bottom (ELSE) part + { + int b_vsize = icon.getTopTopVerticalSize() + icon.getTopBottomVerticalSize() + 1; // always + 1 + int cur_tb_vsize = parent.getBottomTopVerticalSize(); + + if(cur_tb_vsize < b_vsize) + { + n_shift = b_vsize - cur_tb_vsize; + expandBranchVertical(parent, n_shift); + parent.setTopBottomVerticalSize(parent.getTopBottomVerticalSize()+n_shift); + parent.setBottomTopVerticalSize(parent.getBottomTopVerticalSize()+n_shift); + } + + n_shift = Math.abs((icon.getBottomTopVerticalSize()+icon.getBottomBottomVerticalSize()+1)-parent.getBottomBottomVerticalSize()); + if(parent.getBottomBottomVerticalSize() < (icon.getBottomTopVerticalSize() + icon.getBottomBottomVerticalSize() + 1)) + { + parent.setBottomBottomVerticalSize(parent.getBottomBottomVerticalSize()+n_shift); + } + + recursiveShiftIconVerticalDown(parent, n_shift); + } + + } + } + else if(icon instanceof loopIcon) + { + if(parent instanceof loopIcon) + { + n_shift = parent.getBottomVerticalSize() - icon.getBottomVerticalSize(); + if(n_shift < 1) + { + n_shift = Math.abs(n_shift); + n_shift++; + expandRepeatVertical(parent, n_shift); + int tmp_top = icon.getTopVerticalSize(); + if(tmp_top > parent.getTopVerticalSize()) + { + parent.setTopVerticalSize(tmp_top); + } + recursiveShiftIconVerticalDown(parent, n_shift); + } + } + else if(parent instanceof branchIcon) + { + // then update the top and bottom vertical size + if(parent.determineMember(icon) == 0) // icon at the top (IF) part + { + int b_vsize = icon.getBottomVerticalSize(); + int cur_tb_vsize = parent.getTopBottomVerticalSize(); + if(cur_tb_vsize < b_vsize) + { + n_shift = b_vsize - cur_tb_vsize; + expandBranchVertical(parent, n_shift); + parent.setTopBottomVerticalSize(parent.getTopBottomVerticalSize()+n_shift); + parent.setBottomTopVerticalSize(parent.getBottomTopVerticalSize()+n_shift); + + if(icon.getTopVerticalSize() > parent.getTopTopVerticalSize()) + { + parent.setTopTopVerticalSize(icon.getTopVerticalSize()); + } + } + recursiveShiftIconVerticalDown(parent, n_shift); + } + else if(parent.determineMember(icon) == 1) // icon at the bottom (ELSE) part + { + int b_vsize = icon.getTopVerticalSize(); + int cur_tb_vsize = parent.getBottomTopVerticalSize(); + if(cur_tb_vsize < b_vsize) + { + n_shift = b_vsize - cur_tb_vsize; + expandBranchVertical(parent, n_shift); + parent.setTopBottomVerticalSize(parent.getTopBottomVerticalSize()+n_shift); + parent.setBottomTopVerticalSize(parent.getBottomTopVerticalSize()+n_shift); + } + + if(parent.getBottomBottomVerticalSize() < icon.getBottomVerticalSize()) + { + parent.setBottomBottomVerticalSize(icon.getBottomVerticalSize()); + } + if(icon.getTopVerticalSize() > parent.getBottomTopVerticalSize()) + { + parent.setBottomTopVerticalSize(icon.getTopVerticalSize()); + } + recursiveShiftIconVerticalDown(parent, n_shift); + } + } + } + } + + /** + * Recursively moves icons in the up direction (occurs if a branch or repeat within another branch or repeat has been deleted) + * @param icon Removed icon + * @param n_shift Number of shift + * @param member_pos Position of icon (if in a branch) + */ + public void recursiveShiftIconVerticalUp(Icon icon, int n_shift, int member_pos) + { + Icon parent = icon.getParentIcon(); + if(parent instanceof branchIcon) + { + Icon tallest; + int tallest_vert_size = 0; + // get the tallest in the opposite branch too + Icon tallest2; + int tallest_vert_size2 = 0; + if(icon instanceof loopIcon) + { + if(member_pos == -1) + { + member_pos = parent.determineMember(icon); + } + if(member_pos == 0) // if icon is within the IF part of the branch + { + tallest = parent.tallestIfMemberBottom(); + if(tallest instanceof branchIcon) + { + tallest_vert_size = tallest.getBottomBottomVerticalSize() + +tallest.getBottomTopVerticalSize()+1; + } + else if(tallest instanceof loopIcon) + { + tallest_vert_size = tallest.getBottomVerticalSize(); + } + else + { + tallest_vert_size = tallest.getVerticalSize(); + } + + tallest2 = parent.tallestElseMemberTop(); + if(tallest2 instanceof branchIcon) + { + tallest_vert_size2 = tallest2.getTopBottomVerticalSize() + +tallest2.getTopTopVerticalSize()+1; + } + else if(tallest2 instanceof loopIcon) + { + tallest_vert_size2 = tallest2.getTopVerticalSize(); + } + else + { + tallest_vert_size2 = tallest2.getVerticalSize(); + } + + // now determine the n_shift + int shift1 = parent.getTopBottomVerticalSize()-tallest_vert_size; + int shift2 = parent.getBottomTopVerticalSize()-tallest_vert_size2; + + if(shift2 > 0) + { + n_shift = Math.min(Math.abs(shift1), Math.abs(shift2)); + + collapseBranchVertical(parent, n_shift); + parent.setTopBottomVerticalSize(parent.getTopBottomVerticalSize()-n_shift); + parent.setBottomTopVerticalSize(parent.getBottomTopVerticalSize()-n_shift); + } + // need to update the top top vertical size too + int t = 0; + if(parent.tallestIfMemberTop() instanceof branchIcon) + { + t = parent.tallestIfMemberTop().getTopTopVerticalSize() + parent.tallestIfMemberTop().getTopBottomVerticalSize() + 1; + } + else if(parent.tallestIfMemberTop() instanceof loopIcon) + { + t = parent.tallestIfMemberTop().getTopVerticalSize(); + } + else + { + t = parent.tallestIfMemberTop().getVerticalSize(); + } + parent.setTopTopVerticalSize(t); + member_pos = -1; + recursiveShiftIconVerticalUp(parent, n_shift, member_pos); + } + else if(member_pos == 1) // if icon is within the ELSE part of the branch + { + tallest = parent.tallestElseMemberTop(); + if(tallest instanceof branchIcon) + { + tallest_vert_size = tallest.getTopBottomVerticalSize() + +tallest.getTopTopVerticalSize()+1; + } + else if(tallest instanceof loopIcon) + { + tallest_vert_size = tallest.getTopVerticalSize(); + } + else + { + tallest_vert_size = tallest.getVerticalSize(); + } + + tallest2 = parent.tallestIfMemberBottom(); + if(tallest2 instanceof branchIcon) + { + tallest_vert_size2 = tallest2.getBottomBottomVerticalSize() + +tallest2.getBottomTopVerticalSize()+1; + } + else if(tallest2 instanceof loopIcon) + { + tallest_vert_size2 = tallest2.getBottomVerticalSize(); + } + else + { + tallest_vert_size2 = tallest2.getVerticalSize(); + } + // now determine the n_shift + int shift1 = parent.getBottomTopVerticalSize()-tallest_vert_size; + int shift2 = parent.getTopBottomVerticalSize()-tallest_vert_size2; + + if(shift2 > 0) + { + n_shift = Math.min(Math.abs(shift1), Math.abs(shift2)); + + collapseBranchVertical(parent, n_shift); + parent.setTopBottomVerticalSize(parent.getTopBottomVerticalSize()-n_shift); + parent.setBottomTopVerticalSize(parent.getBottomTopVerticalSize()-n_shift); + } + member_pos = -1; + // need to update the bottom bottom vertical size too + int t = 0; + if(parent.tallestElseMemberBottom() instanceof branchIcon) + { + t = parent.tallestElseMemberBottom().getBottomTopVerticalSize() + parent.tallestElseMemberBottom().getBottomBottomVerticalSize() + 1; + } + else if(parent.tallestElseMemberBottom() instanceof loopIcon) + { + t = parent.tallestElseMemberBottom().getBottomVerticalSize(); + } + else + { + t = parent.tallestElseMemberBottom().getVerticalSize(); + } + + parent.setBottomBottomVerticalSize(t); + recursiveShiftIconVerticalUp(parent, n_shift, member_pos); + } + } + else if(icon instanceof branchIcon) + { + if(member_pos == -1) + { + member_pos = parent.determineMember(icon); + } + if(member_pos == 0) + { + tallest = parent.tallestIfMemberBottom(); + if(tallest instanceof branchIcon) + { + tallest_vert_size = tallest.getBottomBottomVerticalSize() + +tallest.getBottomTopVerticalSize()+1; + } + else if(tallest instanceof loopIcon) + { + tallest_vert_size = tallest.getBottomVerticalSize(); + } + else + { + tallest_vert_size = tallest.getVerticalSize(); + } + + tallest2 = parent.tallestElseMemberTop(); + if(tallest2 instanceof branchIcon) + { + tallest_vert_size2 = tallest2.getTopBottomVerticalSize() + +tallest2.getTopTopVerticalSize()+1; + } + else if(tallest2 instanceof loopIcon) + { + tallest_vert_size2 = tallest2.getTopVerticalSize(); + } + else + { + tallest_vert_size2 = tallest2.getVerticalSize(); + } + + // now determine the n_shift + int shift1 = parent.getTopBottomVerticalSize()-tallest_vert_size; + int shift2 = parent.getBottomTopVerticalSize()-tallest_vert_size2; + + if(shift2 > 0) + { + n_shift = Math.min(Math.abs(shift1), Math.abs(shift2)); + + collapseBranchVertical(parent, n_shift); + parent.setTopBottomVerticalSize(parent.getTopBottomVerticalSize()-n_shift); + parent.setBottomTopVerticalSize(parent.getBottomTopVerticalSize()-n_shift); + } + // need to update the top top vertical size too + int t = 0; + if(parent.tallestIfMemberTop() instanceof branchIcon) + { + t = parent.tallestIfMemberTop().getTopTopVerticalSize() + parent.tallestIfMemberTop().getTopBottomVerticalSize() + 1; + } + else if(parent.tallestIfMemberTop() instanceof loopIcon) + { + t = parent.tallestIfMemberTop().getTopVerticalSize(); + } + else + { + t = parent.tallestIfMemberTop().getVerticalSize(); + } + parent.setTopTopVerticalSize(t); + member_pos = -1; + recursiveShiftIconVerticalUp(parent, n_shift, member_pos); + } + else if(member_pos == 1) + { + tallest = parent.tallestElseMemberBottom(); + if(tallest instanceof branchIcon) + { + tallest_vert_size = tallest.getTopBottomVerticalSize() + +tallest.getTopTopVerticalSize()+1; + } + else if(tallest instanceof loopIcon) + { + tallest_vert_size = tallest.getTopVerticalSize(); + } + else + { + tallest_vert_size = tallest.getVerticalSize(); + } + + tallest2 = parent.tallestIfMemberBottom(); + if(tallest2 instanceof branchIcon) + { + tallest_vert_size2 = tallest2.getBottomBottomVerticalSize() + +tallest2.getBottomTopVerticalSize()+1; + } + else if(tallest2 instanceof loopIcon) + { + tallest_vert_size2 = tallest2.getBottomVerticalSize(); + } + else + { + tallest_vert_size2 = tallest2.getVerticalSize(); + } + // now determine the n_shift + int shift1 = parent.getBottomTopVerticalSize()-tallest_vert_size; + int shift2 = parent.getTopBottomVerticalSize()-tallest_vert_size2; + + if(shift2 > 0) + { + n_shift = Math.min(Math.abs(shift1), Math.abs(shift2)); + + collapseBranchVertical(parent, n_shift); + parent.setTopBottomVerticalSize(parent.getTopBottomVerticalSize()-n_shift); + parent.setBottomTopVerticalSize(parent.getBottomTopVerticalSize()-n_shift); + } + // need to update the bottom bottom vertical size too + int t = 0; + if(parent.tallestElseMemberBottom() instanceof branchIcon) + { + t = parent.tallestElseMemberBottom().getBottomTopVerticalSize() + parent.tallestElseMemberBottom().getBottomBottomVerticalSize() + 1; + } + else if(parent.tallestElseMemberBottom() instanceof loopIcon) + { + t = parent.tallestElseMemberBottom().getBottomVerticalSize(); + } + else + { + t = parent.tallestElseMemberBottom().getVerticalSize(); + } + parent.setBottomBottomVerticalSize(t); + member_pos = -1; + recursiveShiftIconVerticalUp(parent, n_shift, member_pos); + } + } + } + else if(parent instanceof loopIcon) + { + if(icon instanceof loopIcon || icon instanceof branchIcon) + { + int tallest_vert_size = 0; + Icon tallest = parent.tallestBottomMember(); + if(tallest instanceof branchIcon) + { + tallest_vert_size = tallest.getBottomBottomVerticalSize() + +tallest.getBottomTopVerticalSize()+1; + } + else if(tallest instanceof loopIcon) + { + tallest_vert_size = tallest.getBottomVerticalSize(); + } + else + { + tallest_vert_size = tallest.getVerticalSize(); + } + n_shift = parent.getBottomVerticalSize() - tallest_vert_size - 1; + + if(n_shift > 0) + { + collapseRepeatVertical(parent, n_shift); + } + int t = 0; + if(parent.tallestTopMember() instanceof branchIcon) + { + t = parent.tallestTopMember().getTopTopVerticalSize() + parent.tallestTopMember().getTopBottomVerticalSize() + 1; + } + else if(parent.tallestTopMember() instanceof loopIcon) + { + t = parent.tallestTopMember().getTopVerticalSize(); + } + else + { + t = parent.tallestTopMember().getVerticalSize(); + } + + parent.setTopVerticalSize(t); + member_pos = -1; + recursiveShiftIconVerticalUp(parent, n_shift, member_pos); + } + } + } + + + // other as equally important method + // will never be called to delete members of a starting icon, so just need to cater for two cases + // 1. members of a branch icon + // 2. members of a repeat icon + /** + * Recursively deletes all icons within a particular icon + * This method is not located in class icons due its nature involving all wiring and icons and the programming window, + * so it is only suitable for the method to reside in this class + * @param icon Initially to be deleted icon + */ + public void delAllIcons(Icon icon) + { + if(icon instanceof loopIcon) + { + deleteIcon(icon); + icon_list.delIcon(icon); + remove(icon); + deleteWire(icon.getRightWire()); + wire_list.delWire(icon.getRightWire()); + deleteWire(icon.getLeftWire()); + wire_list.delWire(icon.getLeftWire()); + deleteWire(icon.getEndIcon().getRightWire()); + wire_list.delWire(icon.getEndIcon().getRightWire()); + java.util.Vector ics = icon.getMembers(); + + for(int i=0; i ics = icon.getIfMembers(); + for(int i=0; i getIconsToChange(Icon left_icon, Icon right_icon) + { + // Obtain the members of the parent + java.util.Vector ics = new java.util.Vector(); + Icon parent = right_icon.getParentIcon(); + if(parent instanceof branchIcon) + { + if(parent.determineMember(right_icon) == 0) + { + ics = parent.getIfMembers(); + } + else if(parent.determineMember(right_icon) == 1) + { + ics = parent.getElseMembers(); + } + } + else + { + ics = parent.getMembers(); + } + + int left_index = 0; + int right_index = 0; + int found = 0; + // Determine the indexes of the icons in the members vector + + for(int i=0; i tmp_ics = new java.util.Vector(); + + for(int i=left_index; i ics = new java.util.Vector(); + ics = tmp_icon.getMembers(); + + if(ics.size()>2) // there are other icons within this repeat + { + Icon tmp_ic = ics.get(1); + int nx; + int ny = jlc_left.getCoordinate().getY(); + if(tmp_ic instanceof loopIcon) + { + nx = tmp_ic.getBeginIcon().getCoordinate().getX(); + nx = gridcalculation.calculateXright(nx) - Constants.gridDistanceX; + } + else + { + nx = tmp_ic.getCoordinate().getX(); + nx = gridcalculation.calculateXright(nx) - Constants.gridDistanceX; + } + ny = gridcalculation.calculateY(ny); + coord co = new coord(nx, ny); + co = gridcalculation.computeCoord(jlc_left, co); + jlc_left.setCoordinate(co); + jlc_left.setBounds(co.getX(), co.getY(), jlc_left.getPreferredSize().width, jlc_left.getPreferredSize().height); + + tmp_ic = ics.get(ics.size()-2); + ny = jlc_right.getCoordinate().getY(); + if(tmp_ic instanceof branchIcon) + { + nx = tmp_ic.getEndBranch().getCoordinate().getX(); + nx = gridcalculation.calculateXright(nx) + Constants.gridDistanceX; + } + else if(tmp_ic instanceof loopIcon) + { + nx = tmp_ic.getEndIcon().getCoordinate().getX(); + nx = gridcalculation.calculateXright(nx) + Constants.gridDistanceX; + } + else + { + nx = tmp_ic.getCoordinate().getX(); + nx = gridcalculation.calculateXright(nx) + Constants.gridDistanceX; + } + + ny = gridcalculation.calculateY(ny); + co = new coord(nx, ny); + co = gridcalculation.computeCoord(jlc_right, co); + jlc_right.setCoordinate(co); + jlc_right.setBounds(co.getX(), co.getY(), jlc_right.getPreferredSize().width, jlc_right.getPreferredSize().height); + } + } + + + /** + * Reposition a repeat icon due to the increase or decrease the number of icons within the repeat segment + * Reposition implies centering the repeat icon relative to the width of the repeat segment + * @param tmp_icon Icon + */ + public void repositionRepeatHorizontal(Icon tmp_icon) + { + Icon jlc_right = tmp_icon.getEndIcon(); + + Icon jlc_left = tmp_icon.getBeginIcon(); + + // now repositioning the repeat icon in the middle + + int new_x; + int new_y; + + int left_width = jlc_left.getCoordinate().getX()+ jlc_left.getWidth(); + new_x = left_width + ((jlc_right.getCoordinate().getX()-left_width)/2); + + new_y = tmp_icon.getCoordinate().getY() + (tmp_icon.getHeight()/2); + + coord tmp_co = gridcalculation.computeCoord(tmp_icon, new coord(new_x, new_y)); + tmp_icon.setCoordinate(tmp_co); + tmp_icon.setBounds(tmp_co.getX(), tmp_co.getY(), tmp_icon.getPreferredSize().width, tmp_icon.getPreferredSize().height); + } + + /** + * Call repositionRepeat repeatedly for all repeat icons + */ + public void repositionAllRepeat() + { + java.util.Vector icons = win_icon; + for(int i=0; i icons = win_icon; + for(int i=0; i members) + { + int ic_count=0; + for(int i=1; i<(members.size()-1); i++) + { + Icon tmp_ic = (Icon) members.get(i); + if(tmp_ic instanceof branchIcon) + { + int end_co = gridcalculation.calculateXright(tmp_ic.getEndBranch().getCoordinate().getX()); + int begin_co = gridcalculation.calculateXright(tmp_ic.getCoordinate().getX()); + ic_count += (end_co - begin_co)/Constants.gridDistanceX; + } + else if(tmp_ic instanceof loopIcon) + { + int end_co = gridcalculation.calculateXright(tmp_ic.getEndIcon().getCoordinate().getX()); + int begin_co = gridcalculation.calculateXright(tmp_ic.getBeginIcon().getCoordinate().getX()); + ic_count += (end_co - begin_co)/Constants.gridDistanceX; + } + ic_count ++; + } + return ic_count; + } + + /** + * Finds out how many of the segments enclosed within a branch or a repeat are free to be used + * This function will only be needed by a branch not a loop and nothing else + * @param icon Icon + * @param type Type = 0 -> the top part (if) type = 1 -> the bottom part (else) + * @return Number of free segments + */ + public int getFreeSegment(Icon icon, int type) + { + int free_count = 0; + java.util.Vector members = new java.util.Vector(); + if(type == 0) + { + members = icon.getIfMembers(); + } + else if(type == 1) + { + members = icon.getElseMembers(); + } + + Icon lefty = icon.getRightNeighbourTop(); + Icon righty = icon.getEndBranch().getLeftNeighbourTop(); + + int x_begin = gridcalculation.calculateXright(lefty.getCoordinate().getX()); + int x_end = gridcalculation.calculateXright(righty.getCoordinate().getX()); + + int num_segment = ((x_end - x_begin)/Constants.gridDistanceX)-1; + + int num_used = getNumUsedSegment(members); + free_count = num_segment - num_used; + return free_count; + } + + + /** + * Make sure every set of icons within a branch segment in the middle takes two major steps + * 1. Come up with the available coordinates that the icons can take within the specified segment + * 2. Place the icons on those coordinates + * @param begin Begin coordinate + * @param end End coordinate + * @param members Set of icons + * @return Set of coordinates + */ + public java.util.Vector returnCoords(coord begin, coord end, java.util.Vector members) + { + java.util.Vector cos = new java.util.Vector(); + int x_begin = begin.getX(); + int x_end = end.getX(); + int seg_count = (x_end-x_begin)/Constants.gridDistanceX+1; + // get the available coordinates + for(int i=0; i ics = new java.util.Vector(); + Icon tmp_ic; + if(dist != 0) // only if needed to move + { + ics = tmp_icon.getMembers(); + for(int i = 0; i ics = new java.util.Vector(); + Icon tmp_ic; + if(dist != 0) // only if needed to move + { + ics = tmp_icon.getMembers(); + for(int i = 0; i ics = new java.util.Vector(); + Icon tmp_ic; + if(dist != 0) // only if needed to move + { + ics = tmp_icon.getIfMembers(); + for(int i=0; i ics = new java.util.Vector(); + Icon tmp_ic; + if(dist != 0) // only if needed to move + { + ics = tmp_icon.getIfMembers(); + for(int i=0; i cos = new java.util.Vector(); + + Icon start_ic; + Icon end_ic; + coord begin; + coord end; + coord tmp_co; + java.awt.Component c; + + // now the real repositioning -- + java.util.Vector ics = tmp_icon.getIfMembers(); + + // 1. Do the if statement + start_ic = tmp_icon.getRightNeighbourTop(); + end_ic = tmp_icon.getEndBranch().getLeftNeighbourTop(); + begin = new coord((gridcalculation.calculateXright(start_ic.getCoordinate().getX())+Constants.gridDistanceX), + gridcalculation.calculateY(start_ic.getCoordinate().getY())); + end = new coord((gridcalculation.calculateXright(end_ic.getCoordinate().getX())-Constants.gridDistanceX), + gridcalculation.calculateY(end_ic.getCoordinate().getY())); + x_begin = begin.getX(); + x_end = end.getX(); + cos = returnCoords(begin, end, tmp_icon.getIfMembers()); + + int i2 = 0; + for(int i=1; i<(ics.size()-1); i++) + { + Icon tmp_ic = ics.get(i); + tmp_co = new coord(); + if((tmp_ic instanceof loopIcon) == false) + { + tmp_co = gridcalculation.computeCoord(tmp_ic, cos.get(i2)); + } + else + { + tmp_co = gridcalculation.computeCoord(tmp_ic.getBeginIcon(), cos.get(i2)); + } + + + if(tmp_ic instanceof branchIcon) + { + // Recursively move this whole branch segment to the required coordinates + moveBranchHorizontal(tmp_ic, (tmp_co.getX()-tmp_ic.getCoordinate().getX())); + // then need to skip the coordinates accordingly + + i2+=((gridcalculation.calculateXright(tmp_ic.getEndBranch().getCoordinate().getX())- + gridcalculation.calculateXright(tmp_ic.getCoordinate().getX()))/Constants.gridDistanceX); + } + else if(tmp_ic instanceof loopIcon) // trickier since the repeat icon is not actually aligned with the branch icon + // and its member + { + // Recursively move this whole repeat segment to the required coordinates + moveRepeatHorizontal(tmp_ic, (tmp_co.getX()-tmp_ic.getBeginIcon().getCoordinate().getX())); + // then need to skip the coordinates accordingly + + i2+=((gridcalculation.calculateXright(tmp_ic.getEndIcon().getCoordinate().getX())- + gridcalculation.calculateXright(tmp_ic.getBeginIcon().getCoordinate().getX()))/Constants.gridDistanceX); + tmp_co.setY(tmp_ic.getCoordinate().getY()); + } + + tmp_ic.setCoordinate(tmp_co); + tmp_ic.setBounds(tmp_co.getX(), tmp_co.getY(), tmp_ic.getPreferredSize().width, tmp_ic.getPreferredSize().height); + i2++; + } + + // 2. Do the else statement + + start_ic = tmp_icon.getRightNeighbourBottom(); + end_ic = tmp_icon.getEndBranch().getLeftNeighbourBottom(); + begin = new coord((gridcalculation.calculateXright(start_ic.getCoordinate().getX())+Constants.gridDistanceX), + gridcalculation.calculateY(start_ic.getCoordinate().getY())); + end = new coord((gridcalculation.calculateXright(end_ic.getCoordinate().getX())-Constants.gridDistanceX), + gridcalculation.calculateY(end_ic.getCoordinate().getY())); + x_begin = begin.getX(); + x_end = end.getX(); + cos = returnCoords(begin, end, tmp_icon.getElseMembers()); + + ics = tmp_icon.getElseMembers(); + i2 = 0; + // don't need to reposition the join icons + for(int i=1; i<(ics.size()-1); i++) + { + Icon tmp_ic = ics.get(i); + tmp_co = new coord(); + if((tmp_ic instanceof loopIcon) == false) + { + tmp_co = gridcalculation.computeCoord(tmp_ic, cos.get(i2)); + } + else + { + tmp_co = gridcalculation.computeCoord(tmp_ic.getBeginIcon(), cos.get(i2)); + } + + if(tmp_ic instanceof branchIcon) + { + // Recursively move this whole branch segment to the required coordinates + moveBranchHorizontal(tmp_ic, (tmp_co.getX()-tmp_ic.getCoordinate().getX())); + i2+=((gridcalculation.calculateXright(tmp_ic.getEndBranch().getCoordinate().getX())- + gridcalculation.calculateXright(tmp_ic.getCoordinate().getX()))/Constants.gridDistanceX); + } + else if(tmp_ic instanceof loopIcon) // trickier since the repeat icon is not actually aligned with the branch icon + // and its member + { + // Recursively move this whole repeat segment to the required coordinates + moveRepeatHorizontal(tmp_ic, (tmp_co.getX()-tmp_ic.getBeginIcon().getCoordinate().getX())); + // then need to skip the coordinates accordingly + + i2+=((gridcalculation.calculateXright(tmp_ic.getEndIcon().getCoordinate().getX())- + gridcalculation.calculateXright(tmp_ic.getBeginIcon().getCoordinate().getX()))/Constants.gridDistanceX); + tmp_co.setY(tmp_ic.getCoordinate().getY()); + } + + tmp_ic.setCoordinate(tmp_co); + tmp_ic.setBounds(tmp_co.getX(), tmp_co.getY(), tmp_ic.getPreferredSize().width, tmp_ic.getPreferredSize().height); + i2++; + } + } + + /** + * Call repositionBranch repeatedly for all branch icons + */ + public void repositionAllBranches() + { + java.util.Vector icons = win_icon; + for(int i=0; i min_xpos) + { + c = getComponentAt(new java.awt.Point(cur_xpos, ypos)); + if((c instanceof Icon) == false) + { + cur_xpos -= Constants.gridDistanceX; + continue; + } + else + { + tmp_icon = (Icon) c; + return tmp_icon; + } + } + } + else if(type == 1) + { + cur_xpos = gridcalculation.calculateXright(cur_xpos); + while(cur_xpos < max_xpos) + { + c = getComponentAt(new java.awt.Point(cur_xpos, ypos)); + if((c instanceof Icon) == false) + { + cur_xpos += Constants.gridDistanceX; + continue; + } + else + { + tmp_icon = (Icon) c; + return tmp_icon; + } + } + } + + // iterate through the x axis + return tmp_icon; + } + + + // function that recalculate the whole programming window for uniform distance between icons + // horizontally + + // THERE SHOULD BE TWO PARTS OF REPOSITIONING + // 1. Horizontally, always be done for the whole program to maintain uniform distances between icons and making + // sure that they are always in the middle relative to both its neighbours + // 2. Vertically, only do the affected segments (e.g. the loop segment where an icon is added to) + // The repositioning functions should be called whenever an addition, editing or deletion of an icon occurs + + // this method only expand the branch if necessary + // if the argument member requires the parent to do so, i.e. the vertical size of member is equal to the current size + // of this branch. A PARENT's VERTICAL SIZE ALWAYS HAS TO BE GREATER THAN ANY OF ITS MEMBER + /** + * Expand a branch's vertical size + * @param icon Icon + * @param n_expand Number of expansion + */ + public void expandBranchVertical(Icon icon, int n_expand) + { + int i_size = icon.getVerticalSize(); + + i_size = i_size + 2*n_expand; // the new size, usually number of grid expansion is one + icon.setVerticalSize(i_size); + // then move the members + // first the top part of the branch + java.util.Vector ics = icon.getIfMembers(); + for(int i=0; i ics = icon.getIfMembers(); + for(int i=0; i ics) + { + int vsize = 0; + for(int i=0; i vsize) + { + vsize = tmp_vs; + } + } + return vsize; + } + + + /** + * Either shift the entire icon down or up # of grid intersection determine by this function's argument + * @param n_shift Number of shift + */ + public void shiftIconsVertical(int n_shift) + { + java.util.Vector icons = win_icon; + Icon tmp_icon; + + int xpos; + int ypos; + coord co; + + for(int i = 0; i icons = icon_list.getIcons().get(1).getMembers(); + java.util.Vector icons = start_ic.getMembers(); + Icon tmp_icon = new Icon(); + + int dist = 0; // distance the icons need to be moved + + int i = 0; + // first of all find the threshold icon's relative position first + + for(i = 0; i ics = new java.util.Vector(); + + Icon parent1 = left_icon.getParentIcon(); + Icon parent2 = right_icon.getParentIcon(); + + if(parent1 != null) + { + if(parent1.getId() != parent2.getId()) // different parent, then decide which is higher up in the hierarchy + // IF left does not contain right and nor right contain left, then + // the parent should be the two's parent + { + + // check whether left contain right + + if(parent1 instanceof branchIcon) + { + ics = parent1.getIfMembers(); + for(int i=0; i instanceof startIcon + if(tic instanceof joinLoopIcon && tic.getParentIcon().getId() != icon.getParentIcon().getId()) + { + icon.getParentIcon().addMember(icon, tic.getBottomNeighbour()); + } + else + { + icon.getParentIcon().addMember(icon, tic); + } + } + else + { + icon.setParentIcon(tmp_son.getParentIcon()); + if(tic instanceof joinLoopIcon && tic.getParentIcon().getId() != icon.getParentIcon().getId()) + { + icon.getParentIcon().addMember(icon, tic.getBottomNeighbour()); + } + else + { + icon.getParentIcon().addMember(icon, tic); + } + } + } + + /** + * Inserts an object icon + * @param icon Icon + * @param tic Icon to the right of icon + * @param tic2 Icon to the left of icon + * @param jsp A scrollpane + */ + public void insertObjectIcon(Icon icon, Icon tic, Icon tic2, javax.swing.JScrollPane jsp) + { + setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR)); + setUpIconParent(icon, tic2, tic); + + // connecting the newly added icon with its neighbouring icons + icon.setRightNeighbour(tic); + tic.setLeftNeighbour(icon); + + icon.setLeftNeighbour(tic2); + tic2.setRightNeighbour(icon); + + coord co = icon.getCoordinate(); + icon.setBounds(co.getX(), co.getY(), icon.getPreferredSize().width, icon.getPreferredSize().height); + + icon_list.addIcon(icon); + addIcon(icon); + add(icon); + + recursiveShiftIconHorizontalRight(icon, 1); + + splitWire(icon, icon_list.getIcons().get(tic.getId())); + + jDirectionsLabel.setText("Icon successfully placed"); + repositionAllBranches(); + repositionAllRepeat(); + updateAllRepeatNeighbours(); + + if(icon instanceof functionIcon || icon instanceof beginTaskIcon || icon instanceof stopTaskIcon || icon instanceof startEvent) + { + icon.setImage(); // refresh the icon's id display + } + + // resize the programming window + resizeProgWindow(jsp); + // viewport.setViewPosition(new java.awt.Point(icon.getCoordinate().getX()-(gridDistanceX*2), icon.getCoordinate().getY()-(gridDistanceY*2))); + + // object_init_replace_listener(icon); + setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); + } + + /** + * Inserts an branch icon and loop icons + * @param icon Icon + * @param tic Icon to the right of icon + * @param tic2 Icon to the left of icon + * @param jsp Scroll pane + * @param jic Join end branch icon of the inserted branch + * @param jic1 Top left join icon of the inserted icon + * @param jic2 Bottom left join icon of the inserted icon + * @param jic3 Bottom right join icon of the inserted icon + * @param jic4 Top right join icon of the inserted icon + */ + public void insertBranchIcon(Icon icon, Icon tic, Icon tic2, javax.swing.JScrollPane jsp, joinEndBranchIcon jic, joinIcon jic1, joinIcon jic2, joinIcon jic3, joinIcon jic4) + { + setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR)); + int xpos = 0; + if(tic2 != null && tic != null) + { + xpos = gridcalculation.midPoint(tic2.getCoordinate(), tic.getCoordinate()); + } + + int ypos = gridcalculation.calculateY(icon.getCoordinate().getY()+(icon.getHeight()/2)); + + setUpIconParent(icon, tic2, tic); + // introduce the join icon to reconnect split wires at the end of the branching segment of the code + + coord co = icon.getCoordinate(); + + // 1. Set up the Branch Icon + icon.setBounds(co.getX(), co.getY(), icon.getPreferredSize().width, icon.getPreferredSize().height); + icon.setVerticalSize(3); // initially a branch have a vertical size of 3 + + // 2. Set up the top left joinIcon + ypos -= Constants.gridDistanceY; // going up one grid segment for the IF + setUpIcon(jic1, xpos, ypos); + + // 3. Set up the bottom left joinIcon + ypos += (Constants.gridDistanceY*2); // going down one grid segment for the ELSE + setUpIcon(jic2, xpos, ypos); + + // 4. Set up the bottom right joinIcon + xpos += Constants.gridDistanceX; + setUpIcon(jic3, xpos, ypos); + + // 5. Set up the top right joinIcon + ypos -= (Constants.gridDistanceY*2); + setUpIcon(jic4, xpos, ypos); + + // 6. Set up the joinEndBranchIcon + + // the coordinate of this joinEndBranchIcon will be 1 grid intersections away from the branch icon + int x = xpos; + int y = ypos + Constants.gridDistanceY; + setUpIcon(jic, x, y); + + // connecting the newly added icon with its neighbouring icons + icon.setRightNeighbourTop(jic1); + icon.setRightNeighbourBottom(jic2); + jic1.setLeftNeighbour(icon); + jic2.setLeftNeighbour(icon); + + jic1.setRightNeighbour(jic4); + jic2.setRightNeighbour(jic3); + + jic3.setLeftNeighbour(jic2); + jic4.setLeftNeighbour(jic1); + + jic3.setRightNeighbour(jic); + jic4.setRightNeighbour(jic); + + jic.setRightNeighbour(tic); + tic.setLeftNeighbour(jic); + jic.setLeftNeighbourTop(jic4); + jic.setLeftNeighbourBottom(jic3); + + icon.setEndBranch(jic); // connect the beginning and end icons of this branch segment + // introduce the wiring and connect the wires with the icons + /* + * ji1--------jic4| + * | | + * tic2----icon| jic----tic + * | | + * jic2-------jic3| + * + */ + + Wire wire = new Wire(); + wire.setLeftIcon(icon); + icon.setRightWireTop(wire); + wire.setRightIcon(jic1); + jic1.setLeftWire(wire); + wire.setType(1); + wire_list.addWire(wire); + addWire(wire); + + wire = new Wire(); + wire.setLeftIcon(icon); + icon.setRightWireBottom(wire); + wire.setRightIcon(jic2); + jic2.setLeftWire(wire); + wire.setType(1); + wire_list.addWire(wire); + addWire(wire); + + newWire(jic1, jic4, 1); + + newWire(jic2, jic3, 1); + + wire = new Wire(); + wire.setLeftIcon(jic4); + jic4.setRightWire(wire); + wire.setRightIcon(jic); + jic.setLeftWireTop(wire); + wire.setType(1); + wire_list.addWire(wire); + addWire(wire); + + wire = new Wire(); + wire.setLeftIcon(jic3); + jic3.setRightWire(wire); + wire.setRightIcon(jic); + jic.setLeftWireBottom(wire); + wire.setType(1); + wire_list.addWire(wire); + addWire(wire); + + icon.setLeftNeighbour(tic2); + tic2.setRightNeighbour(icon); + + tic2.getRightWire().setRightIcon(icon); + icon.setLeftWire(tic2.getRightWire()); + + if(icon.getParentIcon() instanceof branchIcon) + { + newWire(jic, tic, 1); + } + else if(icon.getParentIcon() instanceof loopIcon) + { + newWire(jic, tic, 2); + } + else + { + newWire(jic, tic, 0); + } + + // setting the parent icons + icon_list.addIcon(icon); + icon_list.addIcon(jic); + icon_list.addIcon(jic1); + icon_list.addIcon(jic2); + icon_list.addIcon(jic3); + icon_list.addIcon(jic4); + + addIcon(icon); + addIcon(jic); + addIcon(jic1); + addIcon(jic2); + addIcon(jic3); + addIcon(jic4); + + jic.setParentIcon(icon); // jlc will not be included as a member of the branch icon + jic.setBranchIcon(icon); + jic1.setParentIcon(icon); + // use the starting icon as dummy to put jic1 at the front + + icon.addMember(jic1, getStartIcon()); + jic2.setParentIcon(icon); + icon.addMember(jic2, getStartIcon()); + jic3.setParentIcon(icon); + icon.addMember(jic3, getStartIcon()); + jic4.setParentIcon(icon); + icon.addMember(jic4, getStartIcon()); + + + add(icon); + add(jic); + add(jic1); + add(jic2); + add(jic3); + add(jic4); + + // recursively reposition all affected icons + int shift = gridcalculation.calculateXright(icon.getEndBranch().getCoordinate().getX()) + - gridcalculation.calculateXright(icon.getCoordinate().getX()) + Constants.gridDistanceX; + recursiveShiftIconHorizontalRight(icon, (shift/Constants.gridDistanceX)); + + jDirectionsLabel.setText("Icon successfully placed"); + repositionAllBranches(); + repositionAllRepeat(); + recursiveShiftIconVerticalDown(icon, 1); + updateAllRepeatNeighbours(); + + // resize the programming window + resizeProgWindow(jsp); + // viewport.setViewPosition(new java.awt.Point(evt.getX()-(gridDistanceX*2), evt.getY()-(gridDistanceY*2))); + //branch_init_replace_listener(icon); + setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); + } + + /** + * Inserts a loop icons onto the programming window + * @param lic The to be inserted loop icon + * @param tic Icon to the right of the loop's begin icon + * @param tic2 Icon to the left of the loop's begin icon + * @param tic3 Icon to the right of the loop's end icon + * @param tic4 Icon to the left of the loop's end icon + * @param jsp Scroll Pane + * @param jlc The begin icon of this loop icon + * @param jlc2 The end icon of this loop icon + */ + public void insertLoopIcon(Icon lic, Icon tic, Icon tic2, Icon tic3, Icon tic4, javax.swing.JScrollPane jsp, joinLoopIcon jlc, joinLoopIcon jlc2) + { + setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR)); + int xpos = 0; + if(tic2 != null && tic != null) + { + xpos = gridcalculation.midPoint(tic2.getCoordinate(), tic.getCoordinate()); + } + + // all tic, tic2, tic3 and tic4 gotta have the same y coordinate + int ypos = gridcalculation.calculateY(tic.getCoordinate().getY()+(tic.getHeight()/2)); + + // xpos = gridcalculation.calculateXright(xpos); + ypos = gridcalculation.calculateY(ypos); + + int xpos2 = gridcalculation.calculateXright(gridcalculation.midPoint(tic4.getCoordinate(), tic3.getCoordinate())); + int ypos2 = gridcalculation.calculateY(tic3.getCoordinate().getY()+(tic3.getHeight()/2)); + + int vertical_size = 0; + + icon_list.addIcon(lic); + addIcon(lic); + setUpIconParent(lic, tic2, tic3); + + java.util.Vector ics = new java.util.Vector(); + + setUpIcon(jlc, xpos, ypos); + + // now put the beginning icon + + jlc.setRightNeighbour(tic); + tic.setLeftNeighbour(jlc); + + jlc.setLeftNeighbour(tic2); + tic2.setRightNeighbour(jlc); + + icon_list.addIcon(jlc); + addIcon(jlc); + add(jlc); + + jlc.setParentIcon(lic.getParentIcon()); + if(tic instanceof joinLoopIcon && tic.getParentIcon().getId() != lic.getParentIcon().getId()) + { + lic.getParentIcon().addMember(jlc, tic.getBottomNeighbour()); + } + else + { + lic.getParentIcon().addMember(jlc, tic); + } + + // temporarily removes the lic from the its parent + lic.getParentIcon().delMember(lic); + + recursiveShiftIconHorizontalRight(jlc, 1); + + + splitWire(jlc, icon_list.getIcons().get(tic.getId())); + + if(xpos == xpos2) + { + // then introduce the join icon at the end of the loop + xpos2 += Constants.gridDistanceX;// by this time the clicked position would have been + // moved by 1 grid segment + } + + setUpIcon(jlc2, xpos2, ypos2); + + // now put the beginning icon + + jlc2.setRightNeighbour(tic3); + tic3.setLeftNeighbour(jlc2); + + jlc2.setLeftNeighbour(tic4); + tic4.setRightNeighbour(jlc2); + + icon_list.addIcon(jlc2); + addIcon(jlc2); + add(jlc2); + + jlc2.setParentIcon(lic.getParentIcon()); + if(tic3 instanceof joinLoopIcon && tic3.getParentIcon().getId() != lic.getParentIcon().getId()) + { + lic.getParentIcon().addMember(jlc2, tic3.getBottomNeighbour()); + } + else + { + lic.getParentIcon().addMember(jlc2, tic3); + } + + recursiveShiftIconHorizontalRight(jlc2, 1); + + + splitWire(jlc2, icon_list.getIcons().get(tic3.getId())); + + + lic.getParentIcon().delMember(jlc); + lic.getParentIcon().delMember(jlc2); + jlc.setParentIcon(lic); + jlc2.setParentIcon(lic); + lic.addMember(jlc, getStartIcon()); + lic.addMember(jlc2, getStartIcon()); + + setUpIconParent(lic, tic2, tic3); + + // establish the new links between the old members, new members, old parent and new parent + Icon left_icon = new Icon(); + Icon right_icon = new Icon(); + left_icon = tic2; + right_icon = tic3; + if(tic2 instanceof joinLoopIcon) + { + if(tic2.getParentIcon().getId() != lic.getParentIcon().getId()) + { + left_icon = tic2.getBottomNeighbour(); + } + } + else if(tic2 instanceof joinEndBranchIcon) + { + left_icon = tic2.getBranchIcon(); + } + if(tic3 instanceof joinLoopIcon && tic3.getParentIcon().getId() != lic.getParentIcon().getId()) + { + + right_icon = tic3.getBottomNeighbour(); + } + + ics = getIconsToChange(left_icon, right_icon); + + // reset the parent pointers and also update the wiring colours + int size = ics.size(); + for(int i=0; i tmp_members1; + java.util.Vector tmp_members2; + + // calculate the length of the shifting of this icon, vertically and horizontally, and all of its members + // will follow + + int xpos = 0; + if(tic2 != null && tic != null) + { + xpos = gridcalculation.midPoint(tic2.getCoordinate(), tic.getCoordinate()); + } + int ypos = tic2.getCoordinate().getY()+(tic2.getHeight()/2); // tic2 and tic should have the same coordinate + + coord tmp_co = new coord(xpos, ypos); + coord co = gridcalculation.computeCoord(icon, tmp_co); + icon.setCoordinate(co); + + if(icon instanceof branchIcon) + { + // before we continue the icon has to start fresh, i.e. its members vector has to be cleaned and restarted + // now remove all of this icon's members + // also restart the vertical sizes + icon.setTopTopVerticalSize(0); + icon.setTopBottomVerticalSize(0); + icon.setBottomTopVerticalSize(0); + icon.setBottomBottomVerticalSize(0); + tmp_members1 = icon.getIfMembers(); + tmp_members2 = icon.getElseMembers(); + icon.delAllMembers(); + + // prepare the join icons + joinEndBranchIcon jic = (new joinEndBranchIcon()).Clone(); + joinIcon jic1 = (new joinIcon()).Clone(); + joinIcon jic2 = (new joinIcon()).Clone(); + joinIcon jic3 = (new joinIcon()).Clone(); + joinIcon jic4 = (new joinIcon()).Clone(); + + insertBranchIcon(icon, tic, tic2, jsp, jic, jic1, jic2, jic3, jic4); + + // now insert all of the existing members of this branch + + // do the if_part + for(int i=1; i<(tmp_members1.size()-1); i++) + { + Icon tmp_icon = tmp_members1.get(i); + if(tmp_icon instanceof branchIcon || tmp_icon instanceof loopIcon) + { + insertRecursiveBranchLoopIcon(tmp_icon, icon.getEndBranch().getLeftNeighbourTop(), icon.getEndBranch().getLeftNeighbourTop().getLeftNeighbour(), jsp); + } + else + { + int xpos2 = gridcalculation.calculateXright(icon.getEndBranch().getLeftNeighbourTop().getCoordinate().getX()); + int ypos2 = gridcalculation.calculateY(icon.getEndBranch().getLeftNeighbourTop().getCoordinate().getY()); + setUpIcon(tmp_icon, xpos2, ypos2); + + insertObjectIcon(tmp_icon, icon.getEndBranch().getLeftNeighbourTop(), icon.getEndBranch().getLeftNeighbourTop().getLeftNeighbour(), jsp); + } + } + // then do the else_part + for(int i=1; i<(tmp_members2.size()-1); i++) + { + Icon tmp_icon = tmp_members2.get(i); + if(tmp_icon instanceof branchIcon || tmp_icon instanceof loopIcon) + { + insertRecursiveBranchLoopIcon(tmp_icon, icon.getEndBranch().getLeftNeighbourBottom(), icon.getEndBranch().getLeftNeighbourBottom().getLeftNeighbour(), jsp); + } + else + { + int xpos2 = gridcalculation.calculateXright(icon.getEndBranch().getLeftNeighbourBottom().getCoordinate().getX()); + int ypos2 = gridcalculation.calculateY(icon.getEndBranch().getLeftNeighbourBottom().getCoordinate().getY()); + setUpIcon(tmp_icon, xpos2, ypos2); + insertObjectIcon(tmp_icon, icon.getEndBranch().getLeftNeighbourBottom(), icon.getEndBranch().getLeftNeighbourBottom().getLeftNeighbour(), jsp); + } + } + } + else if(icon instanceof loopIcon) + { + tmp_members1 = icon.getMembers(); + icon.setTopVerticalSize(0); + icon.setBottomVerticalSize(0); + icon.delAllMembers(); + + // prepare the joinLoopIcons + joinLoopIcon jlc = (new joinLoopIcon()).Clone(); + joinLoopIcon jlc2 = (new joinLoopIcon()).Clone(); + insertLoopIcon(icon, tic, tic2, tic, tic2, jsp, jlc, jlc2); // re-insert the loop as if it was empty + + // now insert all of the existing members of this loop + + for(int i=1; i<(tmp_members1.size()-1); i++) + { + Icon tmp_icon = tmp_members1.get(i); + if(tmp_icon instanceof branchIcon || tmp_icon instanceof loopIcon) + { + insertRecursiveBranchLoopIcon(tmp_icon, icon.getEndIcon(), icon.getEndIcon().getLeftNeighbour(), jsp); + } + else + { + int xpos2 = gridcalculation.calculateXright(icon.getEndIcon().getCoordinate().getX()); + int ypos2 = gridcalculation.calculateY(icon.getEndIcon().getCoordinate().getY()); + setUpIcon(tmp_icon, xpos2, ypos2); + + insertObjectIcon(tmp_icon, icon.getEndIcon(), icon.getEndIcon().getLeftNeighbour(), jsp); + } + } + } + } + + /** + * Special deletion of functions as called by the the function window + * @param icon Function icon to be deleted + * @param jScrollPane1 Scroll Pane of the programming window + */ + public void deleteFunctionIcon(Icon icon, javax.swing.JScrollPane jScrollPane1) + { + setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR)); + + // reconnect the neighbouring icons + icon.getLeftNeighbour().setRightNeighbour(icon.getRightNeighbour()); + + icon.getRightNeighbour().setLeftNeighbour(icon.getLeftNeighbour()); + + // recursively shift the icons + recursiveShiftIconHorizontalLeft(icon, 1); + // collapse the wires + collapseWire(icon.getLeftNeighbour(), icon.getRightNeighbour()); + + // remove this icon from its parent's vector of member icons + + deleteIcon(icon); + + icon.getParentIcon().delMember(icon); + icon_list.delIcon(icon); + remove(icon); + repositionAllBranches(); + repositionAllRepeat(); + + jDirectionsLabel.setText("Icon successfully deleted"); + + // resize the programming window + resizeProgWindow(jScrollPane1); + updateAllRepeatNeighbours(); + repaint(); + revalidate(); + setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); + } + + /** + * Ensure that the programming window is in the appropriate size for any kind of icons layout or configuration + * @param jScrollPane1 Scroll pane of the programming window + */ + public void resizeProgWindow(javax.swing.JScrollPane jScrollPane1) + { + Icon tmp_icon = end_ic; // the ending icon always provide the rightmost icon (index = 2) + +// int maxX = gridcalculation.calculateXright(tmp_icon.getCoordinate().getX()) + (Constants.gridDistanceX * 2 ); + int maxX = gridcalculation.calculateXright(tmp_icon.getCoordinate().getX()) + Constants.gridDistanceX; + int maxY = gridcalculation.calculateY(tmp_icon.getCoordinate().getY()) + Constants.gridDistanceY; + // check for the bottom most icons or piece of wire to find the maxY + // no need to take the top most icons into consideration, since before this method is called upon, + // the icons will always be moved down one grid segment. + + java.util.Vector tmp_ic_list; + // tmp_ic_list = icon_list.getIcons(); + tmp_ic_list = getIcons(); + for(int i = 0; i < tmp_ic_list.size(); i++) + { + tmp_icon = tmp_ic_list.get(i); + if(tmp_icon != null) + { + int y = gridcalculation.calculateY(tmp_icon.getCoordinate().getY()); + y += Constants.gridDistanceY; + if(y > maxY) + { + maxY = y; + } + } + } + + int minY = 0; // needed for the vertical repositioning of all icons + // now check the wiring (only the branches wiring, the normal wiring's y values would not be bigger than any icon's y values) + java.util.Vector tmp_wr_list; + // tmp_wr_list = wire_list.getWires(); + tmp_wr_list = win_wire; + Wire topmostWire = null; + int firsttime = 0; // minY is not assigned yet + for(int i = 0; i < tmp_wr_list.size(); i++) + { + Wire tmp_wire = tmp_wr_list.get(i); + if(tmp_wire != null) + { + int y = gridcalculation.calculateY(tmp_wire.getBeginCoordinate().getY()); + if(firsttime == 0) + { + firsttime = 1; + topmostWire = tmp_wire; + minY = y; + } + else + { + if(y < minY) + { + topmostWire = tmp_wire; + minY = y; + } + } + + y += Constants.gridDistanceY; + if(y > maxY) + { + maxY = y; + } + + // --- + + y = gridcalculation.calculateY(tmp_wire.getEndCoordinate().getY()); + if(firsttime == 0) + { + firsttime = 1; + topmostWire = tmp_wire; + minY = y; + } + else + { + if(y < minY) + { + topmostWire = tmp_wire; + minY = y; + } + } + y += Constants.gridDistanceY; + if(y > maxY) + { + maxY = y; + } + } + } + + // check whether it is necessary to shift all icons up or down + int n_shift = minY; + if(n_shift < Constants.gridDistanceY) + { + n_shift = (0 - minY) / Constants.gridDistanceY + 1; + shiftIconsVertical(n_shift); + maxY += n_shift * Constants.gridDistanceY; + } + else if(n_shift > Constants.gridDistanceY) + { + n_shift = minY / Constants.gridDistanceY - 1; + shiftIconsVertical(-n_shift); + maxY -= n_shift * Constants.gridDistanceY; + } + + // LATER GOTTA CHECK FOR TOPMOST ICON DELETION TO ENSURE THE TOP MOST PIECES WIRE & ICONS ARE A DISTANCE-Y FROM THE TOP + + int scrollMaxX = 0; + int scrollMaxY = 0; + if((maxX + Constants.scrollbarWidth) > Constants.maxHorizontalProgWindow) + { + scrollMaxX = Constants.maxHorizontalProgWindow; + } + else + { + scrollMaxX = maxX + Constants.scrollbarWidth; + } + if((maxY + Constants.scrollbarWidth) > Constants.maxVerticalProgWindow) + { + scrollMaxY = Constants.maxVerticalProgWindow; + } + else + { + scrollMaxY = maxY + Constants.scrollbarWidth; + } + + jScrollPane1.setMinimumSize(new java.awt.Dimension(scrollMaxX, scrollMaxY)); + jScrollPane1.setPreferredSize(new java.awt.Dimension(scrollMaxX, scrollMaxY)); + jScrollPane1.setSize(new java.awt.Dimension(scrollMaxX, scrollMaxY)); + + setArea(new java.awt.Dimension(maxX, maxY)); + repaint(); + revalidate(); + } + + + // --------------------------------- + + // methods that overrides the MouseListener and MouseMotionListener + // might be needed for future development + + /** + * Handles mouse clicks + * @param e MouseEvent + */ + public void mouseClicked(java.awt.event.MouseEvent e) { + } + /** + * Handles mouse over enter + * @param e MouseEvent + */ + public void mouseEntered(java.awt.event.MouseEvent e) { + } + /** + * Handles mouse over exit + * @param e MouseEvent + */ + public void mouseExited(java.awt.event.MouseEvent e) { + } + /** + * Handles mouse press + * @param e MouseEvent + */ + public void mousePressed(java.awt.event.MouseEvent e) { + } + /** + * Handles mouse release + * @param e MouseEvent + */ + public void mouseReleased(java.awt.event.MouseEvent e) { + } + /** + * Handle mouse drag + * @param e MouseEvent + */ + public void mouseDragged(java.awt.event.MouseEvent e) { + } + /** + * Handle mouse movements + * @param e MouseEvent + */ + public void mouseMoved(java.awt.event.MouseEvent e) { + } +} \ No newline at end of file diff --git a/src/funsoftware/inter/SplashWindow.java b/src/funsoftware/inter/SplashWindow.java new file mode 100644 index 0000000..98ef39e --- /dev/null +++ b/src/funsoftware/inter/SplashWindow.java @@ -0,0 +1,209 @@ +/* + * SplashWindow.java 2.2 2005-04-03 + * + * Copyright (c) 2003-2005 Werner Randelshofer + * Staldenmattweg 2, Immensee, CH-6405, Switzerland. + * This software is in the public domain. + */ + +package funsoftware.inter; + +import java.awt.*; +import java.awt.event.*; +import java.net.*; +import java.io.*; + +/** + * A Splash window. + *

+ * Usage: MyApplication is your application class. Create a Splasher class which + * opens the splash window, invokes the main method of your Application class, + * and disposes the splash window afterwards. + * Please note that we want to keep the Splasher class and the SplashWindow class + * as small as possible. The less code and the less classes must be loaded into + * the JVM to open the splash screen, the faster it will appear. + *

+ * class Splasher {
+ *    public static void main(String[] args) {
+ *         SplashWindow.splash(Startup.class.getResource("splash.gif"));
+ *         MyApplication.main(args);
+ *         SplashWindow.disposeSplash();
+ *    }
+ * }
+ * 
+ * + * As part of fUNSoftWare, this code is adapted from the above copyrighted named. + * + * @author Thomas Legowo + */ +public class SplashWindow extends Window { + /** + * The current instance of the splash window. + * (Singleton design pattern). + */ + private static SplashWindow instance; + + /** + * The splash image which is displayed on the splash window. + */ + private Image image; + + /** + * This attribute indicates whether the method + * paint(Graphics) has been called at least once since the + * construction of this window.
+ * This attribute is used to notify method splash(Image) + * that the window has been drawn at least once + * by the AWT event dispatcher thread.
+ * This attribute acts like a latch. Once set to true, + * it will never be changed back to false again. + * + * @see #paint + * @see #splash + */ + private boolean paintCalled = false; + + /** + * Creates a new instance. + * @param parent the parent of the window. + * @param image the splash image. + */ + private SplashWindow(Frame parent, Image image) { + super(parent); + this.image = image; + + // Load the image + MediaTracker mt = new MediaTracker(this); + mt.addImage(image,0); + try { + mt.waitForID(0); + } catch(InterruptedException ie){} + + // Center the window on the screen + int imgWidth = image.getWidth(this); + int imgHeight = image.getHeight(this); + setSize(imgWidth, imgHeight); + Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); + setLocation( + (screenDim.width - imgWidth) / 2, + (screenDim.height - imgHeight) / 2 + ); + + // Users shall be able to close the splash window by + // clicking on its display area. This mouse listener + // listens for mouse clicks and disposes the splash window. + MouseAdapter disposeOnClick = new MouseAdapter() { + public void mouseClicked(MouseEvent evt) { + // Note: To avoid that method splash hangs, we + // must set paintCalled to true and call notifyAll. + // This is necessary because the mouse click may + // occur before the contents of the window + // has been painted. + synchronized(SplashWindow.this) { + SplashWindow.this.paintCalled = true; + SplashWindow.this.notifyAll(); + } + dispose(); + } + }; + + addMouseListener(disposeOnClick); + + } + + /** + * Updates the display area of the window. + * @param g The graphic + */ + public void update(Graphics g) { + // Note: Since the paint method is going to draw an + // image that covers the complete area of the component we + // do not fill the component with its background color + // here. This avoids flickering. + paint(g); + } + /** + * Paints the image on the window. + * @param g The graphic + */ + public void paint(Graphics g) { + g.drawImage(image, 0, 0, this); + + // Notify method splash that the window + // has been painted. + // Note: To improve performance we do not enter + // the synchronized block unless we have to. + if (! paintCalled) { + paintCalled = true; + synchronized (this) { notifyAll(); } + } + } + + /** + * Open's a splash window using the specified image. + * @param image The splash image. + */ + public static void splash(Image image) { + if (instance == null && image != null) { + Frame f = new Frame(); + + // Create the splash image + instance = new SplashWindow(f, image); + + // Show the window. + instance.setVisible(true); + + // Note: To make sure the user gets a chance to see the + // splash window we wait until its paint method has been + // called at least once by the AWT event dispatcher thread. + // If more than one processor is available, we don't wait, + // and maximize CPU throughput instead. + if (! EventQueue.isDispatchThread() + && Runtime.getRuntime().availableProcessors() == 1) { + synchronized (instance) { + while (! instance.paintCalled) { + try { instance.wait(); } catch (InterruptedException e) {} + } + } + } + } + } + /** + * Open's a splash window using the specified image. + * @param imageURL The url of the splash image. + */ + public static void splash(URL imageURL) { + if (imageURL != null) { + splash(Toolkit.getDefaultToolkit().createImage(imageURL)); + } + } + + + /** + * Closes the splash window. + */ + public static void disposeSplash() { + if (instance != null) { + instance.getOwner().dispose(); + instance = null; + } + } + + /** + * Invokes the main method of the provided class name. + * @param className The class name to be invoked + * @param args the command line arguments + */ + public static void invokeMain(String className, String[] args) { + try { + Class.forName(className) + .getMethod("main", new Class[] {String[].class}) + .invoke(null, new Object[] {args}); + } catch (Exception e) { + InternalError error = new InternalError("Failed to invoke main method"); + error.initCause(e); + throw error; + } + } +} + diff --git a/src/funsoftware/inter/Splasher.java b/src/funsoftware/inter/Splasher.java new file mode 100644 index 0000000..72a6fd7 --- /dev/null +++ b/src/funsoftware/inter/Splasher.java @@ -0,0 +1,29 @@ +/* + * Splasher.java 2.0 January 31, 2004 + * + * Copyright (c) 2003-2005 Werner Randelshofer + * Staldenmattweg 2, Immensee, CH-6405, Switzerland. + * This software is in the public domain. + */ + +package funsoftware.inter; + +/** + * As part of fUNSoftWare, this code is adapted from the above copyrighted named. + * @author Thomas Legowo + */ +public class Splasher { + /** + * Shows the splash screen, launches the application and then disposes + * the splash screen. + * @param args the command line arguments + */ + public static void main(String[] args) { + SplashWindow.splash(Splasher.class.getResource("/icons/logos/splash_logo.png")); + SplashWindow.invokeMain("funsoftware.inter.window", args); + SplashWindow.disposeSplash(); + } + +} + + diff --git a/src/funsoftware/inter/TabbedWindowEntry.java b/src/funsoftware/inter/TabbedWindowEntry.java new file mode 100644 index 0000000..9e44712 --- /dev/null +++ b/src/funsoftware/inter/TabbedWindowEntry.java @@ -0,0 +1,66 @@ +/* + * TabbedWindowEntry.java + * + * Created on 28 September 2005, 12:18 + * + */ + +package funsoftware.inter; + +/** + * This class simply connect a function id with a panel's position in its parent card layout oriented + * @author Thomas Legowo + * + * + */ +public class TabbedWindowEntry { + + int func_id; // function id + int panel_pos; // panel's position in its parent class + + /** + * Creates a new instance of TabbedWindowEntry + * @param s Function id + * @param p Position of panel in its parent panel + */ + public TabbedWindowEntry(int s, int p) { + func_id = s; + panel_pos = p; + } + + /** + * Set the entry function's id + * @param s Function id + */ + public void setSubId(int s) + { + func_id = s; + } + + /** + * Set the panel position + * @param p Panel position + */ + public void setPanelPos(int p) + { + panel_pos = p; + } + + /** + * Get the entry function id + * @return Function id + */ + public int getSubId() + { + return func_id; + } + + /** + * Get the panel position + * @return Panel position + */ + public int getPanelPos() + { + return panel_pos; + } +} diff --git a/src/funsoftware/inter/TabbedWindowLookupTable.java b/src/funsoftware/inter/TabbedWindowLookupTable.java new file mode 100644 index 0000000..8f6ecc9 --- /dev/null +++ b/src/funsoftware/inter/TabbedWindowLookupTable.java @@ -0,0 +1,97 @@ +/* + * TabbedWindowLookupTable.java + * + * Created on 28 September 2005, 11:38 + */ + +package funsoftware.inter; + +/** + * This class acts as a helper to TabbedWindowManager. + * It keeps track of corresponding panel's position in the card layout and its panel's function id + * @author Thomas Legowo + */ +public class TabbedWindowLookupTable { + + // for singleton design pattern + private static TabbedWindowLookupTable instance = null; + private java.util.Vector twe; + + /** Creates a new instance of TabbedWindowLookupTable */ + protected TabbedWindowLookupTable() { + twe = new java.util.Vector(); + } + + /** + * To ensure only one instance of the tabbedwindowlookuptable is used, use singleton design pattern + * @return Instance of this class + */ + public static TabbedWindowLookupTable Instance() + { + if(instance == null) + { + instance = new TabbedWindowLookupTable(); + } + return instance; + } + + /** + * Get a particular entry's position in this class + * @param num_id Id + * @return Position + */ + public int getEntryPosition(int num_id) + { + int ret_val=0; // default + for(int i=0; i treshold) + { + tmp.setPanelPos(tmp.getPanelPos()-1); + } + } + } +} diff --git a/src/funsoftware/inter/TabbedWindowManager.java b/src/funsoftware/inter/TabbedWindowManager.java new file mode 100644 index 0000000..8464ee8 --- /dev/null +++ b/src/funsoftware/inter/TabbedWindowManager.java @@ -0,0 +1,182 @@ +/* + * TabbedWindowManager.java + * + * Created on 25 September 2005, 22:03 + * + */ + +package funsoftware.inter; + +import funsoftware.consts.*; +import funsoftware.var.*; +import funsoftware.events.*; + +/** + * This class manages the programming window that now is able to show multiple functions one at a time without the need of + * resetting the programming window + * Now this window manager also manages the variable window + * @author Thomas Legowo + */ +public class TabbedWindowManager { + + TabbedWindowLookupTable twt; + private javax.swing.JPanel jCardPanel; // the card panel parent for tabbed windows + +// private javax.swing.JScrollPane jScrollPane1; // this contains jCurrentProgWindow +// private ProgWindow jCurrentProgWindow; // this is the CURRENT programming window +// private javax.swing.JPanel jPanel18; // this contains jScrollPane1 + + private VarWindow varw; + private monitorEventWindow evw; + + // for singleton design pattern + private static TabbedWindowManager instance = null; + + /** + * Creates a new instance of TabbedWindowManager + * @param cardPanel Card panel parent for tabbed windows + * @param varw The variable window + * @param evw The event window + */ + protected TabbedWindowManager(javax.swing.JPanel cardPanel, + VarWindow varw, monitorEventWindow evw) { + // the argument cardPanel indicates the panel that has the card layout + // this class simply decides which of the panel on cardPanel should be displayed + jCardPanel = cardPanel; +// jCurrentProgWindow = jp2; +// jScrollPane1 = jsp; +// jPanel18 = jp3; + this.varw = varw; + this.evw = evw; + + twt = TabbedWindowLookupTable.Instance(); + } + + /** + * Ensure only one instance of the TabbedWindowManager is used, use singleton design pattern + * @return The singleton instance of this class + * @param cardPanel Card panel parent for tabbed windows + * @param varw The variable window + * @param evw The event window + */ + public static TabbedWindowManager Instance(javax.swing.JPanel cardPanel, + VarWindow varw, monitorEventWindow evw) + { + if(instance == null) + { + instance = new TabbedWindowManager(cardPanel, varw, evw); + } + return instance; + } + + /** + * Return the card panel this class manages + * @return Panel + */ + public javax.swing.JPanel getCardPanel() + { + return jCardPanel; + } + + /** + * Decides which panel to show based on the code word + * @param code Code word + */ + public void displayPanel(String code) + { + // this contains jScrollPane1 + javax.swing.JPanel jPanel18 = (javax.swing.JPanel)(jCardPanel.getComponent(twt.getEntryPosition(Integer.parseInt(code)))); + java.awt.CardLayout cl = (java.awt.CardLayout)(jCardPanel.getLayout()); + cl.show(jCardPanel, code); + + javax.swing.JScrollPane jScrollPane1 = (javax.swing.JScrollPane)jPanel18.getComponent(0); +// int tmp_g = Constants.getGridStatus(); + + ProgWindow jCurrentProgWindow = (ProgWindow)(jScrollPane1.getViewport().getView()); + +// Constants.setGridStatus(tmp_g); + window.setProgrammingWindow(jPanel18, jScrollPane1, jCurrentProgWindow); + + varw.switchDisplay(aux_list.Instance().getAuxiliaries().get(Integer.parseInt(code))); + evw.switchDisplay(aux_list.Instance().getAuxiliaries().get(Integer.parseInt(code))); + } + + /** + * Add a panel onto the card-layout panel + * @param new_panel New panel + * @param num_id Function id + */ + public void addPanel(javax.swing.JPanel new_panel, int num_id) + { + jCardPanel.add(new_panel, Integer.toString(num_id)); + + // update the tabbedwindowpanel + twt.addEntry(num_id, jCardPanel.getComponentCount()-1); + } + + /** + * Removes a panel + * @param num_id Function id + */ + public void delPanel(int num_id) + { + jCardPanel.remove(twt.getEntryPosition(num_id)); + twt.delEntry(num_id); + } + + /** + * Reset this class and all of its variables + */ + public void reset() + { + if(jCardPanel.getComponentCount() > 1) + { + int total_comp_count = jCardPanel.getComponentCount(); + for(int i = 1; i < total_comp_count; i++) // remove all except the first panel + { + // As each component is removed, the component index shifts by one, + // so we always act on index 1 until everything at index 1 and above is removed + javax.swing.JPanel tmp_jpanel = (javax.swing.JPanel)jCardPanel.getComponent(1); + javax.swing.JScrollPane tmp_jsp = (javax.swing.JScrollPane)tmp_jpanel.getComponent(0); +// ProgWindow tmp = (ProgWindow)(tmp_jsp.getViewport().getView()); + tmp_jsp.remove(0); + tmp_jpanel.remove(0); + jCardPanel.remove(1); + } + } + +// javax.swing.JPanel tmp_jpanel = (javax.swing.JPanel)jCardPanel.getComponent(0); +// javax.swing.JScrollPane tmp_jsp = (javax.swing.JScrollPane)tmp_jpanel.getComponent(0); +// ProgWindow tmp = (ProgWindow)(tmp_jsp.getViewport().getView()); + } + + /** + * Reset the current programming window and its panels and scroll panels + */ + public void panels_reset() + { +// javax.swing.JPanel tmp_jpanel = (javax.swing.JPanel)jCardPanel.getComponent(0); +// javax.swing.JScrollPane tmp_jsp = (javax.swing.JScrollPane)tmp_jpanel.getComponent(0); +// ProgWindow tmp = (ProgWindow)(tmp_jsp.getViewport().getView()); +// +// window.setProgrammingWindow(tmp_jpanel, tmp_jsp, tmp); + } + + /** + * For resizing window, all of the jScrollPane instances must be resize appropriately + */ + public void resizeAllPanels() + { + if(jCardPanel.getComponentCount() > 1) + { + int total_comp_count = jCardPanel.getComponentCount(); + for(int i=1; i + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/funsoftware/inter/window.java b/src/funsoftware/inter/window.java new file mode 100644 index 0000000..7be4603 --- /dev/null +++ b/src/funsoftware/inter/window.java @@ -0,0 +1,6068 @@ +/* + * window.java + * + * Created on 9 June 2005, 01:57 + */ + +package funsoftware.inter; + +import com.sun.glass.ui.Cursor; +import java.io.*; +import java.net.*; + +import funsoftware.ic.*; +import funsoftware.ic.obj.*; +import funsoftware.ic.bran.*; +import funsoftware.ic.loo.*; +import funsoftware.ic.func.*; +import funsoftware.ic.others.*; +import funsoftware.ic.func.*; +import funsoftware.ic.tsk.*; +import funsoftware.ic.var.*; +import funsoftware.ic.ev.*; +import funsoftware.st.*; +import funsoftware.wr.*; +import funsoftware.gri.*; +import funsoftware.pallette.*; +import funsoftware.comp.*; +import funsoftware.consts.*; +import funsoftware.functs.*; +import funsoftware.tasks.*; +import funsoftware.struct.*; +import funsoftware.var.*; +import funsoftware.events.*; +import funsoftware.properties.*; +import java.awt.Color; +import javax.swing.ScrollPaneConstants; + +/** + * This is the class that cater for the user interface (i.e. all graphics related) + * fUNSoftWare starts from this class. This class contains the main function. + * All of the original buttons, icons, palette, panels and menu are created here as well as their respective event handlers + * @author Thomas Legowo + * + */ +public class window extends javax.swing.JFrame { + + /** Creates new form window */ + public window() { + + initComponents(); + + // initialise the icons to be cloned + initIconClones(); + + // initialise the lookup table for Translator + Translator.init_lookup_table(); + + // initialise the palette sections + initEditingIconsPalette(); + initIconHelpPalette(); + initObjectIconsPalette(); + initBranchIconsPalette(); + initLoopIconsPalette(); + initFunctionsReusePalette(); + + +// // initialise the manually added variables +// initManVariables(); + + initOtherClasses(); + // initialise the programming window + initScrollable(); + //reset all variables + resetVars(); + // initialise the variable window + initVariablesPallette(); + // initialize the event monitor window + initEventMonitor(); + // initialise the task window + initTask(); + // initialise the function window + initFunction(); + // initialise the event window + initEvent(); + + // bind the hot keys + bindHotKeys(); + + // reset + reset(); + + // initialise the two main icons, start and ending icon and the first piece of wire + initIconsWires(); + + // resize the programming window appropriately +// jProgrammingWindow.resizeProgWindow(jScrollPane1); + UndoRedo.update_state(); + + // Set the target device + updateTargetDevice(); + } + + // method to bind the frame with the hot keys + private void bindHotKeys() + { + // new file + jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke( + java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK)); + // open file + jMenuItem7.setAccelerator(javax.swing.KeyStroke.getKeyStroke( + java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK)); + // save file + jMenuItem21.setAccelerator(javax.swing.KeyStroke.getKeyStroke( + java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK)); + // exit + jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke( + java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK)); + // undo + jMenuItem5.setAccelerator(javax.swing.KeyStroke.getKeyStroke( + java.awt.event.KeyEvent.VK_Z, java.awt.event.InputEvent.CTRL_MASK)); + // redo + jMenuItem8.setAccelerator(javax.swing.KeyStroke.getKeyStroke( + java.awt.event.KeyEvent.VK_Y, java.awt.event.InputEvent.CTRL_MASK)); + // cancel last operation + jMenuItem14.setAccelerator(javax.swing.KeyStroke.getKeyStroke( + java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.CTRL_MASK)); + // set or hide grid + jMenuItem13.setAccelerator(javax.swing.KeyStroke.getKeyStroke( + java.awt.event.KeyEvent.VK_G, java.awt.event.InputEvent.SHIFT_MASK)); + // edit grid + jMenuItem10.setAccelerator(javax.swing.KeyStroke.getKeyStroke( + java.awt.event.KeyEvent.VK_G, java.awt.event.InputEvent.CTRL_MASK)); + // create function + jMenuItem11.setAccelerator(javax.swing.KeyStroke.getKeyStroke( + java.awt.event.KeyEvent.VK_U, java.awt.event.InputEvent.CTRL_MASK)); + // just to compile the file + jMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke( + java.awt.event.KeyEvent.VK_F5, 0)); + // compile and download + jMenuItem12.setAccelerator(javax.swing.KeyStroke.getKeyStroke( + java.awt.event.KeyEvent.VK_F6, 0)); + // compile and run + jMenuItem9.setAccelerator(javax.swing.KeyStroke.getKeyStroke( + java.awt.event.KeyEvent.VK_F7, 0)); + // create a task + jMenuItem16.setAccelerator(javax.swing.KeyStroke.getKeyStroke( + java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK)); + // declare a variable + jMenuItem15.setAccelerator(javax.swing.KeyStroke.getKeyStroke( + java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK)); + // to create an arithmetic operation + jMenuItem17.setAccelerator(javax.swing.KeyStroke.getKeyStroke( + java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK)); + // to create an event + jMenuItem18.setAccelerator(javax.swing.KeyStroke.getKeyStroke( + java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.CTRL_MASK)); + // to create an event monitor + jMenuItem20.setAccelerator(javax.swing.KeyStroke.getKeyStroke( + java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.CTRL_MASK)); + } + + // for the prototype design pattern + private void initIconClones() + { + _motor = new motorIcon(); + _stopmotor = new stopMotorIcon(); + _beep = new beepIcon(); + _lamp = new lampIcon(); + _dirmotor = new directionalMotorIcon(); + _timer = new timerIcon(); + _clearsensor = new clearSensorIcon(); + _cleartimer = new clearTimerIcon(); + _playanynote = new playAnyNoteIcon(); + _float = new floatMotorIcon(); + _specificnote = new playSpecificNote(); + _returnicon = new returnIcon(); + _waittouch = new waitTouchIcon(); + _waitlight = new waitLightIcon(); + _waitcelcius = new waitCelciusIcon(); + _waitrotation = new waitRotationalIcon(); + _waittimer = new waitTimerIcon(); + + // the branches + + _Btouch = new BtouchSensorIcon(); + _Blight = new BlightSensorIcon(); + _Bcelcius = new BcelciusSensorIcon(); + _Brotation = new BrotationSensorIcon(); + _Btimer = new BtimerIcon(); + _Brandom = new BrandomIcon(); + _Barithmetic = new BarithmeticIcon(); + + // the loops + + _Lrep = new repeatIcon(); + _Llight = new lightSensorLoopIcon(); + _Linfinite = new infiniteLoopIcon(); + _Ltimer = new timerLoopIcon(); + _Lrotation = new rotationSensorLoopIcon(); + _Lcelcius = new celciusSensorLoopIcon(); + _Ltouch = new touchSensorLoopIcon(); + _Larithmetic = new arithmeticLoopIcon(); + + // the auxiliary + + _Jicon = new joinIcon(); + _Jloop = new joinLoopIcon(); + _JEBIcon = new joinEndBranchIcon(); + + // the task icons + + _Start = new startTaskIcon(); + _End = new endTaskIcon(); + _BeginTask = new beginTaskIcon(); + _StopTask = new stopTaskIcon(); + + // the function icon and the function skeleton + + _Funcby = new functionIcon(); + _Funct = new function(); + _Task = new task(); + _Var = new variable(); + _Event = new Event(); + _mEvent = new monitorEvent(); + _AOIcon = new ArithOpIcon(); + + // the event icons + _SEvent = new startEvent(); + } + + private void reset() + { + jPanelTask.reset(); + jPanelFunction.reset(); + jPanelEvent.reset(); + jPanelEventMonitor.reset(); + jPanelVar.reset(); + + TabbedWindowManager.Instance(CenterCardPanel, jPanelVar, jPanelEventMonitor).reset(); + } + + // this method reset all variables + // 1. icon_list + // 2. wire_list + // 3. jProgrammingWindow's components + // 4. auxiliary list + // 5. variable list + private void resetVars() + { + do_state = states.Instance(); + + // reset the programming window + if (jProgrammingWindow != null) + { + jProgrammingWindow.removeAll(); + jProgrammingWindow.resetWires(); + jProgrammingWindow.resetIcons(); + } + + // reset the function window + fcombo.reset(); + + // reset the button group + radiobuttons.Instance().reset(); + + // reset the icons + icons_list.Instance().resetIconList(); + + // reset the wiring + wires.Instance().resetWireList(); + + // reset function list + aux_list.Instance().resetAuxList(); + + // reset the variable list + var_list.Instance().resetVarList(); + + // reset the event list + event_number_tracker.Instance().resetEvList(); + } + + private void initEditingIconsPalette() + { + javax.swing.JPanel jPanelEditing = new javax.swing.JPanel(); + jPanelEditing.setLayout(new java.awt.GridBagLayout()); + jPanelEditing.setBackground(new java.awt.Color(247, 247, 247)); + jPanelEditing.setBorder(null); + + // insert the object window inside the scroller + javax.swing.JViewport vw = new javax.swing.JViewport(); + vw.setView(jPanelEditing); + EditingPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + EditingPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); + EditingPane.setViewport(vw); + + java.awt.GridBagConstraints gridBagConstraints; + + // Grid-Mode button + jButtonGridMode = new javax.swing.JButton(); + jButtonGridMode.setForeground(new java.awt.Color(212, 208, 200)); + jButtonGridMode.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/other/gridmode.gif"))); + jButtonGridMode.setToolTipText("To display or hide grids"); + jButtonGridMode.setBorder(null); + jButtonGridMode.setMaximumSize(new java.awt.Dimension(32, 32)); + jButtonGridMode.setMinimumSize(new java.awt.Dimension(32, 32)); + jButtonGridMode.setPreferredSize(new java.awt.Dimension(32, 32)); + jButtonGridMode.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton4ActionPerformed(evt); + } + }); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); + jPanelEditing.add(jButtonGridMode, gridBagConstraints); + + // Undo button + jButtonUndo = new javax.swing.JButton(); + jButtonUndo.setForeground(new java.awt.Color(180, 180, 180)); + jButtonUndo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/other/undo.gif"))); + jButtonUndo.setToolTipText("To undo previous action"); + jButtonUndo.setBorder(null); + jButtonUndo.setMaximumSize(new java.awt.Dimension(32, 32)); + jButtonUndo.setMinimumSize(new java.awt.Dimension(32, 32)); + jButtonUndo.setPreferredSize(new java.awt.Dimension(32, 32)); + jButtonUndo.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton11ActionPerformed(evt); + } + }); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); + jPanelEditing.add(jButtonUndo, gridBagConstraints); + + // Redo button + jButtonRedo = new javax.swing.JButton(); + jButtonRedo.setForeground(new java.awt.Color(180, 180, 180)); + jButtonRedo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/other/redo.gif"))); + jButtonRedo.setToolTipText("To redo previous action"); + jButtonRedo.setBorder(null); + jButtonRedo.setMaximumSize(new java.awt.Dimension(32, 32)); + jButtonRedo.setMinimumSize(new java.awt.Dimension(32, 32)); + jButtonRedo.setPreferredSize(new java.awt.Dimension(32, 32)); + jButtonRedo.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton12ActionPerformed(evt); + } + }); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); + jPanelEditing.add(jButtonRedo, gridBagConstraints); + + // Cancel button + jButtonCancel = new javax.swing.JButton(); + jButtonCancel.setText("Cancel"); + jButtonCancel.setToolTipText("To cancel last operation"); + jButtonCancel.setBorder(null); + jButtonCancel.setMaximumSize(new java.awt.Dimension(70, 32)); + jButtonCancel.setMinimumSize(new java.awt.Dimension(70, 32)); + jButtonCancel.setPreferredSize(new java.awt.Dimension(70, 32)); + jButtonCancel.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton5ActionPerformed(evt); + } + }); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 3; + gridBagConstraints.gridy = 0; + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); + jPanelEditing.add(jButtonCancel, gridBagConstraints); + } + + private void initIconHelpPalette() + { + javax.swing.JPanel jPanelHelp = new javax.swing.JPanel(); + jPanelHelp.setLayout(new java.awt.GridBagLayout()); + jPanelHelp.setBackground(new java.awt.Color(247, 247, 247)); + jPanelHelp.setBorder(null); + jPanelHelp.setRequestFocusEnabled(false); + + jLabelHelp = new javax.swing.JLabel(); + jLabelHelp.setText("Select an icon"); + jLabelHelp.setForeground(new java.awt.Color(51, 108, 255)); + jLabelHelp.setFont(new java.awt.Font("Verdana", 0, 12)); + jPanelHelp.add(jLabelHelp, new java.awt.GridBagConstraints()); + + // insert the object window inside the scroller + javax.swing.JViewport vw = new javax.swing.JViewport(); + vw.setView(jPanelHelp); + IconHelpPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + IconHelpPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); + IconHelpPane.setViewport(vw); + } + + // this method initialises all the object icons pallettes + private void initObjectIconsPalette() + { + // set up the object window where the icons will reside + javax.swing.JPanel objwin = new javax.swing.JPanel(); + objwin.setLayout(new java.awt.GridBagLayout()); + objwin.setBackground(new java.awt.Color(247, 247, 247)); + objwin.setBorder(null); + + // insert the object window inside the scroller + javax.swing.JViewport vw = new javax.swing.JViewport(); + vw.setView(objwin); + SinglesPane.setViewport(vw); + + // --- adding the buttons + + createIconicButton(40, 40, "/icons/motors/movemotor/icon_wheel2.gif", 0, 0, objwin, "Motor Icon", _motor); + + createIconicButton(40, 40, "/icons/motors/directional/dir.gif", 1, 0, objwin, "Directional Motor Icon", _dirmotor); + + createIconicButton(40, 40, "/icons/motors/stopmotor/icon_wheel_stop.gif", 2, 0, objwin, "Stop Icon", _stopmotor); + + createIconicButton(40, 40, "/icons/lamps/lamp.gif", 3, 0, objwin, "Lamp Icon", _lamp); + + createIconicButton(40, 40, "/icons/motors/floatmotor/floatmotor.gif", 0, 1, objwin, "Float Motor Icon", _float); + + createIconicButton(40, 40, "/icons/beeps/beeps.gif", 1, 1, objwin, "Beep Icon", _beep); + + createIconicButton(40, 40, "/icons/notes/free/freenote.gif", 2, 1, objwin, "Play Any Note Icon", _playanynote); + + createIconicButton(40, 40, "/icons/notes/specific/specific.gif", 3, 1, objwin, "Play A Note Icon", _specificnote); + + createIconicButton(40, 40, "/icons/timers/wait/icon_time.gif", 0, 2, objwin, "Wait Icon", _timer); + + createIconicButton(40, 40, "/icons/wait/touch/wait_touch.gif", 1, 2, objwin, "Wait Touch Sensor Icon", _waittouch); + + createIconicButton(40, 40, "/icons/wait/light/wait_light.gif", 2, 2, objwin, "Wait Light Sensor Icon", _waitlight); + + createIconicButton(40, 40, "/icons/wait/celcius/wait_celcius.gif", 3, 2, objwin, "Wait Celcius Sensor Icon", _waitcelcius); + + createIconicButton(40, 40, "/icons/wait/rotate/wait_rotate.gif", 0, 3, objwin, "Wait Rotational Sensor Icon", _waitrotation); + + createIconicButton(40, 40, "/icons/wait/timer/wait_timer.gif", 1, 3, objwin, "Wait Timer Sensor Icon", _waittimer); + + createIconicButton(40, 40, "/icons/structure/return/return.gif", 2, 3, objwin, "Return Icon", _returnicon); + + createIconicButton(40, 40, "/icons/sensors/clearsensor.gif", 3, 3, objwin, "Clear Sensors Icon", _clearsensor); + + createIconicButton(40, 40, "/icons/timers/cleart/cleartimer.gif", 0, 4, objwin, "Clear Timer Icon", _cleartimer); + + createIconicButton(40, 40, "/icons/task/start/startTask.gif", 1, 4, objwin, "Start Task Icon", _BeginTask); + + createIconicButton(40, 40, "/icons/task/stop/stopTask.gif", 2, 4, objwin, "Stop Task Icon", _StopTask); + + createIconicButton(40, 40, "/icons/events/start/start.gif", 3, 4, objwin, "Start Event Monitor Icon", _SEvent); + } + + // this method initialises the branch icons window + private void initBranchIconsPalette() + { + // set up the branch window where the icons will reside + javax.swing.JPanel brawin = new javax.swing.JPanel(); + brawin.setLayout(new java.awt.GridBagLayout()); + brawin.setBackground(new java.awt.Color(247, 247, 247)); + brawin.setBorder(null); + + // insert the branch window inside the scroller + javax.swing.JViewport vw = new javax.swing.JViewport(); + vw.setView(brawin); + BranchesPane.setViewport(vw); + + createIconicButton(40, 40, "/icons/branches/touch/icon_if.gif", 0, 0, brawin, "Branch Touch Sensor Icon", _Btouch); + + createIconicButton(40, 40, "/icons/branches/light/light.gif", 1, 0, brawin, "Branch Light Sensor Icon", _Blight); + + createIconicButton(40, 40, "/icons/branches/celcius/celcius.gif", 2, 0, brawin, "Branch Temperature Sensor Icon", _Bcelcius); + + createIconicButton(40, 40, "/icons/branches/rotation/rotation.gif", 3, 0, brawin, "Branch Rotational Sensor Icon", _Brotation); + + createIconicButton(40, 40, "/icons/branches/timer/timer.gif", 0, 1, brawin, "Branch Timer Icon", _Btimer); + + createIconicButton(40, 40, "/icons/branches/random/random.gif", 1, 1, brawin, "Branch Random Icon", _Brandom); + + createIconicButton(40, 40, "/icons/branches/arithmetic/arithmetic.gif", 2, 1, brawin, "Branch Arithmetic Icon", _Barithmetic); + } + + // this method initialises the loop icons window + private void initLoopIconsPalette() + { + // set up the loop window where the icons will reside + javax.swing.JPanel loowin = new javax.swing.JPanel(); + loowin.setLayout(new java.awt.GridBagLayout()); + loowin.setBackground(new java.awt.Color(247, 247, 247)); + loowin.setBorder(null); + + // insert the loop window inside the scroller + javax.swing.JViewport vw = new javax.swing.JViewport(); + vw.setView(loowin); + LoopsPane.setViewport(vw); + + createIconicButton(40, 40, "/icons/loops/repeat/icon_rep.gif", 0, 0, loowin, "Repeat Icon", _Lrep); + + createIconicButton(40, 40, "/icons/loops/infiniteloop/infinite_rep.gif", 1, 0, loowin, "Infinite Repeat Icon", _Linfinite); + + createIconicButton(40, 40, "/icons/loops/lightrep/light_rep.gif", 2, 0, loowin, "Light Sensor Repeat Icon", _Llight); + + createIconicButton(40, 40, "/icons/loops/timer/timer.gif", 3, 0, loowin, "Timer Repeat Icon", _Ltimer); + + createIconicButton(40, 40, "/icons/loops/celcius/celcius.gif", 0, 1, loowin, "Temperature Sensor Repeat Icon", _Lcelcius); + + createIconicButton(40, 40, "/icons/loops/rotation/rotational.gif", 1, 1, loowin, "Rotational Sensor Repeat Icon", _Lrotation); + + createIconicButton(40, 40, "/icons/loops/touch/touch.gif", 2, 1, loowin, "Touch Sensor Repeat Icon", _Ltouch); + + createIconicButton(40, 40, "/icons/loops/arithmetic/arithmetic.gif", 3, 1, loowin, "Arithmetic Repeat Icon", _Larithmetic); + } + + private void initFunctionsReusePalette() + { + javax.swing.JPanel jPanelFuncReuse = new javax.swing.JPanel(); + jPanelFuncReuse.setLayout(new java.awt.GridBagLayout()); + jPanelFuncReuse.setBackground(new java.awt.Color(247, 247, 247)); + jPanelFuncReuse.setBorder(null); + + // insert the loop window inside the scroller + javax.swing.JViewport vw = new javax.swing.JViewport(); + vw.setView(jPanelFuncReuse); + FunctionsReusePane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + FunctionsReusePane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); + FunctionsReusePane.setViewport(vw); + + fcombo = FunctionCombo.Instance(); // the function combo box + fcombo.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + FuncComboBoxActionPerformed(evt); // to duplicate a function + } + }); + + jPanelFuncReuse.add(fcombo, new java.awt.GridBagConstraints()); + } + + + // this method initialises the programming window + private void initScrollable() + { +// jProgrammingWindow = new ProgWindow(DirectionsLabel); +// jProgrammingWindow.setBackground(new java.awt.Color(255, 255, 255)); +// +// jScrollPane1 = new javax.swing.JScrollPane(); +// jScrollPane1.setBackground(new java.awt.Color(255, 255, 255)); +// jScrollPane1.setBorder(null); +// +// javax.swing.JViewport viewport = new javax.swing.JViewport(); +// viewport.setView(jProgrammingWindow); +// jScrollPane1.setViewport(viewport); +// +// javax.swing.JPanel jPanel18 = new javax.swing.JPanel(); +// jPanel18.setLayout(new java.awt.GridBagLayout()); +// jPanel18.setLayout(new javax.swing.BoxLayout(jPanel18, javax.swing.BoxLayout.PAGE_AXIS)); +// jPanel18.add(jScrollPane1); +// +// CenterCardPanel.add(jPanel18, "0"); // the initial main programming window is coded 1 + + TitlePanelLabel panelCardZero = new TitlePanelLabel(); + panelCardZero.setText("Welcome to " + AppProperties.appName + "!"); + CenterCardPanel.add(panelCardZero, "0"); + + // initialise the list of wires and icons first + wire_list = wires.Instance(); + icon_list = icons_list.Instance(); + } + + // the function to initialise the bottom left pallette + // the pallette will display both global and local variables + private void initVariablesPallette() + { + jPanelVar = new VarWindow(this); + javax.swing.JViewport vp = new javax.swing.JViewport(); + vp.setView(jPanelVar); + VariablesPane.setViewport(vp); + } + + // to initialise the task window + private void initTask() + { +// jPanelTask = new TaskWindow(this, jPanel13, jProgrammingWindow, jScrollPane1, jPanel18, DirectionsLabel, jPanelVar, jPanelEventMonitor); + jPanelTask = new TaskWindow(this, CenterCardPanel, DirectionsLabel, jPanelVar, jPanelEventMonitor); + javax.swing.JViewport vp = new javax.swing.JViewport(); + vp.setView(jPanelTask); + TasksPane.setViewport(vp); + } + + // to initialise the function window + private void initFunction() + { +// jPanelFunction = new FunctionWindow(this, jPanel13, jProgrammingWindow, jScrollPane1, jPanel18, DirectionsLabel, jPanelVar, jPanelEventMonitor); + jPanelFunction = new FunctionWindow(this, CenterCardPanel, DirectionsLabel, jPanelVar, jPanelEventMonitor); + javax.swing.JViewport vp = new javax.swing.JViewport(); + vp.setView(jPanelFunction); + FunctionsPane.setViewport(vp); + } + + // to initialise the event window + private void initEvent() + { + jPanelEvent = new eventWindow(this); + javax.swing.JViewport vp = new javax.swing.JViewport(); + vp.setView(jPanelEvent); + EventsPane.setViewport(vp); + } + + // to initialize the event monitor window + private void initEventMonitor() + { +// jPanelEventMonitor = new monitorEventWindow(this, jPanel13, jProgrammingWindow, jScrollPane1, jPanel18, DirectionsLabel, jPanelVar); + jPanelEventMonitor = new monitorEventWindow(this, CenterCardPanel, DirectionsLabel, jPanelVar); + javax.swing.JViewport vp = new javax.swing.JViewport(); + vp.setView(jPanelEventMonitor); + EventMonitorsPane.setViewport(vp); + } + + + // This method initialise the programming window by putting a piece of wire between the start and end icons + // This method will only be called under two circumstances + // 1. When the user clicks on the "New" menu item to initialise the programming window ready to be used. + // 2. If the user loads a program from a saved file + private void initIconsWires() + { + task tsk = _Task.Clone(); + aux_list.Instance().addAuxiliary(tsk); + tsk.setName("main"); + jPanelTask.insertTask(tsk); + + task tmp = (task)(aux_list.Instance().getAuxiliaries().get(1)); + setProgrammingWindow(tmp.getPanel(), tmp.getScroller(), tmp.getProgWindow()); + tmp.getTaskWindow().getTabbedWinMan().displayPanel("1"); + + radiobuttons rb = radiobuttons.Instance(); + javax.swing.ButtonGroup group = rb.getButtonGroup(); + group.getElements().nextElement().setSelected(true); + + // now resize the programming window appropriately +// jProgrammingWindow.resizeProgWindow(jScrollPane1); +// current_aux = aux_list.Instance().getAuxiliaries().get(1); + + repaint(); + validate(); + } + + +// // This method is called upon the initialisation of the interface +// // Used to initialise all manually added variables as well as the sensor variables +// private void initManVariables() +// { +// distanceX = 50; // the horizontal and vertical distances between grid intersections +// distanceY = 55; +// Constants.setGridDistanceX(50); +// Constants.setGridDistanceY(55); +// Constants.setMaxHorizontalProgWindow(640); +// Constants.setMaxVerticalProgWindow(530); +// Constants.setHorizontalWindowSize(this.getWidth()); +// Constants.setVerticalWindowSize(this.getHeight()); +// Constants.setScrollbarWidth(((Integer)javax.swing.UIManager.get("ScrollBar.width")).intValue()); +// current_aux = new auxiliary(); +// maxX = gridDistanceX * 3; +// maxY = gridDistanceY * 2; +// _Current_Save_Path = new String(); +// ConfigFile_Name = getUserAppPath() + AppProperties.appName + "Config.txt"; +// } + + // This method is called upon the initialisation of the interface + // Used to initialise other classes + private void initOtherClasses() + { + // initialise the icon of this program + setIconImage((new javax.swing.ImageIcon(getClass().getResource("/icons/logos/logo.gif"))).getImage()); + + // initialise the undo redo buttons involved in the state tracking processing + UndoRedo.setUndoButton(jButtonUndo); + UndoRedo.setRedoButton(jButtonRedo); + UndoRedo.setUndoMenu(jMenuItem5); + UndoRedo.setRedoMenu(jMenuItem8); + } + + + // to restart --> for undo, redo, open and new file + // type == 0 for new file, 1 for otherwise + private void restartProgWindow(int type) + { + // initialise the two main icons, start and ending icon and the first piece of wire + // reset all variables + jPanelFunction.getTabbedWinMan().panels_reset(); + + do_state.reset(); // for undo operation + + reset(); + resetVars(); + + if(type == 0) + { + initIconsWires(); + ((javax.swing.JRadioButton)jPanelTask.getComponent(0)).setSelected(true); + + // resize the programming window appropriately +// jProgrammingWindow.resizeProgWindow(jScrollPane1); + } + + repaint(); + validate(); + } + + /** + * This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + jDialog1 = new javax.swing.JDialog(); + jFileChooser1 = new javax.swing.JFileChooser(); + buttonGroupTarget = new javax.swing.ButtonGroup(); + jSplitPane1 = new javax.swing.JSplitPane(); + jPanelMainLeft = new javax.swing.JPanel(); + TasksLabel = new funsoftware.pallette.TitlePanelLabel(); + TasksPane = new funsoftware.pallette.RoundedScrollPane(); + FunctionsLabel = new funsoftware.pallette.TitlePanelLabel(); + FunctionsPane = new funsoftware.pallette.RoundedScrollPane(); + EventsLabel = new funsoftware.pallette.TitlePanelLabel(); + EventsPane = new funsoftware.pallette.RoundedScrollPane(); + EventMonitorsLabel = new funsoftware.pallette.TitlePanelLabel(); + EventMonitorsPane = new funsoftware.pallette.RoundedScrollPane(); + VariablesLabel = new funsoftware.pallette.TitlePanelLabel(); + VariablesPane = new funsoftware.pallette.RoundedScrollPane(); + jSplitPane2 = new javax.swing.JSplitPane(); + jPanelMainCenter = new javax.swing.JPanel(); + CenterCardPanel = new funsoftware.pallette.CardPanel(); + DirectionsLabel = new funsoftware.pallette.TitlePanelLabel(); + jPanelMainRight = new javax.swing.JPanel(); + EditingLabel = new funsoftware.pallette.TitlePanelLabel(); + EditingPane = new funsoftware.pallette.RoundedScrollPane(); + IconHelpLabel = new funsoftware.pallette.TitlePanelLabel(); + IconHelpPane = new funsoftware.pallette.RoundedScrollPane(); + SinglesLabel = new funsoftware.pallette.TitlePanelLabel(); + SinglesPane = new funsoftware.pallette.RoundedScrollPane(); + BranchesLabel = new funsoftware.pallette.TitlePanelLabel(); + BranchesPane = new funsoftware.pallette.RoundedScrollPane(); + LoopsLabel = new funsoftware.pallette.TitlePanelLabel(); + LoopsPane = new funsoftware.pallette.RoundedScrollPane(); + FunctionsReuseLabel = new funsoftware.pallette.TitlePanelLabel(); + FunctionsReusePane = new funsoftware.pallette.RoundedScrollPane(); + jMenuBar1 = new javax.swing.JMenuBar(); + jMenu1 = new javax.swing.JMenu(); + jMenuItem1 = new javax.swing.JMenuItem(); + jMenuItem7 = new javax.swing.JMenuItem(); + jMenuItem21 = new javax.swing.JMenuItem(); + jMenuItem2 = new javax.swing.JMenuItem(); + jSeparator1 = new javax.swing.JSeparator(); + jMenuItem3 = new javax.swing.JMenuItem(); + jMenu2 = new javax.swing.JMenu(); + jMenuItem5 = new javax.swing.JMenuItem(); + jMenuItem8 = new javax.swing.JMenuItem(); + jSeparator2 = new javax.swing.JSeparator(); + jMenuItem14 = new javax.swing.JMenuItem(); + jSeparator4 = new javax.swing.JSeparator(); + jMenuItem13 = new javax.swing.JMenuItem(); + jMenuItem10 = new javax.swing.JMenuItem(); + jMenu5 = new javax.swing.JMenu(); + jMenuItem15 = new javax.swing.JMenuItem(); + jMenuItem17 = new javax.swing.JMenuItem(); + jSeparator3 = new javax.swing.JSeparator(); + jMenuItem11 = new javax.swing.JMenuItem(); + jSeparator6 = new javax.swing.JSeparator(); + jMenuItem16 = new javax.swing.JMenuItem(); + jSeparator7 = new javax.swing.JSeparator(); + jMenuItem18 = new javax.swing.JMenuItem(); + jMenuItem20 = new javax.swing.JMenuItem(); + jMenu6 = new javax.swing.JMenu(); + jRadioButtonMenuItemRCX1 = new javax.swing.JRadioButtonMenuItem(); + jRadioButtonMenuItemRCX2 = new javax.swing.JRadioButtonMenuItem(); + jMenu3 = new javax.swing.JMenu(); + jMenuItem4 = new javax.swing.JMenuItem(); + jSeparator5 = new javax.swing.JSeparator(); + jMenuItem12 = new javax.swing.JMenuItem(); + jMenuItem9 = new javax.swing.JMenuItem(); + jMenu4 = new javax.swing.JMenu(); + jMenuItem19 = new javax.swing.JMenuItem(); + jMenuItem22 = new javax.swing.JMenuItem(); + jMenuItem6 = new javax.swing.JMenuItem(); + + jDialog1.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N + jDialog1.getContentPane().setLayout(new java.awt.GridBagLayout()); + jDialog1.getContentPane().add(jFileChooser1, new java.awt.GridBagConstraints()); + + setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); + setTitle("VisualNQC 1.0 - Lego Mindstorms - New File"); + setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); + setExtendedState(javax.swing.JFrame.MAXIMIZED_BOTH); + setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N + setMinimumSize(new java.awt.Dimension(1018, 725)); + setName("appFrame"); // NOI18N + setPreferredSize(new java.awt.Dimension(1018, 725)); + addWindowListener(new java.awt.event.WindowAdapter() { + public void windowClosing(java.awt.event.WindowEvent evt) { + formWindowClosing(evt); + } + public void windowOpened(java.awt.event.WindowEvent evt) { + formWindowOpened(evt); + } + }); + getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.LINE_AXIS)); + + jSplitPane1.setDividerLocation(131); + jSplitPane1.setLastDividerLocation(131); + + jPanelMainLeft.setBackground(new java.awt.Color(234, 234, 234)); + jPanelMainLeft.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); + jPanelMainLeft.setMinimumSize(new java.awt.Dimension(130, 680)); + jPanelMainLeft.setOpaque(false); + jPanelMainLeft.setPreferredSize(new java.awt.Dimension(130, 680)); + jPanelMainLeft.setLayout(new javax.swing.BoxLayout(jPanelMainLeft, javax.swing.BoxLayout.PAGE_AXIS)); + + TasksLabel.setText("Tasks"); + jPanelMainLeft.add(TasksLabel); + jPanelMainLeft.add(TasksPane); + + FunctionsLabel.setText("Functions"); + jPanelMainLeft.add(FunctionsLabel); + jPanelMainLeft.add(FunctionsPane); + + EventsLabel.setText("Events"); + jPanelMainLeft.add(EventsLabel); + jPanelMainLeft.add(EventsPane); + + EventMonitorsLabel.setText("Event Monitors"); + jPanelMainLeft.add(EventMonitorsLabel); + jPanelMainLeft.add(EventMonitorsPane); + + VariablesLabel.setText("Variables"); + jPanelMainLeft.add(VariablesLabel); + jPanelMainLeft.add(VariablesPane); + + jSplitPane1.setLeftComponent(jPanelMainLeft); + + jSplitPane2.setDividerLocation(-211); + jSplitPane2.setResizeWeight(1.0); + jSplitPane2.setLastDividerLocation(-211); + + jPanelMainCenter.setBackground(new java.awt.Color(234, 234, 234)); + jPanelMainCenter.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); + jPanelMainCenter.setMinimumSize(new java.awt.Dimension(640, 680)); + jPanelMainCenter.setName(""); // NOI18N + jPanelMainCenter.setPreferredSize(new java.awt.Dimension(640, 680)); + jPanelMainCenter.setLayout(new javax.swing.BoxLayout(jPanelMainCenter, javax.swing.BoxLayout.PAGE_AXIS)); + jPanelMainCenter.add(CenterCardPanel); + + DirectionsLabel.setForeground(new java.awt.Color(51, 102, 255)); + DirectionsLabel.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N + DirectionsLabel.setText("Welcome"); + jPanelMainCenter.add(DirectionsLabel); + + jSplitPane2.setLeftComponent(jPanelMainCenter); + + jPanelMainRight.setBackground(new java.awt.Color(234, 234, 234)); + jPanelMainRight.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); + jPanelMainRight.setMaximumSize(new java.awt.Dimension(2147483647, 2147483647)); + jPanelMainRight.setMinimumSize(new java.awt.Dimension(210, 680)); + jPanelMainRight.setOpaque(false); + jPanelMainRight.setPreferredSize(new java.awt.Dimension(210, 680)); + jPanelMainRight.setLayout(new javax.swing.BoxLayout(jPanelMainRight, javax.swing.BoxLayout.PAGE_AXIS)); + + EditingLabel.setText("Editing"); + jPanelMainRight.add(EditingLabel); + + EditingPane.setMinimumSize(new java.awt.Dimension(210, 46)); + EditingPane.setPreferredSize(new java.awt.Dimension(210, 46)); + jPanelMainRight.add(EditingPane); + + IconHelpLabel.setText("Icon Help"); + jPanelMainRight.add(IconHelpLabel); + + IconHelpPane.setMinimumSize(new java.awt.Dimension(210, 30)); + IconHelpPane.setPreferredSize(new java.awt.Dimension(210, 30)); + jPanelMainRight.add(IconHelpPane); + + SinglesLabel.setText("Singles"); + jPanelMainRight.add(SinglesLabel); + + SinglesPane.setMinimumSize(new java.awt.Dimension(210, 110)); + SinglesPane.setPreferredSize(new java.awt.Dimension(210, 250)); + jPanelMainRight.add(SinglesPane); + + BranchesLabel.setText("Branches"); + jPanelMainRight.add(BranchesLabel); + + BranchesPane.setMinimumSize(new java.awt.Dimension(210, 100)); + BranchesPane.setPreferredSize(new java.awt.Dimension(210, 100)); + jPanelMainRight.add(BranchesPane); + + LoopsLabel.setText("Loops"); + jPanelMainRight.add(LoopsLabel); + + LoopsPane.setMinimumSize(new java.awt.Dimension(210, 100)); + LoopsPane.setPreferredSize(new java.awt.Dimension(210, 100)); + jPanelMainRight.add(LoopsPane); + + FunctionsReuseLabel.setText("Functions Reuse"); + jPanelMainRight.add(FunctionsReuseLabel); + + FunctionsReusePane.setMinimumSize(new java.awt.Dimension(210, 35)); + FunctionsReusePane.setPreferredSize(new java.awt.Dimension(210, 35)); + jPanelMainRight.add(FunctionsReusePane); + + jSplitPane2.setRightComponent(jPanelMainRight); + + jSplitPane1.setRightComponent(jSplitPane2); + + getContentPane().add(jSplitPane1); + + jMenuBar1.setBorder(null); + + jMenu1.setBorder(null); + jMenu1.setMnemonic('f'); + jMenu1.setText("File"); + + jMenuItem1.setText("New"); + jMenuItem1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jMenuItem1ActionPerformed(evt); + } + }); + jMenu1.add(jMenuItem1); + + jMenuItem7.setText("Open"); + jMenuItem7.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jMenuItem7ActionPerformed(evt); + } + }); + jMenu1.add(jMenuItem7); + + jMenuItem21.setText("Save"); + jMenuItem21.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jMenuItem21ActionPerformed(evt); + } + }); + jMenu1.add(jMenuItem21); + + jMenuItem2.setText("Save As"); + jMenuItem2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jMenuItem2ActionPerformed(evt); + } + }); + jMenu1.add(jMenuItem2); + + jSeparator1.setForeground(new java.awt.Color(0, 0, 0)); + jMenu1.add(jSeparator1); + + jMenuItem3.setText("Exit"); + jMenuItem3.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jMenuItem3ActionPerformed(evt); + } + }); + jMenu1.add(jMenuItem3); + + jMenuBar1.add(jMenu1); + + jMenu2.setBorder(null); + jMenu2.setMnemonic('e'); + jMenu2.setText("Edit"); + + jMenuItem5.setText("Undo"); + jMenuItem5.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jMenuItem5ActionPerformed(evt); + } + }); + jMenu2.add(jMenuItem5); + + jMenuItem8.setText("Redo"); + jMenuItem8.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jMenuItem8ActionPerformed(evt); + } + }); + jMenu2.add(jMenuItem8); + jMenu2.add(jSeparator2); + + jMenuItem14.setText("Cancel Operation"); + jMenuItem14.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton5ActionPerformed(evt); + } + }); + jMenu2.add(jMenuItem14); + jMenu2.add(jSeparator4); + + jMenuItem13.setText("Set/Hide Grid"); + jMenuItem13.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton4ActionPerformed(evt); + } + }); + jMenu2.add(jMenuItem13); + + jMenuItem10.setText("Modify Grid"); + jMenuItem10.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jMenuItem10ActionPerformed(evt); + } + }); + jMenu2.add(jMenuItem10); + + jMenuBar1.add(jMenu2); + + jMenu5.setMnemonic('s'); + jMenu5.setText("Structure"); + + jMenuItem15.setText("Declare A Variable"); + jMenuItem15.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jMenuItem15ActionPerformed(evt); + } + }); + jMenu5.add(jMenuItem15); + + jMenuItem17.setText("Create Arithmetic Operation"); + jMenuItem17.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jMenuItem17ActionPerformed(evt); + } + }); + jMenu5.add(jMenuItem17); + jMenu5.add(jSeparator3); + + jMenuItem11.setText("Create A Function"); + jMenuItem11.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jMenuItem11ActionPerformed(evt); + } + }); + jMenu5.add(jMenuItem11); + jMenu5.add(jSeparator6); + + jMenuItem16.setText("Create A Task"); + jMenuItem16.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jMenuItem16ActionPerformed(evt); + } + }); + jMenu5.add(jMenuItem16); + jMenu5.add(jSeparator7); + + jMenuItem18.setText("Create An Event"); + jMenuItem18.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jMenuItem18ActionPerformed(evt); + } + }); + jMenu5.add(jMenuItem18); + + jMenuItem20.setText("Create An Event Monitor"); + jMenuItem20.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jMenuItem20ActionPerformed(evt); + } + }); + jMenu5.add(jMenuItem20); + + jMenuBar1.add(jMenu5); + + jMenu6.setMnemonic('d'); + jMenu6.setText("Device"); + + buttonGroupTarget.add(jRadioButtonMenuItemRCX1); + jRadioButtonMenuItemRCX1.setText("RCX 1.0"); + jRadioButtonMenuItemRCX1.setEnabled(false); + jRadioButtonMenuItemRCX1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jRadioButtonMenuItemRCX1ActionPerformed(evt); + } + }); + jMenu6.add(jRadioButtonMenuItemRCX1); + + buttonGroupTarget.add(jRadioButtonMenuItemRCX2); + jRadioButtonMenuItemRCX2.setSelected(true); + jRadioButtonMenuItemRCX2.setText("RCX 2.0"); + jRadioButtonMenuItemRCX2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jRadioButtonMenuItemRCX2ActionPerformed(evt); + } + }); + jMenu6.add(jRadioButtonMenuItemRCX2); + + jMenuBar1.add(jMenu6); + + jMenu3.setBorder(null); + jMenu3.setMnemonic('b'); + jMenu3.setText("Build"); + + jMenuItem4.setText("Create NQC Code"); + jMenuItem4.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jMenuItem4ActionPerformed(evt); + } + }); + jMenu3.add(jMenuItem4); + jMenu3.add(jSeparator5); + + jMenuItem12.setText("Compile and Download"); + jMenuItem12.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jMenuItem12ActionPerformed(evt); + } + }); + jMenu3.add(jMenuItem12); + + jMenuItem9.setText("Compile and Run"); + jMenuItem9.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jMenuItem9ActionPerformed(evt); + } + }); + jMenu3.add(jMenuItem9); + + jMenuBar1.add(jMenu3); + + jMenu4.setBorder(null); + jMenu4.setMnemonic('h'); + jMenu4.setText("Help"); + + jMenuItem19.setText("Introduction"); + jMenuItem19.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jMenuItem19ActionPerformed(evt); + } + }); + jMenu4.add(jMenuItem19); + + jMenuItem22.setText("Show Video"); + jMenuItem22.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jMenuItem22ActionPerformed(evt); + } + }); + jMenu4.add(jMenuItem22); + + jMenuItem6.setText("About"); + jMenuItem6.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jMenuItem6ActionPerformed(evt); + } + }); + jMenu4.add(jMenuItem6); + + jMenuBar1.add(jMenu4); + + setJMenuBar(jMenuBar1); + + setSize(new java.awt.Dimension(1020, 738)); + setLocationRelativeTo(null); + }// //GEN-END:initComponents + + // what to do in the event of the program being initialised + // THE FILE fUNSoftWareConfig.txt is a config file needed to determine whether the user had accessed + // the programmed before. + private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened + this.setExtendedState(javax.swing.JFrame.MAXIMIZED_BOTH); + // Disable first-time user check (for now) +// try +// { +// java.io.FileReader finput = new java.io.FileReader(ConfigFile_Name); +// java.io.BufferedReader inputBuffer = new java.io.BufferedReader(finput); +// String output = inputBuffer.readLine(); +// String tmp_string = new String(); +// if(output.compareTo("New=1") == 0) // only continue if it is valid, check the file header +// { +// javax.swing.JOptionPane.showMessageDialog(this, +// "You are new to " + AppProperties.appName + ", watch the video tutorial by selecting Help -> Show Video", +// AppProperties.appName + " video", +// javax.swing.JOptionPane.INFORMATION_MESSAGE); +// } +// } +// catch(Exception e) +// { +// javax.swing.JOptionPane.showMessageDialog(this, +// "You are new to " + AppProperties.appName + ", watch the video tutorial by selecting Help -> Show Video", +// AppProperties.appName + " video", +// javax.swing.JOptionPane.INFORMATION_MESSAGE); +// try +// { +// java.io.FileWriter filewriter = new java.io.FileWriter(ConfigFile_Name); +// filewriter.write("New=0", 0, 5); +// filewriter.close(); +// } +// catch (Exception er) +// { +// System.out.println("Error: " + e.getMessage()); +// } +// } + }//GEN-LAST:event_formWindowOpened + + // to display a default browser containing the flash video presentation of the program + private void jMenuItem22ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem22ActionPerformed + String url = getAppPath() + "flash_presentation/funTutorial.html"; + + // format the file path string for use in a browser + //url = url.replace(' ', '+'); + + openURL(url); + }//GEN-LAST:event_jMenuItem22ActionPerformed + + /** + * Determines the current path of the application and returns it as a string + * @return The current application path, including the trailing slash, as a string + */ + public String getAppPath(){ + String url = (getClass().getResource("")).getPath(); + int endPos = 0; + + System.out.println("URL1 " + url); + + try{ + url = URLDecoder.decode(url, "UTF-8"); + } catch (UnsupportedEncodingException uee) { + System.out.println("ERROR: UnsupportedEncodingException"); + } + + System.out.println("URL2 " + url); + + + // Get the directory of the jar file or class file + if (url.lastIndexOf("!") >= 0){ + endPos = url.lastIndexOf("/", url.lastIndexOf("!")) + 1; + } else if (url.lastIndexOf("/") > 1) { + endPos = url.lastIndexOf("/") + 1; + } else { + endPos = url.length() - 1; + } + url = url.substring(0, endPos); + + System.out.println("URL3 " + url); + + // NOTE: File "protocol" varies by platform and implementation. + // For examle, the "file:" portion is not included when + // debugging in the NetBeans IDE but is when running java + // Thus, remove one leading character at a time + // and test if the directory exists + while (url.length() > 1 && ! (new File(url)).exists()){ + url = url.substring(1); + } + + // Determine if the resulting directory string exists + if (!(new File(url)).exists()){ + // Default to current directory + url = ""; + } else if (System.getProperty("os.name").startsWith("Windows") + && url.length() > 1 && url.startsWith("/") + && url.charAt(2) == ':'){ + url = url.substring(1); + } + + System.out.println("URL4 " + url); + + return url; + } + + /** + * Determines the current user application path + * - creates the application-specific directory if it does not exist + * @return The current user application path, including the trailing slash, as a string + */ + public String getUserAppPath(){ + String path = System.getProperty("user.home"); + path = path + File.separator + "." + AppProperties.appName + File.separator; + + File userAppPath = new File(path); + if (!userAppPath.exists()){ + userAppPath.mkdirs(); + } + + return path; + } + + // code adapted from www.centerkey.com + public void openURL(String url) { + String errMsg = "Error attempting to launch web browser"; + String osName = System.getProperty("os.name"); + try + { + if (osName.startsWith("Mac OS")) + { + /* Class fileMgr = Class.forName("com.apple.eio.FileManager"); + java.lang.reflect.Method openURL = fileMgr.getDeclaredMethod("openURL", + new Class[] {String.class}); + openURL.invoke(null, new Object[] {"file:///"+url});*/ + Runtime.getRuntime().exec("open file:///"+url); + } + else if (osName.startsWith("Windows")) + { + Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler \"" + url + "\""); + } + else // assume Unix or Linux + { + String[] browsers = { + "firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape", "midori" }; + String browser = null; + for (int count = 0; count < browsers.length && browser == null; count++) + { + if (Runtime.getRuntime().exec( + new String[] {"which", browsers[count]}).waitFor() == 0) + { + browser = browsers[count]; + } + } + if (browser == null) + { + throw new Exception("Could not find web browser"); + } + else + { + Runtime.getRuntime().exec(new String[] {browser, url}); + } + } + } + catch (Exception e) + { + javax.swing.JOptionPane.showMessageDialog(null, errMsg + ":\n" + e.getLocalizedMessage()); + } + } + + + + // for save file, NOT SAVE-AS + private void jMenuItem21ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem21ActionPerformed + if(_Current_Save_Path.compareTo("") != 0) + { + jProgrammingWindow.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR)); + String code = Translator.getAlgorithm(icon_list.getIcons().get(1)); + + java.io.File file = new java.io.File(_Current_Save_Path); + + try + { + java.io.FileWriter filewriter = new java.io.FileWriter(file); + filewriter.write(code, 0, code.length()); + filewriter.close(); + do_state.getCurrentState().setSaveStatus(1); + do_state.getCurrentState().setSaveFilePath(file.getAbsolutePath()); + do_state.getCurrentState().setSaveFileName(file.getName()); + updateFileName(file.getName()); + } + catch (Exception e) + { + System.out.println("Error: " + e.getMessage()); + } + jProgrammingWindow.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); + } + else + { + execute_save(); + } + }//GEN-LAST:event_jMenuItem21ActionPerformed + + + // to handle for an event monitor creation + private void jMenuItem20ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem20ActionPerformed + + if(event_number_tracker.Instance().isEmpty() == true) + { + javax.swing.JOptionPane.showMessageDialog(this, + "There has to be at least 1 event defined.\nPlease define one.", + "Error - No Event", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + else + { + // set up the dialog first + monitorEventDialog me_dialog = new monitorEventDialog(this, null, 0); + me_dialog.pack(); + me_dialog.setLocationRelativeTo(this); + me_dialog.setVisible(true); + + String eventName = me_dialog.getEventMonitorName(); + if(eventName.compareTo("") != 0) // user didnt press cancel + { + monitorEvent mE = _mEvent.Clone(); + mE.setName(eventName); + mE.setLevel(me_dialog.getLevel()); + String aux_name = me_dialog.getAuxiliary(); + if(aux_name != null) // local not global + { + mE.setEventElements(me_dialog.getEventType(), aux_list.Instance().getAuxiliary(aux_name)); + } + else + { + mE.setEventElements(me_dialog.getEventType(), null); + } + + + mE.setMonitoredEvents(me_dialog.getEventsMonitored()); + + aux_list.Instance().addAuxiliary(mE); + + jPanelEventMonitor.insertEvent(mE); + + UndoRedo.update_state(); + DirectionsLabel.setText("Event Monitor successfully created"); + } + } + }//GEN-LAST:event_jMenuItem20ActionPerformed + + // To display an introductory help document + private void jMenuItem19ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem19ActionPerformed + + HelpDialog help_dialog = new HelpDialog(this); + help_dialog.pack(); + help_dialog.setLocationRelativeTo(this); + help_dialog.setVisible(true); + + }//GEN-LAST:event_jMenuItem19ActionPerformed + + + // for undo + private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) { + executeUndo(); + } + + // for redo + private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) { + executeRedo(); + } + + // to handle for an event creation + private void jMenuItem18ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem18ActionPerformed + // set up the dialog first + EventNameDialog ev_dialog = new EventNameDialog(this, null, 0); + ev_dialog.pack(); + ev_dialog.setLocationRelativeTo(this); + ev_dialog.setVisible(true); + + String eventName = ev_dialog.getEventName(); + if(eventName.compareTo("") != 0) + { + Event ev = _Event.Clone(); + + int can_add = event_number_tracker.Instance().addEvent(ev); + if(can_add == 0) + { + ev.setName(eventName); + + Operand threshold_to_pass = ev_dialog.getThreshold(); + ev.setEventElements(ev_dialog.getSource(), ev_dialog.getEventSource(), + ev_dialog.getEventType(), threshold_to_pass); + + jPanelEvent.insertEvent(ev); + + UndoRedo.update_state(); + DirectionsLabel.setText("Event successfully created"); + } + else + { + javax.swing.JOptionPane.showMessageDialog(this, + "Event cannot be created, limit reached (16 events).", + "Error - Event Limit Reached", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + } + }//GEN-LAST:event_jMenuItem18ActionPerformed + + + // to handle for closing the program by clicking the cross button located on the top right hand side of the window + private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing + jMenuItem3ActionPerformed(null); + }//GEN-LAST:event_formWindowClosing + + + // to get the current auxiliary (either a function or a task) + private auxiliary getCurrentAuxiliary() + { + int nid=0; + javax.swing.ButtonGroup bg = radiobuttons.Instance().getButtonGroup(); + java.util.Enumeration enum_ab = bg.getElements(); + javax.swing.JRadioButton jrb = new javax.swing.JRadioButton(); + while(enum_ab.hasMoreElements()) + { + jrb = (javax.swing.JRadioButton)enum_ab.nextElement(); + if(jrb.isSelected()) + { + nid = Integer.parseInt(jrb.getActionCommand()); + break; + } + } + return aux_list.Instance().getAuxiliaries().get(nid); + } + + // for initialising an arithmetic operation + private void jMenuItem17ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem17ActionPerformed + // first check that there at least 1 declared variable aside from the input sensors values which are not to be altered but read + // the declared variable can either be a local or global + + local_var_list lvl = new local_var_list(); + if(getCurrentAuxiliary() instanceof function) + { + function f = (function)getCurrentAuxiliary(); + lvl = f.getLocalVarList(); + } + else if(getCurrentAuxiliary() instanceof task) + { + task t = (task)getCurrentAuxiliary(); + lvl = t.getLocalVarList(); + } + else if(getCurrentAuxiliary() instanceof monitorEvent) + { + monitorEvent e = (monitorEvent)getCurrentAuxiliary(); + if(e.getType().compareTo("Local") == 0) + { + lvl = e.getAuxPoint().getLocalVarList(); + } + } + + if(var_list.Instance().isDefinedVariables() == false && lvl.isEmpty() == true) + { + javax.swing.JOptionPane.showMessageDialog(this, + "There has to be at least 1 non input sensor local or global variable.\nPlease declare one.", + "Error - No Variable", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + else + { + VarOperationDialog dv_dialog = new VarOperationDialog(this, getCurrentAuxiliary()); + dv_dialog.pack(); + dv_dialog.setLocationRelativeTo(this); + dv_dialog.setVisible(true); + + // start creating the arithmetic operation class and its multiple operands + ArithmeticOperation ret_val = dv_dialog.getUserInput(); + if(ret_val != null) // an indication that user did not press cancel + { + // create the ArithOpIcon class, then fill in the ArithmeticOperation class that it will point at + ArithOpIcon icon = _AOIcon.Clone(); + icon.setAO(ret_val); + prepIconHandlers(icon, 1); + UndoRedo.update_state(); + } + } + }//GEN-LAST:event_jMenuItem17ActionPerformed + + // handles a variable's declaration + private void jMenuItem15ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem15ActionPerformed + DeclareVariableDialog dv_dialog = new DeclareVariableDialog(this, 0, null); + dv_dialog.pack(); + dv_dialog.setLocationRelativeTo(this); + dv_dialog.setVisible(true); + String[] ret_val = dv_dialog.getUserInput(); + + if(ret_val[0].compareTo("") != 0) // user didn't press the cancel button + { + variable var = _Var.Clone(); + + var.setName(ret_val[0]); + var.setValue(Integer.parseInt(ret_val[3])); + if(ret_val[1].compareTo("Global") == 0) + { + var.setType(0); + var_list.Instance().addVariable(var); + } + else if(ret_val[1].compareTo("Local") == 0) + { + var.setType(1); + auxiliary a = aux_list.Instance().getAuxiliary(ret_val[2]); + var.setAux(a); + a.addVariable(var); + } + jPanelVar.insertVar(var); + UndoRedo.update_state(); + DirectionsLabel.setText("Variable successfully declared"); + } + }//GEN-LAST:event_jMenuItem15ActionPerformed + + // to handle the menu items to create a task including its radio buttons on the task pallette. + private void jMenuItem16ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem16ActionPerformed + // set up the dialog first + TaskNameDialog tsk_dialog = new TaskNameDialog(this, "", 0); + tsk_dialog.pack(); + tsk_dialog.setLocationRelativeTo(this); + tsk_dialog.setVisible(true); + + String taskName = tsk_dialog.getUserInput(); + if(taskName.compareTo("") != 0) + { + createTask(taskName); + } + }//GEN-LAST:event_jMenuItem16ActionPerformed + + // to create a task + private void createTask(String taskName) + { + task tsk = _Task.Clone(); + + aux_list.Instance().addAuxiliary(tsk); + + if(taskName.compareTo("") == 0) + { + tsk.setName("task"+tsk.getNumId()); + } + else + { + tsk.setName(taskName); + } + + jPanelTask.insertTask(tsk); + + UndoRedo.update_state(); + DirectionsLabel.setText("Task successfully created"); + } + + + // ------------------------------------------------------------------------------------ + // ------------------------------------------------------------------------------------ + // >>> THE MENU ITEM HANDLERS + // ------------------------------------------------------------------------------------ + // ------------------------------------------------------------------------------------ + + // This menu is auxiliary, it is only to open a pop up window outlining the "About and Licenses" + // of this program + private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed + javax.swing.JOptionPane.showMessageDialog(jPanelMainCenter, + (new javax.swing.ImageIcon(getClass().getResource("/icons/logos/about.png"))), + AppProperties.appNameVersion + " -- About", + javax.swing.JOptionPane.PLAIN_MESSAGE); + }//GEN-LAST:event_jMenuItem6ActionPerformed + + // to handle for running the previously created NQC file which in turn would run the LEGO Mindstorms + // NQC was developed by Dave Baum + private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem9ActionPerformed + buildAndDownload(true); + }//GEN-LAST:event_jMenuItem9ActionPerformed + + // NQC compiler created by Dave Baum + // this action method simply download the program into the RCX without running it + private void jMenuItem12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem12ActionPerformed + buildAndDownload(false); + }//GEN-LAST:event_jMenuItem12ActionPerformed + + // helper method that builds NQC Code and downloads it + private void buildAndDownload(boolean autoRun) + { + int check = compileProgram(); + if(check == 0) + { + try{ + String[] cmd = new String[3]; + String NQCCommand = "nqc -T" + AppProperties.getDeviceID() + " -d " + AppProperties.appCodeFileName; + if (autoRun) + { + NQCCommand += " -run"; + } + + String osName = System.getProperty("os.name"); + System.out.println(osName); + // to enable platform independence + if(osName.compareTo("Windows 95") == 0 || osName.compareTo("Windows 98") == 0) + { + cmd[0] = "command.com" ; + cmd[1] = "/C" ; + cmd[2] = NQCCommand; + } + // Other, non-legacy Windows platforms (e.g. CE, NT, 2000, XP, Vista) use "cmd.exe" + else if(osName.startsWith("Windows")) + { + cmd[0] = "cmd.exe" ; + cmd[1] = "/C" ; + cmd[2] = NQCCommand; + } + else if(osName.compareTo("Linux") == 0) + { + cmd[0] = "/bin/sh" ; + cmd[1] = "-c" ; + cmd[2] = NQCCommand; + } + else if(osName.compareTo("Mac OS X") == 0) + { + cmd[0] = "/bin/sh" ; + cmd[1] = "-c"; + cmd[2] = NQCCommand; + } + Runtime rt = Runtime.getRuntime(); + + Process proc = rt.exec(cmd, null, new File(getUserAppPath())); + int exitVal = proc.waitFor(); + if(exitVal != 0) + { + DirectionsLabel.setText("Error encountered in the downloading process"); + } + else + { + DirectionsLabel.setText("Your program has been downloaded successfully"); + } + } + catch(Throwable t) + { + t.printStackTrace(); + } + } + } + + // helper method that creates NQC Code + private void createNQCFile() + { + int err = 0; + String NQCcode = Translator.getRCXNQCCode(1); // the string representation of NQC + String url_save = do_state.getCurrentState().returnSaveFilePath(); + String filename = do_state.getCurrentState().returnSaveFileName(); + + url_save = url_save.substring(0, url_save.lastIndexOf(filename)); + url_save += filename + ".nqc"; + java.io.File file = new java.io.File(url_save); + try + { + java.io.FileWriter filewriter = new java.io.FileWriter(file); + filewriter.write(NQCcode, 0, NQCcode.length()); + filewriter.close(); + } + catch (Exception e) + { + System.out.println("Error: " + e.getMessage()); + DirectionsLabel.setText("NQC Error Encountered in the Compilation Process"); + err = 1; + } + if(err == 0) + { + DirectionsLabel.setText("NQC code created successfully."); + } + } + + // method that handles the compiling or translating the program into pseudocode then into NQC which in turn will + // be executed using the NQC compiler + private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed + + if(do_state.getCurrentState().returnSaveStatus() == 0) + { + int user_choice; + user_choice=javax.swing.JOptionPane.showConfirmDialog(jPanelMainCenter, + "Current work not yet saved, you need to save your work\nbefore creating NQC code out of it. Save file?", + "Current work not saved", + javax.swing.JOptionPane.OK_CANCEL_OPTION); + if(user_choice == javax.swing.JOptionPane.CANCEL_OPTION) + { + // return to programming window + } + else if(user_choice == javax.swing.JOptionPane.OK_OPTION) + { + // save the file first + int r = 1; + if(_Current_Save_Path.compareTo("") != 0) + { + jProgrammingWindow.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR)); + String code = Translator.getAlgorithm(icon_list.getIcons().get(1)); + + java.io.File file = new java.io.File(_Current_Save_Path); + + try + { + java.io.FileWriter filewriter = new java.io.FileWriter(file); + filewriter.write(code, 0, code.length()); + filewriter.close(); + do_state.getCurrentState().setSaveStatus(1); + do_state.getCurrentState().setSaveFilePath(file.getAbsolutePath()); + do_state.getCurrentState().setSaveFileName(file.getName()); + updateFileName(file.getName()); + } + catch (Exception e) + { + System.out.println("Error: " + e.getMessage()); + r = 0; + } + jProgrammingWindow.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); + } + else + { + r = execute_save(); + } + if(r == 1) + { + createNQCFile(); + } + } + } + else + { + createNQCFile(); + } + }//GEN-LAST:event_jMenuItem4ActionPerformed + + // to edit the size of the grid (distance between grid intersections) + private void jMenuItem10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem10ActionPerformed + grid_dialog = new GridDialog(this, Constants.gridDistanceX, Constants.gridDistanceY); + grid_dialog.pack(); + grid_dialog.setLocationRelativeTo(this); + grid_dialog.setVisible(true); + int[] grid_sizes = grid_dialog.getUserInput(); + + // preserve the old value for shifting values + int old_dx = Constants.gridDistanceX; + int old_dy = Constants.gridDistanceY; + +// distanceX = grid_sizes[0]; + Constants.setGridDistanceX(grid_sizes[0]); + +// distanceY = grid_sizes[1]; + Constants.setGridDistanceY(grid_sizes[1]); + + java.util.Vector ics = icon_list.getIcons(); + int shiftX = 0; + int shiftY = 0; + if(old_dx != Constants.gridDistanceX || old_dy != Constants.gridDistanceY) + { + for(int i = 1; i < ics.size(); i++) + { + Icon tmp = ics.get(i); + if(tmp != null) + { + // shift its coordinate + int hor_seg = (tmp.getCoordinate().getX()+(tmp.getWidth()/2)) / old_dx; // # segments horizontally + int cur_x = hor_seg * Constants.gridDistanceX; + int old_x = hor_seg * old_dx; + shiftX = cur_x - old_x; + int new_x = tmp.getCoordinate().getX() + shiftX; + + // now do the Y coord + int ver_seg = (tmp.getCoordinate().getY()+(tmp.getHeight()/2)) / old_dy; // # segments horizontally + int cur_y = ver_seg * Constants.gridDistanceY; + int old_y = ver_seg * old_dy; + shiftY = cur_y - old_y; + int new_y = tmp.getCoordinate().getY() + shiftY; + + coord co = new coord(new_x, new_y); + tmp.setCoordinate(co); + tmp.setBounds(co.getX(), co.getY(), tmp.getWidth(), tmp.getHeight()); + } + } + } + // update all tabbed programming windows +// int lim = jPanel13.getComponentCount(); + int lim = CenterCardPanel.getComponentCount(); + for(int i = 1; i < lim; i++) // skip the empty one + { +// javax.swing.JPanel jp = (javax.swing.JPanel)jPanel13.getComponent(i); + javax.swing.JPanel jp = (javax.swing.JPanel)CenterCardPanel.getComponent(i); + javax.swing.JScrollPane jsp = (javax.swing.JScrollPane)jp.getComponent(0); + ProgWindow pw = (ProgWindow)(jsp.getViewport().getView()); + pw.resizeProgWindow(jsp); + jsp.repaint(); + jsp.revalidate(); + } + repaint(); + validate(); + }//GEN-LAST:event_jMenuItem10ActionPerformed + + // to handle redo + private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed + executeRedo(); + }//GEN-LAST:event_jMenuItem8ActionPerformed + + // to handle the undo operation + private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed + executeUndo(); + }//GEN-LAST:event_jMenuItem5ActionPerformed + + // This method simply quits the system, but ensuring user is aware whether the current work has been saved + private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed + int user_choice; + if(do_state.getCurrentState() != null && do_state.getCurrentState().returnSaveStatus() == 0 + && icon_list.getIcons().size() > 3) // not yet saved, then ask user to save first + { + user_choice=javax.swing.JOptionPane.showConfirmDialog(jPanelMainCenter, + "Current work not yet saved, save file before quitting?", + "Current work not saved", + javax.swing.JOptionPane.YES_NO_CANCEL_OPTION); + if(user_choice == javax.swing.JOptionPane.CANCEL_OPTION) + { + // return to programming window + } + else if(user_choice == javax.swing.JOptionPane.YES_OPTION) + { + // save the file first + int r = execute_save(); + if(r == 1) + { + System.exit(0); + } + } + else if(user_choice == javax.swing.JOptionPane.NO_OPTION) + { + System.exit(0); + } + } + else + { + System.exit(0); + } + }//GEN-LAST:event_jMenuItem3ActionPerformed + + // This method handles for when "Save As" menu has been executed + // This should pop up a dialog window asking the user to name and select where to save the file + private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed + execute_save(); + }//GEN-LAST:event_jMenuItem2ActionPerformed + + // The following method open up a file chooser for the user to load a specific file + private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed + // ask the user first whether to save the existing unsaved work + int user_choice; + int allowed = 0; // initially not allowed to proceed + if(do_state.getCurrentState().returnSaveStatus() == 0) // not yet saved, then ask user to save first + { + user_choice=javax.swing.JOptionPane.showConfirmDialog(jPanelMainCenter, + "Current work not yet saved, save file before continuing?", + "Current work not saved", + javax.swing.JOptionPane.YES_NO_CANCEL_OPTION); + if(user_choice == javax.swing.JOptionPane.YES_OPTION) + { + // save the file first + int r = execute_save(); + if(r == 1) + { + allowed = 1; + } + } + else if(user_choice == javax.swing.JOptionPane.NO_OPTION) + { + allowed = 1; + } + } + else + { + allowed = 1; + } + if(allowed == 1) + { + int ret_val = jFileChooser1.showOpenDialog(jDialog1); + String output = new String(); + if (ret_val == javax.swing.JFileChooser.APPROVE_OPTION) { + jProgrammingWindow.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR)); + java.io.File file = jFileChooser1.getSelectedFile(); + try + { + java.io.FileReader finput = new java.io.FileReader(file); + java.io.BufferedReader inputBuffer = new java.io.BufferedReader(finput); + output += inputBuffer.readLine(); + String tmp_string = new String(); + // only continue if it is valid, check the file header + if(output.compareTo(AppProperties.getProgramTypeID()) == 0) + { + while ((tmp_string = inputBuffer.readLine()) != null) + { + output += "\n"; + output += tmp_string; + } + finput.close(); + executeLoad(output); + updateFileName(file.getName()); + UndoRedo.update_state(); + do_state.getCurrentState().setSaveStatus(1); + do_state.getCurrentState().setSaveFilePath(file.getAbsolutePath()); + do_state.getCurrentState().setSaveFileName(file.getName()); + _Current_Save_Path = file.getAbsolutePath(); + jPanel7onListeners(); + } + else + { + finput.close(); + javax.swing.JOptionPane.showMessageDialog(jPanelMainCenter, + "File invalid or incompatible, please reselect the file", + "File Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + } + catch(Exception e) + { + System.out.println("Error: " + e.getMessage()); + javax.swing.JOptionPane.showMessageDialog(jPanelMainCenter, + "File invalid or incompatible, please reselect the file", + "File Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + // reset ALL +// restartProgWindow(1); + restartProgWindow(0); + } + } + jProgrammingWindow.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); + } + }//GEN-LAST:event_jMenuItem7ActionPerformed + + // to restart a program entirely + private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed + // Have to ensure that the current work is saved or unsaved under the consent of the user + int user_choice; + int allowed = 0; // initially not allowed to proceed + if(do_state.getCurrentState() != null && do_state.getCurrentState().returnSaveStatus() == 0) // not yet saved, then ask user to save first + { + user_choice=javax.swing.JOptionPane.showConfirmDialog(jPanelMainCenter, + "Current work not yet saved, save file before continuing?", + "Current work not saved", + javax.swing.JOptionPane.YES_NO_CANCEL_OPTION); + if(user_choice == javax.swing.JOptionPane.YES_OPTION) + { + // save the file first + int r = execute_save(); + if(r == 1) + { + allowed = 1; + } + } + else if(user_choice == javax.swing.JOptionPane.NO_OPTION) + { + allowed = 1; + } + } + else + { + allowed = 1; + } + + if(allowed == 1) + { + updateFileName("New File"); + restartProgWindow(0); + _Current_Save_Path = new String(); + UndoRedo.update_state(); + } + }//GEN-LAST:event_jMenuItem1ActionPerformed + + + // this method will ask the user to click on the programming window for the beginning of the click, + // afterwards the user would need to click on the second position for the ending of the function + private void jMenuItem11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem11ActionPerformed + // creating functions + + jPanel7offListeners(); + + DirectionsLabel.setText("Click on the programming window for the beginning of the function"); + + jProgrammingWindow.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt2) { + FunctionMouseClicked1(evt2); + } + }); + }//GEN-LAST:event_jMenuItem11ActionPerformed + + // ------------------------------------------------------------------------------------ + // >>> END OF MENU ITEM HANDLERS + // ------------------------------------------------------------------------------------ + // ------------------------------------------------------------------------------------ + + // this the method that will add another listener to accept the end of the function + private void FunctionMouseClicked1(java.awt.event.MouseEvent evt) + { + Icon tic = jProgrammingWindow.findIcon(evt.getX(), evt.getY(), 1); // right of icon + Icon tic2 = jProgrammingWindow.findIcon(evt.getX(), evt.getY(), 0); // left of icon + + // instead has to find a mid point between tic and tic2 + + int xpos = 0; + if(tic2 != null && tic != null) + { + xpos = gridcalculation.midPoint(tic2.getCoordinate(), tic.getCoordinate()); + } + + int ypos = gridcalculation.calculateY(evt.getY()); + coord co = new coord(xpos, ypos); + + if(co.getX() < (jProgrammingWindow.getStartIcon().getCoordinate().getX()+jProgrammingWindow.getStartIcon().getWidth()/2) || + co.getX() > (jProgrammingWindow.getEndIcon().getCoordinate().getX()+jProgrammingWindow.getEndIcon().getWidth()/2) || + tic == null || tic2 == null || tic instanceof joinEndBranchIcon) + { + // if the desired place for the new icon is taken by another icon, make sure + // the new icon could not be to the left of the starting icon or to the right of the + // ending icon + + javax.swing.JOptionPane.showMessageDialog(jPanelMainCenter, + "Selection invalid, please reselect the position", + "Selection Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + DirectionsLabel.setText(readyPrompt); + jPanel7onListeners(); + } + else + { + DirectionsLabel.setText("Click on the programming window to position the end of the function"); + final int xx = evt.getX(); + final int yy = evt.getY(); + + jPanel7offListeners(); + + jProgrammingWindow.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt2) { + + // the handler for this repeat icon + createFunction(xx, yy, evt2); + + // reset the listeners + jPanel7onListeners(); + } + }); + } + } + + // now that both beginning and end of the function has been defined, create the function + private void createFunction(int xpos, int ypos, java.awt.event.MouseEvent evt2) + { + coord tmp_co = new coord(evt2.getX(), evt2.getY()); + + // for beginning icon + Icon tic = jProgrammingWindow.findIcon(xpos, ypos, 1); // right of icon + Icon tic2 = jProgrammingWindow.findIcon(xpos, ypos, 0); // left of icon + + xpos = gridcalculation.calculateXright(xpos); + ypos = gridcalculation.calculateY(ypos); + + // for ending icon + Icon tic3 = jProgrammingWindow.findIcon(evt2.getX(), evt2.getY(), 1); // right of icon + Icon tic4 = jProgrammingWindow.findIcon(evt2.getX(), evt2.getY(), 0); // left of icon + + int xpos2 = gridcalculation.calculateXright(evt2.getX()); + int ypos2 = gridcalculation.calculateY(evt2.getY()); + + // for viewport + int v_x = xpos; + int v_y = ypos; + + + // for checking that all icons to be put within this new repeat should have the same parent icon + int allowed = 1; // initially zero for allowed (not allowed = 0) + if(ypos == ypos2 && xpos2 >= xpos) + { + // check for the enclosed icons + Icon tm_p = null; + int x = xpos; + int x_limit = xpos2; + while(x < x_limit) + { + java.awt.Component c = jProgrammingWindow.getComponentAt(x, ypos); + if(c instanceof Icon) + { + Icon ico = (Icon) c; + if(ico instanceof joinLoopIcon) + { + ico = ico.getBottomNeighbour(); + x = gridcalculation.calculateXright(ico.getEndIcon().getCoordinate().getX()); + if(x >= xpos2 && xpos <= gridcalculation.calculateXright(ico.getBeginIcon().getCoordinate().getX())) + { + allowed = 0; + break; + } + } + else if(ico instanceof branchIcon) + { + x = gridcalculation.calculateXright(ico.getEndBranch().getCoordinate().getX()); + } + if(tm_p == null) + { + tm_p = ico.getParentIcon(); + } + else + { + if(ico.getParentIcon().getId() != tm_p.getId()) + { + allowed = 0; + break; + } + } + } + x += Constants.gridDistanceX; + } + } + else + { + allowed = 0; + } + if(allowed == 1) + { + if(tic instanceof joinLoopIcon && tic.getBottomNeighbour().getEndIcon().getId() == tic.getId() && + tic4 instanceof joinLoopIcon && tic4.getBottomNeighbour().getBeginIcon().getId() == tic4.getId()) + { + allowed = 1; + } + else + { + if(tic instanceof joinLoopIcon && tic.getBottomNeighbour().getEndIcon().getId() == tic.getId()) + { + allowed = 0; + } + if(tic4 instanceof joinLoopIcon && tic4.getBottomNeighbour().getBeginIcon().getId() == tic4.getId()) + { + allowed = 0; + } + } + } + + if(xpos == xpos2) // special override, if this repeat meant to start empty, it will be allowed no matter where it is + { + allowed = 1; + } + + if(tmp_co.getX() < (jProgrammingWindow.getStartIcon().getCoordinate().getX()+jProgrammingWindow.getStartIcon().getWidth()/2) || + tmp_co.getX() > (jProgrammingWindow.getEndIcon().getCoordinate().getX()+jProgrammingWindow.getEndIcon().getWidth()/2) || + tic == null || tic2 == null || tic3 == null || tic4 == null || allowed == 0 || tic3 instanceof joinEndBranchIcon) + { + // if the desired place for the new icon is taken by another icon, make sure + // the new icon could not be to the left of the starting icon or to the right of the + // ending icon + + javax.swing.JOptionPane.showMessageDialog(jPanelMainCenter, + "Selection invalid, please reselect the position", + "Selection Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + DirectionsLabel.setText(readyPrompt); + } + else + { + // set up the dialog first + FunctionNameDialog func_dialog = new FunctionNameDialog(this, "", 0); + func_dialog.pack(); + func_dialog.setLocationRelativeTo(this); + func_dialog.setVisible(true); + + String[] functionName = func_dialog.getUserInput(); + local_var_list lvl = func_dialog.getArgumentsInput(); + + if(functionName != null && functionName[0].compareTo("") != 0) // user didn't press cancel, then go ahead + { + // establish the new links between the old members, new members, old parent and new parent + java.util.Vector ics = new java.util.Vector(); + Icon left_icon; // = new Icon(); + Icon right_icon; // = new Icon(); + left_icon = tic2; + right_icon = tic3; + Icon ic = new Icon(); + icon_list.addIcon(ic); + jProgrammingWindow.addIcon(ic); + ic.setCoordinate(tic3.getCoordinate()); + jProgrammingWindow.setUpIconParent(ic, tic2, tic3); + if(tic2 instanceof joinLoopIcon) + { + if(tic2.getParentIcon().getId() != ic.getParentIcon().getId()) + { + left_icon = tic2.getBottomNeighbour(); + } + } + else if(tic2 instanceof joinEndBranchIcon) + { + left_icon = tic2.getBranchIcon(); + } + if(tic3 instanceof joinLoopIcon && tic3.getParentIcon().getId() != ic.getParentIcon().getId()) + { + + right_icon = tic3.getBottomNeighbour(); + } + + ic.getParentIcon().delMember(ic); + jProgrammingWindow.deleteIcon(ic); + icon_list.delIcon(ic); + + ics = jProgrammingWindow.getIconsToChange(left_icon, right_icon); + + functionIcon Ifunc = _Funcby.Clone(); + + function fu = _Funct.Clone(); + fu.setMembers(ics); + // to set the arguments + fu.setLocalVarList(lvl); + java.util.Vector vect_var = lvl.getVariables(); + for(int i=1; i ics) + { + for(int i=0; i enum_ab = bg.getElements(); + javax.swing.JRadioButton jrb; + while(enum_ab.hasMoreElements() == true) + { + jrb = (javax.swing.JRadioButton)enum_ab.nextElement(); + if(jrb.isSelected() == true) + { + name = jrb.getText(); + radioButtonCommand = jrb.getActionCommand(); + break; + } + } + + // reset all variables + jPanelFunction.getTabbedWinMan().panels_reset(); + + reset(); + resetVars(); + + String algo = to_change_to.returnState(); + algo = algo.substring(algo.indexOf("start")); + algo = algo.substring(algo.indexOf("\n")+1); + addOntoProgWindow(algo); + UndoRedo.updateRedoUndoButtons(); + + auxiliary tmp = aux_list.Instance().getAuxiliary(name); + if(tmp == null) + { + radioButtonCommand = "0"; + } + else + { + radioButtonCommand = Integer.toString(tmp.getNumId()); + } + + // to maintain the current's panel view if possible + bg = radiobuttons.Instance().getButtonGroup(); + enum_ab = bg.getElements(); + + if(tmp != null) + { + setProgrammingWindow(tmp.getPanel(), tmp.getScroller(), tmp.getProgWindow()); + + while(enum_ab.hasMoreElements() == true) + { + jrb = (javax.swing.JRadioButton)enum_ab.nextElement(); + + if(jrb.getText().compareTo(name) == 0) + { + jPanelFunction.getTabbedWinMan().displayPanel(radioButtonCommand); + jrb.setSelected(true); + break; + } + } + } + else + { + jPanelTask.getTabbedWinMan().displayPanel("1"); + ((javax.swing.JRadioButton)jPanelTask.getComponent(0)).setSelected(true); + } + } + repaint(); + validate(); + } + + // the ultimate small method that does big thing !! :P + // this method pretty much creates an NQC file which then will be run to move the RCX robot + private int compileProgram() + { + // Check that the program's current state has been saved + String NQCcode = Translator.getRCXNQCCode(1); // the string representation of NQC + java.io.File file = new java.io.File(getUserAppPath() + AppProperties.appCodeFileName); + try + { + java.io.FileWriter filewriter = new java.io.FileWriter(file); + filewriter.write(NQCcode, 0, NQCcode.length()); + filewriter.close(); + return 0; + } + catch (Exception e) + { + System.out.println("Error: " + e.getMessage()); + DirectionsLabel.setText("NQC Error Encountered in the Compilation Process"); + } + + return 0; // default is no error + } + + + // this method handles the click on the function combo box to then duplicate the specified function + private void FuncComboBoxActionPerformed(java.awt.event.ActionEvent evt) + { + // set up its attributes first + javax.swing.JComboBox jcb = (javax.swing.JComboBox)evt.getSource(); + + if(jcb.getSelectedItem() instanceof javax.swing.JMenuItem) + { + final functionIcon func = _Funcby.Clone(); + javax.swing.JMenuItem selected = (javax.swing.JMenuItem)jcb.getSelectedItem(); + String ss = selected.getActionCommand(); + int func_pos = Integer.parseInt(ss); // the num id of the function + + function tmp_func = (function)(aux_list.Instance().getAuxiliaries().get(func_pos)); + + auxiliary current_auxiliary = getCurrentAuxiliary(); + + if(func_pos == current_auxiliary.getNumId()) + { + javax.swing.JOptionPane.showMessageDialog(jPanelMainCenter, + "A function cannot be called within itself.\nReselect other tasks or functions.", + "Function Call Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + DirectionsLabel.setText(readyPrompt); + } + else if(current_auxiliary instanceof function && ((function)current_auxiliary).getLevel() <= tmp_func.getLevel()) + { + javax.swing.JOptionPane.showMessageDialog(jPanelMainCenter, + "A function cannot be called from a lower or equal level function.\nReselect other tasks or functions.", + "Function Call Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + DirectionsLabel.setText(readyPrompt); + } + else if(current_auxiliary instanceof monitorEvent && ((monitorEvent)current_auxiliary).getLevel() <= tmp_func.getLevel()) + { + javax.swing.JOptionPane.showMessageDialog(jPanelMainCenter, + "A function cannot be called from a lower or equal level event monitor.\n", + "Function Call Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + DirectionsLabel.setText(readyPrompt); + } + else + { + func.setNumId(tmp_func.getNumId()); + func.setName(tmp_func.getName()); + func.setFunction(tmp_func); + + func.setImage(); + + // prompt the user to input the value for arguments in the function call + + java.util.Vector ret_val; + if(tmp_func.getArguments().size() > 0) + { + FunctionArgumentDialog fad = new FunctionArgumentDialog(this, tmp_func, getCurrentAuxiliary(), null); + fad.pack(); + fad.setLocationRelativeTo(this); + fad.setVisible(true); + + ret_val = fad.getUserInput(); + } + else + { + ret_val = new java.util.Vector(); + } + + + if(ret_val != null) // user did not press cancel + { + // set the arguments in the functionIcon first + func.setArguments(ret_val); + + DirectionsLabel.setText("Click on the programming window to position the icon"); + jPanel7offListeners(); + + jProgrammingWindow.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt2) { + + jPanel7MouseClicked2(evt2, func, 1); + + // reset the listeners + jPanel7onListeners(); + } + }); + } + } + } + } + + + // the method handles for the insertion of an object or branch icon + private void iconMouseClicked(java.awt.event.MouseEvent evt, Icon icon, int type) { + if(evt.getButton() != 3) // not a right click, right click is for help pop up menu + { + auxiliary current_auxiliary = getCurrentAuxiliary(); + if(current_auxiliary instanceof monitorEvent && icon instanceof startEvent) + { + javax.swing.JOptionPane.showMessageDialog(this, + "An event cannot call another event.\nOnly insert an event call inside a task or a function.", + "Error - Nested Events", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + else if(icon instanceof BarithmeticIcon) + { + if(type == 1) + { + ArithComparatorDialog ACD = new ArithComparatorDialog(this, getCurrentAuxiliary(), null); + ACD.pack(); + ACD.setLocationRelativeTo(this); + ACD.setVisible(true); + + NestedOperation res = ACD.getExpression(); + if(res != null) // user didn't press cancel + { + BarithmeticIcon tmp_icon = (BarithmeticIcon) icon; + tmp_icon.setExpression(res); + prepIconHandlers(icon, type); + } + } + else + { + prepIconHandlers(icon, type); + } + } + else + { + prepIconHandlers(icon, type); + } + } + } + + // the method handles for the insertion of a loop icon + private void iconLoopMouseClicked(java.awt.event.MouseEvent evt, Icon icon, int type) { + if(evt.getButton() != 3) // not a right click, right click is for help pop up menu + { + if(icon instanceof arithmeticLoopIcon) + { + if(type == 1) + { + ArithComparatorDialog ACD = new ArithComparatorDialog(this, getCurrentAuxiliary(), null); + ACD.pack(); + ACD.setLocationRelativeTo(this); + ACD.setVisible(true); + + NestedOperation res = ACD.getExpression(); + if(res != null) // user didn't press cancel + { + arithmeticLoopIcon tmp_icon = (arithmeticLoopIcon) icon; + tmp_icon.setExpression(res); + prepLoopIconHandlers(icon, type); + } + } + else + { + prepLoopIconHandlers(icon, type); + } + } + else + { + prepLoopIconHandlers(icon, type); + } + } + } + + // The following method open up a file chooser for the user to load a specific file + // THE METHOD to finish up a load operation by adding icons onto programming window as indicated by a string + // representation of an fUNSoftWare save file + // The initial checking of the file header has been done in the function that called this function + private void executeLoad(String code) + { + // java.util.StringTokenizer st = new java.util.StringTokenizer(code); + // String line = new String(); + int error = 0; // no error encountered in reading the file if = 0, if error = 1, there is a syntax error in the save file + + if(code.indexOf("start") == -1 || code.indexOf("endprogram") == -1) // if test is passed then introduce begin and end icon + { + javax.swing.JOptionPane.showMessageDialog(jPanelMainCenter, + "Error encountered while reading the file,\nplease reselect the file", + "Error in file reading", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + else + { + // restart + restartProgWindow(1); + + // now skip until the first member of this start icon + code = code.substring(code.indexOf("start")); + code = code.substring(code.indexOf("\n")+1); + + error = addOntoProgWindow(code); + + task tmp = (task)(aux_list.Instance().getAuxiliaries().get(1)); + setProgrammingWindow(tmp.getPanel(), tmp.getScroller(), tmp.getProgWindow()); + + radiobuttons rb = radiobuttons.Instance(); + javax.swing.ButtonGroup group = rb.getButtonGroup(); + tmp.getTaskWindow().getTabbedWinMan().displayPanel("1"); + group.getElements().nextElement().setSelected(true); + ((javax.swing.JRadioButton)jPanelTask.getComponent(0)).setSelected(true); + repaint(); + validate(); + + if(error == 1) + { + javax.swing.JOptionPane.showMessageDialog(jPanelMainCenter, + "Error encountered while reading the file,\nplease reselect the file", + "Error in file reading", + javax.swing.JOptionPane.WARNING_MESSAGE); + // reset all variables + restartProgWindow(1); + } + } + } + + + // the method that automatically adds the icons and wires onto the programming window + // in accordance to a save file, the second argument is the icon to be used as the right neighbour of the + // latest inserted icon in the reverse translation process + private int addOntoProgWindow(String code) + { + int error = 0; + String line = new String(); // to read per line + String argument = new String(); // to be passed along to read a chunk of code (for branches and loops) + + // now code will contain only the elements enclosed by the GREEN icon + if(code.indexOf("endprogram") == 0) // no elements enclosed by these two RED and GREEN icons + { + return 0; + } + // get the tasks and functions + java.util.Vector ss = Translator.getTFTags(code.substring(0, code.indexOf("endprogram")-1)); + + if(ss == null) + { + return 1; // error encountered + } + + for(int i=0; i icl = icons_list.Instance().getIcons(); + for(int i=1; i eventAtt = Translator.getEventMonitorAtt(code.substring(0, code.indexOf("\n"))); + String event_name = Translator.getEventMonitorName(code); + code = code.substring(code.indexOf(beginTag)+beginTag.length()+1); + + // before continuing, gotta initialise the event monitor's attributes first + monitorEvent evt = _mEvent.Clone(); + aux_list.Instance().addAuxiliary(evt); + + evt.setName(event_name); + evt.setLevel(Integer.parseInt(eventAtt.get(2))); + auxiliary to_be_passed; + if(eventAtt.get(3).compareTo(".") == 0) + { + to_be_passed = null; + } + else + { + to_be_passed = aux_list.Instance().getAuxiliary(eventAtt.get(3)); + } + + evt.setEventElements(eventAtt.get(1), to_be_passed); + + java.util.Vector monitored = new java.util.Vector(); + for(int i=4; i 0) + { + code = code.substring(0, code.indexOf(endTag)-1); + + java.util.Vector ss = Translator.getOBLTags(code); + + jProgrammingWindow = evt.getProgWindow(); + jScrollPane1 = evt.getScroller(); +// jPanel18 = evt.getPanel(); + + if(ss == null) + { + return 1; // error encountered + } + for(int i=0; i 0) + { + code = code.substring(0, code.indexOf(endTag)-1); + + java.util.Vector ss = Translator.getOBLTags(code); + + jProgrammingWindow = tmp_tsk.getProgWindow(); + jScrollPane1 = tmp_tsk.getScroller(); +// jPanel18 = tmp_tsk.getPanel(); + + if(ss == null) + { + return 1; // error encountered + } + for(int i=0; i 0) + { + code = code.substring(0, code.indexOf(endTag)-1); + + java.util.Vector ss = Translator.getOBLTags(code); + + // before continuing, gotta initialise the function's attributes first + + function tmp_func = (function)al.getAuxiliary(function_att[0]); + Icon tic = tmp_func.getEndIcon(); + jProgrammingWindow = tmp_func.getProgWindow(); + jScrollPane1 = tmp_func.getScroller(); +// jPanel18 = tmp_func.getPanel(); + + if(ss == null) + { + return 1; // error encountered + } + for(int i=0; i error = 1 + String if_tag = Translator.getIfTag(code); + String endif_tag = Translator.getEndIfTag(code); + String else_tag = Translator.getElseTag(code); + String endelse_tag = Translator.getEndElseTag(code); + String if_line = new String(); + String else_line = new String(); + if(if_tag == null || endif_tag == null || else_tag == null || endelse_tag == null) + { + return 1; // error encountered + } + + // insert the branch icon + Icon icon = Translator.getIcon(code, a); + Icon tic2 = tic.getLeftNeighbour(); // left of icon + + // instead has to find a mid point between tic and tic2 + + int xpos = 0; + if(tic2 != null && tic != null) + { + xpos = gridcalculation.midPoint(tic2.getCoordinate(), tic.getCoordinate()); + } + + int ypos = gridcalculation.calculateY(tic.getCoordinate().getY()+(tic.getHeight()/2)); + coord tmp_co = new coord(xpos, ypos); + coord co = gridcalculation.computeCoord(icon, tmp_co); + icon.setCoordinate(co); + insertBranchIcon(icon, tic, tic2); + + java.util.Vector ss = new java.util.Vector(); + String line = new String(); + + // do the if + + if_line = code.substring(code.indexOf(if_tag)); + code = code.substring(code.indexOf(if_tag)); + + if(if_tag.length()+1 < code.indexOf(endif_tag)-1) + { + if_line = code.substring(if_tag.length()+1, code.indexOf(endif_tag)-1); + ss = Translator.getOBLTags(if_line); + if(ss == null) + { + return 1; // error encountered + } + + for(int i=0; i ss = new java.util.Vector(); + String line = new String(); + + // do the if + + loop_line = code.substring(code.indexOf(begin_tag)); + code = code.substring(code.indexOf(begin_tag)); + + if(begin_tag.length()+1 < code.indexOf(end_tag)-1) + { + loop_line = code.substring(begin_tag.length()+1, code.indexOf(end_tag)-1); + ss = Translator.getOBLTags(loop_line); + if(ss == null) + { + return 1; // error encountered + } + + for(int i=0; i (jProgrammingWindow.getEndIcon().getCoordinate().getX()+jProgrammingWindow.getEndIcon().getWidth()/2) || + tic == null || tic2 == null || tic instanceof joinEndBranchIcon) + { + // if the desired place for the new icon is taken by another icon, make sure + // the new icon could not be to the left of the starting icon or to the right of the + // ending icon + + javax.swing.JOptionPane.showMessageDialog(jPanelMainCenter, + "Insertion invalid, please reselect a position", + "Insertion Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + DirectionsLabel.setText(readyPrompt); + if(icon instanceof loopIcon) + { + jPanel7onListeners(); + } + } + else + { + // three cases of icon insertion + // 1. if it is a branching icon + // 2. if it is a loop icon + // 3. if it is everything else + if(icon instanceof branchIcon) + { + insertBranchIcon(icon, tic, tic2); + UndoRedo.update_state(); + } + else if(icon instanceof loopIcon) + { + DirectionsLabel.setText("Click on the programming window to position the end of the loop"); + final int xx = evt.getX(); + final int yy = evt.getY(); + final Icon lic = icon; + + java.awt.event.MouseListener[] ml = jProgrammingWindow.getMouseListeners(); + + jProgrammingWindow.removeMouseListener(ml[0]); + + jProgrammingWindow.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt2) { + + // the handler for this repeat icon + jPanel7MouseClicked4(xx, yy, evt2, lic); + + // reset the listeners + jPanel7onListeners(); + } + }); + } + else + { + if(icon instanceof beginTaskIcon || icon instanceof stopTaskIcon) + { + if(type == 1) + { + int ret_val = promptTask(icon); + if(ret_val == 1) + { + insertObjectIcon(icon, tic, tic2); + UndoRedo.update_state(); + } + } + else + { + insertObjectIcon(icon, tic, tic2); + UndoRedo.update_state(); + } + + } + else if(icon instanceof startEvent) + { + if(type == 1) + { + int ret_val = promptEvent(icon); + if(ret_val == 1) + { + insertObjectIcon(icon, tic, tic2); + UndoRedo.update_state(); + } + } + else + { + insertObjectIcon(icon, tic, tic2); + UndoRedo.update_state(); + } + } + else + { + insertObjectIcon(icon, tic, tic2); + UndoRedo.update_state(); + } + } + repaint(); + validate(); + } + } + + // handler for object icon replacements + private void objectIconReplaceClicked(java.awt.event.MouseEvent evt, Icon icon, Icon parent) + { + parent.getComponentPopupMenu().setVisible(false); + + if(icon instanceof beginTaskIcon || icon instanceof stopTaskIcon) + { + int ret_val = promptTask(icon); + if(ret_val == 1) + { + icon.setImage(); + put_object_icon(icon, parent); + object_init_replace_listener(icon); + jPanel7onListeners(); + } + } + else if(icon instanceof startEvent) + { + if(getCurrentAuxiliary() instanceof monitorEvent) + { + javax.swing.JOptionPane.showMessageDialog(this, + "An event cannot call another event.\nOnly insert an event call inside a task or a function.", + "Error - Nested Events", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + else + { + int ret_val = promptEvent(icon); + if(ret_val == 1) + { + icon.setImage(); + put_object_icon(icon, parent); + object_init_replace_listener(icon); + jPanel7onListeners(); + } + } + } + else + { + put_object_icon(icon, parent); + object_init_replace_listener(icon); + jPanel7onListeners(); + } + } + + + // handler for icon relocation, this method would then ask for a click on the programming window + // to determine where to put the old icon + private void relocateIconPerformed(java.awt.event.ActionEvent evt, Icon parent) + { + parent.getComponentPopupMenu().setVisible(false); + jPanel7offListeners(); + + DirectionsLabel.setText("Now click where you want to relocate the icon"); + final Icon icon = parent; + jProgrammingWindow.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt2) { + + // the handler for this repeat icon + jPanel7MouseClicked5(evt2, icon); + + // reset the listeners + jPanel7onListeners(); + } + }); + } + + + // handler for icon deletion, this method would delete the specified icon + // the third argument is for a special case, if type == 1 --> delete a repeat icon with all of its members + // type == 2 --> delete a branch icon and keep the top (IF) part + // type == 3 --> delete a branch icon and keep the bottom (ELSE) part + private void deleteIconPerformed(java.awt.event.ActionEvent evt, Icon parent, int type) + { + parent.getComponentPopupMenu().setVisible(false); + if(type == 0) + { + deleteIcon(parent, parent.getLeftNeighbour().getCoordinate().getX(), parent.getLeftNeighbour().getCoordinate().getY()); + } + else if(type == 1) + { + deleteRepeatAll(parent, parent.getEndIcon().getLeftNeighbour().getCoordinate().getX(), + parent.getEndIcon().getLeftNeighbour().getCoordinate().getY()); + } + else if(type == 2) + { + deleteBranchKeepIf(parent, parent.getLeftNeighbour().getCoordinate().getX(), parent.getLeftNeighbour().getCoordinate().getY()); + } + else if(type == 3) + { + deleteBranchKeepElse(parent, parent.getLeftNeighbour().getCoordinate().getX(), parent.getLeftNeighbour().getCoordinate().getY()); + } + UndoRedo.update_state(); + } + + + // to copy an icon with all of its attributes set to the previous icons + private void copyIconPerformed(Icon parent) + { + Icon new_icon = parent.Copy(); + if(new_icon instanceof loopIcon) + { + prepLoopIconHandlers(new_icon, 0); + } + else + { + prepIconHandlers(new_icon, 0); + } + } + + // to edit an existing arithmetic operation + private void arithOpEditPerformed(Icon icon) + { + ArithOpIcon AOI = (ArithOpIcon) icon; + ArithmeticOperation AO = AOI.getAO(); + java.util.Vector vr = new java.util.Vector(); + if(getCurrentAuxiliary() instanceof function) + { + function f = (function)getCurrentAuxiliary(); + vr = f.getVariables(); + } + else if(getCurrentAuxiliary() instanceof task) + { + task t = (task)getCurrentAuxiliary(); + vr = t.getVariables(); + } + else if(getCurrentAuxiliary() instanceof monitorEvent) + { + monitorEvent et = (monitorEvent)getCurrentAuxiliary(); + if(et.getAuxPoint() != null) + { + vr = et.getAuxPoint().getVariables(); + } + } + + if(var_list.Instance().getVariables().size() == 4 && vr.size() == 0) + { + javax.swing.JOptionPane.showMessageDialog(this, + "There has to be at least 1 non input sensor local or global variable.\nPlease declare one.", + "Error - No Variable", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + else + { + VarOperationDialog dv_dialog = new VarOperationDialog(this, AO, getCurrentAuxiliary()); + dv_dialog.pack(); + dv_dialog.setLocationRelativeTo(this); + dv_dialog.setVisible(true); + + ArithmeticOperation ret_val = dv_dialog.getUserInput(); + if(ret_val != null) // an indication that user did not press cancel + { + // create the ArithOpIcon class, then fill in the ArithmeticOperation class that it will point at + AOI.setAO(ret_val); + UndoRedo.update_state(); + } + } + } + + + // to edit the input into a function's arguments + private void editArgPerformed(Icon icon) + { + java.util.Vector ret_val; + functionIcon fic = (functionIcon) icon; + function tmp_func = fic.getFunction(); + if(tmp_func.getArguments().size() > 0) + { + FunctionArgumentDialog fad = new FunctionArgumentDialog(this, tmp_func, getCurrentAuxiliary(), fic); + fad.pack(); + fad.setLocationRelativeTo(this); + fad.setVisible(true); + + ret_val = fad.getUserInput(); + if(ret_val != null) // user did not press cancel + { + // set the arguments in the functionIcon first + fic.setArguments(ret_val); + UndoRedo.update_state(); + } + } + else + { + ret_val = new java.util.Vector(); + javax.swing.JOptionPane.showMessageDialog(this, + "No arguments can be edited.\nThis function does not accept arguments.", + "Zero argument", + javax.swing.JOptionPane.INFORMATION_MESSAGE); + } + } + + // to show the programming window as indicated by the users + private void showProgWindowPerformed(Icon icon) + { + int nid = 1; +// current_aux = aux_list.Instance().getAuxiliaries().get(nid); + if(icon instanceof beginTaskIcon) + { + nid = ((beginTaskIcon)icon).getNumId(); + } + else if(icon instanceof stopTaskIcon) + { + nid = ((stopTaskIcon)icon).getNumId(); + } + else if(icon instanceof functionIcon) + { + nid = ((functionIcon)icon).getNumId(); + } + else if(icon instanceof startEvent) + { + nid = ((startEvent)icon).getNumId(); + } + + jPanelFunction.getTabbedWinMan().displayPanel(Integer.toString(nid)); + + // then have the radio button selected ! + javax.swing.ButtonGroup bg = radiobuttons.Instance().getButtonGroup(); + java.util.Enumeration enum_ab = bg.getElements(); + javax.swing.JRadioButton jrb = new javax.swing.JRadioButton(); + while(enum_ab.hasMoreElements()) + { + jrb = (javax.swing.JRadioButton)enum_ab.nextElement(); + if(jrb.getActionCommand().compareTo(Integer.toString(nid)) == 0) + { + jrb.setSelected(true); + // break; + } + } + } + + // to edit an expression of a branch arithmetic or a loop arithmetic icons + private void expressionEditPerformed(Icon icon) + { + NestedOperation res = new NestedOperation(); + if(icon instanceof BarithmeticIcon) + { + BarithmeticIcon bai = (BarithmeticIcon)icon; + res = bai.getExpression(); + } + else if(icon instanceof arithmeticLoopIcon) + { + arithmeticLoopIcon bai = (arithmeticLoopIcon)icon; + res = bai.getExpression(); + } + + ArithComparatorDialog ACD = new ArithComparatorDialog(this, getCurrentAuxiliary(), res); + ACD.pack(); + ACD.setLocationRelativeTo(this); + ACD.setVisible(true); + + res = ACD.getExpression(); + if(res != null) // user didn't press cancel + { + if(icon instanceof BarithmeticIcon) + { + BarithmeticIcon bai = (BarithmeticIcon)icon; + bai.setExpression(res); + } + else if(icon instanceof arithmeticLoopIcon) + { + arithmeticLoopIcon bai = (arithmeticLoopIcon)icon; + bai.setExpression(res); + } + UndoRedo.update_state(); + } + } + + // for task icons, to remap the task icons related to a task + private void relinkTask(Icon icon) + { + int ret_val = promptTask(icon); + if(ret_val == 1) + { + icon.setImage(); + repaint(); + validate(); + UndoRedo.update_state(); + } + } + + // for event icons, to remap the event icons related to a event + private void relinkEvent(Icon icon) + { + int ret_val = promptEvent(icon); + if(ret_val == 1) + { + icon.setImage(); + repaint(); + validate(); + UndoRedo.update_state(); + } + } + + // for function icons, to remap the function icons related to a function + private void relinkFunction(Icon icon) + { + int ret_val = promptFunction(icon); + if(ret_val == 1) + { + icon.setImage(); + repaint(); + validate(); + UndoRedo.update_state(); + } + } + + + // method called by the object icon replacement handler + private void put_object_icon(Icon icon, Icon parent) + { + // initialise the icon + int new_x = parent.getCoordinate().getX() + ((parent.getWidth()/2)-(icon.getWidth()/2)); + int new_y = parent.getCoordinate().getY() + ((parent.getHeight()/2)-(icon.getHeight()/2)); + icon.setCoordinate(new coord(new_x, new_y)); + icon.setBounds(icon.getCoordinate().getX(), icon.getCoordinate().getY(), icon.getPreferredSize().width, icon.getPreferredSize().height); + + // set the parent member relationship and delete the old one + parent.getParentIcon().delMember(parent); + jProgrammingWindow.setUpIconParent(icon, parent.getLeftNeighbour(), parent.getRightNeighbour()); + + // set the wiring + icon.setLeftWire(parent.getLeftWire()); + icon.setRightWire(parent.getRightWire()); + icon.getLeftWire().setRightIcon(icon); + icon.getRightWire().setLeftIcon(icon); + + icon.setRightNeighbour(parent.getRightNeighbour()); + icon.getRightNeighbour().setLeftNeighbour(icon); + + icon.setLeftNeighbour(parent.getLeftNeighbour()); + icon.getLeftNeighbour().setRightNeighbour(icon); + icon.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); // to change the cursor + icon.turnonListeners(); + + jProgrammingWindow.deleteIcon(parent); + icon_list.delIcon(parent); + icon_list.addIcon(icon); + jProgrammingWindow.addIcon(icon); + + jProgrammingWindow.add(icon); + jProgrammingWindow.remove(parent); + jProgrammingWindow.updateAllRepeatNeighbours(); + repaint(); + validate(); + DirectionsLabel.setText("Object icon successfully replaced"); + UndoRedo.update_state(); + } + + // the method to initialise a pop up menu of an icon + private void object_init_replace_listener(Icon icon) + { + javax.swing.JPopupMenu jpm = new javax.swing.JPopupMenu(); + javax.swing.JMenuItem jm = new javax.swing.JMenuItem(); + javax.swing.JPanel jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + javax.swing.JMenu jm2 = new javax.swing.JMenu(); + javax.swing.JButton jmi = new javax.swing.JButton(); + + java.awt.GridBagConstraints gridBagConstraints; + final Icon parent = icon; + + jm2 = new javax.swing.JMenu("Replace Icon"); + jp.setLayout(new java.awt.GridBagLayout()); + + replaceIconicButton(40, 40, "/icons/motors/movemotor/icon_wheel2.gif", 0, 0, jp, "Motor Icon", _motor, parent); +// jButton1.addMouseListener(new java.awt.event.MouseAdapter() { +// public void mouseClicked(java.awt.event.MouseEvent evt) { +// objectIconReplaceClicked(evt, _motor.Clone(), parent); +// } +// }); + + replaceIconicButton(40, 40, "/icons/motors/directional/dir.gif", 1, 0, jp, "Directional Motor Icon", _dirmotor, parent); +// jButton1.addMouseListener(new java.awt.event.MouseAdapter() { +// public void mouseClicked(java.awt.event.MouseEvent evt) { +// objectIconReplaceClicked(evt, _dirmotor.Clone(), parent); +// } +// }); + + replaceIconicButton(40, 40, "/icons/motors/stopmotor/icon_wheel_stop.gif", 2, 0, jp, "Stop Icon", _stopmotor, parent); +// jButton1.addMouseListener(new java.awt.event.MouseAdapter() { +// public void mouseClicked(java.awt.event.MouseEvent evt) { +// objectIconReplaceClicked(evt, _stopmotor.Clone(), parent); +// } +// }); + + replaceIconicButton(40, 40, "/icons/lamps/lamp.gif", 3, 0, jp, "Lamp Icon", _lamp, parent); +// jButton1.addMouseListener(new java.awt.event.MouseAdapter() { +// public void mouseClicked(java.awt.event.MouseEvent evt) { +// objectIconReplaceClicked(evt, _lamp.Clone(), parent); +// } +// }); + + replaceIconicButton(40, 40, "/icons/motors/floatmotor/floatmotor.gif", 0, 1, jp, "Float Motor Icon", _float, parent); +// jButton1.addMouseListener(new java.awt.event.MouseAdapter() { +// public void mouseClicked(java.awt.event.MouseEvent evt) { +// objectIconReplaceClicked(evt, _float.Clone(), parent); +// } +// }); + + replaceIconicButton(40, 40, "/icons/beeps/beeps.gif", 1, 1, jp, "Beep Icon", _beep, parent); +// jButton1.addMouseListener(new java.awt.event.MouseAdapter() { +// public void mouseClicked(java.awt.event.MouseEvent evt) { +// objectIconReplaceClicked(evt, _beep.Clone(), parent); +// } +// }); + + replaceIconicButton(40, 40, "/icons/notes/free/freenote.gif", 2, 1, jp, "Play Any Note Icon", _playanynote, parent); +// jButton1.addMouseListener(new java.awt.event.MouseAdapter() { +// public void mouseClicked(java.awt.event.MouseEvent evt) { +// objectIconReplaceClicked(evt, _playanynote.Clone(), parent); +// } +// }); + + replaceIconicButton(40, 40, "/icons/notes/specific/specific.gif", 3, 1, jp, "Play A Note Icon", _specificnote, parent); +// jButton1.addMouseListener(new java.awt.event.MouseAdapter() { +// public void mouseClicked(java.awt.event.MouseEvent evt) { +// objectIconReplaceClicked(evt, _specificnote.Clone(), parent); +// } +// }); + + replaceIconicButton(40, 40, "/icons/timers/wait/icon_time.gif", 0, 2, jp, "Wait Icon", _timer, parent); +// jButton1.addMouseListener(new java.awt.event.MouseAdapter() { +// public void mouseClicked(java.awt.event.MouseEvent evt) { +// objectIconReplaceClicked(evt, _timer.Clone(), parent); +// } +// }); + + replaceIconicButton(40, 40, "/icons/wait/touch/wait_touch.gif", 1, 2, jp, "Wait Touch Sensor Icon", _waittouch, parent); +// jButton1.addMouseListener(new java.awt.event.MouseAdapter() { +// public void mouseClicked(java.awt.event.MouseEvent evt) { +// objectIconReplaceClicked(evt, _waittouch.Clone(), parent); +// } +// }); + + replaceIconicButton(40, 40, "/icons/wait/light/wait_light.gif", 2, 2, jp, "Wait Light Sensor Icon", _waitlight, parent); +// jButton1.addMouseListener(new java.awt.event.MouseAdapter() { +// public void mouseClicked(java.awt.event.MouseEvent evt) { +// objectIconReplaceClicked(evt, _waitlight.Clone(), parent); +// } +// }); + + replaceIconicButton(40, 40, "/icons/wait/celcius/wait_celcius.gif", 3, 2, jp, "Wait Celcius Sensor Icon", _waitcelcius, parent); +// jButton1.addMouseListener(new java.awt.event.MouseAdapter() { +// public void mouseClicked(java.awt.event.MouseEvent evt) { +// objectIconReplaceClicked(evt, _waitcelcius.Clone(), parent); +// } +// }); + + replaceIconicButton(40, 40, "/icons/wait/rotate/wait_rotate.gif", 0, 3, jp, "Wait Rotational Sensor Icon", _waitrotation, parent); +// jButton1.addMouseListener(new java.awt.event.MouseAdapter() { +// public void mouseClicked(java.awt.event.MouseEvent evt) { +// objectIconReplaceClicked(evt, _waitrotation.Clone(), parent); +// } +// }); + + replaceIconicButton(40, 40, "/icons/wait/timer/wait_timer.gif", 1, 3, jp, "Wait Timer Sensor Icon", _waittimer, parent); +// jButton1.addMouseListener(new java.awt.event.MouseAdapter() { +// public void mouseClicked(java.awt.event.MouseEvent evt) { +// objectIconReplaceClicked(evt, _waittimer.Clone(), parent); +// } +// }); + + replaceIconicButton(40, 40, "/icons/structure/return/return.gif", 2, 3, jp, "Return Icon", _returnicon, parent); +// jButton1.addMouseListener(new java.awt.event.MouseAdapter() { +// public void mouseClicked(java.awt.event.MouseEvent evt) { +// objectIconReplaceClicked(evt, _returnicon.Clone(), parent); +// } +// }); + + replaceIconicButton(40, 40, "/icons/sensors/clearsensor.gif", 3, 3, jp, "Clear Sensors Icon", _clearsensor, parent); +// jButton1.addMouseListener(new java.awt.event.MouseAdapter() { +// public void mouseClicked(java.awt.event.MouseEvent evt) { +// objectIconReplaceClicked(evt, _clearsensor.Clone(), parent); +// } +// }); + + replaceIconicButton(40, 40, "/icons/timers/cleart/cleartimer.gif", 0, 4, jp, "Clear Timer Icon", _cleartimer, parent); +// jButton1.addMouseListener(new java.awt.event.MouseAdapter() { +// public void mouseClicked(java.awt.event.MouseEvent evt) { +// objectIconReplaceClicked(evt, _cleartimer.Clone(), parent); +// } +// }); + + replaceIconicButton(40, 40, "/icons/task/start/startTask.gif", 1, 4, jp, "Start Task Icon", _BeginTask, parent); +// jButton1.addMouseListener(new java.awt.event.MouseAdapter() { +// public void mouseClicked(java.awt.event.MouseEvent evt) { +// objectIconReplaceClicked(evt, _BeginTask.Clone(), parent); +// } +// }); + + replaceIconicButton(40, 40, "/icons/task/stop/stopTask.gif", 2, 4, jp, "Stop Task Icon", _StopTask, parent); +// jButton1.addMouseListener(new java.awt.event.MouseAdapter() { +// public void mouseClicked(java.awt.event.MouseEvent evt) { +// objectIconReplaceClicked(evt, _StopTask.Clone(), parent); +// } +// }); + + replaceIconicButton(40, 40, "/icons/events/start/start.gif", 3, 4, jp, "Start Event Monitor Icon", _SEvent, parent); +// jButton1.addMouseListener(new java.awt.event.MouseAdapter() { +// public void mouseClicked(java.awt.event.MouseEvent evt) { +// objectIconReplaceClicked(evt, _SEvent.Clone(), parent); +// } +// }); + + jm2.add(jp); + + jpm.add(jm2); + + jm = new javax.swing.JMenuItem("Relocate Icon"); + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + relocateIconPerformed(evt, parent); + } + }); + + jpm.add(jm); + jpm.addSeparator(); + jm = new javax.swing.JMenuItem("Delete Icon"); + jpm.add(jm); + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + deleteIconPerformed(evt, parent, 0); + } + }); + + jm = new javax.swing.JMenuItem("Copy Icon"); + jpm.add(jm); + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + copyIconPerformed(parent); + } + }); + + + if(icon instanceof functionIcon) + { + jpm.addSeparator(); + jm = new javax.swing.JMenuItem("View Function"); + jpm.add(jm); + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + showProgWindowPerformed(parent); + } + }); + + jpm.addSeparator(); + jm = new javax.swing.JMenuItem("Re-Link Function"); + jpm.add(jm); + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + relinkFunction(parent); + } + }); + + jm = new javax.swing.JMenuItem("Edit Argument"); + jpm.add(jm); + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + editArgPerformed(parent); + } + }); + } + else if(icon instanceof ArithOpIcon) + { + jpm.addSeparator(); + jm = new javax.swing.JMenuItem("Edit Operation"); + jpm.add(jm); + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + arithOpEditPerformed(parent); + } + }); + } + else if(icon instanceof beginTaskIcon || icon instanceof stopTaskIcon) + { + jpm.addSeparator(); + jm = new javax.swing.JMenuItem("View Task"); + jpm.add(jm); + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + showProgWindowPerformed(parent); + } + }); + jpm.addSeparator(); + jm = new javax.swing.JMenuItem("Re-Link Task"); + jpm.add(jm); + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + relinkTask(parent); + } + }); + } + else if(icon instanceof startEvent) + { + jpm.addSeparator(); + jm = new javax.swing.JMenuItem("View Event"); + jpm.add(jm); + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + showProgWindowPerformed(parent); + } + }); + jpm.addSeparator(); + jm = new javax.swing.JMenuItem("Re-Link Event"); + jpm.add(jm); + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + relinkEvent(parent); + } + }); + } + + + jpm.addSeparator(); + jm = new javax.swing.JMenuItem("Properties"); + jpm.add(jm); + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + javax.swing.JOptionPane.showMessageDialog(jPanelMainCenter, + parent.getHelpMsg(), + parent.getHelpTitle(), + javax.swing.JOptionPane.INFORMATION_MESSAGE); + } + }); + + jm = new javax.swing.JMenuItem("Help"); + jpm.add(jm); + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + javax.swing.JOptionPane.showMessageDialog(jPanelMainCenter, + parent.getHelpDesc(), + "Context Help -- "+parent.getHelpTitle(), + javax.swing.JOptionPane.INFORMATION_MESSAGE, + parent.getHelpIcon()); + } + }); + + icon.setComponentPopupMenu(jpm); + } + + // handler for branch icon replacement process + private void branchIconReplaceClicked(java.awt.event.MouseEvent evt, Icon icon, Icon parent) + { + parent.getComponentPopupMenu().setVisible(false); + + if(icon instanceof BarithmeticIcon) + { + ArithComparatorDialog ACD = new ArithComparatorDialog(this, getCurrentAuxiliary(), null); + ACD.pack(); + ACD.setLocationRelativeTo(this); + ACD.setVisible(true); + + NestedOperation res = ACD.getExpression(); + if(res != null) // user didn't press cancel + { + BarithmeticIcon tmp_icon = (BarithmeticIcon) icon; + tmp_icon.setExpression(res); + icon.setImage(); + put_branch_icon(icon, parent); + branch_init_replace_listener(icon); + jPanel7onListeners(); + } + } + else + { + put_branch_icon(icon, parent); + branch_init_replace_listener(icon); + jPanel7onListeners(); + } + } + + + // the method that put the new replacement branch icons + private void put_branch_icon(Icon icon, Icon parent) + { + // initialise the icon + int new_x = parent.getCoordinate().getX() + ((parent.getWidth()/2)-(icon.getWidth()/2)); + int new_y = parent.getCoordinate().getY() + ((parent.getHeight()/2)-(icon.getHeight()/2)); + icon.setCoordinate(new coord(new_x, new_y)); + icon.setBounds(icon.getCoordinate().getX(), icon.getCoordinate().getY(), icon.getPreferredSize().width, icon.getPreferredSize().height); + + // set the parent member relationship and delete the old one + parent.getParentIcon().delMember(parent); + jProgrammingWindow.setUpIconParent(icon, parent.getLeftNeighbour(), parent.getEndBranch().getRightNeighbour()); + + // set the join Icons and the end branch icons + icon.setRightNeighbour(parent.getRightNeighbour()); + + icon.setLeftNeighbour(parent.getLeftNeighbour()); + icon.getLeftNeighbour().setRightNeighbour(icon); + + icon.setRightNeighbourTop(parent.getRightNeighbourTop()); + icon.setRightNeighbourBottom(parent.getRightNeighbourBottom()); + icon.getRightNeighbourTop().setLeftNeighbour(icon); + icon.getRightNeighbourBottom().setLeftNeighbour(icon); + + icon.setEndBranch(parent.getEndBranch()); // end branch will stay the same + + // set the wiring connections for this branch + icon.setRightWireTop(parent.getRightWireTop()); + icon.getRightWireTop().setLeftIcon(icon); + icon.setRightWireBottom(parent.getRightWireBottom()); + icon.getRightWireBottom().setLeftIcon(icon); + icon.setLeftWire(parent.getLeftWire()); + icon.getLeftWire().setRightIcon(icon); + + // set the vertical sizes + icon.setTopTopVerticalSize(parent.getTopTopVerticalSize()); + icon.setTopBottomVerticalSize(parent.getTopBottomVerticalSize()); + icon.setBottomTopVerticalSize(parent.getBottomTopVerticalSize()); + icon.setBottomBottomVerticalSize(parent.getBottomBottomVerticalSize()); + icon.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); // to change the cursor + icon.turnonListeners(); + + // set the kid or member icons within !! + + java.util.Vector if_members = parent.getIfMembers(); // the icons enclosed within this branch + java.util.Vector else_members = parent.getElseMembers(); // the icons enclosed within this branch + + for(int i=0; i members = parent.getMembers(); + + for(int i=0; i ics = icon.getIfMembers(); + Icon tic = icon.getEndBranch().getRightNeighbour(); + Icon tic2 = icon.getLeftNeighbour(); + // delete all, reinsert the if_members + deleteIcon(icon, px, py); + + // reinsert the if members, except the join icons + for(int i=1; i<(ics.size()-1); i++) + { + tic2 = tic.getLeftNeighbour(); + Icon tmp_icon = ics.get(i); + tmp_icon.turnoffListeners(); + if(tmp_icon instanceof branchIcon || tmp_icon instanceof loopIcon) + { + insertRecursiveBranchLoopIcon(tmp_icon, tic, tic2); + } + else + { + int xpos = 0; + if(tic2 != null && tic != null) + { + xpos = gridcalculation.midPoint(tic2.getCoordinate(), tic.getCoordinate()); + } + + int ypos = gridcalculation.calculateY(tic2.getCoordinate().getY()+((tic2.getHeight())/2)); + coord tmp_co = new coord(xpos, ypos); + coord co = gridcalculation.computeCoord(icon, tmp_co); + tmp_icon.setCoordinate(co); + insertObjectIcon(tmp_icon, tic, tic2); + } + } + } + + + // special method that deletes a branchIcon but keep the else part of the branch + private void deleteBranchKeepElse(Icon icon, int px, int py) + { + java.util.Vector ics = icon.getElseMembers(); + Icon tic = icon.getEndBranch().getRightNeighbour(); + Icon tic2 = icon.getLeftNeighbour(); + // delete all, reinsert the else_members + deleteIcon(icon, px, py); + + // reinsert the else members, except the join icons + for(int i=1; i<(ics.size()-1); i++) + { + tic2 = tic.getLeftNeighbour(); + Icon tmp_icon = ics.get(i); + tmp_icon.turnoffListeners(); + if(tmp_icon instanceof branchIcon || tmp_icon instanceof loopIcon) + { + insertRecursiveBranchLoopIcon(tmp_icon, tic, tic2); + } + else + { + int xpos = 0; + if(tic2 != null && tic != null) + { + xpos = gridcalculation.midPoint(tic2.getCoordinate(), tic.getCoordinate()); + } + + int ypos = gridcalculation.calculateY(tic2.getCoordinate().getY()+((tic2.getHeight())/2)); + coord tmp_co = new coord(xpos, ypos); + coord co = gridcalculation.computeCoord(icon, tmp_co); + tmp_icon.setCoordinate(co); + insertObjectIcon(tmp_icon, tic, tic2); + } + } + } + + // special method that deletes a repeatIcon and all of its members + private void deleteRepeatAll(Icon icon, int px, int py) + { + jProgrammingWindow.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR)); + // shift all icons as necessary + int n_shift = (gridcalculation.calculateXright(icon.getEndIcon().getRightNeighbour().getCoordinate().getX()) + - gridcalculation.calculateXright(icon.getBeginIcon().getCoordinate().getX())) / Constants.gridDistanceX; + jProgrammingWindow.recursiveShiftIconHorizontalLeft(icon.getBeginIcon(), n_shift); + + // the following line will delete all icons and wires involved + jProgrammingWindow.delAllIcons(icon); + + // set the neighbour relationships + icon.getBeginIcon().getLeftNeighbour().setRightNeighbour(icon.getEndIcon().getRightNeighbour()); + + icon.getEndIcon().getRightNeighbour().setLeftNeighbour(icon.getBeginIcon().getLeftNeighbour()); + + // reconnect wiring + icon.getBeginIcon().getLeftNeighbour().getRightWire().setRightIcon(icon.getEndIcon().getRightNeighbour()); + icon.getEndIcon().getRightNeighbour().setLeftWire(icon.getBeginIcon().getLeftNeighbour().getRightWire()); + + int member_pos=-1; + if(icon.getParentIcon() instanceof branchIcon) + { + member_pos = icon.getParentIcon().determineMember(icon); + } + icon.getParentIcon().delMember(icon); + jProgrammingWindow.recursiveShiftIconVerticalUp(icon, 1, member_pos); + + jProgrammingWindow.repositionAllBranches(); + jProgrammingWindow.repositionAllRepeat(); + jProgrammingWindow.updateAllRepeatNeighbours(); + DirectionsLabel.setText("Icon successfully deleted"); + + // resize the programming window + jProgrammingWindow.resizeProgWindow(jScrollPane1); + +// viewport.setViewPosition(new java.awt.Point(px - (Constants.gridDistanceX * 2), py - (Constants.gridDistanceY * 2))); + jProgrammingWindow.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); + } + + + + // this method does the actual deletion + private void deleteIcon(Icon icon, int px, int py) + { + jProgrammingWindow.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR)); + if(icon instanceof loopIcon) + { + Icon jlicon_left = icon.getBeginIcon(); + Icon jlicon_right = icon.getEndIcon(); + + // reconnect the enclosing icons of this loop + if(icon.getMembers().size() > 2) // there are members in this icon + { + // now delete the wires + jProgrammingWindow.recursiveShiftIconHorizontalLeft(jlicon_left, 1); + jProgrammingWindow.collapseWire(jlicon_left.getLeftNeighbour(), jlicon_left.getRightNeighbour()); + + jProgrammingWindow.recursiveShiftIconHorizontalLeft(jlicon_right, 1); + + jProgrammingWindow.collapseWire(jlicon_right.getLeftNeighbour(), jlicon_right.getRightNeighbour()); + + jlicon_left.getLeftNeighbour().setRightNeighbour(jlicon_left.getRightNeighbour()); + jlicon_left.getRightNeighbour().setLeftNeighbour(jlicon_left.getLeftNeighbour()); + jlicon_right.getRightNeighbour().setLeftNeighbour(jlicon_right.getLeftNeighbour()); + jlicon_right.getLeftNeighbour().setRightNeighbour(jlicon_right.getRightNeighbour()); + } + else + { + jProgrammingWindow.recursiveShiftIconHorizontalLeft(jlicon_left, 1); + + jProgrammingWindow.deleteWire(jlicon_left.getRightWire()); + wire_list.delWire(jlicon_left.getRightWire()); + + + jProgrammingWindow.recursiveShiftIconHorizontalLeft(jlicon_right, 1); + + jProgrammingWindow.deleteWire(jlicon_right.getRightWire()); + wire_list.delWire(jlicon_right.getRightWire()); + + jlicon_right.getRightNeighbour().setLeftWire(jlicon_left.getLeftNeighbour().getRightWire()); + jlicon_left.getLeftNeighbour().getRightWire().setRightIcon(jlicon_right.getRightNeighbour()); + + jlicon_left.getLeftNeighbour().setRightNeighbour(jlicon_right.getRightNeighbour()); + jlicon_right.getRightNeighbour().setLeftNeighbour(jlicon_left.getLeftNeighbour()); + } + + // reconfigure the member with its new parents now that this repeat icon is gone + + java.util.Vector ics = icon.getMembers(); + for(int i = 1; i < (ics.size() - 1); i++) // don't forget to exclude the beginning and end icon of this repeat icon + { + ics.get(i).setParentIcon(icon.getParentIcon()); + if(icon.getRightNeighbour() instanceof joinLoopIcon) + { + if(icon.getRightNeighbour().getBottomNeighbour().getId() == icon.getParentIcon().getId()) + { + icon.getParentIcon().addMember(ics.get(i), icon.getRightNeighbour()); + } + else + { + icon.getParentIcon().addMember(ics.get(i), icon.getRightNeighbour().getBottomNeighbour()); + } + } + else + { + icon.getParentIcon().addMember(ics.get(i), icon.getRightNeighbour()); + } + } + + int wire_type=0; // for the colour type + if(icon.getParentIcon() instanceof branchIcon) + { + wire_type = 1; + } + else if(icon.getParentIcon() instanceof loopIcon) + { + wire_type = 2; + } + // get rid of the members of this repeat + for(int i = 1; i < (ics.size() - 1); i++) + { + icon.delMember(ics.get(i)); + // update the colour of the wiring + + if(ics.get(i) instanceof branchIcon) + { + ics.get(i).getLeftWire().setType(wire_type); + ics.get(i).getEndBranch().getRightWire().setType(wire_type); + } + else if(ics.get(i) instanceof loopIcon) + { + ics.get(i).getBeginIcon().getLeftWire().setType(wire_type); + ics.get(i).getEndIcon().getRightWire().setType(wire_type); + } + else + { + ics.get(i).getLeftWire().setType(wire_type); + ics.get(i).getRightWire().setType(wire_type); + } + } + + // delete the vertical wiring + jProgrammingWindow.deleteWire(icon.getLeftWire()); + wire_list.delWire(icon.getLeftWire()); + jProgrammingWindow.deleteWire(icon.getRightWire()); + wire_list.delWire(icon.getRightWire()); + + // finally delete the icons + jProgrammingWindow.deleteIcon(icon); + icon_list.delIcon(icon); + jProgrammingWindow.remove(icon); + jProgrammingWindow.deleteIcon(jlicon_right); + icon_list.delIcon(jlicon_right); + jProgrammingWindow.remove(jlicon_right); + jProgrammingWindow.deleteIcon(jlicon_left); + icon_list.delIcon(jlicon_left); + jProgrammingWindow.remove(jlicon_left); + + int member_pos = -1; + if(icon.getParentIcon() instanceof branchIcon) + { + member_pos = icon.getParentIcon().determineMember(icon); + } + icon.getParentIcon().delMember(icon); + jProgrammingWindow.recursiveShiftIconVerticalUp(icon, 1, member_pos); + } + else if(icon instanceof branchIcon) + { + // shift all icons as necessary + int n_shift = (gridcalculation.calculateXright(icon.getEndBranch().getRightNeighbour().getCoordinate().getX()) + - gridcalculation.calculateXright(icon.getCoordinate().getX())) / Constants.gridDistanceX; + + jProgrammingWindow.recursiveShiftIconHorizontalLeft(icon, n_shift); + + // the following line will delete all icons and wires involved + jProgrammingWindow.delAllIcons(icon); + + // reconnect the neighbouring icons + icon.getLeftNeighbour().setRightNeighbour(icon.getEndBranch().getRightNeighbour()); + icon.getEndBranch().getRightNeighbour().setLeftNeighbour(icon.getLeftNeighbour()); + + icon.getLeftNeighbour().getRightWire().setRightIcon(icon.getEndBranch().getRightNeighbour()); + icon.getEndBranch().getRightNeighbour().setLeftWire(icon.getLeftNeighbour().getRightWire()); + + int member_pos = -1; + if(icon.getParentIcon() instanceof branchIcon) + { + member_pos = icon.getParentIcon().determineMember(icon); + } + icon.getParentIcon().delMember(icon); + jProgrammingWindow.recursiveShiftIconVerticalUp(icon, 1, member_pos); + } + else + { + // reconnect the neighbouring icons + icon.getLeftNeighbour().setRightNeighbour(icon.getRightNeighbour()); + + icon.getRightNeighbour().setLeftNeighbour(icon.getLeftNeighbour()); + + // recursively shift the icons + jProgrammingWindow.recursiveShiftIconHorizontalLeft(icon, 1); + // collapse the wires + jProgrammingWindow.collapseWire(icon.getLeftNeighbour(), icon.getRightNeighbour()); + + // remove this icon from its parent's vector of member icons + + jProgrammingWindow.deleteIcon(icon); + + icon.getParentIcon().delMember(icon); + icon_list.delIcon(icon); + jProgrammingWindow.remove(icon); + } + + jProgrammingWindow.repositionAllBranches(); + jProgrammingWindow.repositionAllRepeat(); + DirectionsLabel.setText("Icon successfully deleted"); + + // resize the programming window + jProgrammingWindow.resizeProgWindow(jScrollPane1); + +// viewport.setViewPosition(new java.awt.Point(px - (Constants.gridDistanceX * 2), py - (Constants.gridDistanceY * 2))); + + jProgrammingWindow.updateAllRepeatNeighbours(); + + repaint(); + validate(); + + jProgrammingWindow.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); + } + + // this method handles for the second click of a repeat icon placement + // the second click determines the end of the repeat segment + // the lefty and righty arguments are needed for setting up parent-member relationship of the repeat + private void jPanel7MouseClicked4(int xpos, int ypos, java.awt.event.MouseEvent evt2, Icon lic) + { + coord tmp_co = new coord(evt2.getX(), evt2.getY()); + + // for beginning icon + Icon tic = jProgrammingWindow.findIcon(xpos, ypos, 1); // right of icon + Icon tic2 = jProgrammingWindow.findIcon(xpos, ypos, 0); // left of icon + + xpos = gridcalculation.calculateXright(xpos); + ypos = gridcalculation.calculateY(ypos); + + // for ending icon + Icon tic3 = jProgrammingWindow.findIcon(evt2.getX(), evt2.getY(), 1); // right of icon + Icon tic4 = jProgrammingWindow.findIcon(evt2.getX(), evt2.getY(), 0); // left of icon + + int xpos2 = gridcalculation.calculateXright(evt2.getX()); + int ypos2 = gridcalculation.calculateY(evt2.getY()); + + // for viewport + int v_x = xpos; + int v_y = ypos; + + + // for checking that all icons to be put within this new repeat should have the same parent icon + int allowed = 1; // initially zero for allowed (not allowed = 0) + if(ypos == ypos2 && xpos2 >= xpos) + { + // check for the enclosed icons + Icon tm_p = null; + int x = xpos; + int x_limit = xpos2; + while(x < x_limit) + { + java.awt.Component c = jProgrammingWindow.getComponentAt(x, ypos); + if(c instanceof Icon) + { + Icon ico = (Icon) c; + if(ico instanceof joinLoopIcon) + { + ico = ico.getBottomNeighbour(); + x = gridcalculation.calculateXright(ico.getEndIcon().getCoordinate().getX()); + if(x >= xpos2 && xpos <= gridcalculation.calculateXright(ico.getBeginIcon().getCoordinate().getX())) + { + allowed = 0; + break; + } + } + else if(ico instanceof branchIcon) + { + x = gridcalculation.calculateXright(ico.getEndBranch().getCoordinate().getX()); + } + if(tm_p == null) + { + tm_p = ico.getParentIcon(); + } + else + { + if(ico.getParentIcon().getId() != tm_p.getId()) + { + allowed = 0; + break; + } + } + } + x += Constants.gridDistanceX; + } + } + else + { + allowed = 0; + } + if(allowed == 1) + { + if(tic instanceof joinLoopIcon && tic.getBottomNeighbour().getEndIcon().getId() == tic.getId() && + tic4 instanceof joinLoopIcon && tic4.getBottomNeighbour().getBeginIcon().getId() == tic4.getId()) + { + allowed = 1; + } + else + { + if(tic instanceof joinLoopIcon && tic.getBottomNeighbour().getEndIcon().getId() == tic.getId()) + { + allowed = 0; + } + if(tic4 instanceof joinLoopIcon && tic4.getBottomNeighbour().getBeginIcon().getId() == tic4.getId()) + { + allowed = 0; + } + } + } + + if(xpos == xpos2) // special override, if this repeat meant to start empty, it will be allowed no matter where it is + { + allowed = 1; + } + + + if(tmp_co.getX() < (jProgrammingWindow.getStartIcon().getCoordinate().getX()+jProgrammingWindow.getStartIcon().getWidth()/2) || + tmp_co.getX() > (jProgrammingWindow.getEndIcon().getCoordinate().getX()+jProgrammingWindow.getEndIcon().getWidth()/2) || + tic == null || tic2 == null || tic3 == null || tic4 == null || allowed == 0 || tic3 instanceof joinEndBranchIcon) + { + // if the desired place for the new icon is taken by another icon, make sure + // the new icon could not be to the left of the starting icon or to the right of the + // ending icon + + javax.swing.JOptionPane.showMessageDialog(jPanelMainCenter, + "Insertion of repeat was invalid, please reselect a position", + "Insertion Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + DirectionsLabel.setText(readyPrompt); + } + else + { + insertLoopIcon(lic, tic, tic2, tic3, tic4); + UndoRedo.update_state(); + } + } + + + // the method that relocates an icon to its new position + private void jPanel7MouseClicked5(java.awt.event.MouseEvent evt, Icon icon) + { + // get the location of the click + + int new_x = (int) evt.getPoint().getX(); + int new_y = (int) evt.getPoint().getY(); + + Icon tic = jProgrammingWindow.findIcon(new_x, new_y, 1); // right of icon + Icon tic2 = jProgrammingWindow.findIcon(new_x, new_y, 0); // left of icon + + // ensure it is valid first + + if(new_x < (jProgrammingWindow.getStartIcon().getCoordinate().getX()+jProgrammingWindow.getStartIcon().getWidth()/2) || + new_x > (jProgrammingWindow.getEndIcon().getCoordinate().getX()+jProgrammingWindow.getEndIcon().getWidth()/2) || + tic == null || tic2 == null || tic instanceof joinEndBranchIcon) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Position invalid, please reselect a position", + "Position Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + DirectionsLabel.setText(readyPrompt); + } + else + { + // 1. get rid of the icon from its parent's membership lists + // 2. get rid of the icon visually + // 3. shift all icons to the left or top whatever necessary + + if(icon instanceof branchIcon) + { + // this is a special case, the way this feature is implemented differs as to what has been done + // to a normal object icons. This is due to branch icons containing nested icons within + // and deleting and reinserting them will be very hard to do and bug ridden, + // so simply, move and reconnect the branch icons (The icons within will not know that the parent icon + // has change connection to a new parent icon) + + // has to ensure that the new location parent icon is not itself + if(jProgrammingWindow.checkParent(icon, tic, tic2) == false) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Position invalid, please reselect a position", + "Position Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + DirectionsLabel.setText(readyPrompt); + } + else + { + // only reposition if tic2 and tic are not the icon's original neighbours + + if((tic.getId() == icon.getEndBranch().getRightNeighbour().getId() && tic2.getId() == icon.getEndBranch().getId()) + || (tic2.getId() == icon.getLeftNeighbour().getId() && tic.getId() == icon.getId())) + { + + } + else + { + deleteIcon(icon, icon.getCoordinate().getX(), icon.getCoordinate().getX()); + icon.turnoffListeners(); + insertRecursiveBranchLoopIcon(icon, tic, tic2); + } + + // DONE + DirectionsLabel.setText("Icon successfully relocated"); + UndoRedo.update_state(); + } + } + else if(icon instanceof loopIcon) + { + if(jProgrammingWindow.checkParent(icon, tic, tic2) == false) + { + javax.swing.JOptionPane.showMessageDialog(null, + "Position invalid, please reselect a position", + "Position Invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + DirectionsLabel.setText(readyPrompt); + } + else + { + // only reposition if tic2 and tic are not the icon's original neighbours + + if((tic.getId() == icon.getEndIcon().getRightNeighbour().getId() && tic2.getId() == icon.getEndIcon().getId()) + || (tic2.getId() == icon.getBeginIcon().getLeftNeighbour().getId() && tic.getId() == icon.getBeginIcon().getId())) + { + + } + else + { + deleteRepeatAll(icon, icon.getCoordinate().getX(), icon.getCoordinate().getX()); + icon.turnoffListeners(); + insertRecursiveBranchLoopIcon(icon, tic, tic2); + } + // DONE + DirectionsLabel.setText("Icon successfully relocated"); + UndoRedo.update_state(); + } + } + else + { + deleteIcon(icon, icon.getCoordinate().getX(), icon.getCoordinate().getX()); + icon.turnoffListeners(); + // reconfigure the icons + if(tic.getId() == icon.getId()) + { + tic = icon.getRightNeighbour(); + } + else if(tic2.getId() == icon.getId()) + { + tic2 = icon.getLeftNeighbour(); + } + + // 4. introduce the icons to its new parents + // 5. introduce the icons visually (new coordinates and new bounds) + // 6. shift other icons appropriately + + // instead has to find a mid point between tic and tic2 + + int xpos = 0; + if(tic2 != null && tic != null) + { + xpos = gridcalculation.midPoint(tic2.getCoordinate(), tic.getCoordinate()); + } + + int ypos = gridcalculation.calculateY(evt.getY()); // ypos wouldn't change since an object icon would not alter any vertical sizes + coord tmp_co = new coord(xpos, ypos); + coord co = gridcalculation.computeCoord(icon, tmp_co); + icon.setCoordinate(co); + + insertObjectIcon(icon, tic, tic2); + // 7. DONE + DirectionsLabel.setText("Icon successfully relocated"); + UndoRedo.update_state(); + } + } + } + + // method thats insert an object icon + // the fourth argument type is to decide whether to insert a whole new function + private void insertObjectIcon(Icon icon, Icon tic, Icon tic2) + { +// jProgrammingWindow.insertObjectIcon(icon, tic, tic2, jScrollPane1); + jProgrammingWindow.insertObjectIcon(icon, tic, tic2, jScrollPane1); + icon.turnonListeners(); + icon.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); // to change the cursor + object_init_replace_listener(icon); + + repaint(); + validate(); + } + + + // a method that recursively inserts a branch or a loop and its members + // WARNING : THIS METHOD THAT SHOULD ONLY BE USED WHEN THE ICONS WITHIN THE BRANCH AND THE BRANCH ITSELF HAS BEEN INSERTED ONTO + // THE PROGRAMMING WINDOW PREVIOUSLY + private void insertRecursiveBranchLoopIcon(Icon icon, Icon tic, Icon tic2) + { + // temporary variables for the member vectors + // tmp_members1 for member in loop and if_member in branch + // tmp_members2 for else_member in branch + + java.util.Vector tmp_members1; + java.util.Vector tmp_members2; + + // calculate the length of the shifting of this icon, vertically and horizontally, and all of its members + // will follow + + int xpos = 0; + if(tic2 != null && tic != null) + { + xpos = gridcalculation.midPoint(tic2.getCoordinate(), tic.getCoordinate()); + } + int ypos = tic2.getCoordinate().getY()+(tic2.getHeight()/2); // tic2 and tic should have the same coordinate + + coord tmp_co = new coord(xpos, ypos); + coord co = gridcalculation.computeCoord(icon, tmp_co); + icon.setCoordinate(co); + + if(icon instanceof branchIcon) + { + // before we continue the icon has to start fresh, i.e. its members vector has to be cleaned and restarted + // now remove all of this icon's members + // also restart the vertical sizes + icon.setTopTopVerticalSize(0); + icon.setTopBottomVerticalSize(0); + icon.setBottomTopVerticalSize(0); + icon.setBottomBottomVerticalSize(0); + tmp_members1 = icon.getIfMembers(); + // turns off the icon's listeners first + for(int i=0; i void createIconicButton(int width, int height, String filepath, int gridx, int gridy, javax.swing.JPanel panel, String title, TIcon iconPrototype) + { + javax.swing.JButton jButtonIcon = setupIconicButton(width, height, filepath, gridx, gridy, panel, title, iconPrototype); + + if (iconPrototype instanceof loopIcon) + { + jButtonIcon.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + iconLoopMouseClicked(evt, iconPrototype.Clone(), 1); + } + }); + } else { + jButtonIcon.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + iconMouseClicked(evt, iconPrototype.Clone(), 1); + } + }); + } + } + + // to replace an iconic button + private void replaceIconicButton(int width, int height, String filepath, int gridx, int gridy, javax.swing.JPanel panel, String title, TIcon iconReplacementPrototype, TIcon iconParent) + { + javax.swing.JButton jButtonIcon = setupIconicButton(width, height, filepath, gridx, gridy, panel, title, iconReplacementPrototype); + + if (iconReplacementPrototype instanceof objectIcon) + { + jButtonIcon.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + objectIconReplaceClicked(evt, iconReplacementPrototype.Clone(), iconParent); + } + }); + } + else if (iconReplacementPrototype instanceof branchIcon) + { + jButtonIcon.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + branchIconReplaceClicked(evt, iconReplacementPrototype.Clone(), iconParent); + } + }); + } + else if (iconReplacementPrototype instanceof loopIcon) + { + jButtonIcon.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + loopIconReplaceClicked(evt, iconReplacementPrototype.Clone(), iconParent); + } + }); + } + } + + private javax.swing.JButton setupIconicButton(int width, int height, String filepath, int gridx, int gridy, javax.swing.JPanel panel, String title, TIcon iconPrototype) + { + javax.swing.JButton jButtonIcon; + jButtonIcon = prepButton(width, height, filepath); + + javax.swing.JPopupMenu jpm = new javax.swing.JPopupMenu(); + javax.swing.JMenuItem jm = new javax.swing.JMenuItem(); + jm = new javax.swing.JMenuItem("Help"); + jpm.add(jm); + final TIcon parent = (TIcon)(iconPrototype).Clone(); + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + javax.swing.JOptionPane.showMessageDialog(jPanelMainCenter, + parent.getHelpDesc(), + "Context Help -- " + parent.getHelpTitle(), + javax.swing.JOptionPane.INFORMATION_MESSAGE, + parent.getHelpIcon()); + } + }); + + jButtonIcon.setComponentPopupMenu(jpm); + + jButtonIcon.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseEntered(java.awt.event.MouseEvent evt) { + iconMouseEntered(title); + } + public void mouseExited(java.awt.event.MouseEvent evt) { + iconMouseExited(); + } + }); + + java.awt.GridBagConstraints gridBagConstraints= new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = gridx; + gridBagConstraints.gridy = gridy; + gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); + panel.add(jButtonIcon, gridBagConstraints); + + return jButtonIcon; + } + + // for task icons + private int promptTask(Icon icon) + { + java.util.Vector al = aux_list.Instance().getAuxiliaries(); + int total_task=0; + for(int i=1; i 1) + { + ChooseTaskDialog tsk_dialog = new ChooseTaskDialog(this); + tsk_dialog.pack(); + tsk_dialog.setLocationRelativeTo(this); + tsk_dialog.setVisible(true); + int num_id = tsk_dialog.getUserInput(); + if(num_id == -1) + { + return 0; // user pressed cancel + } + icon.setTask((task)aux_list.Instance().getAuxiliaries().get(num_id)); + return 1; // everything is fine + } + else + { + javax.swing.JOptionPane.showMessageDialog(null, + "There should be at least one task apart from 'main' created.\nTask 'main' cannot be started within itself", + "Task setting invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + DirectionsLabel.setText(readyPrompt); + } + return 0; + } + + + // for event icons + // for task icons + private int promptEvent(Icon icon) + { + java.util.Vector al = aux_list.Instance().getAuxiliaries(); + int total_event=0; + for(int i=1; i 0) + { + ChooseEventDialog evt_dialog = new ChooseEventDialog(this, getCurrentAuxiliary()); + evt_dialog.pack(); + evt_dialog.setLocationRelativeTo(this); + evt_dialog.setVisible(true); + monitorEvent to_set = evt_dialog.getUserInput(); + if(to_set == null) + { + return 0; // user pressed cancel + } + icon.setEventMonitor(to_set); + return 1; // everything is fine + } + else + { + javax.swing.JOptionPane.showMessageDialog(null, + "There should be at least one event monitor defined.", + "Event setting invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + DirectionsLabel.setText(readyPrompt); + } + return 0; + } + + // for function icons + private int promptFunction(Icon icon) + { + java.util.Vector al = aux_list.Instance().getAuxiliaries(); + int total_function=0; + for(int i=1; i 0) + { + function f; + if(getCurrentAuxiliary() instanceof function) + { + f = (function)getCurrentAuxiliary(); + } + else + { + f = null; + } + ChooseFunctionDialog func_dialog = new ChooseFunctionDialog(this, f); + func_dialog.pack(); + func_dialog.setLocationRelativeTo(this); + func_dialog.setVisible(true); + int num_id = func_dialog.getUserInput(); + + if(num_id == -1) + { + return 0; // user pressed cancel + } + + function new_func = (function)aux_list.Instance().getAuxiliaries().get(num_id); + functionIcon FI = (functionIcon)icon; + if(new_func.getArguments().size() > 0) + { + FunctionArgumentDialog fad = new FunctionArgumentDialog(this, new_func, getCurrentAuxiliary(), null); + fad.pack(); + fad.setLocationRelativeTo(this); + fad.setVisible(true); + + java.util.Vector ret_val = fad.getUserInput(); + + if(ret_val != null) + { + FI.setFunction(new_func); + FI.setArguments(ret_val); + } + } + else + { + FI.setArguments(new java.util.Vector()); + FI.setFunction(new_func); + } + + return 1; // everything is fine + } + else + { + javax.swing.JOptionPane.showMessageDialog(null, + "There should be at least one function.", + "Function setting invalid", + javax.swing.JOptionPane.WARNING_MESSAGE); + DirectionsLabel.setText(readyPrompt); + } + return 0; + } + + private void updateWindowTitle() { + setTitle(AppProperties.appNameVersion + " - " + AppProperties.getDeviceName() + " - " + _Current_Save_File); + } + + private void updateFileName(String fileName) { + _Current_Save_File = fileName; + updateWindowTitle(); + } + + private void updateTargetDevice() { + if (jRadioButtonMenuItemRCX1.isSelected()) { + AppProperties.setDeviceID("RCX"); + AppProperties.setDeviceName("RCX 1.0"); + } else if (jRadioButtonMenuItemRCX2.isSelected()) { + AppProperties.setDeviceID("RCX2"); + AppProperties.setDeviceName("RCX 2.0"); + } else { + AppProperties.setDeviceID("null"); + AppProperties.setDeviceName("undefined"); + } + + updateWindowTitle(); + } + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private funsoftware.pallette.TitlePanelLabel BranchesLabel; + private funsoftware.pallette.RoundedScrollPane BranchesPane; + private funsoftware.pallette.CardPanel CenterCardPanel; + private funsoftware.pallette.TitlePanelLabel DirectionsLabel; + private funsoftware.pallette.TitlePanelLabel EditingLabel; + private funsoftware.pallette.RoundedScrollPane EditingPane; + private funsoftware.pallette.TitlePanelLabel EventMonitorsLabel; + private funsoftware.pallette.RoundedScrollPane EventMonitorsPane; + private funsoftware.pallette.TitlePanelLabel EventsLabel; + private funsoftware.pallette.RoundedScrollPane EventsPane; + private funsoftware.pallette.TitlePanelLabel FunctionsLabel; + private funsoftware.pallette.RoundedScrollPane FunctionsPane; + private funsoftware.pallette.TitlePanelLabel FunctionsReuseLabel; + private funsoftware.pallette.RoundedScrollPane FunctionsReusePane; + private funsoftware.pallette.TitlePanelLabel IconHelpLabel; + private funsoftware.pallette.RoundedScrollPane IconHelpPane; + private funsoftware.pallette.TitlePanelLabel LoopsLabel; + private funsoftware.pallette.RoundedScrollPane LoopsPane; + private funsoftware.pallette.TitlePanelLabel SinglesLabel; + private funsoftware.pallette.RoundedScrollPane SinglesPane; + private funsoftware.pallette.TitlePanelLabel TasksLabel; + private funsoftware.pallette.RoundedScrollPane TasksPane; + private funsoftware.pallette.TitlePanelLabel VariablesLabel; + private funsoftware.pallette.RoundedScrollPane VariablesPane; + private javax.swing.ButtonGroup buttonGroupTarget; + private javax.swing.JDialog jDialog1; + private javax.swing.JFileChooser jFileChooser1; + private javax.swing.JMenu jMenu1; + private javax.swing.JMenu jMenu2; + private javax.swing.JMenu jMenu3; + private javax.swing.JMenu jMenu4; + private javax.swing.JMenu jMenu5; + private javax.swing.JMenu jMenu6; + private javax.swing.JMenuBar jMenuBar1; + private javax.swing.JMenuItem jMenuItem1; + private javax.swing.JMenuItem jMenuItem10; + private javax.swing.JMenuItem jMenuItem11; + private javax.swing.JMenuItem jMenuItem12; + private javax.swing.JMenuItem jMenuItem13; + private javax.swing.JMenuItem jMenuItem14; + private javax.swing.JMenuItem jMenuItem15; + private javax.swing.JMenuItem jMenuItem16; + private javax.swing.JMenuItem jMenuItem17; + private javax.swing.JMenuItem jMenuItem18; + private javax.swing.JMenuItem jMenuItem19; + private javax.swing.JMenuItem jMenuItem2; + private javax.swing.JMenuItem jMenuItem20; + private javax.swing.JMenuItem jMenuItem21; + private javax.swing.JMenuItem jMenuItem22; + private javax.swing.JMenuItem jMenuItem3; + private javax.swing.JMenuItem jMenuItem4; + private javax.swing.JMenuItem jMenuItem5; + private javax.swing.JMenuItem jMenuItem6; + private javax.swing.JMenuItem jMenuItem7; + private javax.swing.JMenuItem jMenuItem8; + private javax.swing.JMenuItem jMenuItem9; + private javax.swing.JPanel jPanelMainCenter; + private javax.swing.JPanel jPanelMainLeft; + private javax.swing.JPanel jPanelMainRight; + private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItemRCX1; + private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItemRCX2; + private javax.swing.JSeparator jSeparator1; + private javax.swing.JSeparator jSeparator2; + private javax.swing.JSeparator jSeparator3; + private javax.swing.JSeparator jSeparator4; + private javax.swing.JSeparator jSeparator5; + private javax.swing.JSeparator jSeparator6; + private javax.swing.JSeparator jSeparator7; + private javax.swing.JSplitPane jSplitPane1; + private javax.swing.JSplitPane jSplitPane2; + // End of variables declaration//GEN-END:variables + + // manually added variables declaration by me ----- + + // the pallettes + private static ProgWindow jProgrammingWindow; // the programming window +// private objectWindow jPanel2; // the object icons window, can be reused for other similarly coloured pallettes +// private javax.swing.JScrollPane objectScroller; + +// private loopWindow jPanel3; // the loop icons window +// private javax.swing.JScrollPane branchScroller; + +// private branchWindow jPanel5; // the branch icons window +// private javax.swing.JScrollPane loopScroller; + + // -- ALL of the left hand side pallettes + // (all have been moved to designer) + + // for the centralProgrammingWindow +// private CardPanel jPanel13; + +// private bottomRightWindow jPanel11; // the bottom right window +// private directionWindow jPanel10; + private FunctionWindow jPanelFunction; // the function window + private TaskWindow jPanelTask; // the task window + private eventWindow jPanelEvent; // the event window + private monitorEventWindow jPanelEventMonitor; // the event monitor window + private static javax.swing.JScrollPane jScrollPane1; +// private static javax.swing.JPanel jPanel18; // the panel on top of the programming window + private VarWindow jPanelVar; + +// private javax.swing.JPanel jPanel19; // the title panel for object icons +// private javax.swing.JPanel jPanel20; // the title panel for branch icons +// private javax.swing.JPanel jPanel21; // the title panel for loop icons + + // the icon buttons + private javax.swing.JButton jButtonGridMode; // for grid mode button + private javax.swing.JButton jButtonUndo; // for undo button + private javax.swing.JButton jButtonRedo; // for redo button + private javax.swing.JButton jButtonCancel; // for cancel button + + // for icon name help + private javax.swing.JLabel jLabelHelp; + + // the grid dialog and syntax error dialog + private GridDialog grid_dialog; + + // the icons ready to be cloned + // the objects + + private motorIcon _motor; + private stopMotorIcon _stopmotor; + private beepIcon _beep; + private lampIcon _lamp; + private directionalMotorIcon _dirmotor; + private timerIcon _timer; + private clearSensorIcon _clearsensor; + private clearTimerIcon _cleartimer; + private playAnyNoteIcon _playanynote; + private floatMotorIcon _float; + private playSpecificNote _specificnote; + private returnIcon _returnicon; + private waitTouchIcon _waittouch; + private waitLightIcon _waitlight; + private waitCelciusIcon _waitcelcius; + private waitRotationalIcon _waitrotation; + private waitTimerIcon _waittimer; + + // the branches + + private BtouchSensorIcon _Btouch; + private BlightSensorIcon _Blight; + private BcelciusSensorIcon _Bcelcius; + private BrotationSensorIcon _Brotation; + private BtimerIcon _Btimer; + private BrandomIcon _Brandom; + private BarithmeticIcon _Barithmetic; + + // the loops + + private repeatIcon _Lrep; + private lightSensorLoopIcon _Llight; + private infiniteLoopIcon _Linfinite; + private timerLoopIcon _Ltimer; + private rotationSensorLoopIcon _Lrotation; + private celciusSensorLoopIcon _Lcelcius; + private touchSensorLoopIcon _Ltouch; + private arithmeticLoopIcon _Larithmetic; + + // the auxiliary + + private joinIcon _Jicon; + private joinLoopIcon _Jloop; + private joinEndBranchIcon _JEBIcon; + + // the task icons + + private startTaskIcon _Start; + private endTaskIcon _End; + private beginTaskIcon _BeginTask; + private stopTaskIcon _StopTask; + + // the function icon and the function skeleton + + private functionIcon _Funcby; + private function _Funct; + private task _Task; + private Event _Event; + private monitorEvent _mEvent; + + // for events + private startEvent _SEvent; + + // the variable and arithmetic operation icon + private variable _Var; + private ArithOpIcon _AOIcon; + +// private int distanceX; // horizontal uniform distance between grid intersection +// private int distanceY; // vertical uniform distance between grid intersection + + private wires wire_list; // the list containing the wires + private icons_list icon_list; // the list containing the icons + +// private int maxX; // maximum X value of the programming window +// private int maxY; // maximum Y value of the programming window +// private javax.swing.JViewport viewport; // the viewport of the scrollpane1 + + private states do_state = states.Instance(); // for undo and redo (memento design pattern) and to check whether a state has been saved in a file + + private FunctionCombo fcombo; // function combo list + +// private auxiliary current_aux; // currently displayed function or task + + private String _Current_Save_Path = new String(); +// private String ConfigFile_Name; + + // Track the current file name + private String _Current_Save_File = "New File"; + + // The "ready" prompt text + private String readyPrompt = AppProperties.appName + " ready for inputs"; +} \ No newline at end of file diff --git a/src/funsoftware/pallette/CardPanel.java b/src/funsoftware/pallette/CardPanel.java new file mode 100644 index 0000000..854cc2e --- /dev/null +++ b/src/funsoftware/pallette/CardPanel.java @@ -0,0 +1,42 @@ +/* + * CardPanel.java + * + * Created on 9 February 2006, 17:10 + */ + +package funsoftware.pallette; + +/** + * Will be of a card layout and house multiple programming windows + * @author Thomas Legowo + */ +public class CardPanel extends javax.swing.JPanel { + + /** Creates a new instance of CentralWindow */ + public CardPanel() { + super(new java.awt.CardLayout()); + this.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(247, 247, 247), 10, true)); + } + +// // overriding the paintComponent +// /** +// * Paints this object window +// * @param g Graphics +// */ +// protected void paintComponent(java.awt.Graphics g) { +// super.paintComponent(g); +// +// javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/mainWindow/lefttop.gif")); +// g.drawImage(ii.getImage(), 0, 0, this); +// +// ii = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/mainWindow/righttop.gif")); +// g.drawImage(ii.getImage(), getWidth()-30, 0, this); +// +// ii = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/mainWindow/rightbottom.gif")); +// g.drawImage(ii.getImage(), getWidth()-30, getHeight()-30, this); +// +// ii = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/mainWindow/leftbottom.gif")); +// g.drawImage(ii.getImage(), 0, getHeight()-30, this); +// } +} + diff --git a/src/funsoftware/pallette/RoundedScrollPane.java b/src/funsoftware/pallette/RoundedScrollPane.java new file mode 100644 index 0000000..c3ca2fa --- /dev/null +++ b/src/funsoftware/pallette/RoundedScrollPane.java @@ -0,0 +1,22 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package funsoftware.pallette; + +/** + * + * @author Matthew + */ +public class RoundedScrollPane extends javax.swing.JScrollPane { + + public RoundedScrollPane(){ + super(); + + this.setMinimumSize(new java.awt.Dimension(130, 115)); + this.setPreferredSize(this.getMinimumSize()); + this.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(247, 247, 247), 5, true)); + } + +} diff --git a/src/funsoftware/pallette/TitlePanelLabel.java b/src/funsoftware/pallette/TitlePanelLabel.java new file mode 100644 index 0000000..f6f7719 --- /dev/null +++ b/src/funsoftware/pallette/TitlePanelLabel.java @@ -0,0 +1,75 @@ +/* + * TitlePanelLabel.java + * + * Created on 13 December 2018 + * + */ + +package funsoftware.pallette; + +/** + * + * @author Matthew Sheets + */ +public class TitlePanelLabel extends javax.swing.JPanel { + + javax.swing.JLabel jLabelTitle = new javax.swing.JLabel(); + java.awt.GridBagConstraints gridBagConstraints; + + /** Creates a new instance */ + public TitlePanelLabel() { + super(); + + this.setBackground(new java.awt.Color(234, 234, 234)); + this.setForeground(new java.awt.Color(0, 0, 0)); + this.setFont(new java.awt.Font("Verdana", 1, 14)); + + this.setMinimumSize(new java.awt.Dimension(130, 20)); + this.setMaximumSize(new java.awt.Dimension(Integer.MAX_VALUE, this.getMinimumSize().height)); + this.setPreferredSize(this.getMinimumSize()); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + + this.setLayout(new java.awt.GridBagLayout()); + this.add(jLabelTitle, gridBagConstraints); + } + + public String getText() + { + return jLabelTitle.getText(); + } + + public void setText(String text) + { + jLabelTitle.setText(text); + } + + public void setBackground(java.awt.Color color) + { + super.setBackground(color); + if (jLabelTitle != null) + { + jLabelTitle.setBackground(color); + } + } + + public void setForeground(java.awt.Color color) + { + super.setForeground(color); + if (jLabelTitle != null) + { + jLabelTitle.setForeground(color); + } + } + + public void setFont(java.awt.Font font) + { + super.setFont(font); + if (jLabelTitle != null) + { + jLabelTitle.setFont(font); + } + } +} diff --git a/src/funsoftware/pallette/bottomRightWindow.java b/src/funsoftware/pallette/bottomRightWindow.java new file mode 100644 index 0000000..c1c440a --- /dev/null +++ b/src/funsoftware/pallette/bottomRightWindow.java @@ -0,0 +1,45 @@ +/* + * bottomRightWindow.java + * + * Created on 27 August 2005, 20:07 + * + */ + +package funsoftware.pallette; + +/** + * The purpose of this window is to house a list of available and reusable subroutine + * @author Thomas Legowo + * + */ +public class bottomRightWindow extends javax.swing.JPanel { + + /** Creates a new instance of bottomRightWindow */ + public bottomRightWindow() { + super(new java.awt.GridBagLayout()); + java.awt.Dimension area = new java.awt.Dimension(210,55); + setBackground(new java.awt.Color(247, 247, 247)); + super.setPreferredSize(area); + } + + // overriding the paintComponent + /** + * Paints this object window + * @param g Graphics + */ + protected void paintComponent(java.awt.Graphics g) { + super.paintComponent(g); + + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/functionreuse/lefttop.jpg")); + g.drawImage(ii.getImage(), 0, 0, this); + + ii = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/functionreuse/righttop.jpg")); + g.drawImage(ii.getImage(), getWidth()-10, 0, this); + + ii = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/functionreuse/rightbottom.jpg")); + g.drawImage(ii.getImage(), getWidth()-10, getHeight()-10, this); + + ii = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/functionreuse/leftbottom.jpg")); + g.drawImage(ii.getImage(), 0, getHeight()-10, this); + } +} diff --git a/src/funsoftware/pallette/branchWindow.java b/src/funsoftware/pallette/branchWindow.java new file mode 100644 index 0000000..4eaf8ff --- /dev/null +++ b/src/funsoftware/pallette/branchWindow.java @@ -0,0 +1,43 @@ +/* + * branchWindow.java + * + * Created on 27 August 2005, 19:44 + * + */ + +package funsoftware.pallette; + +/** + * This class cater for the branch icons pallettes + * @author Thomas Legowo + */ +public class branchWindow extends javax.swing.JPanel { + + /** Creates a new instance of branchWindow */ + public branchWindow() { + super(new java.awt.GridBagLayout()); + setBorder(null); + setBackground(new java.awt.Color(247, 247, 247)); + } + + // overriding the paintComponent + /** + * Paints this object window + * @param g Graphics + */ + protected void paintComponent(java.awt.Graphics g) { + super.paintComponent(g); + + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/iconWindow/lefttop.jpg")); + g.drawImage(ii.getImage(), 0, 0, this); + + ii = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/iconWindow/righttop.jpg")); + g.drawImage(ii.getImage(), getWidth()-10, 0, this); + + ii = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/iconWindow/rightbottom.jpg")); + g.drawImage(ii.getImage(), getWidth()-10, getHeight()-10, this); + + ii = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/iconWindow/leftbottom.jpg")); + g.drawImage(ii.getImage(), 0, getHeight()-10, this); + } +} diff --git a/src/funsoftware/pallette/directionWindow.java b/src/funsoftware/pallette/directionWindow.java new file mode 100644 index 0000000..e2d8f1a --- /dev/null +++ b/src/funsoftware/pallette/directionWindow.java @@ -0,0 +1,45 @@ +/* + * directionWindow.java + * + * Created on 13 September 2005, 19:17 + * + */ + +package funsoftware.pallette; + +/** + * This class is for the window that gives a real time direction based on what the user previous action was. + * @author Thomas + */ +public class directionWindow extends javax.swing.JPanel { + + /** Creates a new instance of directionWindow */ + public directionWindow() { + super(new java.awt.GridBagLayout()); + } + + // overriding the paintComponent + /** + * Paint the window + * @param g Graphics + */ + protected void paintComponent(java.awt.Graphics g) { + super.paintComponent(g); + + javax.swing.ImageIcon ic; + java.awt.Image image; +/* + ic = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/dirWindow/background.jpg")); + image = ic.getImage(); + g.drawImage(image, 0, 0, getWidth(), getHeight(), this); + + ic = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/dirWindow/bottomtitle.gif")); + image = ic.getImage(); + g.drawImage(image, 115, getHeight()-55, this); + + ic = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/dirWindow/bottomtitle2.gif")); + image = ic.getImage(); + g.drawImage(image, getWidth()-335, getHeight()-60, this); + */ + } +} diff --git a/src/funsoftware/pallette/loopWindow.java b/src/funsoftware/pallette/loopWindow.java new file mode 100644 index 0000000..e9580fc --- /dev/null +++ b/src/funsoftware/pallette/loopWindow.java @@ -0,0 +1,43 @@ +/* + * loopWindow.java + * + * Created on 27 August 2005, 19:44 + * + */ + +package funsoftware.pallette; + +/** + * This class cater for the pallette containing all kind of loop icons + * @author Thomas Legowo + */ +public class loopWindow extends javax.swing.JPanel { + + /** Creates a new instance of loopWindow */ + public loopWindow() { + super(new java.awt.GridBagLayout()); + setBorder(null); + setBackground(new java.awt.Color(247, 247, 247)); + } + + // overriding the paintComponent + /** + * Paints this object window + * @param g Graphics + */ + protected void paintComponent(java.awt.Graphics g) { + super.paintComponent(g); + + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/loopWindow/lefttop.jpg")); + g.drawImage(ii.getImage(), 0, 0, this); + + ii = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/loopWindow/righttop.jpg")); + g.drawImage(ii.getImage(), getWidth()-10, 0, this); + + ii = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/loopWindow/rightbottom.jpg")); + g.drawImage(ii.getImage(), getWidth()-10, getHeight()-10, this); + + ii = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/loopWindow/leftbottom.jpg")); + g.drawImage(ii.getImage(), 0, getHeight()-10, this); + } +} diff --git a/src/funsoftware/pallette/objectWindow.java b/src/funsoftware/pallette/objectWindow.java new file mode 100644 index 0000000..b2e0a1e --- /dev/null +++ b/src/funsoftware/pallette/objectWindow.java @@ -0,0 +1,42 @@ +/* + * objectWindow.java + * + * Created on 27 August 2005, 17:30 + * + */ + +package funsoftware.pallette; + +/** + * This class cater for the pallette holding the singles icons --> motor, lamp, timer, etc etc + * @author Thomas Legowo + */ +public class objectWindow extends javax.swing.JPanel { + + /** Creates a new instance of objectWindow */ + public objectWindow() { + super(new java.awt.GridBagLayout()); + setBorder(null); + setBackground(new java.awt.Color(247, 247, 247)); + } + + /** + * Paints this object window + * @param g Graphics + */ + protected void paintComponent(java.awt.Graphics g) { + super.paintComponent(g); + + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/iconWindow/lefttop.jpg")); + g.drawImage(ii.getImage(), 0, 0, this); + + ii = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/iconWindow/righttop.jpg")); + g.drawImage(ii.getImage(), getWidth()-10, 0, this); + + ii = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/iconWindow/rightbottom.jpg")); + g.drawImage(ii.getImage(), getWidth()-10, getHeight()-10, this); + + ii = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/iconWindow/leftbottom.jpg")); + g.drawImage(ii.getImage(), 0, getHeight()-10, this); + } +} diff --git a/src/funsoftware/pallette/variableWindow.java b/src/funsoftware/pallette/variableWindow.java new file mode 100644 index 0000000..b0d7f41 --- /dev/null +++ b/src/funsoftware/pallette/variableWindow.java @@ -0,0 +1,43 @@ +/* + * variableWindow.java + * + * Created on 10 February 2006, 18:08 + * + */ + +package funsoftware.pallette; + +/** + * For the variable pallette + * @author Thomas Legowo + */ +public class variableWindow extends javax.swing.JPanel{ + + /** Creates a new instance of variableWindow */ + public variableWindow() { + super(new java.awt.GridBagLayout()); + setBorder(null); + setBackground(new java.awt.Color(247, 247, 247)); + } + + // overriding the paintComponent + /** + * Paints this object window + * @param g Graphics + */ + protected void paintComponent(java.awt.Graphics g) { + super.paintComponent(g); + + javax.swing.ImageIcon ii = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/varWindow/lefttop.jpg")); + g.drawImage(ii.getImage(), 0, 0, this); + + ii = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/varWindow/righttop.jpg")); + g.drawImage(ii.getImage(), getWidth()-10, 0, this); + + ii = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/varWindow/rightbottom.jpg")); + g.drawImage(ii.getImage(), getWidth()-10, getHeight()-10, this); + + ii = new javax.swing.ImageIcon(getClass().getResource("/icons/interface/varWindow/leftbottom.jpg")); + g.drawImage(ii.getImage(), 0, getHeight()-10, this); + } +} diff --git a/src/funsoftware/properties/AppProperties.java b/src/funsoftware/properties/AppProperties.java new file mode 100644 index 0000000..7db1928 --- /dev/null +++ b/src/funsoftware/properties/AppProperties.java @@ -0,0 +1,70 @@ +/* + * AppProperties.java + * + * Created on 25 July 2008 + */ + +package funsoftware.properties; + +/** + * Manages global application properties + * @author Matthew Sheets + */ +public class AppProperties { + + // Global constants + /** + * The application name + */ + public static final String appName = "VisualNQC"; + + /** + * The application version + */ + public static final String appVersion = "1.0"; + + /** + * The application name and version + */ + public static final String appNameVersion = appName + " " + appVersion; + + /** + * The name of the NQC code file generated by the application + * NOTE: Filename must NOT contain spaces + */ + public static final String appCodeFileName = "visual.nqc"; + + + public static String getProgramTypeID(){ + return appName + "-" + appVersion + ":" + getDeviceID(); + } + + // Application properties + + // The hardware device ID + private static String _deviceID; + public static String getDeviceID() { + return _deviceID; + } + public static void setDeviceID(String deviceID) { + _deviceID = deviceID; + } + + // The hardware device name + private static String _deviceName; + public static String getDeviceName() { + return _deviceName; + } + public static void setDeviceName(String deviceName) { + _deviceName = deviceName; + } + + // The IR tower communication tty type + private static String _ttyType; + public static String getTtyType() { + return _ttyType; + } + public static void setTtyType(String ttyType) { + _ttyType = ttyType; + } +} diff --git a/src/funsoftware/st/State.java b/src/funsoftware/st/State.java new file mode 100644 index 0000000..da90ffd --- /dev/null +++ b/src/funsoftware/st/State.java @@ -0,0 +1,106 @@ +/* + * State.java + * + * Created on 17 September 2005, 13:24 + * + */ + +package funsoftware.st; + +/** + * This class maintains a state (or states) of a set of icons and wires on the programming window + * Used for --> Memento design patterns (Undo and Redo) and deciding whether a file has been saved + * @author Thomas Legowo + * + */ +public class State { + + int saved; // initially zero for not saved, 1 for saved + String save_file_path; // for save file path + String filename; + String algorithm; // representation of the icons (snapshot of a state) + + /** Creates a new instance of State */ + public State() { + saved = 0; + save_file_path = new String(); + filename = new String(); + algorithm = new String(); + } + + /** + * To set status of the current state whether it has been saved + * @param s Save status + */ + public void setSaveStatus(int s) + { + saved = s; + } + + /** + * To set save file path + * @param s Save file path + */ + public void setSaveFilePath(String s) + { + save_file_path = s; + } + + /** + * To set save file name + * @param s Save file name + */ + public void setSaveFileName(String s) + { + if(s.lastIndexOf(".") != -1) + { + s = s.substring(0, s.lastIndexOf(".")); + } + filename = s; + } + + /** + * Return the save file path + * @return Save file path + */ + public String returnSaveFilePath() + { + return save_file_path; + } + + /** + * Return the save file name + * @return Save file name + */ + public String returnSaveFileName() + { + return filename; + } + + /** + * Return the save status of the current state + * @return Save status + */ + public int returnSaveStatus() + { + return saved; + } + + /** + * Set the current state + * @param a State in string format + */ + public void setState(String a) + { + algorithm = a; + } + + /** + * Return the current state + * @return String format of the state + */ + public String returnState() + { + return algorithm; + } +} diff --git a/src/funsoftware/st/UndoRedo.java b/src/funsoftware/st/UndoRedo.java new file mode 100644 index 0000000..3ae39a1 --- /dev/null +++ b/src/funsoftware/st/UndoRedo.java @@ -0,0 +1,111 @@ +/* + * UndoRedo.java + * + * Created on 27 December 2005, 13:06 + * + */ + +package funsoftware.st; + +import funsoftware.consts.*; +import funsoftware.comp.*; + +/** + * This class manages the undo and redo operations, it commits the state updates and its buttons + * @author Thomas Legowo + */ +public class UndoRedo { + + private static javax.swing.JButton UndoButton; + private static javax.swing.JButton RedoButton; + private static javax.swing.JMenuItem UndoMenu; + private static javax.swing.JMenuItem RedoMenu; + + /** + * To set the undo button + * @param NUndo The undo button + */ + public static void setUndoButton(javax.swing.JButton NUndo) + { + UndoButton = NUndo; + } + + /** + * To set the redo button + * @param NRedo The redo button + */ + public static void setRedoButton(javax.swing.JButton NRedo) + { + RedoButton = NRedo; + } + + /** + * To set the undo menu + * @param NUndo The undo menu + */ + public static void setUndoMenu(javax.swing.JMenuItem NUndo) + { + UndoMenu = NUndo; + } + + /** + * To set the redo menu + * @param NRedo The redo menu + */ + public static void setRedoMenu(javax.swing.JMenuItem NRedo) + { + RedoMenu = NRedo; + } + + /** + * To update the state of the undo redo buttons + */ + public static void updateRedoUndoButtons() + { + states do_state = states.Instance(); + if(do_state.getUndoState().size() == 0) + { + UndoButton.setForeground(new java.awt.Color(180, 180, 180)); + UndoMenu.setForeground(new java.awt.Color(180, 180, 180)); + } + else if(do_state.getUndoState().size() > 0) + { + UndoButton.setForeground(new java.awt.Color(0, 0, 0)); + UndoMenu.setForeground(new java.awt.Color(0, 0, 0)); + } + if(do_state.getRedoState().size() == 0) + { + RedoButton.setForeground(new java.awt.Color(180, 180, 180)); + RedoMenu.setForeground(new java.awt.Color(180, 180, 180)); + } + else if(do_state.getRedoState().size() > 0) + { + RedoButton.setForeground(new java.awt.Color(0, 0, 0)); + RedoMenu.setForeground(new java.awt.Color(0, 0, 0)); + } + } + + /** + * To update the state of the program + */ + public static void update_state() + { + states do_state = states.Instance(); + State tmp_state = new State(); + icons_list icon_list = icons_list.Instance(); + tmp_state.setState(Translator.getAlgorithm(icon_list.getIcons().get(1))); + do_state.forward(tmp_state); + updateRedoUndoButtons(); + } + + /** + * To reset the state of the undo/redo buttons and menu items + */ + public static void reset() + { + UndoButton.setForeground(new java.awt.Color(180, 180, 180)); + UndoMenu.setForeground(new java.awt.Color(180, 180, 180)); + RedoButton.setForeground(new java.awt.Color(180, 180, 180)); + RedoMenu.setForeground(new java.awt.Color(180, 180, 180)); + } +} diff --git a/src/funsoftware/st/states.java b/src/funsoftware/st/states.java new file mode 100644 index 0000000..d8e2acb --- /dev/null +++ b/src/funsoftware/st/states.java @@ -0,0 +1,174 @@ +/* + * states.java + * + * Created on 17 September 2005, 14:17 + */ + +package funsoftware.st; + +/** + * This class handles for different states of the program, it contains a vector of State(s). + * @author Thomas Legowo + */ +public class states { + + private java.util.Vector undo_state; + private java.util.Vector redo_state; + private State current_state; + private int undo_lim_states; // num of states stored in undo + private int redo_lim_states; // num of states stored in redo + + // for singleton design pattern + private static states instance = null; + + /** Creates a new instance of states */ + protected states() { + undo_state = new java.util.Vector(); + redo_state = new java.util.Vector(); + current_state = null; // initially + undo_lim_states = 20; // maximum 20 states to undo + redo_lim_states = 20; // maximum 20 states to redo + } + + /** + * To ensure only one instance of the states list is used, use singleton design pattern + * @return Instance of this class + */ + public static states Instance() { + if(instance == null) { + instance = new states(); + } + return instance; + } + + /** + * Resets this states object and its attributes + */ + public void reset() { + undo_state = new java.util.Vector(); + redo_state = new java.util.Vector(); + current_state = null; // initially + undo_lim_states = 20; + redo_lim_states = 20; + } + + /** + * Gets the current state of the program + * @return Current state + */ + public State getCurrentState() { + return current_state; + } + + // dealing with the states to be used in Undo operations + /** + * Adds a state in the undo database + * @param new_state New state + */ + public void addStateInUndo(State new_state) { + if(undo_state.size() == undo_lim_states) // limit reached, so overwrite the oldest first + { + undo_state.removeElementAt(undo_lim_states-1); + } + undo_state.add(0, new_state); + } + + // remove the first one always and return it + /** + * Removes a state from the undo database + * @return A state in undo database + */ + public State removeStateInUndo() { + State ret_val; + ret_val = undo_state.get(0); + undo_state.removeElementAt(0); + + return ret_val; + } + + // to do the undo operation + // the return value is the current state set to be the next available state in the undo state list + /** + * Execute the undo operation + * @return Current state + */ + public State commitUndo() { + if(undo_state.size() == 0) // can't undo anymore + { + return null; + } + addStateInRedo(current_state); // preserve the current state in redo + current_state = removeStateInUndo(); + + return current_state; + } + + // dealing with the states to be used in Redo operations + /** + * Adds a state in the redo database + * @param new_state New state + */ + public void addStateInRedo(State new_state) { + if(redo_state.size() == redo_lim_states) // limit reached, so overwrite the oldest first + { + redo_state.removeElementAt(redo_lim_states-1); + } + redo_state.add(0, new_state); + } + + /** + * Removes a state from the redo database + * @return A state in redo database + */ + public State removeStateInRedo() { + State ret_val; + ret_val = redo_state.get(0); + redo_state.removeElementAt(0); + return ret_val; + } + + // to do the redo operation + /** + * Execute the redo operation + * @return Current state + */ + public State commitRedo() { + if(redo_state.size() == 0) // can't redo anymore + { + return null; + } + addStateInUndo(current_state); // preserve the current state in undo + current_state = removeStateInRedo(); + return current_state; + } + + // the method to keep on going forward from one state to another + // i.e. keep filling in the Undo state vector + /** + * Going forward and taking more states as users execute operations + * @param new_state New state to be stored in the undo database + */ + public void forward(State new_state) { + if(current_state != null) // not the beginning + { + addStateInUndo(current_state); // move current state to undo + } + redo_state = new java.util.Vector(); // reset the redo + current_state = new_state; // set the current_state + } + + /** + * Get the states from the undo database + * @return Set of states + */ + public java.util.Vector getUndoState() { + return undo_state; + } + /** + * Get the states from the undo database + * @return Set of states + */ + public java.util.Vector getRedoState() { + return redo_state; + } +} diff --git a/src/funsoftware/struct/auxiliary.java b/src/funsoftware/struct/auxiliary.java new file mode 100644 index 0000000..48b00c7 --- /dev/null +++ b/src/funsoftware/struct/auxiliary.java @@ -0,0 +1,165 @@ +/* + * auxiliary.java + * + * Created on 30 December 2005, 14:54 + * + */ + +package funsoftware.struct; + +import funsoftware.ic.*; +import funsoftware.var.*; +import funsoftware.inter.*; + +/** + * This class is a superclass for all auxiliary elements that require new programming windows. They are tasks, event monitors and functions. + * @author Thomas Legowo + */ +public class auxiliary { + + /** Creates a new instance of auxiliary */ + public auxiliary() { + } + + /** + * To return the auxiliary's name + * @return The name + */ + public String getName() + { + return null; + } + + /** + * To set the numId of this auxiliary + * @param i The new numId + */ + public void setNumId(int i) + { + } + + /** + * To return the NQC function header + * @return The NQC function header + */ + public String getNQCFunctionHeader() + { + return null; + } + + /** + * The return the begin icon + * @return The begin icon + */ + public Icon getBeginIcon() + { + return null; + } + + /** + * To return the numId of the auxiliary + * @return The numId + */ + public int getNumId() + { + return 0; + } + + /** + * To return the translation of this auxiliary + * @param id_separator To separate ids + * @param id_att_separator To separate id with attribute + * @param att_boundary_begin To start attributes + * @param att_boundary_end To end attributes + * @param att_value_connector To separate attributes and its values + * @param att_separator To separate attributes + * @return Translation + */ + public String getTranslation(String id_separator, String id_att_separator, + String att_boundary_begin, String att_boundary_end, String att_value_connector, String att_separator) + { + return null; + } + + /** + * Returns the NQC task header + * @return The NQC task header + */ + public String getNQCTaskHeader() + { + return null; + } + + /** + * To add a local variable onto the list + * @param nv A local variable + */ + public void addVariable(variable nv) + { + + } + + /** + * To delete a local variable from this auxiliary + * @param nv A local variable to be deleted + */ + public void delVariable(variable nv) + { + + } + + /** + * To return the list of the local variables that this auxiliary owns + * @return The list of the local variables + */ + public java.util.Vector getVariables() + { + java.util.Vector tmp = new java.util.Vector(); + return tmp; + } + + /** + * To return the list of the local variables list manager that this auxiliary owns + * @return The list of the local variables list manager + */ + public local_var_list getLocalVarList() + { + local_var_list lvl = new local_var_list(); // for events linking to auxiliaries using their local variables + return lvl; + } + + /** + * To return an individual local variable that this auxiliary structure has + * @param name The name of the variable + * @return The variable + */ + public variable getVariable(String name) + { + return null; + } + + /** + * Returns the panel this task's member are on, not the individual task's icon itself + * @return The programming window + */ + public ProgWindow getProgWindow() + { + return null; + } + /** + * Returns the scroll pane of the programming window + * @return Programming window's scroller + */ + public javax.swing.JScrollPane getScroller() + { + return null; + } + /** + * Returns the panel on top of the programming window + * @return Programming window's parent panel + */ + public javax.swing.JPanel getPanel() + { + return null; + } +} diff --git a/src/funsoftware/struct/local_var_list.java b/src/funsoftware/struct/local_var_list.java new file mode 100644 index 0000000..a9bbcfd --- /dev/null +++ b/src/funsoftware/struct/local_var_list.java @@ -0,0 +1,186 @@ +/* + * local_var_list.java + * + * Created on 17 January 2006, 12:07 + * + */ + +package funsoftware.struct; + +import funsoftware.var.*; + +/** + * Acts like a var_list but is not unique and each auxiliary has one (for local variables) + * @author Thomas Legowo + */ +public class local_var_list { + + // BUT IT RECYCLES THE ID + // i.e. the element's id corresponds to its location in the vector for quick access + private java.util.Vector list_of_vars; + private java.util.Vector list_of_available_id; + + /** Creates a new instance of local_var_list */ + public local_var_list() { + list_of_vars = new java.util.Vector(); + list_of_vars.setSize(1); + list_of_available_id = new java.util.Vector(); + } + + /** + * Adds a variable + * @param var The variable + */ + public void addVariable(variable var) + { + int id = getFirstAvailableId(); + + var.setNumId(id); + + if(id < list_of_vars.size()) + { + list_of_vars.setElementAt(var, id); + } + else + { + list_of_vars.add(id, var); + } + } + + /** + * Deletes a variable, no need to decrease the size of the vector by 1 since the id is reusable + * @param num_id Variable to be deleted + */ + public void delVariable(int num_id) + { + list_of_vars.setElementAt(null, num_id); + list_of_available_id.addElement(num_id); + } + + /** + * Returns the first available id to be recycled, an id will never equal to zero. + * If there is no id available to be reused, this function will return the size of the list + * @return Id + */ + public int getFirstAvailableId() + { + int id; + if(list_of_available_id.size() > 0) // if there are any recycled id + { + id = list_of_available_id.get(0); // get the first available one + list_of_available_id.removeElementAt(0); // remove it of the list + } + else + { + id = list_of_vars.size(); + } + return id; + } + + /** + * Gets the list of variables + * @return Set of variable structures + */ + public java.util.Vector getVariables() + { + return list_of_vars; + } + + /** + * Resets this class' list of variables + */ + public void resetVarList() + { + list_of_vars = new java.util.Vector(); + list_of_vars.setSize(1); + list_of_available_id = new java.util.Vector(); + } + + /** + * Returns 1 if the name is not unique, 0 otherwise, 2 if does not conform to rules of allowed characters + * @param name The name to be checked + * @param num_id The num_id of the local variable + * @return The status of the process' outcome + */ + public int checkName(String name, int num_id) + { + int maxIndex; + + if(num_id != 0 && name.compareTo(list_of_vars.get(num_id).getName()) == 0) // for unchanged name + { + } + else + { + maxIndex = list_of_vars.size(); + for(int i=1; i= 65 && c <= 90) || (c >= 97 && c <= 122) || c == 95)) + || (index > 0 && ((c >=48 && c <= 57) || (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || c == 95))) + { + index++; + continue; + } + else + { + return 2; + } + } + } + + return 0; + } + + /** + * For the reverse translation process + * @param name The name of the variable to be searched + * @return The variable + */ + public variable getVariable(String name) + { + variable tmp = null; + for(int i=1; i 1) + { + for(int i=1; i Tasks; // the members, each being a task icon + private java.awt.Dimension area; // the area of the panel + + // the four temporary variables needed for the construction of a ProgWindow + private TitlePanelLabel jDirectionsLabel; + + private javax.swing.JFrame jFrame; + + // the tabbed window manager + private TabbedWindowManager twm; + + /** + * Creates a new instance of TaskWindow + * @param jf The frame + * @param jPanel13 Panel on top of programming window + * @param njDirectionsLabel Real time direction palette + * @param evw The event window + */ + public TaskWindow(javax.swing.JFrame jf, javax.swing.JPanel jPanel13, + TitlePanelLabel njDirectionsLabel, VarWindow varw, monitorEventWindow evw) + { + super(); + super.setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS)); + jFrame = jf; + Tasks = new java.util.Vector(); + twm = TabbedWindowManager.Instance(jPanel13, varw, evw); + jDirectionsLabel = njDirectionsLabel; + setBackground(new java.awt.Color(247, 247, 247)); + } + + /** + * To paint this task window + * @param g Graphics + */ + protected void paintComponent(java.awt.Graphics g) + { + // update the radio buttons texts + int lim = getComponentCount(); + for(int i=0; i New + */ + public void reset() + { + removeAll(); + Tasks = new java.util.Vector(); + + refreshContainer(); + } + + /** + * Insert a new task radio button onto this task window + * @param tsk A task icon + */ + public void insertTask(task tsk) + { + javax.swing.JRadioButton tskrb = new javax.swing.JRadioButton(tsk.getName()); + tskrb.setBackground(new java.awt.Color(247, 247, 247)); + tskrb.setActionCommand(Integer.toString(tsk.getNumId())); + tskrb.addActionListener(this); + Tasks.addElement(tsk); + radiobuttons.Instance().getButtonGroup().add(tskrb); + add(tskrb); + + // to set up the component pop up menu + javax.swing.JPopupMenu jpm = new javax.swing.JPopupMenu(); + javax.swing.JMenuItem jm = new javax.swing.JMenuItem(); + jm = new javax.swing.JMenuItem("Delete Task"); + final int num_id = tsk.getNumId(); + + if(num_id != 1) // the task Main has id = 1, cannot delete nor rename it + { + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + deleteTaskPerformed(num_id); + } + }); + jpm.add(jm); + jm = new javax.swing.JMenuItem("Rename Task"); + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + renameTaskPerformed(num_id); + } + }); + jpm.add(jm); + tskrb.setComponentPopupMenu(jpm); + } + javax.swing.JPanel jp = tsk.setUpAllIcons(jDirectionsLabel, this); + twm.addPanel(jp, tsk.getNumId()); + + refreshContainer(); + } + + // to edit the task's attributes, being its name + private void renameTaskPerformed(int num_id) + { + TaskNameDialog tsk_dialog = new TaskNameDialog(jFrame, aux_list.Instance().getAuxiliaries().get(num_id).getName(), 1); + tsk_dialog.pack(); + tsk_dialog.setLocationRelativeTo(jFrame); + tsk_dialog.setVisible(true); + + String tmpName = aux_list.Instance().getAuxiliaries().get(num_id).getName(); + String taskName = tsk_dialog.getUserInput(); + if(taskName.compareTo("") != 0 && taskName.compareTo(tmpName) != 0) // not the current value and not an empty string + { + // change the names for this task and all of its associated task begin and stop icons + task tmp = (task)aux_list.Instance().getAuxiliaries().get(num_id); + tmp.setName(taskName); + + java.util.Vector ics = (icons_list.Instance()).getIcons(); + for(int i=1; i ics = icon_list.getIcons(); + for(int i=1; i enum_ab = radiobuttons.Instance().getButtonGroup().getElements(); + javax.swing.JRadioButton jrb; + int sel_id = 1; + while(enum_ab.hasMoreElements() == true) + { + jrb = (javax.swing.JRadioButton)enum_ab.nextElement(); + if(jrb.isSelected() == true) + { + rad_butt_command = jrb.getActionCommand(); + sel_id = Integer.parseInt(rad_butt_command); + break; + } + } + + if(sel_id == id_del) + { + return true; + } + return false; + } + + /** + * Delete a task button and all task icons representing that task on this task window based on the given num_id + * @param num_id Task id + */ + public void deleteTask(int num_id) + { + int del_pos = 0; + for(int i=0; i ics; + + // a vector that is there to preserve the positions of the icons + private java.util.Vector backup_coord; + private ProgWindow prog_panel; + private javax.swing.JScrollPane scroller; + private javax.swing.JPanel panel; + + // the task window + private TaskWindow tskwin; + + /** Creates a new instance of task */ + public task() + { + super(); + num_id = 0; // not assigned originally, this id will be assigned by the task_list (called from ProgWindow class) + name = "task"; + ics = new java.util.Vector(); + backup_coord = new java.util.Vector(); + start_icon = (new startTaskIcon()).Clone(); + end_icon = (new endTaskIcon()).Clone(); + list_var = new local_var_list(); + } + + /** + * Sets up the beginning, ending and the member icons to be together. Programming window and its connected panels are also set up here + * @param njDirectionsLabel The real time direction label + * @param njPanel17 The task window + * @return The panel on top of the programming window to be + */ + public javax.swing.JPanel setUpAllIcons(TitlePanelLabel njDirectionsLabel, TaskWindow njPanel17) + { + int ndx = Constants.gridDistanceX; + int ndy = Constants.gridDistanceY; + // configure the parent panel + javax.swing.JPanel jp = new javax.swing.JPanel(); + panel = jp; + panel.setLayout(new java.awt.GridBagLayout()); + // configure the scrollpane + javax.swing.JScrollPane jsp = new javax.swing.JScrollPane(); + + scroller = jsp; + + jsp.setBorder(null); + + panel.add(jsp); + panel.setPreferredSize(new java.awt.Dimension(Constants.maxHorizontalProgWindow, Constants.maxVerticalProgWindow)); + panel.setMinimumSize(new java.awt.Dimension(Constants.maxHorizontalProgWindow, Constants.maxVerticalProgWindow)); + panel.setOpaque(false); + panel.setBackground(new java.awt.Color(255,255,255)); + // configure the programming panel within the JScrollPane + ProgWindow jP2 = new ProgWindow(njDirectionsLabel); + jsp.setBackground(new java.awt.Color(255,255,255)); + jP2.setLayout(null); + jP2.setArea(new java.awt.Dimension(ndx*4, ndy*2)); + prog_panel = jP2; + + + int p_width = (int)jP2.getPreferredSize().getWidth(); + int p_height = (int)jP2.getPreferredSize().getHeight(); + + jsp.setPreferredSize(new java.awt.Dimension(p_width, p_height)); + jsp.setMinimumSize(new java.awt.Dimension(p_width, p_height)); + jP2.setBackground(new java.awt.Color(255,255,255)); + javax.swing.JViewport viewport = new javax.swing.JViewport(); + viewport.setView(jP2); + jsp.setViewport(viewport); + + + icons_list icon_list = icons_list.Instance(); + wires wire_list = wires.Instance(); + + // add the start icon + + icon_list.addIcon(start_icon); + + int xpos = gridcalculation.calculateXleft(ndx); + int ypos = gridcalculation.calculateY(ndy); + + coord tmp_co = new coord(xpos, ypos); + + coord co = gridcalculation.computeCoord(start_icon, tmp_co); + start_icon.setCoordinate(co); + start_icon.setBounds(co.getX(), co.getY(), start_icon.getPreferredSize().width,start_icon.getPreferredSize().height); + start_icon.setProgWindow(jP2); + start_icon.setScroller(jsp); + start_icon.setTask(this); + jP2.add(start_icon); + jP2.addIcon(start_icon); + jP2.setStartIcon(start_icon); + + // add the end icon + icon_list.addIcon(end_icon); + + // finish up the end icon construction + xpos = ndx*2; + ypos = ndy; + + // update the y coordinate of start_ic now that all members have been read + + tmp_co = new coord(xpos, ypos); + co = new coord(); + co = gridcalculation.computeCoord(start_icon, tmp_co); + end_icon.setCoordinate(co); + end_icon.setBounds(co.getX(), co.getY(), end_icon.getPreferredSize().width, end_icon.getPreferredSize().height); + end_icon.setTask(this); + jP2.addIcon(end_icon); + jP2.setEndIcon(end_icon); + + jP2.add(end_icon); + + // add this ending icon as the starting icon's first member + start_icon.setParentIcon(null); + end_icon.setParentIcon(start_icon); // will be the beginning icon --> instanceof startIcon + end_icon.getParentIcon().addMember(end_icon, start_icon); + + // connect the two initial starting and ending icons + start_icon.setRightNeighbour(end_icon); + end_icon.setLeftNeighbour(start_icon); + + Wire tmp_wire = new Wire(); + tmp_wire.setLeftIcon(start_icon); + tmp_wire.setRightIcon(end_icon); + start_icon.setRightWire(tmp_wire); + end_icon.setLeftWire(tmp_wire); + + wire_list.addWire(tmp_wire); + jP2.addWire(tmp_wire); + + jP2.resizeProgWindow(jsp); + + // assign the task window + tskwin = njPanel17; + + // complete the members + for(int i=0; i 0) + { + left = ics.get(i-1); + if(left instanceof loopIcon) + { + left = left.getEndIcon(); + } + else if(left instanceof branchIcon) + { + left = left.getEndBranch(); + } + } + else + { + left = start_icon; + } + Icon right = end_icon; + + if(tmp_icon instanceof branchIcon) + { + jP2.insertRecursiveBranchLoopIcon(tmp_icon, right, left, jsp); + } + else if(tmp_icon instanceof loopIcon) + { + jP2.insertRecursiveBranchLoopIcon(tmp_icon, right, left, jsp); + } + else + { + // then set the coordinate + xpos = gridcalculation.midPoint(left.getCoordinate(), right.getCoordinate()); + ypos = left.getCoordinate().getY()+(left.getHeight()/2); + tmp_co = new coord(xpos, ypos); + co = gridcalculation.computeCoord(tmp_icon, tmp_co); + tmp_icon.setCoordinate(co); + tmp_icon.setBounds(co.getX(), co.getY(), tmp_icon.getWidth(), tmp_icon.getHeight()); + jP2.insertObjectIcon(tmp_icon, right, left, jsp); + } + } + return jp; + } + + // for the task icon + /** + * Returns the task window associated to this task + * @return The task window + */ + public TaskWindow getTaskWindow() + { + return tskwin; + } + + // for reinsertion, need to place the panel, jscrollpane and progwindow + + /** + * Returns the panel this task's member are on, not the individual task's icon itself + * @return The programming window + */ + public ProgWindow getProgWindow() + { + return prog_panel; + } + /** + * Returns the scroll pane of the programming window + * @return Programming window's scroller + */ + public javax.swing.JScrollPane getScroller() + { + return scroller; + } + /** + * Returns the panel on top of the programming window + * @return Programming window's parent panel + */ + public javax.swing.JPanel getPanel() + { + return panel; + } + + + /** + * Alters the id of the task this icon is representing + * @param i New task id + */ + public void setNumId(int i) + { + num_id = i; + } + + /** + * Returns the id of the task this icon is representing + * @return task id + */ + public int getNumId() + { + return num_id; + } + + /** + * Sets the name of this task + * @param n New task name + */ + public void setName(String n) + { + name = n; + } + /** + * Returns this task icon's name + * @return task name + */ + public String getName() + { + return name; + } + + /** + * Returns the list of icons this task contains + * @return Set of icons + */ + public java.util.Vector getMembers() + { + ics = start_icon.getMembers(); + return ics; + } + /** + * Sets the members of this task icon + * @param nics Set of icons + */ + public void setMembers(java.util.Vector nics) + { + ics = nics; + for(int i=0; i tmp_list_var = list_var.getVariables(); + for(int i=1; i getVariables() + { + return list_var.getVariables(); + } + + /** + * To return the list of the local variables list manager that this task owns + * @return The list of the local variables list manager + */ + public local_var_list getLocalVarList() + { + return list_var; + } + + /** + * To return an individual local variable that this task has + * @param name The variable name + * @return The local variable + */ + public variable getVariable(String name) + { + variable tmp_var = list_var.getVariable(name); + return tmp_var; + } +} diff --git a/src/funsoftware/var/ArithmeticOperation.java b/src/funsoftware/var/ArithmeticOperation.java new file mode 100644 index 0000000..aa5590e --- /dev/null +++ b/src/funsoftware/var/ArithmeticOperation.java @@ -0,0 +1,97 @@ +/* + * ArithmeticOperation.java + * + * Created on 11 January 2006, 20:33 + * + */ + +package funsoftware.var; + +/** + * This class controls an arithmetic operations that contain the three operands and the lone operator. + * @author Thomas Legowo + */ +public class ArithmeticOperation { + + // private variables + private Operand op1; + + private variable res; + + /** Creates a new instance of ArithmeticOperation */ + public ArithmeticOperation() { + } + + + /** + * Sets the operand + * @param o1 The operand + */ + public void setOperand1(Operand o1) + { + op1 = o1; + } + + /** + * Sets the variable on the left hand side of the operation + * @param v The variable + */ + public void setVariable(variable v) + { + res = v; + } + + /** + * Returns the operand + * @return The operand + */ + public Operand getOperand1() + { + return op1; + } + + /** + * Returns the variable on the left hand side of the operation + * @return The variable + */ + public variable getVariable() + { + return res; + } + + /** + * Returns a string format of the NQCCode representation of this object + * @param indentation Indentation + * @return The NQC Code + */ + public String getNQCCode(String indentation) + { + String NQCCode = new String(); + NQCCode += indentation; + NQCCode += res.getNQCCode()+" = "+op1.getNQCCode()+";\n"; + return NQCCode; + } + + /** + * To get a translation + * @param id_separator To separate ids + * @param id_att_separator To separate id with attribute + * @param att_boundary_begin To start attributes + * @param att_boundary_end To end attributes + * @param att_value_connector To separate attributes and its values + * @param att_separator To separate attributes + * @return Translation + */ + public String getAOTranslation(String id_separator, String id_att_separator, + String att_boundary_begin, String att_boundary_end, String att_value_connector, String att_separator) + { + String algo = new String(); + algo += att_boundary_begin; + algo += "res"+att_value_connector; + algo += res.getAOTranslation(id_separator, id_att_separator, att_boundary_begin, att_boundary_end, att_value_connector, att_separator); + algo += att_separator; + algo += "op1"+att_value_connector; + algo += op1.getAOTranslation(id_separator, id_att_separator, att_boundary_begin, att_boundary_end, att_value_connector, att_separator); + return algo; + } +} diff --git a/src/funsoftware/var/DeclareVariableDialog.java b/src/funsoftware/var/DeclareVariableDialog.java new file mode 100644 index 0000000..627922d --- /dev/null +++ b/src/funsoftware/var/DeclareVariableDialog.java @@ -0,0 +1,458 @@ +/* + * DeclareVariableDialog.java + * + * Created on 10 January 2006, 12:03 + * + */ + +package funsoftware.var; + +import funsoftware.consts.*; +import funsoftware.struct.*; +import funsoftware.events.*; +import funsoftware.tasks.*; +import funsoftware.functs.*; + +/** + * This class acts as a dialog window to ask the user for a variable name and whether it is a global or local + * @author Thomas Legowo + */ +public class DeclareVariableDialog extends javax.swing.JDialog{ + + // private variables + private javax.swing.JComboBox type_of_var; + private javax.swing.JComboBox functions; + private javax.swing.JTextField var_name; + private javax.swing.JTextField var_value; + + java.awt.GridBagConstraints gridBagConstraints; + + private javax.swing.JPanel jp_top; + private javax.swing.JPanel jp_bottom; + private javax.swing.JPanel jp_function; // for function selection + private javax.swing.JPanel jp; + private javax.swing.JLabel jl; + private javax.swing.JButton button; + + private String msg_top; + private String msg_bottom; + private String msg_function; + private String guide_top; + private String guide_bottom; + private String guide_function; + + // return values + private String[] ret_vals; + + private variable to_edit; + + /** + * Creates a new instance of DeclareVariableDialog, type 0 means new variable, type 1 means to be edited variable + * @param frame The frame + * @param type The type + * @param to_edit The variable to be edited + */ + public DeclareVariableDialog(java.awt.Frame frame, int type, variable to_edit) { + super(frame, true); + if(type == 0) + { + setTitle("Declare Variable"); + } + else + { + setTitle("Edit Variable"); + } + + + ret_vals = new String[4]; + ret_vals[0] = ""; // the name of the variable + ret_vals[1] = "Local"; + ret_vals[2] = ""; // the function's name it is supposed to be in if it is a local variable + ret_vals[3] = "0"; // the value of the variable (in string, it is suppose to be in integers) + + type_of_var = new javax.swing.JComboBox(); + functions = new javax.swing.JComboBox(); + var_name = new javax.swing.JTextField(ret_vals[0], 8); + var_value = new javax.swing.JTextField(Integer.toString(0), 8); + + if(type == 0) + { + type_of_var.addItem("Global"); // the default value + type_of_var.addItem("Local"); + this.to_edit = null; + } + else if(type == 1) + { + if(to_edit.getType() == 0) + { + type_of_var.addItem("Global"); + } + else + { + type_of_var.addItem("Local"); + } + this.to_edit = to_edit; + } + + msg_top = "Variable Name"; + msg_bottom = "Variable Type"; + msg_function = "Function or Task"; + guide_top = "Input at least 1 valid character"; + guide_bottom = "Select One"; + guide_function = "Select One"; + + jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + + // before we do anything set up the jpanel for function selection first + jp_function = new javax.swing.JPanel(); + jp_function.setLayout(new java.awt.GridBagLayout()); + + java.util.Vector al = aux_list.Instance().getAuxiliaries(); + for(int i=1; i a_list = aux_list.Instance().getAuxiliaries(); + for(int i=1; i list_var; + + private java.awt.Frame frame; + private javax.swing.JComboBox operand1; + private javax.swing.JButton operand1_button; + private javax.swing.JComboBox operator; + + private javax.swing.JComboBox main_selop1; + private javax.swing.JComboBox main_selop2; + private javax.swing.JComboBox main_selop3; + + // for the textfields to get a constant value + private javax.swing.JTextField text1; + + private javax.swing.JLabel left_bracket; + private javax.swing.JLabel right_bracket; + private javax.swing.JLabel top_left_bracket; + private javax.swing.JLabel top_right_bracket; + private auxiliary aux; + + private javax.swing.JPanel jp_block1; // variable block + private javax.swing.JPanel jp_block2; // constant block + private javax.swing.JPanel jp_block3; // nested operation block + + // for nested operations + private NOPanel NO1; + private NOPanel NO2; + + private NOPanel parent; + + /** + * Creates a new instance of NOPanel + * @param frame The frame + * @param jdg The parent dialog that calls this dialog + * @param aux The auxiliary on the arithmetic operation + */ + public NOPanel(java.awt.Frame frame, VarOperationDialog jdg, auxiliary aux) { + initSetUp(frame, jdg, aux, null); + } + + + /** + * Creates a new instance of NOPanel for editing operation purposes + * @param frame The frame + * @param NOp The operand + * @param jdg The parent dialog that calls this dialog + * @param aux The auxiliary on the arithmetic operation + */ + public NOPanel(java.awt.Frame frame, Operand NOp, VarOperationDialog jdg, auxiliary aux) { + initSetUp(frame, jdg, aux, NOp); + } + + + /** + * To set up the default panels, buttons and menus for a minimum set up of a variable related arithmetic operation dialog + * @param frame The frame + * @param jdg The parent dialog that calls this dialog + * @param aux_local The auxiliary on the arithmetic operation + * @param NOp The operand + */ + public void initSetUp(java.awt.Frame frame, VarOperationDialog jdg, auxiliary aux_local, Operand NOp) + { + jd = jdg; + + this.aux = aux_local; + this.frame = frame; + // Initialise the panels with all of its elements + + if(aux instanceof monitorEvent) + { + monitorEvent e = (monitorEvent)aux_local; + this.aux = e.getAuxPoint(); + } + + list_var = aux.getVariables(); + + operand1 = new javax.swing.JComboBox(); + operator = new javax.swing.JComboBox(); + operator.setBackground(new java.awt.Color(255, 255, 190)); + main_selop1 = new javax.swing.JComboBox(); + main_selop1.setBackground(new java.awt.Color(255, 255, 190)); + main_selop2 = new javax.swing.JComboBox(); + main_selop2.setBackground(new java.awt.Color(255, 255, 190)); + main_selop3 = new javax.swing.JComboBox(); + main_selop3.setBackground(new java.awt.Color(255, 255, 190)); + + text1 = new javax.swing.JTextField(); + text1.setFont(new java.awt.Font("Tahoma", 0, 12)); + text1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + text1.setPreferredSize(new java.awt.Dimension(70,20)); + text1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + + main_selop1.addItem("Variable"); + main_selop1.addItem("Constant"); + main_selop1.addItem("Operation"); + + main_selop2.addItem("Variable"); + main_selop2.addItem("Constant"); + main_selop2.addItem("Operation"); + + main_selop3.addItem("Variable"); + main_selop3.addItem("Constant"); + main_selop3.addItem("Operation"); + + left_bracket = new javax.swing.JLabel("("); + left_bracket.setFont(new java.awt.Font("Tahoma", 1, 16)); + left_bracket.setForeground(new java.awt.Color(0, 155, 255)); + right_bracket = new javax.swing.JLabel(")"); + right_bracket.setFont(new java.awt.Font("Tahoma", 1, 16)); + right_bracket.setForeground(new java.awt.Color(0, 155, 255)); + + top_left_bracket = new javax.swing.JLabel("("); + top_left_bracket.setFont(new java.awt.Font("Tahoma", 1, 16)); + top_left_bracket.setForeground(new java.awt.Color(0, 155, 255)); + top_right_bracket = new javax.swing.JLabel(")"); + top_right_bracket.setFont(new java.awt.Font("Tahoma", 1, 16)); + top_right_bracket.setForeground(new java.awt.Color(0, 155, 255)); + + // fill in the variables' drop down menu + java.util.Vector vv = var_list.Instance().getVariables(); + for(int i=1; i list_var; + private auxiliary aux; + + private String equal; + + // return values + private ArithmeticOperation ret_val; // an Arithmetic Operation + + /** + * Creates a new instance of VarOperationDialog + * @param frame The frame + * @param aux The auxiliary related to this auxiliary + */ + public VarOperationDialog(java.awt.Frame frame, auxiliary aux) { + super(frame, true); + initSetUp(frame, aux, null); + } + + /** + * Creates a new instance of VarOperationDialog but for editing purposes + * In this case the dialog would be in its expanded state according to data obtained from the ArithmeticOperation class + * @param frame The frame + * @param ArithOp The arithmetic operation + * @param aux The auxiliary related to this auxiliary + */ + public VarOperationDialog(java.awt.Frame frame, ArithmeticOperation ArithOp, auxiliary aux) { + super(frame, true); + initSetUp(frame, aux, ArithOp); + } + + /** + * To set up the default panels, buttons and menus for a minimum set up of a variable related arithmetic operation dialog + * @param frame The frame + * @param aux_local The auxiliary related to this auxiliary + * @param ArithOp The arithmetic operation + */ + public void initSetUp(java.awt.Frame frame, auxiliary aux_local, ArithmeticOperation ArithOp) + { + this.aux = aux_local; + this.frame = frame; + + if(aux_local instanceof monitorEvent) + { + monitorEvent e = (monitorEvent)aux_local; + if(e.getType().compareTo("Local") == 0) + { + this.aux = e.getAuxPoint(); + } + else + { + this.aux = new auxiliary(); + } + } + + list_var = aux.getVariables(); + + jsp_parent = new javax.swing.JPanel(); + jsp_parent.setLayout(new java.awt.GridBagLayout()); + + dummy = new javax.swing.JPanel(); + dummy.setMinimumSize(new java.awt.Dimension(1,1)); + + setTitle("Create an Arithmetic Operation"); + jsp = new javax.swing.JScrollPane(); + jp = new javax.swing.JPanel(); + jp.setLayout(new java.awt.GridBagLayout()); + viewport = new javax.swing.JViewport(); + viewport.setView(jp); + jsp.setViewport(viewport); + + // the label(s) + equal = "="; + + ret_val = new ArithmeticOperation(); + + NO = new NOPanel(frame, this, aux); + + variable = new javax.swing.JComboBox(); + + selop1 = new javax.swing.JComboBox(); + selop1.addItem("Variable"); + selop1.setBackground(new java.awt.Color(255, 255, 190)); + + + + // fill in the global variables' drop down menu + java.util.Vector vv = var_list.Instance().getVariables(); + for(int i=1; i 3) // the sensors being the first three global variables cannot have their values manually assigned + { + variable.addItem(tmp_v.getName()); + } + } + } + + // now add the local variables + for(int i=1; i= 1000) + { + maxX = 1000; + } + + jsp.setMinimumSize(new java.awt.Dimension(maxX, maxY)); + jsp.setPreferredSize(new java.awt.Dimension(maxX, maxY)); + jsp.setSize(new java.awt.Dimension(maxX, maxY)); + + jsp_parent.repaint(); + jsp_parent.revalidate(); + pack(); + } + + /** + * This method reacts to state changes in the combo box containing the types of an operand. + * @param type The type of the operand + * @param e ActionEvent + */ + public void typeOperAction(java.awt.event.ActionEvent e, int type) + { + if(type == 1) + { + variable.setVisible(false); + var_button.setVisible(true); + var_button.setText((String)(variable.getSelectedItem())); + } + } + + /** + * This method reacts to state changes in the variable button. + * @param type The type of the operand + * @param e ActionEvent + */ + public void buttonSelect(java.awt.event.ActionEvent e, int type) + { + if(type == 1) + { + var_button.setVisible(false); + variable.setVisible(true); + } + } + + + /** + * For the nested operations panels, returns the viewport of the dialog's scrollpane + * @return The viewport + */ + public javax.swing.JViewport getViewport() + { + return viewport; + } + + /** This method clears the dialog and hides it. */ + public void clearAndHide() { + setVisible(false); + } + + /** + * Returns the old viewpoint of the viewports + */ + public void resetViewport() + { + java.awt.Point ret = viewport.getViewPosition(); + pack(); + maintainSize(); + viewport.setViewPosition(new java.awt.Point((int)(ret.getX()+120), (int)(ret.getY()+80))); + repaint(); + } + +} diff --git a/src/funsoftware/var/VarWindow.java b/src/funsoftware/var/VarWindow.java new file mode 100644 index 0000000..ad00447 --- /dev/null +++ b/src/funsoftware/var/VarWindow.java @@ -0,0 +1,462 @@ +/* + * LocalVarWindow.java + * + * Created on 15 January 2006, 22:50 + * + */ + +package funsoftware.var; + +import funsoftware.consts.*; +import funsoftware.ic.var.ArithOpIcon; +import funsoftware.ic.*; +import funsoftware.struct.*; +import funsoftware.st.*; +import funsoftware.functs.*; +import funsoftware.tasks.*; +import funsoftware.events.*; + +/** + * To display all of the local variables. + * @author Thomas Legowo + */ + +public class VarWindow extends javax.swing.JPanel{ + + // the private variables + private java.util.Vector GlobalVars; // the members, each being a variable + private java.util.Vector LocalVars; // the members, each being a variable + + // the temporary variables needed for the construction of a ProgWindow + + private javax.swing.JFrame jframe; + + private javax.swing.JPanel GlobalPane; + private javax.swing.JPanel LocalPane; + private javax.swing.JSeparator[] lines = new javax.swing.JSeparator[2]; + + private auxiliary current_aux; + + /** + * Creates a new instance of VarWindow + * @param frame The frame + */ + public VarWindow(javax.swing.JFrame frame) + { + super(); + super.setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.PAGE_AXIS)); + jframe = frame; + GlobalVars = new java.util.Vector(); + LocalVars = new java.util.Vector(); + GlobalPane = new javax.swing.JPanel(); + GlobalPane.setLayout(new javax.swing.BoxLayout(GlobalPane, javax.swing.BoxLayout.PAGE_AXIS)); + LocalPane = new javax.swing.JPanel(); + LocalPane.setLayout(new javax.swing.BoxLayout(LocalPane, javax.swing.BoxLayout.PAGE_AXIS)); + + GlobalPane.setOpaque(false); + LocalPane.setOpaque(false); + + for (int i = 0; i < lines.length; i++) + { + lines[i] = new javax.swing.JSeparator(); + lines[i].setForeground(new java.awt.Color(0, 0, 0)); + lines[i].setAlignmentX(0.5f); + lines[i].setAlignmentY(0.5f); + lines[i].setPreferredSize(new java.awt.Dimension(0, 1)); + lines[i].setMaximumSize(new java.awt.Dimension(Integer.MAX_VALUE, 1)); + } + + // add the initial 3 input sensors variables + for (int i = 1; i <= 3; i++) + { + variable sensor = new variable(); + sensor.setName("SENSOR_" + i); + sensor.setType(0); + var_list.Instance().addVariable(sensor); + javax.swing.JLabel varlb = new javax.swing.JLabel("SENSOR_" + i); + + add(varlb); + } + + add(javax.swing.Box.createVerticalStrut(2)); + add(lines[0]); + add(javax.swing.Box.createVerticalStrut(2)); + + add(GlobalPane); + + add(javax.swing.Box.createVerticalStrut(2)); + add(lines[1]); + add(javax.swing.Box.createVerticalStrut(2)); + + add(LocalPane); + + setBackground(new java.awt.Color(247, 247, 247)); + } + + /** + * To paint this task window + * @param g Graphics + */ + protected void paintComponent(java.awt.Graphics g) + { + // update the radio buttons texts + int lim = GlobalPane.getComponentCount(); + for(int i=0; i New + */ + public void reset() + { + GlobalPane.removeAll(); + LocalPane.removeAll(); + LocalVars = new java.util.Vector(); + GlobalVars = new java.util.Vector(); + + variable sensor = new variable(); + sensor.setName("SENSOR_1"); + sensor.setType(0); + var_list.Instance().addVariable(sensor); + sensor = new variable(); + sensor.setName("SENSOR_2"); + sensor.setType(0); + var_list.Instance().addVariable(sensor); + sensor = new variable(); + sensor.setName("SENSOR_3"); + sensor.setType(0); + var_list.Instance().addVariable(sensor); + + refreshContainer(); + } + + /** + * Insert a new variable label onto this variable window + * @param var The variable to be inserted + */ + public void insertVar(variable var) + { + javax.swing.JLabel varlb = new javax.swing.JLabel(); + varlb.setBackground(new java.awt.Color(247, 247, 247)); + String name = var.getName(); + + if(var.getType() == 0) // global variables + { + GlobalVars.addElement(var); + varlb.setText(name); + GlobalPane.add(varlb); + } + else if(var.getType() == 1) // local variables + { + LocalVars.addElement(var); + varlb.setText(name); + if(var.getAux().getNumId() == current_aux.getNumId()) + { + LocalPane.add(varlb); + } + } + + // to set up the component pop up menu + javax.swing.JPopupMenu jpm = new javax.swing.JPopupMenu(); + javax.swing.JMenuItem jm = new javax.swing.JMenuItem(); + + if(name.compareTo("SENSOR_1") != 0 && name.compareTo("SENSOR_2") != 0 && name.compareTo("SENSOR_3") != 0 && var.getType() != 2) + { + jm = new javax.swing.JMenuItem("Edit Variable"); + final variable vari = var; + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + renameVarPerformed(evt, vari); + } + }); + jpm.add(jm); + jm = new javax.swing.JMenuItem("Delete Variable"); + jm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + deleteVarPerformed(evt, vari); + } + }); + jpm.add(jm); + varlb.setComponentPopupMenu(jpm); + } + +// update_panel(); + refreshContainer(); + } + + // to edit the variables by changing the name or its initial value + private void renameVarPerformed(java.awt.event.ActionEvent evt, variable var) + { + DeclareVariableDialog dv_dialog = new DeclareVariableDialog(jframe, 1, var); + dv_dialog.pack(); + dv_dialog.setLocationRelativeTo(jframe); + dv_dialog.setVisible(true); + String[] ret_val = dv_dialog.getUserInput(); + + if(ret_val[0].compareTo("") != 0) // user didn't press the cancel button + { + String varName = ret_val[0]; + + // change the name for this variable + var.setName(varName); + var.setValue(Integer.parseInt(ret_val[3])); + + UndoRedo.update_state(); +// update_panel(); + + refreshContainer(); + } + UndoRedo.update_state(); + } + + // the action handler for the radio button's pop up menu + private void deleteVarPerformed(java.awt.event.ActionEvent evt, variable var) + { + int del_pos = 0; + int to_delete = 0; + String name = var.getName(); + + java.util.Vector ics = icons_list.Instance().getIcons(); + for(int i=1; i(); + LocalPane.removeAll(); + + java.util.Vector list_var; + if(a instanceof monitorEvent) + { + monitorEvent evt_tmp = (monitorEvent)a; + if(evt_tmp.getType().compareTo("Local") == 0) + { + list_var = evt_tmp.getAuxPoint().getVariables(); + } + else + { + list_var = new java.util.Vector(); + } + } + else + { + list_var = a.getVariables(); + } + + for(int i=1; i widest) +// { +// widest = (int)jlb.getPreferredSize().getWidth(); +// } +// } +// +// lim = LocalPane.getComponentCount(); +// for(int i=0; i widest) +// { +// widest = (int)jlb.getPreferredSize().getWidth(); +// } +// } +// +// if(widest < 120) +// { +// widest = 120; +// } +// +// LocalPane.setPreferredSize(new java.awt.Dimension(widest, height_local)); +// LocalPane.setMinimumSize(new java.awt.Dimension(widest, height_local)); +// GlobalPane.setPreferredSize(new java.awt.Dimension(widest, height_global)); +// GlobalPane.setMinimumSize(new java.awt.Dimension(widest, height_global)); +//// line1.setPreferredSize(new java.awt.Dimension(widest, 1)); +//// line2.setPreferredSize(new java.awt.Dimension(widest, 1)); +// } + + /** + * Refresh the UI for this component and its parent + */ + public void refreshContainer() + { + this.repaint(); + this.revalidate(); + + if (this.getParent() != null) + { + this.getParent().revalidate(); + } + } +} \ No newline at end of file diff --git a/src/funsoftware/var/constant.java b/src/funsoftware/var/constant.java new file mode 100644 index 0000000..f9e5cdf --- /dev/null +++ b/src/funsoftware/var/constant.java @@ -0,0 +1,72 @@ +/* + * constant.java + * + * Created on 11 January 2006, 20:33 + * + */ + +package funsoftware.var; + +/** + * This class represent a contant in an arithmetic operation + * @author Thomas Legowo + */ +public class constant extends Operand{ + + private int value; + + /** Creates a new instance of constant */ + public constant() { + value = 0; + } + + /** + * Sets the value of this constant + * @param v The new value + */ + public void setValue(int v) + { + value = v; + } + + /** + * Returns the value of this constant + * @return The value + */ + public int getValue() + { + return value; + } + + /** + * To get an NQCCode translation of this constant + * @return The NQC code + */ + public String getNQCCode() + { + return (Integer.toString(value)); + } + + /** + * To get a translation + * @param id_separator To separate ids + * @param id_att_separator To separate id with attribute + * @param att_boundary_begin To start attributes + * @param att_boundary_end To end attributes + * @param att_value_connector To separate attributes and its values + * @param att_separator To separate attributes + * @return Translation + */ + public String getAOTranslation(String id_separator, String id_att_separator, + String att_boundary_begin, String att_boundary_end, String att_value_connector, String att_separator) + { + String algo = new String(); + algo += "c"; + algo += id_att_separator; + algo += att_boundary_begin; + algo += "value"+att_value_connector; + algo += value; + algo += att_boundary_end; + return algo; + } +} diff --git a/src/funsoftware/var/variable.java b/src/funsoftware/var/variable.java new file mode 100644 index 0000000..7c44c1d --- /dev/null +++ b/src/funsoftware/var/variable.java @@ -0,0 +1,232 @@ +/* + * variable.java + * + * Created on 10 January 2006, 15:13 + * + */ + +package funsoftware.var; + +import funsoftware.struct.*; + +/** + * This class represents an individual variable + * @author Thomas Legowo + */ +public class variable extends Operand{ + + // private variables + private int num_id; // id can be the same but in different functions + private String name; + private int value; // the value this variable holds + private auxiliary aux; + + // the type + private int type; // 0 if global, 1 if local, 2 if an argument + + /** Creates a new instance of variable */ + public variable() { + name = new String(); + type = 0; + value = 0; + aux = new auxiliary(); + } + + /** + * To set the id of this variable + * @param nid the new id + */ + public void setNumId(int nid) + { + num_id = nid; + } + + /** + * To get the id of this variable + * @return The numId + */ + public int getNumId() + { + return num_id; + } + + /** + * To set the name of this variable + * @param n the new name + */ + public void setName(String n) + { + name = n; + } + + /** + * To get the name of this variable + * @return The variable's name + */ + public String getName() + { + return name; + } + + /** + * To set the type of this variable + * @param t The type of this variable + */ + public void setType(int t) + { + type = t; + } + + /** + * To get the current value of this variable + * @return The current value of the variable + */ + public int getValue() + { + return value; + } + + /** + * To set the current value of this variable + * @param t The current value of this variable + */ + public void setValue(int t) + { + value = t; + } + + /** + * To get the type of this variable + * @return The type of this variable + */ + public int getType() + { + return type; + } + + /** + * To set the auxiliary that owns this variable + * @param a The auxiliary that owns this variable + */ + public void setAux(auxiliary a) + { + aux = a; + } + + /** + * To get the auxiliary that owns this variable + * @return The auxiliary that owns this variable + */ + public auxiliary getAux() + { + return aux; + } + + /** + * Algorithm translation for the Translator object to create a text representation of this icon + * @param id_separator To separate ids + * @param id_att_separator To separate id with attribute + * @param att_boundary_begin To start attributes + * @param att_boundary_end To end attributes + * @param att_value_connector To separate attributes and its values + * @param att_separator To separate attributes + * @return Translation + */ + public String getTranslation(String id_separator, String id_att_separator, + String att_boundary_begin, String att_boundary_end, String att_value_connector, String att_separator) + { + String algo = new String(); + algo += "\n"; // to begin with + algo += "variable"; + algo += id_separator; + algo += num_id; + algo += id_att_separator; + algo += att_boundary_begin; + algo += "name"+att_value_connector; + algo += name; + algo += att_separator; + algo += "value"+att_value_connector; + algo += value; + algo += att_separator; + algo += "type"+att_value_connector; + algo += type; + algo += att_boundary_end; + // add the arguments where possible + return algo; + } + + + /** + * To get a translation + * @param id_separator To separate ids + * @param id_att_separator To separate id with attribute + * @param att_boundary_begin To start attributes + * @param att_boundary_end To end attributes + * @param att_value_connector To separate attributes and its values + * @param att_separator To separate attributes + * @return Translation + */ + public String getAOTranslation(String id_separator, String id_att_separator, + String att_boundary_begin, String att_boundary_end, String att_value_connector, String att_separator) + { + String algo = new String(); + algo += "v"; + algo += id_att_separator; + algo += att_boundary_begin; + algo += "name"+att_value_connector; + algo += name; + algo += att_boundary_end; + return algo; + } + + /** + * For variable declaration in NQC translated version + * @return The NQC declaration + */ + public String getNQCDeclaration() + { + return ("int "+name+" = "+value+";\n"); + } + + /** + * To be incorporated with other operands in an arithmetic operation + * @return The NQC code + */ + public String getNQCCode() + { + return name; + } + + /** + * To clone this variable + * @return New instance of this variable + */ + public variable Clone() + { + return new variable(); + } + + /** + * Set its own attributes given a string from a text representation of it + * @param att Attributes + * @param att_value_connector Attribute connector + * @param att_separator Attribute separator + */ + public void setAttributes(String att, String att_value_connector, String att_separator) + { + String[] sp = att.split(att_separator); + String[] sp2 = new String[2]; + + // do the first one --> name + sp2 = sp[0].split(att_value_connector); + name = sp2[1]; + + // do the second one --> value + sp2 = sp[1].split(att_value_connector); + value = Integer.parseInt(sp2[1]); + + // do the third one --> type + sp2 = sp[2].split(att_value_connector); + type = Integer.parseInt(sp2[1]); + } +} diff --git a/src/funsoftware/wr/Wire.java b/src/funsoftware/wr/Wire.java new file mode 100644 index 0000000..fa04478 --- /dev/null +++ b/src/funsoftware/wr/Wire.java @@ -0,0 +1,272 @@ +/* + * Wire.java + * + * Created on 14 July 2005, 23:22 + */ + +package funsoftware.wr; + +import funsoftware.gri.*; +import funsoftware.ic.*; +import funsoftware.consts.*; + +/** + * This class cater for an individual piece of wire. + * Note that a piece of wire ALWAYS has two ends. + * Unlike an icon, a piece of wire does not have one pair of coordinates. + * Instead a piece of wire will have two pairs of coordinates for its two ends. + * @author Thomas Legowo + */ +public class Wire { + + // The local attributes + private String id; // the id of this wire, id will never equal to zero, it will be preceeded by the letter W + + // wires do not go diagonal! + // So if the beginning and ending coordinate of the wire differs, then the wire will go one grid segment across, + // then up a couple of grid segments to match to the destination's Y-coordinates, then one grid segment across. + // the beginning coordinate of the wire + private coord begin; + // the ending coordinate of the wire + private coord end; + + // A piece of wire can be connected to two icons, one on its left, the other one on its right + // A piece of wire can also be connected to one icon and one wire or one wire and one icon + private Icon ileft; + private Icon iright; + + // the type of the wire + // if type = 0 -> normal wiring + // if type = 1 -> wiring system for branching (Vertical) + // if type = 2 -> normal wiring inside a loop but with different colour to type 1 + // if type = 3 -> wiring system for initial looping (left side) + // if type = 4 -> wiring system for initial looping (right side) + private int type; + + private int thickness; // the thickness of this wire + + // The length of the wire is always a block of grid's length + + /** Creates a new instance of Wire */ + public Wire() { + type = 0;// initially type is 0 + begin = new coord(); + end = new coord(); + thickness = 2; // initially thickness is 2 + } + + // This is due to the id of the wire should be unique and can only be determined by the set of wire that is + // searched through using a hash map technique + /** + * Sets the wire's id. A wire's id will be unique + * @param nid Wire id + */ + public void setId(String nid) + { + id = nid; + } + + /** + * Return the id of this wire without the letter 'W' + * @return Wire id + */ + public int getId() + { + int ii = Integer.parseInt(id.substring(1)); // get rid of the W from the id + return ii; + } + + /** + * Return the full id with the letter 'W' + * @return Full wire id + */ + public String getFullId() + { + return id; + } + + // set and return methods + /** + * Set left icon of this piece of wire + * @param left Left icon + */ + public void setLeftIcon(Icon left) + { + ileft = left; + } + + /** + * Set right icon of this piece of wire + * @param right Right icon + */ + public void setRightIcon(Icon right) + { + iright = right; + } + + /** + * The begin and end set coordinate should be called after the neighbouring icons are set. + * Set the begin coordinate of this wire. + */ + public void setBeginCoordinate() + { + if(type == 1 || type == 3 || type == 4) // only for looping + { + begin.setX(getLeftIcon().getCoordinate().getX()+(getLeftIcon().getWidth()/2 - (thickness/2))); + } + else + { + begin.setX(getLeftIcon().getCoordinate().getX()+getLeftIcon().getWidth()); + } + begin.setY(getLeftIcon().getCoordinate().getY()+(getLeftIcon().getHeight()/2- (thickness/2))); + } + + /** + * Set the end coordinate of this wire. + */ + public void setEndCoordinate() + { + if(type == 1 || type == 3 || type == 4) // only for looping + { + end.setX(getRightIcon().getCoordinate().getX()+(getRightIcon().getWidth()/2- (thickness/2))); + } + else + { + end.setX(getRightIcon().getCoordinate().getX()); + } + end.setY(iright.getCoordinate().getY()+(getRightIcon().getHeight()/2- (thickness/2))); + } + + /** + * To set the type of this piece of wire. Types are important for colouring of this wire + * @param ntype New type + */ + public void setType(int ntype) + { + type = ntype; + } + + /** + * Sets the thickness of the wire + * @param nth Wire thickness + */ + public void setWireThickness(int nth) + { + thickness = nth; + } + + /** + * Gets left icon of this wire + * @return Left icon + */ + public Icon getLeftIcon() + { + return ileft; + } + + /** + * Gets right icon of this wire + * @return Right icon + */ + public Icon getRightIcon() + { + return iright; + } + + /** + * Gets the begin coordinate of this wire + * @return Begin coordinate + */ + public coord getBeginCoordinate() + { + setBeginCoordinate(); + return begin; + } + + /** + * Gets the end coordinate of this wire + * @return End coordinate + */ + public coord getEndCoordinate() + { + setEndCoordinate(); + return end; + } + + /** + * Get the type of this particular piece of wire + * @return Type + */ + public int getType() + { + return type; + } + + // Wire is different to icon and it is harder to draw since it can bend twice before reaching its end point + // So it is best to leave the drawing of the wire within its own object + // the argument gridDistanceX is the length of one segment horizontally while gridDistanceY is vertically + /** + * Draw this wire. + * @param g Graphics + */ + public void draw(java.awt.Graphics g) + { + setBeginCoordinate(); + setEndCoordinate(); + int distanceX = Constants.gridDistanceX; + int distanceY = Constants.gridDistanceY; + + if(type == 0) + { + g.setColor(new java.awt.Color(0,0,0)); + } + else if(type == 1) + { + g.setColor(new java.awt.Color(255,80,0,100)); + } + else if(type == 2) + { + g.setColor(new java.awt.Color(152,32,255,100)); + } + + if(type == 0 || type == 1 || type == 2) + { + if((end.getY()-begin.getY()) == 0) + { + g.fillRect(begin.getX(), begin.getY(), (end.getX()-begin.getX()), thickness); + } + else + { + if(begin.getY()>end.getY()) + { + g.fillRect(end.getX(), end.getY(), thickness, Math.abs(end.getY()-begin.getY())+thickness); + } + else + { + g.fillRect(begin.getX(), begin.getY(), thickness, Math.abs(end.getY()-begin.getY())+thickness); + g.drawLine(begin.getX(), begin.getY(), end.getX(), end.getY()); + + } + } + } + // the rest are for the looping + // beginning of loop + else if(type == 3) + { + g.setColor(new java.awt.Color(152,32,255,100)); + + g.fillRect(begin.getX(), begin.getY(), thickness, (end.getY() - begin.getY())); + + g.fillRect(begin.getX(), end.getY(), (end.getX()-begin.getX()), thickness); + } + // end of loop + else if(type == 4) + { + g.setColor(new java.awt.Color(152,32,255,100)); + + g.fillRect(begin.getX(), begin.getY(), (end.getX()-begin.getX()), thickness); + + g.fillRect(end.getX(), end.getY(), thickness, Math.abs(end.getY() - begin.getY())+thickness); + } + } +} diff --git a/src/icons/arithmetic/opIcon.gif b/src/icons/arithmetic/opIcon.gif new file mode 100644 index 0000000..c69f066 Binary files /dev/null and b/src/icons/arithmetic/opIcon.gif differ diff --git a/src/icons/beeps/beeps.gif b/src/icons/beeps/beeps.gif new file mode 100644 index 0000000..4f0ea4a Binary files /dev/null and b/src/icons/beeps/beeps.gif differ diff --git a/src/icons/beeps/bottomleftbeep.gif b/src/icons/beeps/bottomleftbeep.gif new file mode 100644 index 0000000..f8262a5 Binary files /dev/null and b/src/icons/beeps/bottomleftbeep.gif differ diff --git a/src/icons/beeps/topbeep.gif b/src/icons/beeps/topbeep.gif new file mode 100644 index 0000000..7bce820 Binary files /dev/null and b/src/icons/beeps/topbeep.gif differ diff --git a/src/icons/branches/arithmetic/arithmetic.gif b/src/icons/branches/arithmetic/arithmetic.gif new file mode 100644 index 0000000..ac37e9e Binary files /dev/null and b/src/icons/branches/arithmetic/arithmetic.gif differ diff --git a/src/icons/branches/celcius/celcius.gif b/src/icons/branches/celcius/celcius.gif new file mode 100644 index 0000000..219434e Binary files /dev/null and b/src/icons/branches/celcius/celcius.gif differ diff --git a/src/icons/branches/celcius/celcius_field.gif b/src/icons/branches/celcius/celcius_field.gif new file mode 100644 index 0000000..854cb0b Binary files /dev/null and b/src/icons/branches/celcius/celcius_field.gif differ diff --git a/src/icons/branches/celcius/top.gif b/src/icons/branches/celcius/top.gif new file mode 100644 index 0000000..e315e55 Binary files /dev/null and b/src/icons/branches/celcius/top.gif differ diff --git a/src/icons/branches/comparator/comp1.gif b/src/icons/branches/comparator/comp1.gif new file mode 100644 index 0000000..084c88e Binary files /dev/null and b/src/icons/branches/comparator/comp1.gif differ diff --git a/src/icons/branches/comparator/comp2.gif b/src/icons/branches/comparator/comp2.gif new file mode 100644 index 0000000..c8d53a4 Binary files /dev/null and b/src/icons/branches/comparator/comp2.gif differ diff --git a/src/icons/branches/comparator/comp3.gif b/src/icons/branches/comparator/comp3.gif new file mode 100644 index 0000000..2140661 Binary files /dev/null and b/src/icons/branches/comparator/comp3.gif differ diff --git a/src/icons/branches/comparator/comp4.gif b/src/icons/branches/comparator/comp4.gif new file mode 100644 index 0000000..ad56835 Binary files /dev/null and b/src/icons/branches/comparator/comp4.gif differ diff --git a/src/icons/branches/comparator/comp5.gif b/src/icons/branches/comparator/comp5.gif new file mode 100644 index 0000000..4b12ccb Binary files /dev/null and b/src/icons/branches/comparator/comp5.gif differ diff --git a/src/icons/branches/comparator/comp6.gif b/src/icons/branches/comparator/comp6.gif new file mode 100644 index 0000000..56a1273 Binary files /dev/null and b/src/icons/branches/comparator/comp6.gif differ diff --git a/src/icons/branches/light/light.gif b/src/icons/branches/light/light.gif new file mode 100644 index 0000000..0ea5d2e Binary files /dev/null and b/src/icons/branches/light/light.gif differ diff --git a/src/icons/branches/light/light_field.gif b/src/icons/branches/light/light_field.gif new file mode 100644 index 0000000..854cb0b Binary files /dev/null and b/src/icons/branches/light/light_field.gif differ diff --git a/src/icons/branches/light/top.gif b/src/icons/branches/light/top.gif new file mode 100644 index 0000000..5cb5eab Binary files /dev/null and b/src/icons/branches/light/top.gif differ diff --git a/src/icons/branches/random/random.gif b/src/icons/branches/random/random.gif new file mode 100644 index 0000000..f78d6ba Binary files /dev/null and b/src/icons/branches/random/random.gif differ diff --git a/src/icons/branches/rotation/rotation.gif b/src/icons/branches/rotation/rotation.gif new file mode 100644 index 0000000..6cd6e54 Binary files /dev/null and b/src/icons/branches/rotation/rotation.gif differ diff --git a/src/icons/branches/rotation/rotation_field.gif b/src/icons/branches/rotation/rotation_field.gif new file mode 100644 index 0000000..854cb0b Binary files /dev/null and b/src/icons/branches/rotation/rotation_field.gif differ diff --git a/src/icons/branches/rotation/rotationtop.gif b/src/icons/branches/rotation/rotationtop.gif new file mode 100644 index 0000000..652b4c8 Binary files /dev/null and b/src/icons/branches/rotation/rotationtop.gif differ diff --git a/src/icons/branches/timer/timer.gif b/src/icons/branches/timer/timer.gif new file mode 100644 index 0000000..92788ad Binary files /dev/null and b/src/icons/branches/timer/timer.gif differ diff --git a/src/icons/branches/timer/timer_field.gif b/src/icons/branches/timer/timer_field.gif new file mode 100644 index 0000000..7ee970e Binary files /dev/null and b/src/icons/branches/timer/timer_field.gif differ diff --git a/src/icons/branches/timer/top.gif b/src/icons/branches/timer/top.gif new file mode 100644 index 0000000..cd4f218 Binary files /dev/null and b/src/icons/branches/timer/top.gif differ diff --git a/src/icons/branches/touch/comp1.gif b/src/icons/branches/touch/comp1.gif new file mode 100644 index 0000000..55f53b0 Binary files /dev/null and b/src/icons/branches/touch/comp1.gif differ diff --git a/src/icons/branches/touch/comp2.gif b/src/icons/branches/touch/comp2.gif new file mode 100644 index 0000000..fe2920f Binary files /dev/null and b/src/icons/branches/touch/comp2.gif differ diff --git a/src/icons/branches/touch/icon_if.gif b/src/icons/branches/touch/icon_if.gif new file mode 100644 index 0000000..f25d1ad Binary files /dev/null and b/src/icons/branches/touch/icon_if.gif differ diff --git a/src/icons/branches/touch/touch_if_bottom.gif b/src/icons/branches/touch/touch_if_bottom.gif new file mode 100644 index 0000000..5519186 Binary files /dev/null and b/src/icons/branches/touch/touch_if_bottom.gif differ diff --git a/src/icons/branches/touch/touch_if_top.gif b/src/icons/branches/touch/touch_if_top.gif new file mode 100644 index 0000000..8d24b1f Binary files /dev/null and b/src/icons/branches/touch/touch_if_top.gif differ diff --git a/src/icons/closures/argument.gif b/src/icons/closures/argument.gif new file mode 100644 index 0000000..0bd040b Binary files /dev/null and b/src/icons/closures/argument.gif differ diff --git a/src/icons/closures/ret_val.gif b/src/icons/closures/ret_val.gif new file mode 100644 index 0000000..aab7f9b Binary files /dev/null and b/src/icons/closures/ret_val.gif differ diff --git a/src/icons/events/start/start.gif b/src/icons/events/start/start.gif new file mode 100644 index 0000000..e9579a1 Binary files /dev/null and b/src/icons/events/start/start.gif differ diff --git a/src/icons/events/start/start_top.gif b/src/icons/events/start/start_top.gif new file mode 100644 index 0000000..2a83f6d Binary files /dev/null and b/src/icons/events/start/start_top.gif differ diff --git a/src/icons/function/Thumbs.db b/src/icons/function/Thumbs.db new file mode 100644 index 0000000..0a032bb Binary files /dev/null and b/src/icons/function/Thumbs.db differ diff --git a/src/icons/function/bottomleft.gif b/src/icons/function/bottomleft.gif new file mode 100644 index 0000000..b46e279 Binary files /dev/null and b/src/icons/function/bottomleft.gif differ diff --git a/src/icons/function/bottomright.gif b/src/icons/function/bottomright.gif new file mode 100644 index 0000000..525a20f Binary files /dev/null and b/src/icons/function/bottomright.gif differ diff --git a/src/icons/function/function.gif b/src/icons/function/function.gif new file mode 100644 index 0000000..728de33 Binary files /dev/null and b/src/icons/function/function.gif differ diff --git a/src/icons/function/functionbottom.gif b/src/icons/function/functionbottom.gif new file mode 100644 index 0000000..5e6d046 Binary files /dev/null and b/src/icons/function/functionbottom.gif differ diff --git a/src/icons/function/functiontop.gif b/src/icons/function/functiontop.gif new file mode 100644 index 0000000..49a5019 Binary files /dev/null and b/src/icons/function/functiontop.gif differ diff --git a/src/icons/function/nameField.gif b/src/icons/function/nameField.gif new file mode 100644 index 0000000..23dc4bc Binary files /dev/null and b/src/icons/function/nameField.gif differ diff --git a/src/icons/helps/ArithOpIcon.gif b/src/icons/helps/ArithOpIcon.gif new file mode 100644 index 0000000..eb3e1ed Binary files /dev/null and b/src/icons/helps/ArithOpIcon.gif differ diff --git a/src/icons/helps/BarithmeticIcon.gif b/src/icons/helps/BarithmeticIcon.gif new file mode 100644 index 0000000..958adb5 Binary files /dev/null and b/src/icons/helps/BarithmeticIcon.gif differ diff --git a/src/icons/helps/BcelciusSensorIcon.gif b/src/icons/helps/BcelciusSensorIcon.gif new file mode 100644 index 0000000..8731ac3 Binary files /dev/null and b/src/icons/helps/BcelciusSensorIcon.gif differ diff --git a/src/icons/helps/BlightSensorIcon.gif b/src/icons/helps/BlightSensorIcon.gif new file mode 100644 index 0000000..ff83d28 Binary files /dev/null and b/src/icons/helps/BlightSensorIcon.gif differ diff --git a/src/icons/helps/BrandomIcon.gif b/src/icons/helps/BrandomIcon.gif new file mode 100644 index 0000000..4947af5 Binary files /dev/null and b/src/icons/helps/BrandomIcon.gif differ diff --git a/src/icons/helps/BrotationSensorIcon.gif b/src/icons/helps/BrotationSensorIcon.gif new file mode 100644 index 0000000..1151a73 Binary files /dev/null and b/src/icons/helps/BrotationSensorIcon.gif differ diff --git a/src/icons/helps/BtimerIcon.gif b/src/icons/helps/BtimerIcon.gif new file mode 100644 index 0000000..a36cb48 Binary files /dev/null and b/src/icons/helps/BtimerIcon.gif differ diff --git a/src/icons/helps/BtouchSensorIcon.gif b/src/icons/helps/BtouchSensorIcon.gif new file mode 100644 index 0000000..06d796e Binary files /dev/null and b/src/icons/helps/BtouchSensorIcon.gif differ diff --git a/src/icons/helps/arithmeticLoopIcon.gif b/src/icons/helps/arithmeticLoopIcon.gif new file mode 100644 index 0000000..ae85c88 Binary files /dev/null and b/src/icons/helps/arithmeticLoopIcon.gif differ diff --git a/src/icons/helps/beepIcon.gif b/src/icons/helps/beepIcon.gif new file mode 100644 index 0000000..c0cfdab Binary files /dev/null and b/src/icons/helps/beepIcon.gif differ diff --git a/src/icons/helps/beginTaskIcon.gif b/src/icons/helps/beginTaskIcon.gif new file mode 100644 index 0000000..c097ef1 Binary files /dev/null and b/src/icons/helps/beginTaskIcon.gif differ diff --git a/src/icons/helps/breakIcon.gif b/src/icons/helps/breakIcon.gif new file mode 100644 index 0000000..d466ba7 Binary files /dev/null and b/src/icons/helps/breakIcon.gif differ diff --git a/src/icons/helps/celciusSensorLoopIcon.gif b/src/icons/helps/celciusSensorLoopIcon.gif new file mode 100644 index 0000000..8bd7b2b Binary files /dev/null and b/src/icons/helps/celciusSensorLoopIcon.gif differ diff --git a/src/icons/helps/clearSensorIcon.gif b/src/icons/helps/clearSensorIcon.gif new file mode 100644 index 0000000..60c69a1 Binary files /dev/null and b/src/icons/helps/clearSensorIcon.gif differ diff --git a/src/icons/helps/clearTimerIcon.gif b/src/icons/helps/clearTimerIcon.gif new file mode 100644 index 0000000..0801e9c Binary files /dev/null and b/src/icons/helps/clearTimerIcon.gif differ diff --git a/src/icons/helps/continueIcon.gif b/src/icons/helps/continueIcon.gif new file mode 100644 index 0000000..0369f9f Binary files /dev/null and b/src/icons/helps/continueIcon.gif differ diff --git a/src/icons/helps/directionalMotorIcon.gif b/src/icons/helps/directionalMotorIcon.gif new file mode 100644 index 0000000..fe1654c Binary files /dev/null and b/src/icons/helps/directionalMotorIcon.gif differ diff --git a/src/icons/helps/floatMotorIcon.gif b/src/icons/helps/floatMotorIcon.gif new file mode 100644 index 0000000..7ede352 Binary files /dev/null and b/src/icons/helps/floatMotorIcon.gif differ diff --git a/src/icons/helps/functionIcon.gif b/src/icons/helps/functionIcon.gif new file mode 100644 index 0000000..0d9d2fd Binary files /dev/null and b/src/icons/helps/functionIcon.gif differ diff --git a/src/icons/helps/infiniteLoopIcon.gif b/src/icons/helps/infiniteLoopIcon.gif new file mode 100644 index 0000000..e9d8487 Binary files /dev/null and b/src/icons/helps/infiniteLoopIcon.gif differ diff --git a/src/icons/helps/lampIcon.gif b/src/icons/helps/lampIcon.gif new file mode 100644 index 0000000..3572662 Binary files /dev/null and b/src/icons/helps/lampIcon.gif differ diff --git a/src/icons/helps/lightSensorLoopIcon.gif b/src/icons/helps/lightSensorLoopIcon.gif new file mode 100644 index 0000000..fd1bac8 Binary files /dev/null and b/src/icons/helps/lightSensorLoopIcon.gif differ diff --git a/src/icons/helps/motorIcon.gif b/src/icons/helps/motorIcon.gif new file mode 100644 index 0000000..ec03669 Binary files /dev/null and b/src/icons/helps/motorIcon.gif differ diff --git a/src/icons/helps/playAnyNoteIcon.gif b/src/icons/helps/playAnyNoteIcon.gif new file mode 100644 index 0000000..2ae8d0a Binary files /dev/null and b/src/icons/helps/playAnyNoteIcon.gif differ diff --git a/src/icons/helps/playSpecificNoteIcon.gif b/src/icons/helps/playSpecificNoteIcon.gif new file mode 100644 index 0000000..9d13d1b Binary files /dev/null and b/src/icons/helps/playSpecificNoteIcon.gif differ diff --git a/src/icons/helps/repeatIcon.gif b/src/icons/helps/repeatIcon.gif new file mode 100644 index 0000000..8643678 Binary files /dev/null and b/src/icons/helps/repeatIcon.gif differ diff --git a/src/icons/helps/returnIcon.gif b/src/icons/helps/returnIcon.gif new file mode 100644 index 0000000..c281254 Binary files /dev/null and b/src/icons/helps/returnIcon.gif differ diff --git a/src/icons/helps/rotationSensorLoopIcon.gif b/src/icons/helps/rotationSensorLoopIcon.gif new file mode 100644 index 0000000..ac7febd Binary files /dev/null and b/src/icons/helps/rotationSensorLoopIcon.gif differ diff --git a/src/icons/helps/startEvent.gif b/src/icons/helps/startEvent.gif new file mode 100644 index 0000000..e253777 Binary files /dev/null and b/src/icons/helps/startEvent.gif differ diff --git a/src/icons/helps/stopMotorIcon.gif b/src/icons/helps/stopMotorIcon.gif new file mode 100644 index 0000000..63d03bb Binary files /dev/null and b/src/icons/helps/stopMotorIcon.gif differ diff --git a/src/icons/helps/stopTaskIcon.gif b/src/icons/helps/stopTaskIcon.gif new file mode 100644 index 0000000..0edb86e Binary files /dev/null and b/src/icons/helps/stopTaskIcon.gif differ diff --git a/src/icons/helps/timerIcon.gif b/src/icons/helps/timerIcon.gif new file mode 100644 index 0000000..fd12f3f Binary files /dev/null and b/src/icons/helps/timerIcon.gif differ diff --git a/src/icons/helps/timerLoopIcon.gif b/src/icons/helps/timerLoopIcon.gif new file mode 100644 index 0000000..bd5e227 Binary files /dev/null and b/src/icons/helps/timerLoopIcon.gif differ diff --git a/src/icons/helps/touchSensorLoopIcon.gif b/src/icons/helps/touchSensorLoopIcon.gif new file mode 100644 index 0000000..5c32924 Binary files /dev/null and b/src/icons/helps/touchSensorLoopIcon.gif differ diff --git a/src/icons/helps/waitCelciusIcon.gif b/src/icons/helps/waitCelciusIcon.gif new file mode 100644 index 0000000..0397aee Binary files /dev/null and b/src/icons/helps/waitCelciusIcon.gif differ diff --git a/src/icons/helps/waitLightIcon.gif b/src/icons/helps/waitLightIcon.gif new file mode 100644 index 0000000..61486b0 Binary files /dev/null and b/src/icons/helps/waitLightIcon.gif differ diff --git a/src/icons/helps/waitRotationalIcon.gif b/src/icons/helps/waitRotationalIcon.gif new file mode 100644 index 0000000..389787f Binary files /dev/null and b/src/icons/helps/waitRotationalIcon.gif differ diff --git a/src/icons/helps/waitTimerIcon.gif b/src/icons/helps/waitTimerIcon.gif new file mode 100644 index 0000000..224bc8c Binary files /dev/null and b/src/icons/helps/waitTimerIcon.gif differ diff --git a/src/icons/helps/waitTouchIcon.gif b/src/icons/helps/waitTouchIcon.gif new file mode 100644 index 0000000..e792849 Binary files /dev/null and b/src/icons/helps/waitTouchIcon.gif differ diff --git a/src/icons/interface/dirWindow/LEGOani.gif b/src/icons/interface/dirWindow/LEGOani.gif new file mode 100644 index 0000000..1c798ff Binary files /dev/null and b/src/icons/interface/dirWindow/LEGOani.gif differ diff --git a/src/icons/interface/dirWindow/background.jpg b/src/icons/interface/dirWindow/background.jpg new file mode 100644 index 0000000..9d51d8e Binary files /dev/null and b/src/icons/interface/dirWindow/background.jpg differ diff --git a/src/icons/interface/dirWindow/bottomlogo.gif b/src/icons/interface/dirWindow/bottomlogo.gif new file mode 100644 index 0000000..b329a98 Binary files /dev/null and b/src/icons/interface/dirWindow/bottomlogo.gif differ diff --git a/src/icons/interface/dirWindow/bottomtitle.gif b/src/icons/interface/dirWindow/bottomtitle.gif new file mode 100644 index 0000000..4d611f2 Binary files /dev/null and b/src/icons/interface/dirWindow/bottomtitle.gif differ diff --git a/src/icons/interface/dirWindow/bottomtitle2.gif b/src/icons/interface/dirWindow/bottomtitle2.gif new file mode 100644 index 0000000..ac70eab Binary files /dev/null and b/src/icons/interface/dirWindow/bottomtitle2.gif differ diff --git a/src/icons/interface/functionreuse/leftbottom.jpg b/src/icons/interface/functionreuse/leftbottom.jpg new file mode 100644 index 0000000..2afc60b Binary files /dev/null and b/src/icons/interface/functionreuse/leftbottom.jpg differ diff --git a/src/icons/interface/functionreuse/lefttop.jpg b/src/icons/interface/functionreuse/lefttop.jpg new file mode 100644 index 0000000..5cddab9 Binary files /dev/null and b/src/icons/interface/functionreuse/lefttop.jpg differ diff --git a/src/icons/interface/functionreuse/rightbottom.jpg b/src/icons/interface/functionreuse/rightbottom.jpg new file mode 100644 index 0000000..08b4b32 Binary files /dev/null and b/src/icons/interface/functionreuse/rightbottom.jpg differ diff --git a/src/icons/interface/functionreuse/righttop.jpg b/src/icons/interface/functionreuse/righttop.jpg new file mode 100644 index 0000000..506d826 Binary files /dev/null and b/src/icons/interface/functionreuse/righttop.jpg differ diff --git a/src/icons/interface/iconWindow/leftbottom.jpg b/src/icons/interface/iconWindow/leftbottom.jpg new file mode 100644 index 0000000..d3c74e2 Binary files /dev/null and b/src/icons/interface/iconWindow/leftbottom.jpg differ diff --git a/src/icons/interface/iconWindow/lefttop.jpg b/src/icons/interface/iconWindow/lefttop.jpg new file mode 100644 index 0000000..2b6b64b Binary files /dev/null and b/src/icons/interface/iconWindow/lefttop.jpg differ diff --git a/src/icons/interface/iconWindow/rightbottom.jpg b/src/icons/interface/iconWindow/rightbottom.jpg new file mode 100644 index 0000000..6c19cc8 Binary files /dev/null and b/src/icons/interface/iconWindow/rightbottom.jpg differ diff --git a/src/icons/interface/iconWindow/righttop.jpg b/src/icons/interface/iconWindow/righttop.jpg new file mode 100644 index 0000000..ff3a34f Binary files /dev/null and b/src/icons/interface/iconWindow/righttop.jpg differ diff --git a/src/icons/interface/loopWindow/leftbottom.jpg b/src/icons/interface/loopWindow/leftbottom.jpg new file mode 100644 index 0000000..a4e2a05 Binary files /dev/null and b/src/icons/interface/loopWindow/leftbottom.jpg differ diff --git a/src/icons/interface/loopWindow/lefttop.jpg b/src/icons/interface/loopWindow/lefttop.jpg new file mode 100644 index 0000000..2b6b64b Binary files /dev/null and b/src/icons/interface/loopWindow/lefttop.jpg differ diff --git a/src/icons/interface/loopWindow/rightbottom.jpg b/src/icons/interface/loopWindow/rightbottom.jpg new file mode 100644 index 0000000..f62c9f0 Binary files /dev/null and b/src/icons/interface/loopWindow/rightbottom.jpg differ diff --git a/src/icons/interface/loopWindow/righttop.jpg b/src/icons/interface/loopWindow/righttop.jpg new file mode 100644 index 0000000..ff3a34f Binary files /dev/null and b/src/icons/interface/loopWindow/righttop.jpg differ diff --git a/src/icons/interface/mainWindow/leftbottom.gif b/src/icons/interface/mainWindow/leftbottom.gif new file mode 100644 index 0000000..5153372 Binary files /dev/null and b/src/icons/interface/mainWindow/leftbottom.gif differ diff --git a/src/icons/interface/mainWindow/lefttop.gif b/src/icons/interface/mainWindow/lefttop.gif new file mode 100644 index 0000000..0a3c93f Binary files /dev/null and b/src/icons/interface/mainWindow/lefttop.gif differ diff --git a/src/icons/interface/mainWindow/rightbottom.gif b/src/icons/interface/mainWindow/rightbottom.gif new file mode 100644 index 0000000..365feee Binary files /dev/null and b/src/icons/interface/mainWindow/rightbottom.gif differ diff --git a/src/icons/interface/mainWindow/righttop.gif b/src/icons/interface/mainWindow/righttop.gif new file mode 100644 index 0000000..1acaecf Binary files /dev/null and b/src/icons/interface/mainWindow/righttop.gif differ diff --git a/src/icons/interface/mainWindow/topwatermark.jpg b/src/icons/interface/mainWindow/topwatermark.jpg new file mode 100644 index 0000000..3d6fb38 Binary files /dev/null and b/src/icons/interface/mainWindow/topwatermark.jpg differ diff --git a/src/icons/interface/mainWindow/topwatermark.png b/src/icons/interface/mainWindow/topwatermark.png new file mode 100644 index 0000000..c356a39 Binary files /dev/null and b/src/icons/interface/mainWindow/topwatermark.png differ diff --git a/src/icons/interface/taskScroll/leftbottom.gif b/src/icons/interface/taskScroll/leftbottom.gif new file mode 100644 index 0000000..ec4ad96 Binary files /dev/null and b/src/icons/interface/taskScroll/leftbottom.gif differ diff --git a/src/icons/interface/taskScroll/lefttop.gif b/src/icons/interface/taskScroll/lefttop.gif new file mode 100644 index 0000000..f375e6d Binary files /dev/null and b/src/icons/interface/taskScroll/lefttop.gif differ diff --git a/src/icons/interface/taskScroll/rightbottom.gif b/src/icons/interface/taskScroll/rightbottom.gif new file mode 100644 index 0000000..6246e49 Binary files /dev/null and b/src/icons/interface/taskScroll/rightbottom.gif differ diff --git a/src/icons/interface/taskScroll/righttop.gif b/src/icons/interface/taskScroll/righttop.gif new file mode 100644 index 0000000..6e7fa08 Binary files /dev/null and b/src/icons/interface/taskScroll/righttop.gif differ diff --git a/src/icons/interface/varWindow/leftbottom.jpg b/src/icons/interface/varWindow/leftbottom.jpg new file mode 100644 index 0000000..3291768 Binary files /dev/null and b/src/icons/interface/varWindow/leftbottom.jpg differ diff --git a/src/icons/interface/varWindow/lefttop.jpg b/src/icons/interface/varWindow/lefttop.jpg new file mode 100644 index 0000000..b0d74c7 Binary files /dev/null and b/src/icons/interface/varWindow/lefttop.jpg differ diff --git a/src/icons/interface/varWindow/rightbottom.jpg b/src/icons/interface/varWindow/rightbottom.jpg new file mode 100644 index 0000000..c29eb9c Binary files /dev/null and b/src/icons/interface/varWindow/rightbottom.jpg differ diff --git a/src/icons/interface/varWindow/righttop.jpg b/src/icons/interface/varWindow/righttop.jpg new file mode 100644 index 0000000..5ac28d0 Binary files /dev/null and b/src/icons/interface/varWindow/righttop.jpg differ diff --git a/src/icons/lamps/A_off.gif b/src/icons/lamps/A_off.gif new file mode 100644 index 0000000..a21c336 Binary files /dev/null and b/src/icons/lamps/A_off.gif differ diff --git a/src/icons/lamps/A_on.gif b/src/icons/lamps/A_on.gif new file mode 100644 index 0000000..5fba412 Binary files /dev/null and b/src/icons/lamps/A_on.gif differ diff --git a/src/icons/lamps/B_off.gif b/src/icons/lamps/B_off.gif new file mode 100644 index 0000000..2688c07 Binary files /dev/null and b/src/icons/lamps/B_off.gif differ diff --git a/src/icons/lamps/B_on.gif b/src/icons/lamps/B_on.gif new file mode 100644 index 0000000..55fc6e0 Binary files /dev/null and b/src/icons/lamps/B_on.gif differ diff --git a/src/icons/lamps/C_off.gif b/src/icons/lamps/C_off.gif new file mode 100644 index 0000000..e994efa Binary files /dev/null and b/src/icons/lamps/C_off.gif differ diff --git a/src/icons/lamps/C_on.gif b/src/icons/lamps/C_on.gif new file mode 100644 index 0000000..2ef39b3 Binary files /dev/null and b/src/icons/lamps/C_on.gif differ diff --git a/src/icons/lamps/lamp.gif b/src/icons/lamps/lamp.gif new file mode 100644 index 0000000..8db84a0 Binary files /dev/null and b/src/icons/lamps/lamp.gif differ diff --git a/src/icons/lamps/power_field.gif b/src/icons/lamps/power_field.gif new file mode 100644 index 0000000..0e88ee5 Binary files /dev/null and b/src/icons/lamps/power_field.gif differ diff --git a/src/icons/lamps/symbol.gif b/src/icons/lamps/symbol.gif new file mode 100644 index 0000000..ff19bd8 Binary files /dev/null and b/src/icons/lamps/symbol.gif differ diff --git a/src/icons/logos/about.png b/src/icons/logos/about.png new file mode 100644 index 0000000..743d110 Binary files /dev/null and b/src/icons/logos/about.png differ diff --git a/src/icons/logos/about_orig.png b/src/icons/logos/about_orig.png new file mode 100644 index 0000000..b76f2f7 Binary files /dev/null and b/src/icons/logos/about_orig.png differ diff --git a/src/icons/logos/logo.gif b/src/icons/logos/logo.gif new file mode 100644 index 0000000..f33fa47 Binary files /dev/null and b/src/icons/logos/logo.gif differ diff --git a/src/icons/logos/splash_logo.png b/src/icons/logos/splash_logo.png new file mode 100644 index 0000000..e1d86f0 Binary files /dev/null and b/src/icons/logos/splash_logo.png differ diff --git a/src/icons/loops/arithmetic/arithmetic.gif b/src/icons/loops/arithmetic/arithmetic.gif new file mode 100644 index 0000000..fde999b Binary files /dev/null and b/src/icons/loops/arithmetic/arithmetic.gif differ diff --git a/src/icons/loops/celcius/celcius.gif b/src/icons/loops/celcius/celcius.gif new file mode 100644 index 0000000..dc4017e Binary files /dev/null and b/src/icons/loops/celcius/celcius.gif differ diff --git a/src/icons/loops/celcius/celcius_field.gif b/src/icons/loops/celcius/celcius_field.gif new file mode 100644 index 0000000..7ee970e Binary files /dev/null and b/src/icons/loops/celcius/celcius_field.gif differ diff --git a/src/icons/loops/celcius/comp1.gif b/src/icons/loops/celcius/comp1.gif new file mode 100644 index 0000000..76a6b3e Binary files /dev/null and b/src/icons/loops/celcius/comp1.gif differ diff --git a/src/icons/loops/celcius/comp2.gif b/src/icons/loops/celcius/comp2.gif new file mode 100644 index 0000000..82df6ab Binary files /dev/null and b/src/icons/loops/celcius/comp2.gif differ diff --git a/src/icons/loops/celcius/comp3.gif b/src/icons/loops/celcius/comp3.gif new file mode 100644 index 0000000..6c430ad Binary files /dev/null and b/src/icons/loops/celcius/comp3.gif differ diff --git a/src/icons/loops/celcius/comp4.gif b/src/icons/loops/celcius/comp4.gif new file mode 100644 index 0000000..35dd3ba Binary files /dev/null and b/src/icons/loops/celcius/comp4.gif differ diff --git a/src/icons/loops/celcius/comp5.gif b/src/icons/loops/celcius/comp5.gif new file mode 100644 index 0000000..305f74b Binary files /dev/null and b/src/icons/loops/celcius/comp5.gif differ diff --git a/src/icons/loops/celcius/comp6.gif b/src/icons/loops/celcius/comp6.gif new file mode 100644 index 0000000..7806838 Binary files /dev/null and b/src/icons/loops/celcius/comp6.gif differ diff --git a/src/icons/loops/celcius/topcelcius.gif b/src/icons/loops/celcius/topcelcius.gif new file mode 100644 index 0000000..7745687 Binary files /dev/null and b/src/icons/loops/celcius/topcelcius.gif differ diff --git a/src/icons/loops/infiniteloop/infinite_rep.gif b/src/icons/loops/infiniteloop/infinite_rep.gif new file mode 100644 index 0000000..83628f9 Binary files /dev/null and b/src/icons/loops/infiniteloop/infinite_rep.gif differ diff --git a/src/icons/loops/lightrep/comp1.gif b/src/icons/loops/lightrep/comp1.gif new file mode 100644 index 0000000..6cbf9a7 Binary files /dev/null and b/src/icons/loops/lightrep/comp1.gif differ diff --git a/src/icons/loops/lightrep/comp2.gif b/src/icons/loops/lightrep/comp2.gif new file mode 100644 index 0000000..d20a6d9 Binary files /dev/null and b/src/icons/loops/lightrep/comp2.gif differ diff --git a/src/icons/loops/lightrep/comp3.gif b/src/icons/loops/lightrep/comp3.gif new file mode 100644 index 0000000..38ed4b4 Binary files /dev/null and b/src/icons/loops/lightrep/comp3.gif differ diff --git a/src/icons/loops/lightrep/comp4.gif b/src/icons/loops/lightrep/comp4.gif new file mode 100644 index 0000000..43cafbc Binary files /dev/null and b/src/icons/loops/lightrep/comp4.gif differ diff --git a/src/icons/loops/lightrep/comp5.gif b/src/icons/loops/lightrep/comp5.gif new file mode 100644 index 0000000..58bbf91 Binary files /dev/null and b/src/icons/loops/lightrep/comp5.gif differ diff --git a/src/icons/loops/lightrep/comp6.gif b/src/icons/loops/lightrep/comp6.gif new file mode 100644 index 0000000..c74d555 Binary files /dev/null and b/src/icons/loops/lightrep/comp6.gif differ diff --git a/src/icons/loops/lightrep/light_field.gif b/src/icons/loops/lightrep/light_field.gif new file mode 100644 index 0000000..7ee970e Binary files /dev/null and b/src/icons/loops/lightrep/light_field.gif differ diff --git a/src/icons/loops/lightrep/light_rep.gif b/src/icons/loops/lightrep/light_rep.gif new file mode 100644 index 0000000..7ee2dd5 Binary files /dev/null and b/src/icons/loops/lightrep/light_rep.gif differ diff --git a/src/icons/loops/lightrep/toploop.gif b/src/icons/loops/lightrep/toploop.gif new file mode 100644 index 0000000..5deb1fc Binary files /dev/null and b/src/icons/loops/lightrep/toploop.gif differ diff --git a/src/icons/loops/repeat/icon_rep.gif b/src/icons/loops/repeat/icon_rep.gif new file mode 100644 index 0000000..eb54700 Binary files /dev/null and b/src/icons/loops/repeat/icon_rep.gif differ diff --git a/src/icons/loops/repeat/toploop.gif b/src/icons/loops/repeat/toploop.gif new file mode 100644 index 0000000..4f3d7e5 Binary files /dev/null and b/src/icons/loops/repeat/toploop.gif differ diff --git a/src/icons/loops/rotation/comp1.gif b/src/icons/loops/rotation/comp1.gif new file mode 100644 index 0000000..a3cf481 Binary files /dev/null and b/src/icons/loops/rotation/comp1.gif differ diff --git a/src/icons/loops/rotation/comp2.gif b/src/icons/loops/rotation/comp2.gif new file mode 100644 index 0000000..986a206 Binary files /dev/null and b/src/icons/loops/rotation/comp2.gif differ diff --git a/src/icons/loops/rotation/comp3.gif b/src/icons/loops/rotation/comp3.gif new file mode 100644 index 0000000..59e7915 Binary files /dev/null and b/src/icons/loops/rotation/comp3.gif differ diff --git a/src/icons/loops/rotation/comp4.gif b/src/icons/loops/rotation/comp4.gif new file mode 100644 index 0000000..f5980d8 Binary files /dev/null and b/src/icons/loops/rotation/comp4.gif differ diff --git a/src/icons/loops/rotation/comp5.gif b/src/icons/loops/rotation/comp5.gif new file mode 100644 index 0000000..a0fb15f Binary files /dev/null and b/src/icons/loops/rotation/comp5.gif differ diff --git a/src/icons/loops/rotation/comp6.gif b/src/icons/loops/rotation/comp6.gif new file mode 100644 index 0000000..43c49ae Binary files /dev/null and b/src/icons/loops/rotation/comp6.gif differ diff --git a/src/icons/loops/rotation/rotation_field.gif b/src/icons/loops/rotation/rotation_field.gif new file mode 100644 index 0000000..7ee970e Binary files /dev/null and b/src/icons/loops/rotation/rotation_field.gif differ diff --git a/src/icons/loops/rotation/rotational.gif b/src/icons/loops/rotation/rotational.gif new file mode 100644 index 0000000..35dad71 Binary files /dev/null and b/src/icons/loops/rotation/rotational.gif differ diff --git a/src/icons/loops/rotation/toprotation.gif b/src/icons/loops/rotation/toprotation.gif new file mode 100644 index 0000000..4381fd1 Binary files /dev/null and b/src/icons/loops/rotation/toprotation.gif differ diff --git a/src/icons/loops/timer/comp1.gif b/src/icons/loops/timer/comp1.gif new file mode 100644 index 0000000..504d49e Binary files /dev/null and b/src/icons/loops/timer/comp1.gif differ diff --git a/src/icons/loops/timer/comp2.gif b/src/icons/loops/timer/comp2.gif new file mode 100644 index 0000000..49a3f19 Binary files /dev/null and b/src/icons/loops/timer/comp2.gif differ diff --git a/src/icons/loops/timer/comp3.gif b/src/icons/loops/timer/comp3.gif new file mode 100644 index 0000000..c62e5f9 Binary files /dev/null and b/src/icons/loops/timer/comp3.gif differ diff --git a/src/icons/loops/timer/comp4.gif b/src/icons/loops/timer/comp4.gif new file mode 100644 index 0000000..cda41e0 Binary files /dev/null and b/src/icons/loops/timer/comp4.gif differ diff --git a/src/icons/loops/timer/comp5.gif b/src/icons/loops/timer/comp5.gif new file mode 100644 index 0000000..012cd43 Binary files /dev/null and b/src/icons/loops/timer/comp5.gif differ diff --git a/src/icons/loops/timer/comp6.gif b/src/icons/loops/timer/comp6.gif new file mode 100644 index 0000000..11fb6c4 Binary files /dev/null and b/src/icons/loops/timer/comp6.gif differ diff --git a/src/icons/loops/timer/timer.gif b/src/icons/loops/timer/timer.gif new file mode 100644 index 0000000..19cb3c4 Binary files /dev/null and b/src/icons/loops/timer/timer.gif differ diff --git a/src/icons/loops/timer/timer_field.gif b/src/icons/loops/timer/timer_field.gif new file mode 100644 index 0000000..7ee970e Binary files /dev/null and b/src/icons/loops/timer/timer_field.gif differ diff --git a/src/icons/loops/timer/toploop.gif b/src/icons/loops/timer/toploop.gif new file mode 100644 index 0000000..dcbe043 Binary files /dev/null and b/src/icons/loops/timer/toploop.gif differ diff --git a/src/icons/loops/touch/signal0.gif b/src/icons/loops/touch/signal0.gif new file mode 100644 index 0000000..08d3936 Binary files /dev/null and b/src/icons/loops/touch/signal0.gif differ diff --git a/src/icons/loops/touch/signal1.gif b/src/icons/loops/touch/signal1.gif new file mode 100644 index 0000000..92b569c Binary files /dev/null and b/src/icons/loops/touch/signal1.gif differ diff --git a/src/icons/loops/touch/toptouch.gif b/src/icons/loops/touch/toptouch.gif new file mode 100644 index 0000000..40c2947 Binary files /dev/null and b/src/icons/loops/touch/toptouch.gif differ diff --git a/src/icons/loops/touch/touch.gif b/src/icons/loops/touch/touch.gif new file mode 100644 index 0000000..e006cdc Binary files /dev/null and b/src/icons/loops/touch/touch.gif differ diff --git a/src/icons/motors/directional/A_norm.gif b/src/icons/motors/directional/A_norm.gif new file mode 100644 index 0000000..95ff768 Binary files /dev/null and b/src/icons/motors/directional/A_norm.gif differ diff --git a/src/icons/motors/directional/A_rev.gif b/src/icons/motors/directional/A_rev.gif new file mode 100644 index 0000000..ab2743d Binary files /dev/null and b/src/icons/motors/directional/A_rev.gif differ diff --git a/src/icons/motors/directional/B_norm.gif b/src/icons/motors/directional/B_norm.gif new file mode 100644 index 0000000..1f04d0e Binary files /dev/null and b/src/icons/motors/directional/B_norm.gif differ diff --git a/src/icons/motors/directional/B_rev.gif b/src/icons/motors/directional/B_rev.gif new file mode 100644 index 0000000..dd64d9c Binary files /dev/null and b/src/icons/motors/directional/B_rev.gif differ diff --git a/src/icons/motors/directional/C_norm.gif b/src/icons/motors/directional/C_norm.gif new file mode 100644 index 0000000..49ca688 Binary files /dev/null and b/src/icons/motors/directional/C_norm.gif differ diff --git a/src/icons/motors/directional/C_rev.gif b/src/icons/motors/directional/C_rev.gif new file mode 100644 index 0000000..6890875 Binary files /dev/null and b/src/icons/motors/directional/C_rev.gif differ diff --git a/src/icons/motors/directional/dir.gif b/src/icons/motors/directional/dir.gif new file mode 100644 index 0000000..a9c20f0 Binary files /dev/null and b/src/icons/motors/directional/dir.gif differ diff --git a/src/icons/motors/directional/topdir.gif b/src/icons/motors/directional/topdir.gif new file mode 100644 index 0000000..89b2f7f Binary files /dev/null and b/src/icons/motors/directional/topdir.gif differ diff --git a/src/icons/motors/floatmotor/Afloat.gif b/src/icons/motors/floatmotor/Afloat.gif new file mode 100644 index 0000000..828db14 Binary files /dev/null and b/src/icons/motors/floatmotor/Afloat.gif differ diff --git a/src/icons/motors/floatmotor/Anofloat.gif b/src/icons/motors/floatmotor/Anofloat.gif new file mode 100644 index 0000000..95ff768 Binary files /dev/null and b/src/icons/motors/floatmotor/Anofloat.gif differ diff --git a/src/icons/motors/floatmotor/Bfloat.gif b/src/icons/motors/floatmotor/Bfloat.gif new file mode 100644 index 0000000..2b3bc89 Binary files /dev/null and b/src/icons/motors/floatmotor/Bfloat.gif differ diff --git a/src/icons/motors/floatmotor/Bnofloat.gif b/src/icons/motors/floatmotor/Bnofloat.gif new file mode 100644 index 0000000..1f04d0e Binary files /dev/null and b/src/icons/motors/floatmotor/Bnofloat.gif differ diff --git a/src/icons/motors/floatmotor/Cfloat.gif b/src/icons/motors/floatmotor/Cfloat.gif new file mode 100644 index 0000000..cbf5ebd Binary files /dev/null and b/src/icons/motors/floatmotor/Cfloat.gif differ diff --git a/src/icons/motors/floatmotor/Cnofloat.gif b/src/icons/motors/floatmotor/Cnofloat.gif new file mode 100644 index 0000000..49ca688 Binary files /dev/null and b/src/icons/motors/floatmotor/Cnofloat.gif differ diff --git a/src/icons/motors/floatmotor/floatmotor.gif b/src/icons/motors/floatmotor/floatmotor.gif new file mode 100644 index 0000000..30a8ddb Binary files /dev/null and b/src/icons/motors/floatmotor/floatmotor.gif differ diff --git a/src/icons/motors/floatmotor/topfloat.gif b/src/icons/motors/floatmotor/topfloat.gif new file mode 100644 index 0000000..73b5998 Binary files /dev/null and b/src/icons/motors/floatmotor/topfloat.gif differ diff --git a/src/icons/motors/movemotor/A_off.gif b/src/icons/motors/movemotor/A_off.gif new file mode 100644 index 0000000..a21c336 Binary files /dev/null and b/src/icons/motors/movemotor/A_off.gif differ diff --git a/src/icons/motors/movemotor/A_on.gif b/src/icons/motors/movemotor/A_on.gif new file mode 100644 index 0000000..5fba412 Binary files /dev/null and b/src/icons/motors/movemotor/A_on.gif differ diff --git a/src/icons/motors/movemotor/B_off.gif b/src/icons/motors/movemotor/B_off.gif new file mode 100644 index 0000000..2688c07 Binary files /dev/null and b/src/icons/motors/movemotor/B_off.gif differ diff --git a/src/icons/motors/movemotor/B_on.gif b/src/icons/motors/movemotor/B_on.gif new file mode 100644 index 0000000..55fc6e0 Binary files /dev/null and b/src/icons/motors/movemotor/B_on.gif differ diff --git a/src/icons/motors/movemotor/C_off.gif b/src/icons/motors/movemotor/C_off.gif new file mode 100644 index 0000000..e994efa Binary files /dev/null and b/src/icons/motors/movemotor/C_off.gif differ diff --git a/src/icons/motors/movemotor/C_on.gif b/src/icons/motors/movemotor/C_on.gif new file mode 100644 index 0000000..2ef39b3 Binary files /dev/null and b/src/icons/motors/movemotor/C_on.gif differ diff --git a/src/icons/motors/movemotor/backward.gif b/src/icons/motors/movemotor/backward.gif new file mode 100644 index 0000000..8735e1f Binary files /dev/null and b/src/icons/motors/movemotor/backward.gif differ diff --git a/src/icons/motors/movemotor/forward.gif b/src/icons/motors/movemotor/forward.gif new file mode 100644 index 0000000..67212b7 Binary files /dev/null and b/src/icons/motors/movemotor/forward.gif differ diff --git a/src/icons/motors/movemotor/icon_wheel2.gif b/src/icons/motors/movemotor/icon_wheel2.gif new file mode 100644 index 0000000..5ef3428 Binary files /dev/null and b/src/icons/motors/movemotor/icon_wheel2.gif differ diff --git a/src/icons/motors/movemotor/power_field.gif b/src/icons/motors/movemotor/power_field.gif new file mode 100644 index 0000000..6bffbbb Binary files /dev/null and b/src/icons/motors/movemotor/power_field.gif differ diff --git a/src/icons/motors/stopmotor/A_off.gif b/src/icons/motors/stopmotor/A_off.gif new file mode 100644 index 0000000..1c239bc Binary files /dev/null and b/src/icons/motors/stopmotor/A_off.gif differ diff --git a/src/icons/motors/stopmotor/A_on.gif b/src/icons/motors/stopmotor/A_on.gif new file mode 100644 index 0000000..95ff768 Binary files /dev/null and b/src/icons/motors/stopmotor/A_on.gif differ diff --git a/src/icons/motors/stopmotor/B_off.gif b/src/icons/motors/stopmotor/B_off.gif new file mode 100644 index 0000000..14c033d Binary files /dev/null and b/src/icons/motors/stopmotor/B_off.gif differ diff --git a/src/icons/motors/stopmotor/B_on.gif b/src/icons/motors/stopmotor/B_on.gif new file mode 100644 index 0000000..1f04d0e Binary files /dev/null and b/src/icons/motors/stopmotor/B_on.gif differ diff --git a/src/icons/motors/stopmotor/C_off.gif b/src/icons/motors/stopmotor/C_off.gif new file mode 100644 index 0000000..b7af345 Binary files /dev/null and b/src/icons/motors/stopmotor/C_off.gif differ diff --git a/src/icons/motors/stopmotor/C_on.gif b/src/icons/motors/stopmotor/C_on.gif new file mode 100644 index 0000000..49ca688 Binary files /dev/null and b/src/icons/motors/stopmotor/C_on.gif differ diff --git a/src/icons/motors/stopmotor/icon_wheel_stop.gif b/src/icons/motors/stopmotor/icon_wheel_stop.gif new file mode 100644 index 0000000..f0b964e Binary files /dev/null and b/src/icons/motors/stopmotor/icon_wheel_stop.gif differ diff --git a/src/icons/motors/stopmotor/topstopmotor.gif b/src/icons/motors/stopmotor/topstopmotor.gif new file mode 100644 index 0000000..83a589a Binary files /dev/null and b/src/icons/motors/stopmotor/topstopmotor.gif differ diff --git a/src/icons/notes/free/freenote.gif b/src/icons/notes/free/freenote.gif new file mode 100644 index 0000000..b49f8d0 Binary files /dev/null and b/src/icons/notes/free/freenote.gif differ diff --git a/src/icons/notes/free/left.gif b/src/icons/notes/free/left.gif new file mode 100644 index 0000000..0b6e060 Binary files /dev/null and b/src/icons/notes/free/left.gif differ diff --git a/src/icons/notes/free/line.gif b/src/icons/notes/free/line.gif new file mode 100644 index 0000000..e4c93b6 Binary files /dev/null and b/src/icons/notes/free/line.gif differ diff --git a/src/icons/notes/free/middle.gif b/src/icons/notes/free/middle.gif new file mode 100644 index 0000000..a8f2091 Binary files /dev/null and b/src/icons/notes/free/middle.gif differ diff --git a/src/icons/notes/free/textField.gif b/src/icons/notes/free/textField.gif new file mode 100644 index 0000000..e8b61b1 Binary files /dev/null and b/src/icons/notes/free/textField.gif differ diff --git a/src/icons/notes/specific/durationField.gif b/src/icons/notes/specific/durationField.gif new file mode 100644 index 0000000..58c4cd4 Binary files /dev/null and b/src/icons/notes/specific/durationField.gif differ diff --git a/src/icons/notes/specific/noteField.gif b/src/icons/notes/specific/noteField.gif new file mode 100644 index 0000000..dbc27af Binary files /dev/null and b/src/icons/notes/specific/noteField.gif differ diff --git a/src/icons/notes/specific/specific.gif b/src/icons/notes/specific/specific.gif new file mode 100644 index 0000000..12c097d Binary files /dev/null and b/src/icons/notes/specific/specific.gif differ diff --git a/src/icons/notes/specific/topleft.gif b/src/icons/notes/specific/topleft.gif new file mode 100644 index 0000000..334df37 Binary files /dev/null and b/src/icons/notes/specific/topleft.gif differ diff --git a/src/icons/notes/specific/topright.gif b/src/icons/notes/specific/topright.gif new file mode 100644 index 0000000..b6de1db Binary files /dev/null and b/src/icons/notes/specific/topright.gif differ diff --git a/src/icons/other/freeplace.gif b/src/icons/other/freeplace.gif new file mode 100644 index 0000000..047168d Binary files /dev/null and b/src/icons/other/freeplace.gif differ diff --git a/src/icons/other/gridmode.gif b/src/icons/other/gridmode.gif new file mode 100644 index 0000000..39cd26c Binary files /dev/null and b/src/icons/other/gridmode.gif differ diff --git a/src/icons/other/join.gif b/src/icons/other/join.gif new file mode 100644 index 0000000..6559dd3 Binary files /dev/null and b/src/icons/other/join.gif differ diff --git a/src/icons/other/joinLoop.gif b/src/icons/other/joinLoop.gif new file mode 100644 index 0000000..52a0cb1 Binary files /dev/null and b/src/icons/other/joinLoop.gif differ diff --git a/src/icons/other/redo.gif b/src/icons/other/redo.gif new file mode 100644 index 0000000..06b531b Binary files /dev/null and b/src/icons/other/redo.gif differ diff --git a/src/icons/other/undo.gif b/src/icons/other/undo.gif new file mode 100644 index 0000000..536fd46 Binary files /dev/null and b/src/icons/other/undo.gif differ diff --git a/src/icons/sensors/clearsensor.gif b/src/icons/sensors/clearsensor.gif new file mode 100644 index 0000000..d557c71 Binary files /dev/null and b/src/icons/sensors/clearsensor.gif differ diff --git a/src/icons/sensors/input1_clear.gif b/src/icons/sensors/input1_clear.gif new file mode 100644 index 0000000..5c4d5a1 Binary files /dev/null and b/src/icons/sensors/input1_clear.gif differ diff --git a/src/icons/sensors/input1_off.gif b/src/icons/sensors/input1_off.gif new file mode 100644 index 0000000..132a6db Binary files /dev/null and b/src/icons/sensors/input1_off.gif differ diff --git a/src/icons/sensors/input2_clear.gif b/src/icons/sensors/input2_clear.gif new file mode 100644 index 0000000..17b136f Binary files /dev/null and b/src/icons/sensors/input2_clear.gif differ diff --git a/src/icons/sensors/input2_off.gif b/src/icons/sensors/input2_off.gif new file mode 100644 index 0000000..25af075 Binary files /dev/null and b/src/icons/sensors/input2_off.gif differ diff --git a/src/icons/sensors/input3_clear.gif b/src/icons/sensors/input3_clear.gif new file mode 100644 index 0000000..eaee8b9 Binary files /dev/null and b/src/icons/sensors/input3_clear.gif differ diff --git a/src/icons/sensors/input3_off.gif b/src/icons/sensors/input3_off.gif new file mode 100644 index 0000000..e866052 Binary files /dev/null and b/src/icons/sensors/input3_off.gif differ diff --git a/src/icons/sensors/top.gif b/src/icons/sensors/top.gif new file mode 100644 index 0000000..3258d63 Binary files /dev/null and b/src/icons/sensors/top.gif differ diff --git a/src/icons/structure/return/return.gif b/src/icons/structure/return/return.gif new file mode 100644 index 0000000..d7d7ed8 Binary files /dev/null and b/src/icons/structure/return/return.gif differ diff --git a/src/icons/task/start/nameField.gif b/src/icons/task/start/nameField.gif new file mode 100644 index 0000000..f38d451 Binary files /dev/null and b/src/icons/task/start/nameField.gif differ diff --git a/src/icons/task/start/startTask.gif b/src/icons/task/start/startTask.gif new file mode 100644 index 0000000..58b75c0 Binary files /dev/null and b/src/icons/task/start/startTask.gif differ diff --git a/src/icons/task/start/startbottom.gif b/src/icons/task/start/startbottom.gif new file mode 100644 index 0000000..3ef5662 Binary files /dev/null and b/src/icons/task/start/startbottom.gif differ diff --git a/src/icons/task/start/startleft.gif b/src/icons/task/start/startleft.gif new file mode 100644 index 0000000..aacd58d Binary files /dev/null and b/src/icons/task/start/startleft.gif differ diff --git a/src/icons/task/start/startright.gif b/src/icons/task/start/startright.gif new file mode 100644 index 0000000..5c37cb5 Binary files /dev/null and b/src/icons/task/start/startright.gif differ diff --git a/src/icons/task/start/starttop.gif b/src/icons/task/start/starttop.gif new file mode 100644 index 0000000..0e29f25 Binary files /dev/null and b/src/icons/task/start/starttop.gif differ diff --git a/src/icons/task/stop/nameField.gif b/src/icons/task/stop/nameField.gif new file mode 100644 index 0000000..19ce244 Binary files /dev/null and b/src/icons/task/stop/nameField.gif differ diff --git a/src/icons/task/stop/stopTask.gif b/src/icons/task/stop/stopTask.gif new file mode 100644 index 0000000..924e8cf Binary files /dev/null and b/src/icons/task/stop/stopTask.gif differ diff --git a/src/icons/task/stop/stopbottom.gif b/src/icons/task/stop/stopbottom.gif new file mode 100644 index 0000000..b83e7ab Binary files /dev/null and b/src/icons/task/stop/stopbottom.gif differ diff --git a/src/icons/task/stop/stopleft.gif b/src/icons/task/stop/stopleft.gif new file mode 100644 index 0000000..e0d2ba1 Binary files /dev/null and b/src/icons/task/stop/stopleft.gif differ diff --git a/src/icons/task/stop/stopright.gif b/src/icons/task/stop/stopright.gif new file mode 100644 index 0000000..5c37cb5 Binary files /dev/null and b/src/icons/task/stop/stopright.gif differ diff --git a/src/icons/task/stop/stoptop.gif b/src/icons/task/stop/stoptop.gif new file mode 100644 index 0000000..f8c071e Binary files /dev/null and b/src/icons/task/stop/stoptop.gif differ diff --git a/src/icons/timers/cleart/Thumbs.db b/src/icons/timers/cleart/Thumbs.db new file mode 100644 index 0000000..7c5a5e8 Binary files /dev/null and b/src/icons/timers/cleart/Thumbs.db differ diff --git a/src/icons/timers/cleart/bottomleft.gif b/src/icons/timers/cleart/bottomleft.gif new file mode 100644 index 0000000..3bf9183 Binary files /dev/null and b/src/icons/timers/cleart/bottomleft.gif differ diff --git a/src/icons/timers/cleart/cleartimer.gif b/src/icons/timers/cleart/cleartimer.gif new file mode 100644 index 0000000..e994450 Binary files /dev/null and b/src/icons/timers/cleart/cleartimer.gif differ diff --git a/src/icons/timers/cleart/timer_field.gif b/src/icons/timers/cleart/timer_field.gif new file mode 100644 index 0000000..5d55943 Binary files /dev/null and b/src/icons/timers/cleart/timer_field.gif differ diff --git a/src/icons/timers/cleart/top.gif b/src/icons/timers/cleart/top.gif new file mode 100644 index 0000000..6cdf9ec Binary files /dev/null and b/src/icons/timers/cleart/top.gif differ diff --git a/src/icons/timers/wait/bottomtime.gif b/src/icons/timers/wait/bottomtime.gif new file mode 100644 index 0000000..aaa6baa Binary files /dev/null and b/src/icons/timers/wait/bottomtime.gif differ diff --git a/src/icons/timers/wait/fullbottomtime.gif b/src/icons/timers/wait/fullbottomtime.gif new file mode 100644 index 0000000..431686f Binary files /dev/null and b/src/icons/timers/wait/fullbottomtime.gif differ diff --git a/src/icons/timers/wait/fulltoptime.gif b/src/icons/timers/wait/fulltoptime.gif new file mode 100644 index 0000000..173b62d Binary files /dev/null and b/src/icons/timers/wait/fulltoptime.gif differ diff --git a/src/icons/timers/wait/icon_time.gif b/src/icons/timers/wait/icon_time.gif new file mode 100644 index 0000000..be3b183 Binary files /dev/null and b/src/icons/timers/wait/icon_time.gif differ diff --git a/src/icons/timers/wait/lefttime.gif b/src/icons/timers/wait/lefttime.gif new file mode 100644 index 0000000..e631be9 Binary files /dev/null and b/src/icons/timers/wait/lefttime.gif differ diff --git a/src/icons/timers/wait/rightime.gif b/src/icons/timers/wait/rightime.gif new file mode 100644 index 0000000..22b771d Binary files /dev/null and b/src/icons/timers/wait/rightime.gif differ diff --git a/src/icons/timers/wait/timer_field.gif b/src/icons/timers/wait/timer_field.gif new file mode 100644 index 0000000..97226b9 Binary files /dev/null and b/src/icons/timers/wait/timer_field.gif differ diff --git a/src/icons/timers/wait/toptime.gif b/src/icons/timers/wait/toptime.gif new file mode 100644 index 0000000..908de37 Binary files /dev/null and b/src/icons/timers/wait/toptime.gif differ diff --git a/src/icons/wait/celcius/celciusField.gif b/src/icons/wait/celcius/celciusField.gif new file mode 100644 index 0000000..58c4cd4 Binary files /dev/null and b/src/icons/wait/celcius/celciusField.gif differ diff --git a/src/icons/wait/celcius/comp1.gif b/src/icons/wait/celcius/comp1.gif new file mode 100644 index 0000000..899a22d Binary files /dev/null and b/src/icons/wait/celcius/comp1.gif differ diff --git a/src/icons/wait/celcius/comp2.gif b/src/icons/wait/celcius/comp2.gif new file mode 100644 index 0000000..f456f63 Binary files /dev/null and b/src/icons/wait/celcius/comp2.gif differ diff --git a/src/icons/wait/celcius/comp3.gif b/src/icons/wait/celcius/comp3.gif new file mode 100644 index 0000000..8ea9eeb Binary files /dev/null and b/src/icons/wait/celcius/comp3.gif differ diff --git a/src/icons/wait/celcius/comp4.gif b/src/icons/wait/celcius/comp4.gif new file mode 100644 index 0000000..3b966ea Binary files /dev/null and b/src/icons/wait/celcius/comp4.gif differ diff --git a/src/icons/wait/celcius/comp5.gif b/src/icons/wait/celcius/comp5.gif new file mode 100644 index 0000000..f89f84f Binary files /dev/null and b/src/icons/wait/celcius/comp5.gif differ diff --git a/src/icons/wait/celcius/comp6.gif b/src/icons/wait/celcius/comp6.gif new file mode 100644 index 0000000..83b9a1e Binary files /dev/null and b/src/icons/wait/celcius/comp6.gif differ diff --git a/src/icons/wait/celcius/top_left.gif b/src/icons/wait/celcius/top_left.gif new file mode 100644 index 0000000..ad94335 Binary files /dev/null and b/src/icons/wait/celcius/top_left.gif differ diff --git a/src/icons/wait/celcius/wait_celcius.gif b/src/icons/wait/celcius/wait_celcius.gif new file mode 100644 index 0000000..2148498 Binary files /dev/null and b/src/icons/wait/celcius/wait_celcius.gif differ diff --git a/src/icons/wait/light/comp1.gif b/src/icons/wait/light/comp1.gif new file mode 100644 index 0000000..4543e4b Binary files /dev/null and b/src/icons/wait/light/comp1.gif differ diff --git a/src/icons/wait/light/comp2.gif b/src/icons/wait/light/comp2.gif new file mode 100644 index 0000000..bb36b15 Binary files /dev/null and b/src/icons/wait/light/comp2.gif differ diff --git a/src/icons/wait/light/comp3.gif b/src/icons/wait/light/comp3.gif new file mode 100644 index 0000000..6539d48 Binary files /dev/null and b/src/icons/wait/light/comp3.gif differ diff --git a/src/icons/wait/light/comp4.gif b/src/icons/wait/light/comp4.gif new file mode 100644 index 0000000..cde8a88 Binary files /dev/null and b/src/icons/wait/light/comp4.gif differ diff --git a/src/icons/wait/light/comp5.gif b/src/icons/wait/light/comp5.gif new file mode 100644 index 0000000..ae46f6b Binary files /dev/null and b/src/icons/wait/light/comp5.gif differ diff --git a/src/icons/wait/light/comp6.gif b/src/icons/wait/light/comp6.gif new file mode 100644 index 0000000..50456fe Binary files /dev/null and b/src/icons/wait/light/comp6.gif differ diff --git a/src/icons/wait/light/lightField.gif b/src/icons/wait/light/lightField.gif new file mode 100644 index 0000000..58c4cd4 Binary files /dev/null and b/src/icons/wait/light/lightField.gif differ diff --git a/src/icons/wait/light/top_left.gif b/src/icons/wait/light/top_left.gif new file mode 100644 index 0000000..ad94335 Binary files /dev/null and b/src/icons/wait/light/top_left.gif differ diff --git a/src/icons/wait/light/wait_light.gif b/src/icons/wait/light/wait_light.gif new file mode 100644 index 0000000..8886683 Binary files /dev/null and b/src/icons/wait/light/wait_light.gif differ diff --git a/src/icons/wait/rotate/comp1.gif b/src/icons/wait/rotate/comp1.gif new file mode 100644 index 0000000..2287783 Binary files /dev/null and b/src/icons/wait/rotate/comp1.gif differ diff --git a/src/icons/wait/rotate/comp2.gif b/src/icons/wait/rotate/comp2.gif new file mode 100644 index 0000000..1c687b2 Binary files /dev/null and b/src/icons/wait/rotate/comp2.gif differ diff --git a/src/icons/wait/rotate/comp3.gif b/src/icons/wait/rotate/comp3.gif new file mode 100644 index 0000000..821e512 Binary files /dev/null and b/src/icons/wait/rotate/comp3.gif differ diff --git a/src/icons/wait/rotate/comp4.gif b/src/icons/wait/rotate/comp4.gif new file mode 100644 index 0000000..285d071 Binary files /dev/null and b/src/icons/wait/rotate/comp4.gif differ diff --git a/src/icons/wait/rotate/comp5.gif b/src/icons/wait/rotate/comp5.gif new file mode 100644 index 0000000..7f1b5e7 Binary files /dev/null and b/src/icons/wait/rotate/comp5.gif differ diff --git a/src/icons/wait/rotate/comp6.gif b/src/icons/wait/rotate/comp6.gif new file mode 100644 index 0000000..e988956 Binary files /dev/null and b/src/icons/wait/rotate/comp6.gif differ diff --git a/src/icons/wait/rotate/rotateField.gif b/src/icons/wait/rotate/rotateField.gif new file mode 100644 index 0000000..58c4cd4 Binary files /dev/null and b/src/icons/wait/rotate/rotateField.gif differ diff --git a/src/icons/wait/rotate/top_left.gif b/src/icons/wait/rotate/top_left.gif new file mode 100644 index 0000000..ad94335 Binary files /dev/null and b/src/icons/wait/rotate/top_left.gif differ diff --git a/src/icons/wait/rotate/wait_rotate.gif b/src/icons/wait/rotate/wait_rotate.gif new file mode 100644 index 0000000..29650ea Binary files /dev/null and b/src/icons/wait/rotate/wait_rotate.gif differ diff --git a/src/icons/wait/timer/comp1.gif b/src/icons/wait/timer/comp1.gif new file mode 100644 index 0000000..23caa59 Binary files /dev/null and b/src/icons/wait/timer/comp1.gif differ diff --git a/src/icons/wait/timer/comp2.gif b/src/icons/wait/timer/comp2.gif new file mode 100644 index 0000000..2d0eff6 Binary files /dev/null and b/src/icons/wait/timer/comp2.gif differ diff --git a/src/icons/wait/timer/comp3.gif b/src/icons/wait/timer/comp3.gif new file mode 100644 index 0000000..f0d22dc Binary files /dev/null and b/src/icons/wait/timer/comp3.gif differ diff --git a/src/icons/wait/timer/comp4.gif b/src/icons/wait/timer/comp4.gif new file mode 100644 index 0000000..740a732 Binary files /dev/null and b/src/icons/wait/timer/comp4.gif differ diff --git a/src/icons/wait/timer/comp5.gif b/src/icons/wait/timer/comp5.gif new file mode 100644 index 0000000..a52f16d Binary files /dev/null and b/src/icons/wait/timer/comp5.gif differ diff --git a/src/icons/wait/timer/comp6.gif b/src/icons/wait/timer/comp6.gif new file mode 100644 index 0000000..ab1a6d9 Binary files /dev/null and b/src/icons/wait/timer/comp6.gif differ diff --git a/src/icons/wait/timer/timerField.gif b/src/icons/wait/timer/timerField.gif new file mode 100644 index 0000000..58c4cd4 Binary files /dev/null and b/src/icons/wait/timer/timerField.gif differ diff --git a/src/icons/wait/timer/top_left.gif b/src/icons/wait/timer/top_left.gif new file mode 100644 index 0000000..ad94335 Binary files /dev/null and b/src/icons/wait/timer/top_left.gif differ diff --git a/src/icons/wait/timer/wait_timer.gif b/src/icons/wait/timer/wait_timer.gif new file mode 100644 index 0000000..7a8d789 Binary files /dev/null and b/src/icons/wait/timer/wait_timer.gif differ diff --git a/src/icons/wait/touch/comp1.gif b/src/icons/wait/touch/comp1.gif new file mode 100644 index 0000000..0b13210 Binary files /dev/null and b/src/icons/wait/touch/comp1.gif differ diff --git a/src/icons/wait/touch/comp2.gif b/src/icons/wait/touch/comp2.gif new file mode 100644 index 0000000..60ecbd8 Binary files /dev/null and b/src/icons/wait/touch/comp2.gif differ diff --git a/src/icons/wait/touch/top_left.gif b/src/icons/wait/touch/top_left.gif new file mode 100644 index 0000000..62d50fd Binary files /dev/null and b/src/icons/wait/touch/top_left.gif differ diff --git a/src/icons/wait/touch/wait_touch.gif b/src/icons/wait/touch/wait_touch.gif new file mode 100644 index 0000000..22601dd Binary files /dev/null and b/src/icons/wait/touch/wait_touch.gif differ diff --git a/src/readme.txt b/src/readme.txt new file mode 100644 index 0000000..d04ab81 --- /dev/null +++ b/src/readme.txt @@ -0,0 +1,391 @@ + ---------------- +----- fUNSoftWare ----- + ---------------- + +Version: 1.0 +Author: Thomas Legowo and Eric Martin +Copyright of UNSW School of Computer Science and Engineering + +--------------------------------- +| Table of Contents | +--------------------------------- + +1 Requirements +2 Introduction +3 Basic features + 3.1 Icon types + 3.2 Icon insertion + 3.3 Icon deletion + 3.4 Icon replacement + 3.5 Icon relocation + 3.6 Copying an icon + 3.7 Editing icon attributes + 3.8 Displaying icon properties and help + 3.9 Undo/Redo + 3.10 Execution to RCX +4 Advanced Features + 4.1 Tasks + 4.2 Functions + 4.3 Events + 4.4 Variables and arithmetic operations + 4.5 NQC code +5 Acknowledgements + +---------------------------------- + + +>>>>> 1 Requirements <<<<< +---------------------------------------- + +fUNSoftWare needs the following set-up: + +1. Java 1.5 or above. +The latest Java environment can be downloaded from +http://java.sun.com/j2se/1.5.0/download.jsp +2. NQC 3.1 r4 or above +The latest version of NQC can be downloaded from +http://bricxcc.sourceforge.net/nqc/welcome.html + +fUNSoftWare can be run on any Operating System, with Windows and MacOS +as the recommended operating systems. + + +>>>>> 2 Introduction <<<<< +-------------------------------------- + +fUNSoftWare is an icon based software program used to program the LEGO Mindstorms robots. +It is able to utilise the robots' motors, lamps, sensors (touch sensors, light sensors, +rotational sensors, temperature sensors), timers, and speakers. Equipped with powerful +features, fUNSoftWare also teaches the basics of programming concepts: functions, variables, +branches, loops, and arithmetic operations. It even encourages modular programming. + +In order to program a robot, you will have to do the following steps: +1. Create a program that involves stringing together icons from left to right and editing +them where appropriate. fUNSoftWare might generate some error messages throughout the +process if you attempt to execute an illegal operation. One of the great features of fUNSoftWare +is that all the wiring is done automatically. Whether you want to insert or delete icons, the necessary +wires that link the icon you are working on with the surrounding icons will be created or +deleted automatically. +2. After you are satisfied with the program, you will need to compile it. The result +of the compilation is an NQC (Not Quite C) text code that is guaranteed to run (though +maybe not as you want it to run!) on the LEGO robot. +3. The robot might not perform the task you wanted because you inserted icons that do not perform +their intended operations. You will then need to edit the program and repeat processes 2 +and 3 until everything works as you originally had in mind. + +Now understanding the basics of creating a program in fUNSoftWare. + +You will start off with a main graph consisting of two traffic light icons, the left one of being set +to green and the right one to red. Any icon that you wish to use should be placed between the +green and red traffic lights, and the program will read them sequentially from left to right. It is +possible to create another graph with different sets of icons and a new set of traffic lights in one of +three kinds of structures, called tasks, functions or events. + + +>>>>> 3 Basic features <<<<< +---------------------------------------- + +-->> 3.1 Icon types +============== + +There are three types of icons: +1. Singles + An icon of this type accomplishes one single operation. Upon execution, this icon + does not affect the rest of the program. + +Following is a schematic representation of two "single" icons strung next to each other: + +---- ---- +| |------| | +---- ---- + + +2. Branches + An icon of this type determines one out of two possible paths that the program takes + based on a check on whether a specified condition (can be using sensor readings or an + arithmetic expression) is met. + +Following is a schematic representation of a "branch" icon: + + |--- + | +----| +| | +----| + | + |--- + +3. Loops + An icon of this type decides whether or not to repeat a designated sequence of icons + based on a check on whether a specified condition (can be using sensor readings or an + arithmetic expression) is met. + +Following is a schematic representation of a "loop" icon: + + | | + | ---- | + |-------| |-------| + ---- + + +-->> 3.2 Icon insertion +================ + +To insert a "single" typed icon, simply click on the "single" icon that you want, then click +once more on the programming palette to place it. + +To insert a "branch" typed icon, simply click on the "branch" icon that you want, then click +once more on the programming palette to place it. + +To insert a "loop" typed icon, simply click on the "loop" icon that you want, then you will +need to click twice on the programming palette to determine the beginning and the end of +the loop, respectively. + +The program will let you know if the icon insertion process was unsuccessful due to illegal +steps taken by you. + +If after you have selected an icon, you decide not to insert it, then simply select the +"Cancel" button on the top right hand side of the window. + + +-->> 3.3 Icon deletion +=============== + +To delete a "single" typed icon, simply right click on the "single" icon that you want to +delete, then select "Delete icon". + +To delete a "branch" typed icon, simply right click on the "branch" icon that you want to +delete, then select "Delete". You will then need to select whether to delete the branch +with all of the icons inside both of its paths or just one of the paths (in which case you will have +to indicate which path you want to delete and which one you want to keep). + +To delete a "loop" typed icon, simply right click on the "loop" icon that you want to +delete, then select "Delete". You will then need to indicate whether to delete the loop icon +with all of the icons inside it or just the icon itself. + + +-->> 3.4 Icon replacement +================== + +You can replace an icon by simply right clicking the icon, then select "Replace icon", then +select the desired icon as the replacement. + + +-->> 3.5 Icon relocation +================= + +For a "single" typed icon, simply right click on the icon, then select "Relocate icon". You will +then need to click on the programming palette to determine the new position of the icon. + +For a "branch" typed icon, simply right click on the icon then select "Relocate icon". You will +then need to click on the programming palette to determine the new position of the icon. All icons +in its paths will also be relocated to positions relative to the branch icon. + +For a "loop" typed icon, simply right click on the icon then select "Relocate icon". You will +then need to click on the programming palette to determine the new position of the icon. All +icons enclosed will also be relocated to positions relative to the loop icon. + + +-->> 3.6 Copying an icon +================= + +Simply right click on the desired icon, then left click on the programming palette to place +the copied icon. The copied icon will have the same attribute values as the original icon. + +For a "loop" icon, after "Copy icon" is selected, you will need to click twice on the programming +palette just as if you were inserting a new "loop" icon. + + +-->> 3.7 Editing icon attributes +====================== + +All kinds of icons in fUNSoftWare have their attributes ready to be edited without the need to add +more icons. Some attributes are displayed and can be edited by clicking on them. Other attributes +can be edited through a small pop up window. + +For certain attributes, you will need to have the following information before continuing: +1. Light sensor value: + ranges between 0 (bright) to 100 (dark) +2. Temperature sensor value: + 1 = 1/10 Celcius +3. Rotational sensor value: + 1 = 1/16 of one motor rotation +4. Timer value: + 1 = 1/10 seconds +5. Note duration: + 1 = 1/100 seconds + + +-->> 3.8 Displaying icon properties and help +=============================== + + +By right clicking on any icon and selecting "Properties", the corresponding icon's attributes and +their respective values will be displayed. + +By right clicking on any icon and selecting "Help", the corresponding icon's context help will be +displayed. This will explain each of the icon's attributes. + +-->> 3.9 Undo/Redo +=============== + +On the top right corner of the program's window, there are two buttons for undo and redo. "Undo" +is used to restore the previous state of the program and "Redo" is used to restore the state of +the program before an undo operation was carried out. + + +-->> 3.10 Execution to RCX +==================== + +If you select "Compile and Download" or "Compile and Run" in the menu, an NQC code will be +generated and executed on the robot. "Compile and Download" will download your program into +the LEGO robot and then you will need to press the green button "run" on the robot to get it to start +on running your program. "Compile and Run" will download and automatically run your program +on the LEGO robot. + +You should make sure that the robot is within the infrared tower's range, and is properly +equipped to accomplish your task. + + +>>>>> 4 Advanced features <<<<< +----------------------------------------------- + +-->> 4.1 Tasks +=========== + +A task can be executed in parallel to other tasks and can be started or stopped anytime. A task called +"main" is set by default and cannot be renamed nor deleted. It is the starting point whenever a +program of your creation is to be executed. + + +-->> 4.2 Functions +============= + +A function is different to a task. It can be re-used anywhere. It is used to make programs more +modular and readable. + +A "level" attribute for function is used to determine "who calls whom". A function can only call +another function if and only if its level is higher than the level of the called functions. + +A function can have arguments. Arguments are local variables that are passed onto the function to +be used within the function only. + + +-->> 4.3 Events +=========== + +There are two elements for this feature: +1. Event Definition + +An event is a process where the LEGO robot checks a selected sensor or timer. It consists of: +1. Type of sensor or timer +2. Input port of the sensor or the timer number +3. Comparator. (E.g. for a touch sensor, detect whether the sensor is being touched or released +whereas for a light sensor, detect whether its reading is greater than or less than a specified value). + +A maximum of 16 different events can be defined in a program. + +2. Event Monitor + +An event monitor is a process where the LEGO robot executes a set of icons while waiting for one or +more events to be satisfied. + +An event monitor consists of: + +1. Type (Local or Global) +2. Events to be monitored. +3. Associated code to be executed as long as no event has detected the associated reading. +If and when an event that is being monitored "happens", then execution of the code associated +with the event monitor stops and execution of the program jumps to right after the icon that has +started monitoring the event. + +A "Local" event monitor implies that it can only be started from a specified task or function that has +a higher level than the event monitor. An arithmetic operation in such event monitor can use the +specified task or function's local variables. + +A "Global" event monitor implies that it can be started from any task or function, but then cannot use +any of the local variables of the task or function. + +No event monitor can start another event monitor. + +A "level" attribute for event monitor is used to determine "which function call it". A function can only +call an event monitor if and only if its level is higher than the level of the called event monitor. + +-->> 4.4 Variables and arithmetic operations +================================ + +Variable take integer values. These values change according to arithmetic operations applied to +the variable. + +An arithmetic operation is of the form + +Variable = Operand + +where "Operand" is one of +1. Constant +2. Variable +3. Operand Operator Operand + +and "Operator" is one of +1. + +2. - +3. * +4. / + +The variables SENSOR_1, SENSOR_2 and SENSOR_3 are special: they hold the values of the sensors +connected to ports 1, 2 and 3, respectively, if any. So their values will change over time, and as +such they are variables. But contrary to other kinds of (global or local) variables, their values cannot +be set or changed by the user. + +A variable that you have defined can be used in some icon attributes. You need to click on the +desired attribute in the usual way, then you will need to type in "v". A small pop up window will appear +and ask you to select which variable should be associated with the attribute. + +Icons that allow the use of variable together with the attribute: +1. Motor Icon for its power level +2. Lamp Icon for its power level +3. Play Any Note Icon for its frequency +4. Wait Icon for the amount of time to wait +5. Wait Light Sensor Icon for the value threshold +6. Wait Temperature Sensor Icon for the value threshold +7. Wait Rotational Sensor Icon for the value threshold +8. Wait Timer Sensor Icon for the value threshold +9. Branch Light Sensor Icon for the value threshold +10. Branch Temperature Sensor Icon for the value threshold +11. Branch Rotational Sensor Icon for the value threshold +12. Branch Timer Sensor Icon for the value threshold +13. Loop Light Sensor Icon for the value threshold +14. Loop Temperature Sensor Icon for the value threshold +15. Loop Rotational Sensor Icon for the value threshold +16. Loop Timer Sensor Icon for the value threshold +17. Repeat Icon for the number of repeat + + +-->> 4.5 NQC code +============= + +NQC is Not Quite C and it is a text based program used to program the LEGO robot. Unlike fUNSoftWare, +you will need to input purely text without the use of any icons. +To create a corresponding NQC code from your current program, you will need to save your program, +then select the menu "Build", then "Create NQC Code". Alternatively, you can just press "F-5". An NQC +file will be created afterwards and that file will use the same name as your save file but with "nqc" as the +extension of the file. The location of the NQC file will also be in the same directory as your save file. + +Example: If you saved your program with under a name "runfast", then the NQC file generated +will be named "runfast.nqc". + + +>>>>> 5 Acknowledgements <<<<< +------------------------------------------------ + +Mindstorms and LEGO are trademarks of the LEGO Group +NQC is a free software released under the Mozilla Public License (MPL). + +fUNSoftWare development team: +Eric Martin --> Supervisor +Thomas Legowo --> Programmer +Geoffrey Roberts --> Graphic Designer + +fUNSoftWare is released under the University of New South Wales School of Computer Science +and Engineering. +