diff --git a/README.md b/README.md index d1e3123..0834968 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # SeSim -SeSim - Sock Exchange Simulator \ No newline at end of file +OpenSeSim - Open Source Sock Exchange Simulator \ No newline at end of file diff --git a/build.xml b/build.xml index 17d82f4..ae789e2 100644 --- a/build.xml +++ b/build.xml @@ -109,30 +109,30 @@ --> - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - + @@ -147,10 +147,10 @@ - + diff --git a/master-application.jnlp b/master-application.jnlp deleted file mode 100644 index 1859df2..0000000 --- a/master-application.jnlp +++ /dev/null @@ -1,22 +0,0 @@ - - - ${APPLICATION.TITLE} - ${APPLICATION.VENDOR} - - ${APPLICATION.DESC} - ${APPLICATION.DESC.SHORT} - - - - - - - - - - - - - - - diff --git a/master-component.jnlp b/master-component.jnlp deleted file mode 100644 index 53d6d41..0000000 --- a/master-component.jnlp +++ /dev/null @@ -1,20 +0,0 @@ - - - ${APPLICATION.TITLE} - ${APPLICATION.VENDOR} - - ${APPLICATION.DESC} - ${APPLICATION.DESC.SHORT} - - - - - - - - - - - - - diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml index dee7575..fa32622 100644 --- a/nbproject/build-impl.xml +++ b/nbproject/build-impl.xml @@ -1,1421 +1,1766 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set src.dir - Must set test.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 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.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/configs/JWS_generated.properties b/nbproject/configs/JWS_generated.properties deleted file mode 100644 index 7a873bf..0000000 --- a/nbproject/configs/JWS_generated.properties +++ /dev/null @@ -1,4 +0,0 @@ -$label=Web Start -$target.debug=jws-debug -$target.run=jws-run -compile.on.save.unsupported.javawebstart=true diff --git a/nbproject/configs/sesimws.properties b/nbproject/configs/sesimws.properties deleted file mode 100644 index e69de29..0000000 diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties index 8b5eadf..fe5af1e 100644 --- a/nbproject/genfiles.properties +++ b/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=fc4f97ad -build.xml.script.CRC32=72406d8f -build.xml.stylesheet.CRC32=8064a381@1.79.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=56c4c4cc -nbproject/build-impl.xml.script.CRC32=5f99364f -nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 +build.xml.data.CRC32=fc4f97ad +build.xml.script.CRC32=72406d8f +build.xml.stylesheet.CRC32=8064a381@1.79.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=65c6cbee +nbproject/build-impl.xml.script.CRC32=ae093a94 +nbproject/build-impl.xml.stylesheet.CRC32=3a2fa800@1.89.1.48 diff --git a/nbproject/jnlp-impl_backup.xml b/nbproject/jnlp-impl_backup.xml index 32bd923..96d4bfd 100644 --- a/nbproject/jnlp-impl_backup.xml +++ b/nbproject/jnlp-impl_backup.xml @@ -1,47 +1,23 @@ @@ -261,7 +237,7 @@ made subject to such option by the copyright holder. - + @@ -306,7 +282,7 @@ made subject to such option by the copyright holder. - + @@ -866,18 +842,6 @@ made subject to such option by the copyright holder. description="Debug javaws project in IDE"/> - - - - - - - - - - - - @@ -889,7 +853,7 @@ made subject to such option by the copyright holder. - + diff --git a/nbproject/project.properties b/nbproject/project.properties index 219988d..914f34c 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,4 +1,4 @@ -#Sat, 27 Jan 2018 22:25:12 +0100 +#Fri, 30 Nov 2018 10:49:27 +0100 annotation.processing.enabled=true annotation.processing.enabled.in.editor=false annotation.processing.processors.list= @@ -8,8 +8,17 @@ ant.customtasks.libs=JWSAntTasks application.desc=SeSim - Stock Exchange Simulator application.homepage=blog.cauwersin.com application.splash= -application.title=SeSim +application.title=OpenSeSim application.vendor=Cauwersin +auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.expand-tabs=true +auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.indent-shift-width=4 +auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.spaces-per-tab=4 +auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.tab-size=8 +auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.text-limit-width=80 +auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.text-line-wrap=none +auxiliary.org-netbeans-modules-editor-indent.CodeStyle.usedProfile=project +auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsEnabled=true +auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml build.classes.dir=${build.dir}/classes build.classes.excludes=**/*.java,**/*.form # This directory is removed when the project is cleaned: @@ -23,12 +32,14 @@ build.test.results.dir=${build.dir}/test/results # Uncomment to specify the preferred debugger connection transport: #debug.transport=dt_socket debug.classpath=${run.classpath} +debug.modulepath=${run.modulepath} debug.test.classpath=${run.test.classpath} +debug.test.modulepath=${run.test.modulepath} # Files in build.classes.dir which should be excluded from distribution jar dist.archive.excludes= # This directory is removed when the project is cleaned: dist.dir=dist -dist.jar=${dist.dir}/SeSim.jar +dist.jar=${dist.dir}/OpenSeSim.jar dist.javadoc.dir=${dist.dir}/javadoc endorsed.classpath= excludes= @@ -41,10 +52,13 @@ javac.classpath=${ivy.classpath}\:${libs.absolutelayout.classpath} javac.compilerargs= javac.deprecation=false javac.external.vm=true +javac.modulepath= +javac.processormodulepath= javac.processorpath=${javac.classpath} javac.source=1.8 javac.target=1.8 -javac.test.classpath=${javac.classpath}\:${build.classes.dir} +javac.test.classpath=${javac.classpath}\:${build.classes.dir}\:${libs.junit_4.classpath}\:${libs.hamcrest.classpath}\:${libs.testng.classpath} +javac.test.modulepath=${javac.modulepath} javac.test.processorpath=${javac.test.classpath} javadoc.additionalparam= javadoc.author=false @@ -61,6 +75,7 @@ jnlp.applet.height=300 jnlp.applet.width=300 jnlp.codebase.type=user jnlp.codebase.url=$$$$codebase +jnlp.codebase.user= jnlp.descriptor=component jnlp.enabled=false jnlp.icon= @@ -69,7 +84,8 @@ jnlp.offline-allowed=true jnlp.signed=true jnlp.signing=key jnlp.signing.alias=SeSim -main.class=gui.SeSimApplication +jnlp.signing.keystore= +main.class=opensesim.gui.SeSimApplication # Optional override of default Application-Library-Allowable-Codebase attribute identifying the locations where your signed RIA is expected to be found. manifest.custom.application.library.allowable.codebase= # Optional override of default Caller-Allowable-Codebase attribute identifying the domains from which JavaScript code can make calls to your RIA without security prompts. @@ -88,7 +104,9 @@ run.classpath=${javac.classpath}\:${build.classes.dir} # You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. # To set system properties for unit tests define test-sys-prop.name=value: run.jvmargs= +run.modulepath=${javac.modulepath} run.test.classpath=${javac.test.classpath}\:${build.test.classes.dir} +run.test.modulepath=${javac.test.modulepath} source.encoding=UTF-8 src.dir=src test.src.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml index f6b6657..878572a 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -9,7 +9,7 @@ - SeSim + OpenSeSim diff --git a/preview-application.html b/preview-application.html deleted file mode 100644 index 4834dd8..0000000 --- a/preview-application.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - Test page for launching the application via JNLP - - -

Test page for launching the application via JNLP

- - - - - - diff --git a/src/gui/OrderBookPanel_old.form b/src/gui/OrderBookPanel_old.form deleted file mode 100644 index 4b11b03..0000000 --- a/src/gui/OrderBookPanel_old.form +++ /dev/null @@ -1,459 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/src/opensesim/AbstractAsset.java b/src/opensesim/AbstractAsset.java new file mode 100644 index 0000000..0b35d76 --- /dev/null +++ b/src/opensesim/AbstractAsset.java @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim; + + +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.JPanel; +import opensesim.sesim.interfaces.Configurable; +import opensesim.util.IDGenerator.Id; +import org.json.JSONException; +import org.json.JSONObject; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public abstract class AbstractAsset implements Configurable { + + private Id id; + private String symbol; + private String name; + private String description; + int decimals; + + /** + * Constructor + */ + protected AbstractAsset() { + id = null; + } + + public abstract String getTypeName(); + + + + public void setDecimals(int decimals) { + this.decimals = decimals; + } + + public int getDecimals() { + return decimals; + } + + public void setDescription(String description) { + this.description = description; + } + + public Id getID() { + return id; + } + + public String getSymbol() { + return symbol; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public boolean isCurrency(){ + return false; + } + public boolean isAsset(){ + return false; + } + + + + public static final String JSON_ID ="id"; + public static final String JSON_CLASS = "class"; + public static final String JSON_SYMBOL = "symbol"; + public static final String JSON_NAME = "name"; + public static final String JSON_DESCRIPTION = "description"; + public static final String JSON_DECIMALS = "decimals"; + public static final int DECIMALS_DEFAULT = 2; + + public static void rename(World world, AbstractAsset a, String symbol) throws Exception { + if (world.assetsBySymbol.get(symbol) != null) { + throw new java.lang.Exception("Can't rename asset symbol. Symbol '" + symbol + "' is already in use."); + } + + world.assetsBySymbol.remove(a.getSymbol()); + a.symbol = symbol; + world.assetsBySymbol.put(a.getSymbol(), a); + + } + + public static AbstractAsset create(World world, Class cls, String symbol) throws Exception { + AbstractAsset a = cls.newInstance(); + + if (world.assetsBySymbol.get(symbol) != null) { + throw new java.lang.Exception("Can't create asset. Symbol '" + symbol + "' is already in use."); + } + + a.id = world.assetIdGenerator.getNext(); + a.symbol=symbol; + + + world.assetsById.put(a.id, a); + world.assetsBySymbol.put(a.getSymbol(), a); + + return a; + } + + public static AbstractAsset create(World world, JSONObject cfg){ + AbstractAsset a; + String class_name; + Class cls; + + String symbol; + try { + symbol = cfg.getString(JSON_SYMBOL); + class_name = cfg.getString(JSON_CLASS); + cls = Class.forName(class_name); + a = create(world,cls,symbol); + a.name = cfg.optString(JSON_NAME, symbol); + a.description = cfg.optString(JSON_DESCRIPTION); + a.decimals = cfg.optInt(JSON_DECIMALS); + + }catch (JSONException ex){ + return null; + } catch (ClassNotFoundException ex) { + Logger.getLogger(AbstractAsset.class.getName()).log(Level.SEVERE, null, ex); + return null; + } catch (Exception ex) { + Logger.getLogger(AbstractAsset.class.getName()).log(Level.SEVERE, null, ex); + } + return null; + } + + @Override + public JSONObject getConfig() { + JSONObject cfg = new JSONObject(); + cfg.put(AbstractAsset.JSON_ID,id.toString()); + cfg.put(AbstractAsset.JSON_CLASS, this.getClass().getName()); + cfg.put(AbstractAsset.JSON_SYMBOL, this.getSymbol()); + cfg.put(AbstractAsset.JSON_DECIMALS, this.getDecimals()); + cfg.put(AbstractAsset.JSON_NAME, this.getName()); + cfg.put(AbstractAsset.JSON_DESCRIPTION, this.getDescription()); + return cfg; + } + + @Override + public void putConfig(JSONObject cfg) { + symbol = cfg.optString(AbstractAsset.JSON_SYMBOL); + decimals = cfg.optInt(AbstractAsset.JSON_DECIMALS, AbstractAsset.DECIMALS_DEFAULT); + name = cfg.optString(AbstractAsset.JSON_NAME, ""); + description = cfg.optString(AbstractAsset.JSON_DESCRIPTION); + } + + public JPanel getEditGui(){ + return null; + } +} diff --git a/src/opensesim/Account.java b/src/opensesim/Account.java new file mode 100644 index 0000000..06167b8 --- /dev/null +++ b/src/opensesim/Account.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim; + +import opensesim.Exchange; +import java.util.concurrent.ConcurrentHashMap; +import opensesim.sesim.interfaces.Asset; +import opensesim.sesim.interfaces.Trader; + +/** + * Class to hold account data of traders + * @author 7u83 <7u83@mail.ru> + */ +public class Account { + ConcurrentHashMap assets; + + Trader owner; + + Account(Exchange exchange){ + assets = new ConcurrentHashMap<>(); + } + + + + +} diff --git a/src/opensesim/DefaultFeeModel.java b/src/opensesim/DefaultFeeModel.java new file mode 100644 index 0000000..7fce4d5 --- /dev/null +++ b/src/opensesim/DefaultFeeModel.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim; + +import opensesim.sesim.AssetPair; +import opensesim.sesim.interfaces.FeeModel; +import opensesim.util.AssetVol; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class DefaultFeeModel implements FeeModel{ + + + public AssetVol xgetTakerFee(AssetPair pair) { + double vol = 5; + return new AssetVol(pair.getCurrency(),vol); + + } + + @Override + public double getTakerFee(double x) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + +} diff --git a/src/opensesim/Exchange.java b/src/opensesim/Exchange.java new file mode 100644 index 0000000..7d2e97f --- /dev/null +++ b/src/opensesim/Exchange.java @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.SortedSet; +import java.util.TreeSet; +import opensesim.World; +import opensesim.sesim.AssetPair; +import opensesim.sesim.Order; +import opensesim.sesim.interfaces.Configurable; +import org.json.JSONObject; + +/** + * + * @author 7u83 + */ +public class Exchange implements Configurable{ + + private World world; + private String name; + private String symbol; + + public void setName(String name) { + this.name = name; + } + + //private final HashMap asset_pairs; + + private final HashMap asset_pairs; + + Exchange(World world, String symbol) { + asset_pairs = new HashMap<>(); + this.world = world; + this.symbol=symbol; + } + + private void reset() { + asset_pairs.clear(); + } + + public String getName() { + return name; + } + + public String getSymbol(){ + return symbol; + } + + Account createAccount() { + Account a = new Account(this); + return a; + } + + public Order createOrder(Account account, AssetPair pair, Order.Type type, double volume, double limit) { + + return null; + } + + public Collection getOrderBook(AssetPair a){ + TradingEnv e = asset_pairs.get(a); + SortedSet ob = e.order_books.get(Order.Type.BUYLIMIT); + return Collections.unmodifiableCollection(ob); + } + + @Override + public JSONObject getConfig() { + JSONObject cfg = new JSONObject(); + cfg.put("symbol", getSymbol()); + cfg.put("name", getName()); + return cfg; + + } + + @Override + public void putConfig(JSONObject cfg) { + + + } + + class TradingEnv { + + protected HashMap> order_books; + + TradingEnv() { + reset(); + } + + public final void reset() { + order_books = new HashMap(); + + // Create an order book for each order type + for (Order.Type type : Order.Type.values()) { + order_books.put(type, new TreeSet<>()); + } + + // quoteHistory = new TreeSet(); + // ohlc_data = new HashMap(); + } + + + + } + + + // public void add + +} diff --git a/src/opensesim/World.java b/src/opensesim/World.java new file mode 100644 index 0000000..8ebc5e1 --- /dev/null +++ b/src/opensesim/World.java @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import opensesim.sesim.AssetPair; +import opensesim.sesim.interfaces.Configurable; +import opensesim.util.IDGenerator; +import opensesim.util.IDGenerator.Id; +import opensesim.util.SeSimException; +import org.json.JSONArray; +import org.json.JSONObject; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class World implements Configurable { + + HashMap assetsById = new HashMap<>(); + HashMap assetsBySymbol = new HashMap<>(); + IDGenerator assetIdGenerator = new IDGenerator(); + + HashSet assetPairs = new HashSet<>(); + + ArrayList exchanges = new ArrayList<>(); + + /** + * Create a World object. + */ + public World() { + + } + + public Collection getAssetCollection() { + return Collections.unmodifiableCollection(assetsById.values()); + } + + public Collection getAssetPairsCollection() { + return Collections.unmodifiableCollection(assetPairs); + } + + public Collection getExchangeCollection() { + return Collections.unmodifiableCollection(exchanges); + } + + public void add(AssetPair pair) { + assetPairs.add(pair); + } + + public Exchange addExchange(String symbol) throws SeSimException { + for (Exchange ex : getExchangeCollection()) { + if (ex.getSymbol().equals(symbol)) { + throw (new SeSimException("Exchange already defined.")); + } + } + + Exchange ex = new Exchange(this, symbol); + exchanges.add(ex); + return ex; + } + + static final String JSON_ASSET = "asset"; + static final String JSON_EXCHANGES = "exchanges"; + + @Override + public JSONObject getConfig() { + JSONObject cfg = new JSONObject(); + + // save assets + JSONArray arr; + arr = new JSONArray(); + for (AbstractAsset a : getAssetCollection()) { + arr.put(a.getConfig()); + } + cfg.put(JSON_ASSET, arr); + + // save exchanges + arr = new JSONArray(); + for (Exchange ex : getExchangeCollection()) { + arr.put(ex.getConfig()); + } + cfg.put(JSON_EXCHANGES, arr); + + return cfg; + } + + @Override + public void putConfig(JSONObject cfg) { + JSONArray arr = cfg.optJSONArray(JSON_ASSET); + if (arr == null) { + arr = new JSONArray(); + } + for (Object o : arr) { + JSONObject acfg = (JSONObject) o; + AbstractAsset.create(this, acfg); + } + } + + public AbstractAsset createAsset(Class cls, String symbol) throws Exception { + return AbstractAsset.create(this, cls, symbol); + } + + /* + static public JSONArray toJson() { + + JSONArray all = new JSONArray(); + for (Map.Entry entry : assetsById.entrySet()) { + Id key = entry.getKey(); + Asset value = entry.getValue(); + all.put(value.getConfig()); + + } + + return all; + } + */ +} diff --git a/src/chart/Chart.form b/src/opensesim/chart/Chart.form similarity index 100% rename from src/chart/Chart.form rename to src/opensesim/chart/Chart.form diff --git a/src/chart/Chart.java b/src/opensesim/chart/Chart.java similarity index 98% rename from src/chart/Chart.java rename to src/opensesim/chart/Chart.java index e15ca6c..f240fae 100644 --- a/src/chart/Chart.java +++ b/src/opensesim/chart/Chart.java @@ -4,19 +4,19 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package chart; +package opensesim.chart; -import sesim.OHLCDataItem; -import sesim.OHLCData; +import opensesim.old_sesim.OHLCDataItem; +import opensesim.old_sesim.OHLCData; import java.awt.*; -import sesim.Exchange.*; -import sesim.Quote; -import gui.Globals; +import opensesim.old_sesim.Exchange.*; +import opensesim.old_sesim.Quote; +import opensesim.gui.Globals; import java.util.ArrayList; import javax.swing.JViewport; import javax.swing.Scrollable; -import sesim.MinMax; -import sesim.Scheduler; +import opensesim.old_sesim.MinMax; +import opensesim.old_sesim.Scheduler; diff --git a/src/chart/Help.form b/src/opensesim/chart/Help.form similarity index 80% rename from src/chart/Help.form rename to src/opensesim/chart/Help.form index 1dc7cc4..82ca670 100644 --- a/src/chart/Help.form +++ b/src/opensesim/chart/Help.form @@ -25,10 +25,10 @@ - - - - + + + + @@ -37,10 +37,10 @@ - - - - + + + + diff --git a/src/chart/Help.java b/src/opensesim/chart/Help.java similarity index 89% rename from src/chart/Help.java rename to src/opensesim/chart/Help.java index 9e07989..31fb560 100644 --- a/src/chart/Help.java +++ b/src/opensesim/chart/Help.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package chart; +package opensesim.chart; import java.net.URL; import java.util.Locale; import javax.help.*; @@ -71,19 +71,19 @@ public class Help extends javax.swing.JDialog { layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 400, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(jButton1) - .addGap(0, 0, Short.MAX_VALUE))) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap(153, Short.MAX_VALUE) + .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(124, Short.MAX_VALUE))) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 300, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(jButton1) - .addGap(0, 0, Short.MAX_VALUE))) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap(137, Short.MAX_VALUE) + .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(114, Short.MAX_VALUE))) ); pack(); diff --git a/src/chart/MChart.form b/src/opensesim/chart/MChart.form similarity index 100% rename from src/chart/MChart.form rename to src/opensesim/chart/MChart.form diff --git a/src/chart/MChart.java b/src/opensesim/chart/MChart.java similarity index 99% rename from src/chart/MChart.java rename to src/opensesim/chart/MChart.java index 66c920d..bdbd1de 100644 --- a/src/chart/MChart.java +++ b/src/opensesim/chart/MChart.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package chart; +package opensesim.chart; import javax.swing.JPanel; import javax.swing.border.Border; diff --git a/src/chart/MMChart.form b/src/opensesim/chart/MMChart.form similarity index 100% rename from src/chart/MMChart.form rename to src/opensesim/chart/MMChart.form diff --git a/src/chart/MMChart.java b/src/opensesim/chart/MMChart.java similarity index 94% rename from src/chart/MMChart.java rename to src/opensesim/chart/MMChart.java index 714c8d2..ef53299 100644 --- a/src/chart/MMChart.java +++ b/src/opensesim/chart/MMChart.java @@ -23,15 +23,15 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package chart; +package opensesim.chart; -import chart.painter.ChartCrossPainter; -import chart.painter.ChartPainter; -import chart.painter.OHLCChartPainter; -import chart.painter.XLegendDetail; -import chart.painter.XLegendPainter; -import chart.painter.YLegendPainter; -import gui.Globals; +import opensesim.chart.painter.ChartCrossPainter; +import opensesim.chart.painter.ChartPainter; +import opensesim.chart.painter.OHLCChartPainter; +import opensesim.chart.painter.XLegendDetail; +import opensesim.chart.painter.XLegendPainter; +import opensesim.chart.painter.YLegendPainter; +import opensesim.gui.Globals; import java.awt.Color; import java.awt.Cursor; import java.awt.Dimension; @@ -42,10 +42,10 @@ import java.awt.event.MouseListener; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.border.Border; -import sesim.ChartDef; -import sesim.ChartPanel; -import sesim.OHLCData; -import sesim.Stock; +import opensesim.old_sesim.ChartDef; +import opensesim.old_sesim.ChartPanel; +import opensesim.old_sesim.OHLCData; +import opensesim.old_sesim.Stock; /** * diff --git a/src/chart/MasterChart.form b/src/opensesim/chart/MasterChart.form similarity index 97% rename from src/chart/MasterChart.form rename to src/opensesim/chart/MasterChart.form index 67ff2fe..1196826 100644 --- a/src/chart/MasterChart.form +++ b/src/opensesim/chart/MasterChart.form @@ -68,7 +68,7 @@ - + @@ -96,7 +96,7 @@ - + @@ -111,7 +111,7 @@ - + @@ -142,4 +142,4 @@ - + \ No newline at end of file diff --git a/src/chart/MasterChart.java b/src/opensesim/chart/MasterChart.java similarity index 92% rename from src/chart/MasterChart.java rename to src/opensesim/chart/MasterChart.java index 855a874..3cee60f 100644 --- a/src/chart/MasterChart.java +++ b/src/opensesim/chart/MasterChart.java @@ -23,25 +23,25 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package chart; +package opensesim.chart; -import sesim.ChartDef; -import chart.painter.CandleStickChartPainter; -import chart.painter.ChartPainter; -import chart.painter.XLegendPainter; -import chart.painter.ChartCrossPainter; -import chart.painter.LineChartPainter; -import chart.painter.OHLCChartPainter; -import chart.painter.YLegendPainter; -import gui.Globals; +import opensesim.old_sesim.ChartDef; +import opensesim.chart.painter.CandleStickChartPainter; +import opensesim.chart.painter.ChartPainter; +import opensesim.chart.painter.XLegendPainter; +import opensesim.chart.painter.ChartCrossPainter; +import opensesim.chart.painter.LineChartPainter; +import opensesim.chart.painter.OHLCChartPainter; +import opensesim.chart.painter.YLegendPainter; +import opensesim.gui.Globals; import java.util.ArrayList; -import sesim.Exchange.QuoteReceiver; -import sesim.Indicator; -import sesim.MinMax; -import sesim.OHLCData; -import sesim.OHLCDataItem; -import sesim.Quote; -import indicators.SMAIndicator; +import opensesim.old_sesim.Exchange.QuoteReceiver; +import opensesim.old_sesim.Indicator; +import opensesim.old_sesim.MinMax; +import opensesim.old_sesim.OHLCData; +import opensesim.old_sesim.OHLCDataItem; +import opensesim.old_sesim.Quote; +import opensesim.indicators.SMAIndicator; import java.util.Objects; import javax.swing.ButtonGroup; import javax.swing.JRadioButtonMenuItem; @@ -170,7 +170,7 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver { chart.setXSCrollBar(xScrollBar); chart.addChartPainter(new ChartCrossPainter()); - sma1 = new indicators.SMAIndicator(); + sma1 = new opensesim.indicators.SMAIndicator(); sma1.setParent(mydata); JSONObject co; @@ -183,7 +183,7 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver { chart.addChartPainter(p); - sma2 = new indicators.SMAIndicator(); + sma2 = new opensesim.indicators.SMAIndicator(); sma2.setParent(mydata); co = new JSONObject("{\"len\": 20}"); sma2.putConfig(co); @@ -213,9 +213,9 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver { ctxMenu = new javax.swing.JPopupMenu(); jMenu1 = new javax.swing.JMenu(); jMenuItem1 = new javax.swing.JMenuItem(); - chart = new sesim.ChartPanel(); - yLegend = new sesim.ChartPanel(); - xLegend = new sesim.ChartPanel(); + chart = new opensesim.old_sesim.ChartPanel(); + yLegend = new opensesim.old_sesim.ChartPanel(); + xLegend = new opensesim.old_sesim.ChartPanel(); xScrollBar = new javax.swing.JScrollBar(); jMenu1.setText("jMenu1"); @@ -369,13 +369,13 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver { // Variables declaration - do not modify//GEN-BEGIN:variables - private sesim.ChartPanel chart; + private opensesim.old_sesim.ChartPanel chart; private javax.swing.JPopupMenu ctxMenu; private javax.swing.JMenu jMenu1; private javax.swing.JMenuItem jMenuItem1; - private sesim.ChartPanel xLegend; + private opensesim.old_sesim.ChartPanel xLegend; private javax.swing.JScrollBar xScrollBar; - private sesim.ChartPanel yLegend; + private opensesim.old_sesim.ChartPanel yLegend; // End of variables declaration//GEN-END:variables @Override diff --git a/src/chart/NewPanel.form b/src/opensesim/chart/NewPanel.form similarity index 100% rename from src/chart/NewPanel.form rename to src/opensesim/chart/NewPanel.form diff --git a/src/chart/NewPanel.java b/src/opensesim/chart/NewPanel.java similarity index 99% rename from src/chart/NewPanel.java rename to src/opensesim/chart/NewPanel.java index e03afae..d99210a 100644 --- a/src/chart/NewPanel.java +++ b/src/opensesim/chart/NewPanel.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package chart; +package opensesim.chart; /** * diff --git a/src/chart/SuperDlg.form b/src/opensesim/chart/SuperDlg.form similarity index 100% rename from src/chart/SuperDlg.form rename to src/opensesim/chart/SuperDlg.form diff --git a/src/chart/SuperDlg.java b/src/opensesim/chart/SuperDlg.java similarity index 97% rename from src/chart/SuperDlg.java rename to src/opensesim/chart/SuperDlg.java index ff5afc0..bf151b9 100644 --- a/src/chart/SuperDlg.java +++ b/src/opensesim/chart/SuperDlg.java @@ -23,7 +23,8 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package chart; +package opensesim.chart; +import opensesim.*; /** * @@ -49,7 +50,7 @@ public class SuperDlg extends javax.swing.JDialog { // //GEN-BEGIN:initComponents private void initComponents() { - masterChart1 = new chart.MasterChart(); + masterChart1 = new opensesim.chart.MasterChart(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); @@ -115,6 +116,6 @@ public class SuperDlg extends javax.swing.JDialog { } // Variables declaration - do not modify//GEN-BEGIN:variables - private chart.MasterChart masterChart1; + private opensesim.chart.MasterChart masterChart1; // End of variables declaration//GEN-END:variables } diff --git a/src/chart/painter/CandleStickChartPainter.java b/src/opensesim/chart/painter/CandleStickChartPainter.java similarity index 96% rename from src/chart/painter/CandleStickChartPainter.java rename to src/opensesim/chart/painter/CandleStickChartPainter.java index 956cece..2a73cb4 100644 --- a/src/chart/painter/CandleStickChartPainter.java +++ b/src/opensesim/chart/painter/CandleStickChartPainter.java @@ -23,13 +23,13 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package chart.painter; +package opensesim.chart.painter; import java.awt.Color; import java.awt.Graphics2D; import javax.swing.JScrollBar; -import sesim.OHLCData; -import sesim.OHLCDataItem; +import opensesim.old_sesim.OHLCData; +import opensesim.old_sesim.OHLCDataItem; /** * diff --git a/src/chart/painter/ChartCrossPainter.java b/src/opensesim/chart/painter/ChartCrossPainter.java similarity index 93% rename from src/chart/painter/ChartCrossPainter.java rename to src/opensesim/chart/painter/ChartCrossPainter.java index 793f5b9..87f79b7 100644 --- a/src/chart/painter/ChartCrossPainter.java +++ b/src/opensesim/chart/painter/ChartCrossPainter.java @@ -23,13 +23,13 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package chart.painter; +package opensesim.chart.painter; -import sesim.ChartDef; -import sesim.ChartPanel; +import opensesim.old_sesim.ChartDef; +import opensesim.old_sesim.ChartPanel; import java.awt.Graphics2D; import java.awt.Point; -import sesim.OHLCDataItem; +import opensesim.old_sesim.OHLCDataItem; /** diff --git a/src/chart/painter/ChartPainter.java b/src/opensesim/chart/painter/ChartPainter.java similarity index 90% rename from src/chart/painter/ChartPainter.java rename to src/opensesim/chart/painter/ChartPainter.java index abe2cf6..15fdf03 100644 --- a/src/chart/painter/ChartPainter.java +++ b/src/opensesim/chart/painter/ChartPainter.java @@ -23,15 +23,15 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package chart.painter; +package opensesim.chart.painter; -import sesim.ChartDef; -import sesim.ChartPanel; +import opensesim.old_sesim.ChartDef; +import opensesim.old_sesim.ChartPanel; import java.awt.Dimension; import java.awt.Graphics2D; -import sesim.ChartPainterInterface; -import sesim.MinMax; -import sesim.OHLCData; +import opensesim.old_sesim.ChartPainterInterface; +import opensesim.old_sesim.MinMax; +import opensesim.old_sesim.OHLCData; /** * diff --git a/src/chart/painter/LineChartPainter.java b/src/opensesim/chart/painter/LineChartPainter.java similarity index 96% rename from src/chart/painter/LineChartPainter.java rename to src/opensesim/chart/painter/LineChartPainter.java index c2aabad..53d766c 100644 --- a/src/chart/painter/LineChartPainter.java +++ b/src/opensesim/chart/painter/LineChartPainter.java @@ -23,11 +23,11 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package chart.painter; +package opensesim.chart.painter; import java.awt.Color; import java.awt.Graphics2D; -import sesim.OHLCDataItem; +import opensesim.old_sesim.OHLCDataItem; /** * diff --git a/src/chart/painter/OHLCChartPainter.java b/src/opensesim/chart/painter/OHLCChartPainter.java similarity index 96% rename from src/chart/painter/OHLCChartPainter.java rename to src/opensesim/chart/painter/OHLCChartPainter.java index 2ab5888..27b5d77 100644 --- a/src/chart/painter/OHLCChartPainter.java +++ b/src/opensesim/chart/painter/OHLCChartPainter.java @@ -23,18 +23,18 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package chart.painter; +package opensesim.chart.painter; -import sesim.ChartDef; -import sesim.ChartPanel; +import opensesim.old_sesim.ChartDef; +import opensesim.old_sesim.ChartPanel; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics2D; import javax.swing.JPanel; import javax.swing.JScrollBar; -import sesim.MinMax; -import sesim.OHLCData; -import sesim.OHLCDataItem; +import opensesim.old_sesim.MinMax; +import opensesim.old_sesim.OHLCData; +import opensesim.old_sesim.OHLCDataItem; /** * diff --git a/src/chart/painter/XLegendDetail.java b/src/opensesim/chart/painter/XLegendDetail.java similarity index 95% rename from src/chart/painter/XLegendDetail.java rename to src/opensesim/chart/painter/XLegendDetail.java index 1ace59e..8ed1ada 100644 --- a/src/chart/painter/XLegendDetail.java +++ b/src/opensesim/chart/painter/XLegendDetail.java @@ -23,14 +23,14 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package chart.painter; +package opensesim.chart.painter; import java.awt.Color; import java.awt.Graphics2D; import java.awt.Point; -import sesim.ChartDef; -import sesim.ChartPanel; -import sesim.Scheduler; +import opensesim.old_sesim.ChartDef; +import opensesim.old_sesim.ChartPanel; +import opensesim.old_sesim.Scheduler; /** * diff --git a/src/chart/painter/XLegendPainter.java b/src/opensesim/chart/painter/XLegendPainter.java similarity index 91% rename from src/chart/painter/XLegendPainter.java rename to src/opensesim/chart/painter/XLegendPainter.java index 7d38eee..8d35ed5 100644 --- a/src/chart/painter/XLegendPainter.java +++ b/src/opensesim/chart/painter/XLegendPainter.java @@ -23,14 +23,14 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package chart.painter; +package opensesim.chart.painter; -import sesim.ChartDef; -import sesim.ChartPanel; +import opensesim.old_sesim.ChartDef; +import opensesim.old_sesim.ChartPanel; import java.awt.Dimension; import java.awt.Graphics2D; -import sesim.OHLCData; -import sesim.OHLCDataItem; +import opensesim.old_sesim.OHLCData; +import opensesim.old_sesim.OHLCDataItem; /** * Paints an x-legend for OHLC charts @@ -42,7 +42,7 @@ public class XLegendPainter extends OHLCChartPainter { private String getTimeStrAt(OHLCData data, int unit) { int fs = data.getFrameSize(); - return sesim.Scheduler.formatTimeMillis(0 + (long) unit * (long) fs); + return opensesim.old_sesim.Scheduler.formatTimeMillis(0 + (long) unit * (long) fs); } diff --git a/src/chart/painter/YLegendPainter.java b/src/opensesim/chart/painter/YLegendPainter.java similarity index 95% rename from src/chart/painter/YLegendPainter.java rename to src/opensesim/chart/painter/YLegendPainter.java index 9bcbcb9..3a31269 100644 --- a/src/chart/painter/YLegendPainter.java +++ b/src/opensesim/chart/painter/YLegendPainter.java @@ -23,18 +23,18 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package chart.painter; +package opensesim.chart.painter; -import chart.Chart; +import opensesim.chart.Chart; import java.awt.Color; -import sesim.ChartDef; -import sesim.ChartPanel; +import opensesim.old_sesim.ChartDef; +import opensesim.old_sesim.ChartPanel; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.Rectangle; -import sesim.MinMax; -import sesim.OHLCData; -import sesim.OHLCDataItem; +import opensesim.old_sesim.MinMax; +import opensesim.old_sesim.OHLCData; +import opensesim.old_sesim.OHLCDataItem; /** * diff --git a/src/gui/AskBook.java b/src/opensesim/gui/AskBook.java similarity index 94% rename from src/gui/AskBook.java rename to src/opensesim/gui/AskBook.java index 71f36e1..279c73b 100644 --- a/src/gui/AskBook.java +++ b/src/opensesim/gui/AskBook.java @@ -23,11 +23,11 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui; import java.util.ArrayList; -import sesim.Order.OrderType; -import sesim.Order; +import opensesim.old_sesim.Order.OrderType; +import opensesim.old_sesim.Order; /** diff --git a/src/opensesim/gui/AssetEditor/AssetEditorDialog.form b/src/opensesim/gui/AssetEditor/AssetEditorDialog.form new file mode 100644 index 0000000..29eeabb --- /dev/null +++ b/src/opensesim/gui/AssetEditor/AssetEditorDialog.form @@ -0,0 +1,77 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/opensesim/gui/AssetEditor/AssetEditorDialog.java b/src/opensesim/gui/AssetEditor/AssetEditorDialog.java new file mode 100644 index 0000000..9606eb6 --- /dev/null +++ b/src/opensesim/gui/AssetEditor/AssetEditorDialog.java @@ -0,0 +1,284 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.gui.AssetEditor; + +import java.awt.Dialog; + +import javax.swing.InputVerifier; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JTextField; +import opensesim.AbstractAsset; +import opensesim.World; +import opensesim.gui.EscDialog; +import opensesim.gui.Globals; +import opensesim.sesim.Assets.BasicAsset; +import opensesim.util.IDGenerator.Id; +import org.json.JSONException; +import org.json.JSONObject; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class AssetEditorDialog extends EscDialog { + + AbstractAsset asset; + World world; + + /** + * Creates new form CreateAssetDialog + */ + public AssetEditorDialog(Dialog parent, AbstractAsset asset) { + super(parent, true); + initComponents(); + world = Globals.world; + } + + /** + * 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. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + cancelButton = new javax.swing.JButton(); + okButton = new javax.swing.JButton(); + assetEditorPanel = new opensesim.gui.AssetEditor.AssetEditorPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setModal(true); + + cancelButton.setText("Cancel"); + cancelButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + cancelButtonActionPerformed(evt); + } + }); + + okButton.setText("Ok"); + okButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + okButtonActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(okButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cancelButton)) + .addComponent(assetEditorPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 527, Short.MAX_VALUE)) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(assetEditorPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(cancelButton) + .addComponent(okButton)) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents + + private Id newId = null; + + public Id getCreatedId() { + return newId; + } + + private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed + + if (this.asset == null) { + try { + int selected = this.assetEditorPanel.assetTypesComboBox.getSelectedIndex(); + Class cls = (Class) this.assetEditorPanel.asset_types.get(selected); + asset = AbstractAsset.create(world, cls, assetEditorPanel.symField.getText()); + + + //new BasicAsset(assetEditor.symField.getText()); + // newId = BasicAsset.newAssed(asset); + } catch (Exception ex) { + javax.swing.JOptionPane.showMessageDialog(this, ex.getMessage(), + "Error", + javax.swing.JOptionPane.ERROR_MESSAGE); + return; + } + } + + /*else { + if (!this.asset.getSymbol().equals(assetEditor.symField.getText())) { + try { + BasicAsset.rename(asset, assetEditor.symField.getText()); + + } catch (Exception ex) { + javax.swing.JOptionPane.showMessageDialog(this, ex.getMessage(), + "Error", + javax.swing.JOptionPane.ERROR_MESSAGE); + return; + } + } else { + } + + }*/ + asset.setName(assetEditorPanel.nameField.getText()); + asset.setDecimals((int) assetEditorPanel.decimalsField.getValue()); + + JSONObject cfg = world.getConfig(); + + try { + String jstr = cfg.toString(5); + } catch (JSONException ex) { + System.out.println(ex.getMessage()); + } + System.out.printf("JSONARRAY %s\n", cfg.toString(3)); + JSONObject world_cfg = Globals.world.getConfig(); + Globals.prefs.put("world", world_cfg.toString()); + dispose(); + + }//GEN-LAST:event_okButtonActionPerformed + + private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed + // TODO add your handling code here: + dispose(); + + }//GEN-LAST:event_cancelButtonActionPerformed + + static public Id runDialog(Dialog parent, AbstractAsset asset) { + AssetEditorDialog dialog = new AssetEditorDialog(parent, asset); + dialog.assetEditorPanel.initFields(asset); + + dialog.assetEditorPanel.dialog = dialog; + dialog.setLocationRelativeTo(parent); + dialog.setVisible(true); + + return dialog.newId; + } + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(AssetEditorDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(AssetEditorDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(AssetEditorDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(AssetEditorDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the dialog */ + /* java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + CreateAssetDialog dialog = new CreateAssetDialog(new javax.swing.JFrame(), true); + dialog.addWindowListener(new java.awt.event.WindowAdapter() { + @Override + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + }); + dialog.setVisible(true); + } + //
+ + /* Create and display the dialog */ + /* java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + CreateAssetDialog dialog = new CreateAssetDialog(new javax.swing.JFrame(), true); + dialog.addWindowListener(new java.awt.event.WindowAdapter() { + @Override + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + }); + dialog.setVisible(true); + } + // + + /* Create and display the dialog */ + /* java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + CreateAssetDialog dialog = new CreateAssetDialog(new javax.swing.JFrame(), true); + dialog.addWindowListener(new java.awt.event.WindowAdapter() { + @Override + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + }); + dialog.setVisible(true); + } + // + + /* Create and display the dialog */ + /* java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + CreateAssetDialog dialog = new CreateAssetDialog(new javax.swing.JFrame(), true); + dialog.addWindowListener(new java.awt.event.WindowAdapter() { + @Override + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + }); + dialog.setVisible(true); + } + });*/ + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private opensesim.gui.AssetEditor.AssetEditorPanel assetEditorPanel; + private javax.swing.JButton cancelButton; + private javax.swing.JButton okButton; + // End of variables declaration//GEN-END:variables +} diff --git a/src/opensesim/gui/AssetEditor/AssetEditorPanel.form b/src/opensesim/gui/AssetEditor/AssetEditorPanel.form new file mode 100644 index 0000000..5cd0cc4 --- /dev/null +++ b/src/opensesim/gui/AssetEditor/AssetEditorPanel.form @@ -0,0 +1,186 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/opensesim/gui/AssetEditor/AssetEditorPanel.java b/src/opensesim/gui/AssetEditor/AssetEditorPanel.java new file mode 100644 index 0000000..38726e6 --- /dev/null +++ b/src/opensesim/gui/AssetEditor/AssetEditorPanel.java @@ -0,0 +1,292 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.gui.AssetEditor; + +import java.awt.Dialog; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.util.ArrayList; +import java.util.Vector; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.ComboBoxModel; +import javax.swing.DefaultComboBoxModel; +import javax.swing.JDialog; +import javax.swing.JPanel; +import opensesim.AbstractAsset; +import opensesim.gui.Globals; +import opensesim.sesim.interfaces.Asset; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class AssetEditorPanel extends javax.swing.JPanel { + + /** + * Creates new form AssetEditor + */ + public AssetEditorPanel() { + super(); + asset_types = Globals.getAvailableAssetsTypes(); + initComponents(); + symField.setLimit(Globals.MAX.SYMLEN); + nameField.setLimit(Globals.MAX.NAMELEN); + + } + + + void initFields(AbstractAsset asset){ + if(asset==null) + return; + + symField.setText(asset.getSymbol()); + nameField.setText(asset.getName()); + } + + + + + public JDialog dialog; + + ArrayList> asset_types; + + ComboBoxModel getComboBoxModel() { + ArrayList vector = new ArrayList(); + + // in case asset types are not initialized return a demo + // combo box, so it will be displaeyd in NetBens designer + if (asset_types == null) { + vector.add(0, "Currency"); + vector.add(1, "Stock"); + + return new DefaultComboBoxModel(vector.toArray()); + } + + int i; + + for (i = 0; i < asset_types.size(); i++) { + AbstractAsset ait; + Class asset_type = asset_types.get(i); + try { + + ait = (AbstractAsset) asset_type.newInstance(); + vector.add(i, ait.getTypeName()); + // assetTypesComboBox.addItem(ait.getTypeName()); + + } catch (InstantiationException | IllegalAccessException | ClassCastException ex) { + Logger.getLogger(AssetEditorPanel.class.getName()).log(Level.SEVERE, null, ex); + } + + } + + return new DefaultComboBoxModel(vector.toArray()); + } + + /** + * 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. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jLabel1 = new javax.swing.JLabel(); + assetTypesComboBox = new javax.swing.JComboBox<>(); + jLabel2 = new javax.swing.JLabel(); + symField = new opensesim.gui.util.JTextFieldLimit(); + jLabel3 = new javax.swing.JLabel(); + nameField = new opensesim.gui.util.JTextFieldLimit(); + jLabel4 = new javax.swing.JLabel(); + decimalsField = new javax.swing.JSpinner(); + guiPanel = new javax.swing.JPanel(); + defaultGuiPanel = new javax.swing.JPanel(); + label = new javax.swing.JLabel(); + + jLabel1.setText("Symbol:"); + + assetTypesComboBox.setModel(getComboBoxModel()); + assetTypesComboBox.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + assetTypesComboBoxActionPerformed(evt); + } + }); + + jLabel2.setText("Type:"); + + jLabel3.setText("Name:"); + + jLabel4.setText("Decimals:"); + + decimalsField.setModel(new javax.swing.SpinnerNumberModel(0, 0, 8, 1)); + + guiPanel.setLayout(new java.awt.BorderLayout()); + + defaultGuiPanel.setMinimumSize(new java.awt.Dimension(360, 25)); + + label.setText("no config"); + + javax.swing.GroupLayout defaultGuiPanelLayout = new javax.swing.GroupLayout(defaultGuiPanel); + defaultGuiPanel.setLayout(defaultGuiPanelLayout); + defaultGuiPanelLayout.setHorizontalGroup( + defaultGuiPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 360, Short.MAX_VALUE) + .addGroup(defaultGuiPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(defaultGuiPanelLayout.createSequentialGroup() + .addGap(0, 148, Short.MAX_VALUE) + .addComponent(label) + .addGap(0, 149, Short.MAX_VALUE))) + ); + defaultGuiPanelLayout.setVerticalGroup( + defaultGuiPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 25, Short.MAX_VALUE) + .addGroup(defaultGuiPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(defaultGuiPanelLayout.createSequentialGroup() + .addGap(0, 5, Short.MAX_VALUE) + .addComponent(label) + .addGap(0, 5, Short.MAX_VALUE))) + ); + + guiPanel.add(defaultGuiPanel, java.awt.BorderLayout.CENTER); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(guiPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE)) + .addGap(12, 12, 12) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(symField, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jLabel2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(assetTypesComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(nameField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(decimalsField, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(0, 0, Short.MAX_VALUE))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(assetTypesComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel1) + .addComponent(symField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(nameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel3)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel4) + .addComponent(decimalsField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(guiPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addContainerGap()) + ); + }// //GEN-END:initComponents + + private void assetTypesComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_assetTypesComboBoxActionPerformed + + int i = this.assetTypesComboBox.getSelectedIndex(); + AbstractAsset a; + try { + a = (AbstractAsset) asset_types.get(i).newInstance(); + } catch (InstantiationException | IllegalAccessException ex) { + Logger.getLogger(AssetEditorPanel.class.getName()).log(Level.SEVERE, null, ex); + return; + } + + JPanel gui = a.getEditGui(); + + guiPanel.removeAll(); + if (gui != null) { + + guiPanel.add(gui, java.awt.BorderLayout.CENTER); + gui.setVisible(true); + + } else { + guiPanel.add(defaultGuiPanel, java.awt.BorderLayout.CENTER); + } + + //dialog.setPreferredSize(new Dimension(200,200)); + + dialog.pack(); + dialog.revalidate(); + + + // dialog.validate(); + + //validate(); + //this.getParent().getW; + //((Dialog)(this.dialog)).getS + + +/* this.getParent().validate(); + this.getParent().repaint(); + (this.getParent().getParent()).repaint(); + this.dialog.pack(); + this.dialog.validate(); + this.dialog.repaint(); + Dimension rrr = this.dialog.getContentPane().getSize(); + this.dialog.resize(rrr); + */ + + // dialog.pack(); + System.out.printf("Action performed on combobox %d %s\n", i, a.getTypeName()); + + }//GEN-LAST:event_assetTypesComboBoxActionPerformed + + + // Variables declaration - do not modify//GEN-BEGIN:variables + public javax.swing.JComboBox assetTypesComboBox; + public javax.swing.JSpinner decimalsField; + private javax.swing.JPanel defaultGuiPanel; + private javax.swing.JPanel guiPanel; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; + private javax.swing.JLabel label; + protected opensesim.gui.util.JTextFieldLimit nameField; + protected opensesim.gui.util.JTextFieldLimit symField; + // End of variables declaration//GEN-END:variables +} diff --git a/src/opensesim/gui/AssetEditor/AssetListDialog.form b/src/opensesim/gui/AssetEditor/AssetListDialog.form new file mode 100644 index 0000000..0e29690 --- /dev/null +++ b/src/opensesim/gui/AssetEditor/AssetListDialog.form @@ -0,0 +1,100 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/opensesim/gui/AssetEditor/AssetListDialog.java b/src/opensesim/gui/AssetEditor/AssetListDialog.java new file mode 100644 index 0000000..c217fc1 --- /dev/null +++ b/src/opensesim/gui/AssetEditor/AssetListDialog.java @@ -0,0 +1,247 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.gui.AssetEditor; + +import com.sun.rowset.internal.Row; +import java.awt.Frame; +import java.awt.Window; +import javax.swing.JFrame; +import javax.swing.SwingUtilities; +import opensesim.gui.EscDialog; +import opensesim.sesim.Assets.BasicAsset; +import opensesim.util.IDGenerator.Id; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class AssetListDialog extends EscDialog { + + /** + * Creates new form EditAssetsDialog + */ + public AssetListDialog(java.awt.Frame parent, boolean modal) { + super(parent, modal); + initComponents(); + } + + /** + * 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. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jButton1 = new javax.swing.JButton(); + newButton = new javax.swing.JButton(); + jButton3 = new javax.swing.JButton(); + editButton = new javax.swing.JButton(); + assetListPanel1 = new opensesim.gui.AssetEditor.AssetListPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setTitle("Edit Assets"); + setModal(true); + + jButton1.setText("Done"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + newButton.setText("New ..."); + newButton.setToolTipText("Creates a new Asset"); + newButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + newButtonActionPerformed(evt); + } + }); + + jButton3.setText("Delete"); + + editButton.setText("Edit ..."); + editButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + editButtonActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(0, 250, Short.MAX_VALUE) + .addComponent(jButton3) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(editButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(newButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jButton1)) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(assetListPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(assetListPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 282, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(newButton) + .addComponent(jButton1) + .addComponent(jButton3) + .addComponent(editButton)) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents + + private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newButtonActionPerformed + + AssetEditorDialog.runDialog(this, null); + this.assetListPanel1.reload(); + /* javax.swing.JOptionPane.showMessageDialog(this, "Hello", "Error", + javax.swing.JOptionPane.ERROR_MESSAGE);*/ + /* Id id = AssteEditorDialog.runDialog(this, null); + if (id != null) { + assetList1.addAsset(id); + } + */ this.repaint(); + // JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(this); + + /* + // CreateAssetDialog dlg = new CreateAssetDialog(); + CreateAssetDialog.runDialog(this); + + javax.swing.JOptionPane.showMessageDialog(this, "Hello", "Error", + javax.swing.JOptionPane.ERROR_MESSAGE); + + frame = (JFrame) SwingUtilities.getAncestorOfClass(Frame.class, this); + dialog = new CreateAssetDialog(frame, false); + dialog.setModal(true); + this.setModal(true); + this.setModalityType(ModalityType.DOCUMENT_MODAL); + // addPropertyChangeListener(new ValuePropertyHandler(dialog)); + +//dialog.setAlwaysOnTop(true); +//this.setVisible(false); + dialog.setLocationRelativeTo(this); + dialog.setModalityType(ModalityType.DOCUMENT_MODAL); + dialog.setModal(true); + // dialog.setVisible(true); + dialog.show(); + + Id id = dialog.getCreatedId(); + this.setModal(true); + this.setVisible(true); + + dialog.dispose(); + if (id != null) { + assetList1.addAsset(id); + } + this.repaint(); + */ + }//GEN-LAST:event_newButtonActionPerformed + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + dispose(); + }//GEN-LAST:event_jButton1ActionPerformed + + private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editButtonActionPerformed + +// int row = assetList1.assetList.getSelectedRow(); +// Id selId = (Id)assetList1.assetList.getValueAt(row, 0); +/* + BasicAsset a = BasicAsset.getAsset(selId); + Id id = AssteEditorDialog.runDialog(this, a); + if (id != null) { + // assetList1.addAsset(id); + } + this.assetList1.reload(); + this.repaint(); + */ + }//GEN-LAST:event_editButtonActionPerformed + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(AssetListDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(AssetListDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(AssetListDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(AssetListDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + // + + /* Create and display the dialog */ + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + AssetListDialog dialog = new AssetListDialog(new javax.swing.JFrame(), true); + dialog.addWindowListener(new java.awt.event.WindowAdapter() { + @Override + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + }); + dialog.setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private opensesim.gui.AssetEditor.AssetListPanel assetListPanel1; + private javax.swing.JButton editButton; + private javax.swing.JButton jButton1; + private javax.swing.JButton jButton3; + private javax.swing.JButton newButton; + // End of variables declaration//GEN-END:variables +} diff --git a/src/opensesim/gui/AssetEditor/AssetListPanel.form b/src/opensesim/gui/AssetEditor/AssetListPanel.form new file mode 100644 index 0000000..0235079 --- /dev/null +++ b/src/opensesim/gui/AssetEditor/AssetListPanel.form @@ -0,0 +1,58 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/opensesim/gui/AssetEditor/AssetListPanel.java b/src/opensesim/gui/AssetEditor/AssetListPanel.java new file mode 100644 index 0000000..194841d --- /dev/null +++ b/src/opensesim/gui/AssetEditor/AssetListPanel.java @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.gui.AssetEditor; + +import java.util.AbstractMap; +import java.util.Map; +import javax.swing.table.AbstractTableModel; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableModel; +import opensesim.AbstractAsset; +import opensesim.sesim.Assets.BasicAsset; +import opensesim.World; +import opensesim.gui.Globals; +import opensesim.util.IDGenerator.Id; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class AssetListPanel extends javax.swing.JPanel { + + World world; + + /** + * Creates new form AssetList + */ + public AssetListPanel() { + world = Globals.world; + initComponents(); + reload(); + + assetList.setRowSelectionAllowed(true); + assetList.getColumnModel().getColumn(0).setPreferredWidth(10); + assetList.getColumnModel().getColumn(1).setPreferredWidth(30); + assetList.getColumnModel().getColumn(2).setPreferredWidth(300); + assetList.getColumnModel().getColumn(3).setPreferredWidth(30); + } + + final void reload() { + DefaultTableModel m = (DefaultTableModel) assetList.getModel(); + /* m.setRowCount(0); + Map assets = BasicAsset.getAssets(); + for (Object key : assets.keySet()) { + addAsset((Id) key); + } + m.fireTableDataChanged(); + */ + if (world == null) { + return; + } + m.setRowCount(0); + for (AbstractAsset a : world.getAssetCollection()) { + m.addRow(new Object[]{ + a.getID(), + a.getSymbol(), + a.getName(), + a.getTypeName() + }); + + } + + } + + public TableModel getModel() { + + class TModel extends DefaultTableModel { + + private TModel(Object[] object, int i) { + super(object, i); + } + + @Override + public boolean isCellEditable(int row, int column) { + //all cells false + return false; + } + } + + DefaultTableModel model = new TModel( + new Object[]{"ID", "Symbol", "Name", "Type"}, 0 + ); + + assetList.setAutoCreateRowSorter(true); + assetList.getTableHeader().setReorderingAllowed(false); + return model; + + } + + public void uppdate() { + DefaultTableModel m; + + m = (DefaultTableModel) this.assetList.getModel(); + m.fireTableDataChanged(); + + } + + /* public void addAsset(Id id) { + + BasicAsset a = (BasicAsset) BasicAsset.getAsset(id); + DefaultTableModel m = (DefaultTableModel) this.assetList.getModel(); + m.addRow(new Object[]{ + a.getID(), + a.getSymbol(), + a.getName()}); + } + */ + /** + * 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. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jScrollPane1 = new javax.swing.JScrollPane(); + assetList = new javax.swing.JTable(); + + assetList.setModel(getModel()); + assetList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); + jScrollPane1.setViewportView(assetList); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 548, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 362, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 362, Short.MAX_VALUE)) + ); + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + public javax.swing.JTable assetList; + private javax.swing.JScrollPane jScrollPane1; + // End of variables declaration//GEN-END:variables +} diff --git a/src/opensesim/gui/AssetEditor/NewJPanel.form b/src/opensesim/gui/AssetEditor/NewJPanel.form new file mode 100644 index 0000000..5bb455b --- /dev/null +++ b/src/opensesim/gui/AssetEditor/NewJPanel.form @@ -0,0 +1,47 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/src/opensesim/gui/AssetEditor/NewJPanel.java b/src/opensesim/gui/AssetEditor/NewJPanel.java new file mode 100644 index 0000000..be7ee9d --- /dev/null +++ b/src/opensesim/gui/AssetEditor/NewJPanel.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.gui.AssetEditor; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class NewJPanel extends javax.swing.JPanel { + + /** + * Creates new form NewJPanel + */ + public NewJPanel() { + initComponents(); + } + + /** + * 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. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jTextFieldLimit1 = new opensesim.gui.util.JTextFieldLimit(); + + jTextFieldLimit1.setText("jTextFieldLimit1"); + jTextFieldLimit1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jTextFieldLimit1ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jTextFieldLimit1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(532, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jTextFieldLimit1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(353, Short.MAX_VALUE)) + ); + }// //GEN-END:initComponents + + private void jTextFieldLimit1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldLimit1ActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_jTextFieldLimit1ActionPerformed + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private opensesim.gui.util.JTextFieldLimit jTextFieldLimit1; + // End of variables declaration//GEN-END:variables +} diff --git a/src/opensesim/gui/AssetPairEditor/EditAssetPairPanel.form b/src/opensesim/gui/AssetPairEditor/EditAssetPairPanel.form new file mode 100644 index 0000000..d82cb65 --- /dev/null +++ b/src/opensesim/gui/AssetPairEditor/EditAssetPairPanel.form @@ -0,0 +1,94 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/opensesim/gui/AssetPairEditor/EditAssetPairPanel.java b/src/opensesim/gui/AssetPairEditor/EditAssetPairPanel.java new file mode 100644 index 0000000..fc8c4fb --- /dev/null +++ b/src/opensesim/gui/AssetPairEditor/EditAssetPairPanel.java @@ -0,0 +1,125 @@ +package opensesim.gui.AssetPairEditor; + +import java.util.Collection; +import opensesim.AbstractAsset; +import opensesim.World; +import opensesim.gui.Globals; + +/* + * Copyright (c) 2018, tohe + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * + * @author tohe + */ +public class EditAssetPairPanel extends javax.swing.JPanel { + + World world; + /** + * Creates new form EditAssetPairPanel + */ + public EditAssetPairPanel() { + world = Globals.world; + initComponents(); + if (world == null) + return; + + assetBox.removeAllItems(); + currencyBox.removeAllItems(); + + Collection ac = world.getAssetCollection(); + for (AbstractAsset asset: ac ){ + if (asset.isCurrency()){ + this.currencyBox.addItem(asset.getSymbol()); + } + if (asset.isAsset()){ + this.assetBox.addItem(asset.getSymbol()); + } + + } + } + + /** + * 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. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jLabel1 = new javax.swing.JLabel(); + currencyBox = new javax.swing.JComboBox<>(); + jLabel2 = new javax.swing.JLabel(); + assetBox = new javax.swing.JComboBox<>(); + + jLabel1.setText("Currency:"); + + currencyBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); + + jLabel2.setText("Asset:"); + + assetBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(assetBox, 0, 376, Short.MAX_VALUE) + .addComponent(currencyBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel1) + .addComponent(jLabel2)) + .addGap(0, 0, Short.MAX_VALUE))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(currencyBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jLabel2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(assetBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JComboBox assetBox; + private javax.swing.JComboBox currencyBox; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + // End of variables declaration//GEN-END:variables +} diff --git a/src/opensesim/gui/AssetPairEditor/NewJDialog.form b/src/opensesim/gui/AssetPairEditor/NewJDialog.form new file mode 100644 index 0000000..bcf12bc --- /dev/null +++ b/src/opensesim/gui/AssetPairEditor/NewJDialog.form @@ -0,0 +1,67 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/opensesim/gui/AssetPairEditor/NewJDialog.java b/src/opensesim/gui/AssetPairEditor/NewJDialog.java new file mode 100644 index 0000000..76c66a2 --- /dev/null +++ b/src/opensesim/gui/AssetPairEditor/NewJDialog.java @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2018, tohe + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.gui.AssetPairEditor; + +import opensesim.World; +import opensesim.gui.EscDialog; +import opensesim.gui.Globals; + +/** + * + * @author tohe + */ +public class NewJDialog extends EscDialog /*javax.swing.JDialog*/ { + World world; + + /** + * Creates new form NewJDialog + */ + public NewJDialog(java.awt.Frame parent, boolean modal) { + super(parent, modal); + world = Globals.world; + initComponents(); + } + + /** + * 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. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jButton1 = new javax.swing.JButton(); + editAssetPairPanel2 = new opensesim.gui.AssetPairEditor.EditAssetPairPanel(); + jButton2 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + + jButton1.setText("Add"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + jButton2.setText("Cancel"); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jButton1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jButton2) + .addContainerGap()) + .addComponent(editAssetPairPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(editAssetPairPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jButton1) + .addComponent(jButton2)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + dispose(); + }//GEN-LAST:event_jButton1ActionPerformed + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(NewJDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(NewJDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(NewJDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(NewJDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the dialog */ + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + NewJDialog dialog = new NewJDialog(new javax.swing.JFrame(), true); + dialog.addWindowListener(new java.awt.event.WindowAdapter() { + @Override + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + }); + dialog.setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private opensesim.gui.AssetPairEditor.EditAssetPairPanel editAssetPairPanel2; + private javax.swing.JButton jButton1; + private javax.swing.JButton jButton2; + // End of variables declaration//GEN-END:variables +} diff --git a/src/gui/BidBook.java b/src/opensesim/gui/BidBook.java similarity index 94% rename from src/gui/BidBook.java rename to src/opensesim/gui/BidBook.java index 3ced6fa..a733ff5 100644 --- a/src/gui/BidBook.java +++ b/src/opensesim/gui/BidBook.java @@ -23,12 +23,12 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui; import java.util.ArrayList; -import sesim.Order; -import sesim.Order.OrderType; +import opensesim.old_sesim.Order; +import opensesim.old_sesim.Order.OrderType; /** * diff --git a/src/gui/Clock.form b/src/opensesim/gui/Clock.form similarity index 100% rename from src/gui/Clock.form rename to src/opensesim/gui/Clock.form diff --git a/src/gui/Clock.java b/src/opensesim/gui/Clock.java similarity index 95% rename from src/gui/Clock.java rename to src/opensesim/gui/Clock.java index b28c920..ac41503 100644 --- a/src/gui/Clock.java +++ b/src/opensesim/gui/Clock.java @@ -23,12 +23,12 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui; import java.util.Timer; import java.util.TimerTask; -import sesim.Exchange.Statistics; -import sesim.Scheduler; +import opensesim.old_sesim.Exchange.Statistics; +import opensesim.old_sesim.Scheduler; /** * @@ -40,7 +40,7 @@ public class Clock extends javax.swing.JPanel { TimerTask clockUpdater; - class ClockUpdater implements sesim.Scheduler.TimerTaskRunner{ + class ClockUpdater implements opensesim.old_sesim.Scheduler.TimerTaskRunner{ @Override public long timerTask() { diff --git a/src/gui/ClockDialog.form b/src/opensesim/gui/ClockDialog.form similarity index 100% rename from src/gui/ClockDialog.form rename to src/opensesim/gui/ClockDialog.form diff --git a/src/gui/ClockDialog.java b/src/opensesim/gui/ClockDialog.java similarity index 98% rename from src/gui/ClockDialog.java rename to src/opensesim/gui/ClockDialog.java index bca8f65..bc8c0bf 100644 --- a/src/gui/ClockDialog.java +++ b/src/opensesim/gui/ClockDialog.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui; /** * @@ -49,7 +49,7 @@ public class ClockDialog extends javax.swing.JDialog { // //GEN-BEGIN:initComponents private void initComponents() { - clock1 = new gui.Clock(); + clock1 = new opensesim.gui.Clock(); jButton1 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); @@ -138,7 +138,7 @@ public class ClockDialog extends javax.swing.JDialog { } // Variables declaration - do not modify//GEN-BEGIN:variables - private gui.Clock clock1; + private opensesim.gui.Clock clock1; private javax.swing.JButton jButton1; // End of variables declaration//GEN-END:variables } diff --git a/src/gui/EditAutoTraderList.form b/src/opensesim/gui/EditAutoTraderList.form similarity index 100% rename from src/gui/EditAutoTraderList.form rename to src/opensesim/gui/EditAutoTraderList.form diff --git a/src/gui/EditAutoTraderList.java b/src/opensesim/gui/EditAutoTraderList.java similarity index 99% rename from src/gui/EditAutoTraderList.java rename to src/opensesim/gui/EditAutoTraderList.java index 4c787bb..dc7fe6a 100644 --- a/src/gui/EditAutoTraderList.java +++ b/src/opensesim/gui/EditAutoTraderList.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui; import java.io.IOException; import java.util.ArrayList; diff --git a/src/gui/EditAutoTraderListDialog.form b/src/opensesim/gui/EditAutoTraderListDialog.form similarity index 100% rename from src/gui/EditAutoTraderListDialog.form rename to src/opensesim/gui/EditAutoTraderListDialog.form diff --git a/src/gui/EditAutoTraderListDialog.java b/src/opensesim/gui/EditAutoTraderListDialog.java similarity index 98% rename from src/gui/EditAutoTraderListDialog.java rename to src/opensesim/gui/EditAutoTraderListDialog.java index 5f420b0..bf1b81c 100644 --- a/src/gui/EditAutoTraderListDialog.java +++ b/src/opensesim/gui/EditAutoTraderListDialog.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui; /** * @@ -55,7 +55,7 @@ public class EditAutoTraderListDialog extends javax.swing.JDialog { jButton1 = new javax.swing.JButton(); jOkButton = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); - editAutoTraderList1 = new gui.EditAutoTraderList(); + editAutoTraderList1 = new opensesim.gui.EditAutoTraderList(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); @@ -173,7 +173,7 @@ public class EditAutoTraderListDialog extends javax.swing.JDialog { } // Variables declaration - do not modify//GEN-BEGIN:variables - private gui.EditAutoTraderList editAutoTraderList1; + private opensesim.gui.EditAutoTraderList editAutoTraderList1; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jOkButton; diff --git a/src/gui/EditExchangeDialog.form b/src/opensesim/gui/EditExchangeDialog.form similarity index 100% rename from src/gui/EditExchangeDialog.form rename to src/opensesim/gui/EditExchangeDialog.form diff --git a/src/gui/EditExchangeDialog.java b/src/opensesim/gui/EditExchangeDialog.java similarity index 99% rename from src/gui/EditExchangeDialog.java rename to src/opensesim/gui/EditExchangeDialog.java index 3dbf45f..faa22cd 100644 --- a/src/gui/EditExchangeDialog.java +++ b/src/opensesim/gui/EditExchangeDialog.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui; import org.json.JSONObject; diff --git a/src/gui/EditStrategies.form b/src/opensesim/gui/EditStrategies.form similarity index 100% rename from src/gui/EditStrategies.form rename to src/opensesim/gui/EditStrategies.form diff --git a/src/gui/EditStrategies.java b/src/opensesim/gui/EditStrategies.java similarity index 99% rename from src/gui/EditStrategies.java rename to src/opensesim/gui/EditStrategies.java index 9022840..8975604 100644 --- a/src/gui/EditStrategies.java +++ b/src/opensesim/gui/EditStrategies.java @@ -23,9 +23,9 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui; -import static gui.Globals.LOGGER; +import static opensesim.gui.Globals.LOGGER; import java.awt.Frame; import java.util.ArrayList; import java.util.HashMap; @@ -36,8 +36,8 @@ import java.util.logging.Logger; import javax.swing.JPanel; import org.json.JSONArray; import org.json.JSONObject; -import sesim.AutoTraderGui; -import sesim.AutoTraderInterface; +import opensesim.old_sesim.AutoTraderGui; +import opensesim.old_sesim.AutoTraderInterface; /** * diff --git a/src/gui/EscDialog.form b/src/opensesim/gui/EscDialog.form similarity index 91% rename from src/gui/EscDialog.form rename to src/opensesim/gui/EscDialog.form index fcd4ff1..05d9eba 100644 --- a/src/gui/EscDialog.form +++ b/src/opensesim/gui/EscDialog.form @@ -8,9 +8,6 @@ - - - diff --git a/src/gui/EscDialog.java b/src/opensesim/gui/EscDialog.java similarity index 81% rename from src/gui/EscDialog.java rename to src/opensesim/gui/EscDialog.java index 64ba93f..831d3a9 100644 --- a/src/gui/EscDialog.java +++ b/src/opensesim/gui/EscDialog.java @@ -23,7 +23,15 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui; + +import java.awt.Dialog; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.awt.event.WindowEvent; +import javax.swing.JComponent; +import javax.swing.KeyStroke; /** * @@ -31,21 +39,38 @@ package gui; */ public class EscDialog extends javax.swing.JDialog { - /** - * Creates new form EscDialog - */ - public EscDialog(java.awt.Frame parent, boolean modal) { - super(parent, modal); - initComponents(); - System.out.printf("Adding Key Listener\n", ""); - addKeyListener(new java.awt.event.KeyAdapter() { - public void keyReleased(java.awt.event.KeyEvent evt) { - formKeyReleased(evt); - } - }); - this.setLocationRelativeTo(parent); + final void addEscListener() { + javax.swing.JDialog dialog = this; + + ActionListener escListener = (ActionEvent e) -> { + dispatchEvent(new WindowEvent( + dialog, WindowEvent.WINDOW_CLOSING + )); + }; + getRootPane().registerKeyboardAction(escListener, + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, true), + JComponent.WHEN_IN_FOCUSED_WINDOW); } + /** + * Creates new form EscDialog + * + * @param parent + * @param modal + */ + public EscDialog(java.awt.Window parent, boolean modal) { + super(parent, modal ? ModalityType.DOCUMENT_MODAL : ModalityType.MODELESS); + initComponents(); + addEscListener(); + } + +/* public EscDialog(Dialog parent, boolean modal) { + super(parent, modal); + initComponents(); + addEscListener(); + } +*/ + /** * 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 @@ -56,11 +81,6 @@ public class EscDialog extends javax.swing.JDialog { private void initComponents() { setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); - addKeyListener(new java.awt.event.KeyAdapter() { - public void keyReleased(java.awt.event.KeyEvent evt) { - formKeyReleased(evt); - } - }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); @@ -76,10 +96,6 @@ public class EscDialog extends javax.swing.JDialog { pack(); }// //GEN-END:initComponents - private void formKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyReleased - dispose(); - }//GEN-LAST:event_formKeyReleased - /** * @param args the command line arguments */ @@ -109,6 +125,7 @@ public class EscDialog extends javax.swing.JDialog { /* Create and display the dialog */ java.awt.EventQueue.invokeLater(new Runnable() { + @Override public void run() { EscDialog dialog = new EscDialog(new javax.swing.JFrame(), true); dialog.addWindowListener(new java.awt.event.WindowAdapter() { diff --git a/src/gui/Globals.java b/src/opensesim/gui/Globals.java similarity index 56% rename from src/gui/Globals.java rename to src/opensesim/gui/Globals.java index 51ae791..1e1f28d 100644 --- a/src/gui/Globals.java +++ b/src/opensesim/gui/Globals.java @@ -23,12 +23,15 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; @@ -38,26 +41,35 @@ import java.util.logging.Level; import java.util.logging.Logger; import java.util.prefs.Preferences; import javax.swing.JComboBox; +import javax.swing.JDialog; import javax.swing.JFrame; +import javax.swing.LookAndFeel; +import javax.swing.SwingUtilities; import javax.swing.UIManager; +import javax.swing.UIManager.LookAndFeelInfo; +import opensesim.AbstractAsset; +import opensesim.World; import org.json.JSONArray; import org.json.JSONObject; -import sesim.AutoTraderInterface; -import sesim.AutoTraderLoader; -import sesim.Indicator; -import sesim.IndicatorLoader; -import sesim.SeSimClassLoader; +import opensesim.old_sesim.AutoTraderInterface; +import opensesim.old_sesim.AutoTraderLoader; +import opensesim.old_sesim.Indicator; +import opensesim.old_sesim.IndicatorLoader; +import opensesim.sesim.interfaces.Asset; +import opensesim.util.XClassLoader; /** * * @author 7u83 <7u83@mail.ru> */ public class Globals { + + public static World world; public static final String SESIM_FILEEXTENSION = "sesim"; public static final Double SESIM_FILEVERSION = 0.1; - public static final String SESIM_APPTITLE = "SeSim - Stock Exchange Simulator"; + public static final String SESIM_APPTITLE = "OpenSeSim - Stock Exchange Simulator"; public interface CfgListener { @@ -80,16 +92,19 @@ public class Globals { // static final String STRATEGYPREFS = "Strategies"; // static final String TRADERPREFS = "Traders"; - static final String DEVELSTATUS = "devel_status"; + public static final String DEVELSTATUS = "devel_status"; public static final String GODMODE = "godmode"; - static public sesim.Exchange se; + static public opensesim.old_sesim.Exchange se; /** * Defines keys for preferences */ public static final class PrefKeys { + public static final String XCLASSPATH = "xclasspath"; + public static final String LAF = "laf"; + public static String WORKDIR = "workdir"; public static final String CURRENTFILE = "currentfile"; @@ -98,12 +113,21 @@ public class Globals { public static final String TRADERS = "traders"; } + + public static final class MAX{ + public static final int SYMLEN = 6; + public static final int NAMELEN = 64; + } + /** + * Preferences + */ static public Preferences prefs; public static class CfgStrings { public static final String GODMODE = "godmode"; + } public static String DEFAULT_EXCHANGE_CFG @@ -112,57 +136,173 @@ public class Globals { + " shares_decimals: 0" + "}"; - //CfgStrings - static void setLookAndFeel(String selected) { - - try { - String look = "com.seaglasslookandfeel.SeaGlassLookAndFeel"; - Class.forName(look); - UIManager.installLookAndFeel("Sea Glass", look); - } catch (ClassNotFoundException e) { - } + /** + * + * @param selected + */ + public static void setLookAndFeel(String selected) { + ClassLoader old; + old = Globals.setXClassLoader(); + Logger.getLogger(Globals.class.getName()).log(Level.SEVERE, "Setting LAF:" + selected); UIManager.LookAndFeelInfo[] lafInfo = UIManager.getInstalledLookAndFeels(); for (UIManager.LookAndFeelInfo lafInfo1 : lafInfo) { if (lafInfo1.getName().equals(selected)) { String lafClassName = lafInfo1.getClassName(); try { + Logger.getLogger(Globals.class.getName()).log(Level.SEVERE, "Setting LAF:" + lafClassName); + JFrame.setDefaultLookAndFeelDecorated(true); + JDialog.setDefaultLookAndFeelDecorated(true); + UIManager.setLookAndFeel(lafClassName); - // UIManager.setLookAndFeel("com.seaglasslookandfeel.SeaGlassLookAndFeel"); break; } catch (Exception e) { - + Logger.getLogger(Globals.class.getName()).log(Level.SEVERE, null, e); } } } + + Globals.unsetXClassLoader(old); } static AutoTraderLoader tloader; static IndicatorLoader iloader; - static void initGlobals() { - ArrayList default_pathlist = new ArrayList<>(); - String default_path = new java.io.File(SeSimApplication.class.getProtectionDomain() - .getCodeSource() - .getLocation() - .getPath()).toString(); + static ArrayList default_pathlist = new ArrayList<>(); - default_pathlist.add(default_path); + static ArrayList urllist; + + static public void updateUrlList() { + urllist = new ArrayList<>(); + URL url; + try { + url = new java.io.File(Globals.class.getProtectionDomain() + .getCodeSource() + .getLocation() + .getPath()).toURI().toURL(); + urllist.add(url); + } catch (MalformedURLException ex) { + Logger.getLogger(Globals.class.getName()).log(Level.SEVERE, null, ex); + } + + String xpath; + xpath = prefs.get(Globals.PrefKeys.XCLASSPATH, null); + + urllist.addAll(opensesim.util.XClassLoader.getXPathUrlList(xpath)); + } + + static ClassLoader setXClassLoader() { + ClassLoader old_classloader = Thread.currentThread().getContextClassLoader(); + if (urllist ==null) + return old_classloader; + URL[] urls = urllist.toArray(new URL[urllist.size()]); + URLClassLoader cl; + cl = new URLClassLoader(urls, old_classloader); + Thread.currentThread().setContextClassLoader(cl); + return old_classloader; + } + + static void unsetXClassLoader(ClassLoader old_classloader) { + Thread.currentThread().setContextClassLoader(old_classloader); + + } + + + + + static public ArrayList> getAvailableAssetsTypes(){ + ArrayList> asset_types_raw; + ClassLoader old = setXClassLoader(); + asset_types_raw = opensesim.util.XClassLoader.getClassesList(urllist, AbstractAsset.class); + unsetXClassLoader(old); + + ArrayList> asset_types=new ArrayList<>(); + for (Class a: asset_types_raw ){ + Class aa = a; + asset_types.add(aa); + // asset_types.put(a.cast(AbstractAsset.class)); + } + + return asset_types; + } + + static public void installLookAndFeels() { + ArrayList> lafs; + lafs = opensesim.util.XClassLoader.getClassesList(urllist, LookAndFeel.class); + + ClassLoader currentThreadClassLoader + = Thread.currentThread().getContextClassLoader(); + URL[] urls = urllist.toArray(new URL[urllist.size()]); + URLClassLoader cl; + cl = new URLClassLoader(urls, currentThreadClassLoader); + Thread.currentThread().setContextClassLoader(cl); + + for (Class cls : lafs) { + System.out.println("Class:"); + System.out.println(cls.getName()); + + Class lafc; + lafc = (Class) cls; + LookAndFeel laf; + try { + laf = lafc.newInstance(); + } catch (InstantiationException | IllegalAccessException | InternalError ex) { + Logger.getLogger(SeSimApplication.class.getName()).log(Level.SEVERE, null, ex); + continue; + } + + + + System.out.println("LAF:"); + System.out.println(laf.getName()); + UIManager.installLookAndFeel(laf.getName()+" - "+laf.getDescription(), lafc.getName()); + + } + + Thread.currentThread().setContextClassLoader(currentThreadClassLoader); + + // UIManager.installLookAndFeel(laf.getName(), lafc.getName()); + } + + static void initGlobals(Class c) { + + prefs = Preferences.userNodeForPackage(c); + + world = new World(); + + // initialize urllist used by class loader + updateUrlList(); + + installLookAndFeels(); + + /* + ArrayList> res; + + res = cl.getInstalledClasses(default_pathlist); + + for (Class laf : res) { + System.out.print(laf.getCanonicalName()); + } + */ + /* System.out.print("PATH LIST\n"); + System.out.print(default_pathlist); + System.out.print("END PL\n"); + */ tloader = new AutoTraderLoader(default_pathlist); - + iloader = new IndicatorLoader(default_pathlist); - + iloader.getNames(); // SeSimClassLoader il = new SeSimClassLoader<>(Indicator.class); // il.setDefaultPathList(default_pathlist); // ArrayList> ires = il.getInstalledClasses(); - } static public final Logger LOGGER = Logger.getLogger("com.cauwersin.sesim"); static public final JSONArray getTraders() { + String traders_json = Globals.prefs.get(PrefKeys.TRADERS, "[]"); JSONArray traders = new JSONArray(traders_json); return traders; diff --git a/src/gui/LoggerDialog.form b/src/opensesim/gui/LoggerDialog.form similarity index 100% rename from src/gui/LoggerDialog.form rename to src/opensesim/gui/LoggerDialog.form diff --git a/src/gui/LoggerDialog.java b/src/opensesim/gui/LoggerDialog.java similarity index 99% rename from src/gui/LoggerDialog.java rename to src/opensesim/gui/LoggerDialog.java index 74a032f..0f7be19 100644 --- a/src/gui/LoggerDialog.java +++ b/src/opensesim/gui/LoggerDialog.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui; import java.util.logging.Handler; import java.util.logging.LogRecord; diff --git a/src/gui/MainChart.form b/src/opensesim/gui/MainChart.form similarity index 100% rename from src/gui/MainChart.form rename to src/opensesim/gui/MainChart.form diff --git a/src/gui/MainChart.java b/src/opensesim/gui/MainChart.java similarity index 98% rename from src/gui/MainChart.java rename to src/opensesim/gui/MainChart.java index ea5a173..acd6311 100644 --- a/src/gui/MainChart.java +++ b/src/opensesim/gui/MainChart.java @@ -3,9 +3,9 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package gui; +package opensesim.gui; -import chart.Chart; +import opensesim.chart.Chart; import java.awt.Color; import java.awt.Cursor; import java.util.ArrayList; @@ -14,14 +14,14 @@ import javax.swing.ButtonGroup; import javax.swing.JCheckBoxMenuItem; import javax.swing.JMenuItem; import javax.swing.JRadioButtonMenuItem; -import sesim.Exchange; -import sesim.OHLCData; +import opensesim.old_sesim.Exchange; +import opensesim.old_sesim.OHLCData; /** * * @author 7u83 <7u83@mail.ru> */ -public class MainChart extends chart.Chart { +public class MainChart extends opensesim.chart.Chart { class MyCursor extends Cursor{ diff --git a/src/gui/NewStrategyDialog.form b/src/opensesim/gui/NewStrategyDialog.form similarity index 100% rename from src/gui/NewStrategyDialog.form rename to src/opensesim/gui/NewStrategyDialog.form diff --git a/src/gui/NewStrategyDialog.java b/src/opensesim/gui/NewStrategyDialog.java similarity index 99% rename from src/gui/NewStrategyDialog.java rename to src/opensesim/gui/NewStrategyDialog.java index 7809412..cac027f 100644 --- a/src/gui/NewStrategyDialog.java +++ b/src/opensesim/gui/NewStrategyDialog.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui; import java.util.ArrayList; diff --git a/src/gui/OderBookPanelNew.form b/src/opensesim/gui/OderBookPanelNew.form similarity index 100% rename from src/gui/OderBookPanelNew.form rename to src/opensesim/gui/OderBookPanelNew.form diff --git a/src/gui/OderBookPanelNew.java b/src/opensesim/gui/OderBookPanelNew.java similarity index 92% rename from src/gui/OderBookPanelNew.java rename to src/opensesim/gui/OderBookPanelNew.java index d3e3015..11baf95 100644 --- a/src/gui/OderBookPanelNew.java +++ b/src/opensesim/gui/OderBookPanelNew.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui; /** * @@ -47,9 +47,9 @@ public class OderBookPanelNew extends javax.swing.JPanel { // //GEN-BEGIN:initComponents private void initComponents() { - quotePanel1 = new gui.QuotePanel(); - orderBookNew3 = new gui.orderbook.OrderBook(); - orderBookNew4 = new gui.orderbook.OrderBook(); + quotePanel1 = new opensesim.gui.QuotePanel(); + orderBookNew3 = new opensesim.gui.orderbook.OrderBook(); + orderBookNew4 = new opensesim.gui.orderbook.OrderBook(); filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 32767)); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); @@ -88,8 +88,8 @@ public class OderBookPanelNew extends javax.swing.JPanel { // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.Box.Filler filler1; - private gui.orderbook.OrderBook orderBookNew3; - private gui.orderbook.OrderBook orderBookNew4; - private gui.QuotePanel quotePanel1; + private opensesim.gui.orderbook.OrderBook orderBookNew3; + private opensesim.gui.orderbook.OrderBook orderBookNew4; + private opensesim.gui.QuotePanel quotePanel1; // End of variables declaration//GEN-END:variables } diff --git a/src/gui/OpenOrdersList.form b/src/opensesim/gui/OpenOrdersList.form similarity index 100% rename from src/gui/OpenOrdersList.form rename to src/opensesim/gui/OpenOrdersList.form diff --git a/src/gui/OpenOrdersList.java b/src/opensesim/gui/OpenOrdersList.java similarity index 97% rename from src/gui/OpenOrdersList.java rename to src/opensesim/gui/OpenOrdersList.java index 4c02211..aa81edb 100644 --- a/src/gui/OpenOrdersList.java +++ b/src/opensesim/gui/OpenOrdersList.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui; import java.awt.MouseInfo; @@ -34,10 +34,10 @@ import java.util.Map; import javax.swing.table.DefaultTableModel; -import sesim.Account; -import sesim.Order; -import sesim.Order.OrderType; -import traders.ManTrader.CreateOrderDialog; +import opensesim.old_sesim.Account; +import opensesim.old_sesim.Order; +import opensesim.old_sesim.Order.OrderType; +import opensesim.traders.ManTrader.CreateOrderDialog; /** * diff --git a/src/gui/OrderBook.form b/src/opensesim/gui/OrderBook.form similarity index 100% rename from src/gui/OrderBook.form rename to src/opensesim/gui/OrderBook.form diff --git a/src/gui/OrderBook.java b/src/opensesim/gui/OrderBook.java similarity index 98% rename from src/gui/OrderBook.java rename to src/opensesim/gui/OrderBook.java index d9e6c16..4b31ecd 100644 --- a/src/gui/OrderBook.java +++ b/src/opensesim/gui/OrderBook.java @@ -23,10 +23,10 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui; -import sesim.Exchange; -import sesim.Exchange.*; +import opensesim.old_sesim.Exchange; +import opensesim.old_sesim.Exchange.*; import java.util.ArrayList; import java.util.Formatter; import javax.swing.table.AbstractTableModel; @@ -36,7 +36,7 @@ import java.awt.*; import java.text.DecimalFormat; import javax.swing.*; import javax.swing.table.*; -import sesim.Order; +import opensesim.old_sesim.Order; /** * diff --git a/src/gui/OrderBookDialog.form b/src/opensesim/gui/OrderBookDialog.form similarity index 100% rename from src/gui/OrderBookDialog.form rename to src/opensesim/gui/OrderBookDialog.form diff --git a/src/gui/OrderBookDialog.java b/src/opensesim/gui/OrderBookDialog.java similarity index 92% rename from src/gui/OrderBookDialog.java rename to src/opensesim/gui/OrderBookDialog.java index 391ca31..8c1e19b 100644 --- a/src/gui/OrderBookDialog.java +++ b/src/opensesim/gui/OrderBookDialog.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui; /** * @@ -48,9 +48,9 @@ public class OrderBookDialog extends javax.swing.JDialog { // //GEN-BEGIN:initComponents private void initComponents() { - orderBookNew1 = new gui.orderbook.OrderBook(); - quotePanel1 = new gui.QuotePanel(); - orderBookNew2 = new gui.orderbook.OrderBook(); + orderBookNew1 = new opensesim.gui.orderbook.OrderBook(); + quotePanel1 = new opensesim.gui.QuotePanel(); + orderBookNew2 = new opensesim.gui.orderbook.OrderBook(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); getContentPane().setLayout(new java.awt.FlowLayout()); @@ -104,8 +104,8 @@ public class OrderBookDialog extends javax.swing.JDialog { } // Variables declaration - do not modify//GEN-BEGIN:variables - private gui.orderbook.OrderBook orderBookNew1; - private gui.orderbook.OrderBook orderBookNew2; - private gui.QuotePanel quotePanel1; + private opensesim.gui.orderbook.OrderBook orderBookNew1; + private opensesim.gui.orderbook.OrderBook orderBookNew2; + private opensesim.gui.QuotePanel quotePanel1; // End of variables declaration//GEN-END:variables } diff --git a/src/opensesim/gui/OrderBookPanel_old.form b/src/opensesim/gui/OrderBookPanel_old.form new file mode 100644 index 0000000..fa973b8 --- /dev/null +++ b/src/opensesim/gui/OrderBookPanel_old.form @@ -0,0 +1,81 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/gui/OrderBookPanel_old.java b/src/opensesim/gui/OrderBookPanel_old.java similarity index 63% rename from src/gui/OrderBookPanel_old.java rename to src/opensesim/gui/OrderBookPanel_old.java index 6fecd22..5944754 100644 --- a/src/gui/OrderBookPanel_old.java +++ b/src/opensesim/gui/OrderBookPanel_old.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui; //import SeSim.*; import static java.lang.Thread.sleep; @@ -39,7 +39,7 @@ import static java.lang.Thread.sleep; */ public class OrderBookPanel_old extends javax.swing.JPanel { - sesim.Exchange se; + opensesim.old_sesim.Exchange se; public OrderBookPanel_old() { this.se = Globals.se; @@ -61,51 +61,15 @@ public class OrderBookPanel_old extends javax.swing.JPanel { @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { - java.awt.GridBagConstraints gridBagConstraints; - - askBook1 = new gui.AskBook(); - bidBook1 = new gui.BidBook(); - quotePanel2 = new gui.QuotePanel(); setPreferredSize(new java.awt.Dimension(220, 262)); java.awt.GridBagLayout layout = new java.awt.GridBagLayout(); layout.columnWidths = new int[] {0}; layout.rowHeights = new int[] {0, 5, 0, 5, 0}; setLayout(layout); - - askBook1.setPreferredSize(new java.awt.Dimension(200, 200)); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 0; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.weighty = 1.0; - add(askBook1, gridBagConstraints); - - bidBook1.setPreferredSize(new java.awt.Dimension(200, 200)); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 4; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.weighty = 1.0; - add(bidBook1, gridBagConstraints); - - quotePanel2.setOpaque(false); - quotePanel2.setPreferredSize(new java.awt.Dimension(587, 200)); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 2; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.weightx = 0.5; - gridBagConstraints.weighty = 0.5; - add(quotePanel2, gridBagConstraints); }// //GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables - private gui.AskBook askBook1; - private gui.BidBook bidBook1; - private gui.QuotePanel quotePanel2; // End of variables declaration//GEN-END:variables } diff --git a/src/gui/EditPreferencesDialog.form b/src/opensesim/gui/PreferencesEditor/EditPreferencesDialog.form similarity index 58% rename from src/gui/EditPreferencesDialog.form rename to src/opensesim/gui/PreferencesEditor/EditPreferencesDialog.form index 2295939..af27bbe 100644 --- a/src/gui/EditPreferencesDialog.form +++ b/src/opensesim/gui/PreferencesEditor/EditPreferencesDialog.form @@ -3,6 +3,10 @@
+ + + + @@ -27,17 +31,13 @@ - - + + - - - - - - + + @@ -46,30 +46,62 @@ + + + + + + + + + + + + + + + + + + - + - + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - @@ -135,5 +167,20 @@ + + + + + + + + + + + + + + + diff --git a/src/gui/EditPreferencesDialog.java b/src/opensesim/gui/PreferencesEditor/EditPreferencesDialog.java similarity index 67% rename from src/gui/EditPreferencesDialog.java rename to src/opensesim/gui/PreferencesEditor/EditPreferencesDialog.java index 0f190f0..da3117a 100644 --- a/src/gui/EditPreferencesDialog.java +++ b/src/opensesim/gui/PreferencesEditor/EditPreferencesDialog.java @@ -23,12 +23,17 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui.PreferencesEditor; +import opensesim.gui.Globals; import java.awt.Frame; import java.awt.Window; +import java.io.File; import java.util.logging.Level; import java.util.logging.Logger; +import javax.swing.JDialog; +import javax.swing.JFileChooser; +import javax.swing.JFrame; import javax.swing.LookAndFeel; import javax.swing.SwingUtilities; import javax.swing.UIManager; @@ -38,7 +43,7 @@ import javax.swing.UnsupportedLookAndFeelException; * * @author 7u83 <7u83@mail.ru> */ -public class EditPreferencesDialog extends javax.swing.JDialog { +public class EditPreferencesDialog extends opensesim.gui.EscDialog { UIManager.LookAndFeelInfo[] lafInfo; @@ -60,7 +65,7 @@ public class EditPreferencesDialog extends javax.swing.JDialog { for (UIManager.LookAndFeelInfo lafInfo1 : lafInfo) { lafComboBox.addItem(lafInfo1.getName()); } - lafComboBox.setSelectedItem(Globals.prefs.get("laf", "Nimbus")); + lafComboBox.setSelectedItem(Globals.prefs.get(Globals.PrefKeys.LAF, "Nimbus")); String selstr; selstr = Globals.prefs.get(Globals.DEVELSTATUS, "false"); @@ -68,8 +73,8 @@ public class EditPreferencesDialog extends javax.swing.JDialog { selstr = Globals.prefs.get(Globals.GODMODE, "false"); this.godmodeCheckBox.setSelected(selstr.equals("true")); - - + + xClassPath.setText(Globals.prefs.get(Globals.PrefKeys.XCLASSPATH, "")); } @@ -89,8 +94,13 @@ public class EditPreferencesDialog extends javax.swing.JDialog { jLabel1 = new javax.swing.JLabel(); jDevleopmentFeaturesCheckBox = new javax.swing.JCheckBox(); godmodeCheckBox = new javax.swing.JCheckBox(); + classPathChoseButton = new javax.swing.JButton(); + jLabel2 = new javax.swing.JLabel(); + xClassPath = new javax.swing.JTextField(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setTitle("OpenSeSim Preferences"); + setMinimumSize(new java.awt.Dimension(551, 343)); lafComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); lafComboBox.addActionListener(new java.awt.event.ActionListener() { @@ -129,6 +139,15 @@ public class EditPreferencesDialog extends javax.swing.JDialog { godmodeCheckBox.setText("Godmode"); + classPathChoseButton.setText("Choose ..."); + classPathChoseButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + classPathChoseButtonActionPerformed(evt); + } + }); + + jLabel2.setText("Additional Path:"); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( @@ -137,21 +156,31 @@ public class EditPreferencesDialog extends javax.swing.JDialog { .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addComponent(jLabel1) - .addGap(80, 80, 80) + .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(28, 28, 28) .addComponent(lafComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGap(0, 201, Short.MAX_VALUE) - .addComponent(okButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(applyButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cancelButton)) + .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGap(418, 418, 418)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(godmodeCheckBox) .addComponent(jDevleopmentFeaturesCheckBox)) - .addGap(0, 0, Short.MAX_VALUE))) + .addGap(0, 0, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(okButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(applyButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cancelButton)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(xClassPath) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(classPathChoseButton, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGap(3, 3, 3))) .addContainerGap()) ); layout.setVerticalGroup( @@ -161,16 +190,26 @@ public class EditPreferencesDialog extends javax.swing.JDialog { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lafComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(godmodeCheckBox) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jDevleopmentFeaturesCheckBox) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 188, Short.MAX_VALUE) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(cancelButton) - .addComponent(applyButton) - .addComponent(okButton)) - .addContainerGap()) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(godmodeCheckBox) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jDevleopmentFeaturesCheckBox) + .addGap(28, 28, 28) + .addComponent(jLabel2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(classPathChoseButton) + .addComponent(xClassPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(68, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(cancelButton) + .addComponent(applyButton) + .addComponent(okButton)) + .addContainerGap()))) ); pack(); @@ -183,6 +222,10 @@ public class EditPreferencesDialog extends javax.swing.JDialog { private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed if (old_laf != new_laf) { try { + JFrame.setDefaultLookAndFeelDecorated(true); + JDialog.setDefaultLookAndFeelDecorated(true); + JFrame.setDefaultLookAndFeelDecorated(true); + JDialog.setDefaultLookAndFeelDecorated(true); UIManager.setLookAndFeel(old_laf); } catch (UnsupportedLookAndFeelException ex) { Logger.getLogger(EditPreferencesDialog.class.getName()).log(Level.SEVERE, null, ex); @@ -201,15 +244,13 @@ public class EditPreferencesDialog extends javax.swing.JDialog { } private void applyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyButtonActionPerformed - String selected = (String) this.lafComboBox.getSelectedItem(); Globals.setLookAndFeel(selected); new_laf = UIManager.getLookAndFeel(); resetUI(); - - + }//GEN-LAST:event_applyButtonActionPerformed @@ -222,10 +263,43 @@ public class EditPreferencesDialog extends javax.swing.JDialog { Globals.prefs.put(Globals.DEVELSTATUS, sel); sel = this.godmodeCheckBox.isSelected() == true ? "true" : "false"; Globals.prefs.put(Globals.GODMODE, sel); - Globals.notifyCfgListeners(); + + Globals.prefs.put(Globals.PrefKeys.XCLASSPATH, xClassPath.getText()); + + Globals.notifyCfgListeners(); this.dispose(); }//GEN-LAST:event_okButtonActionPerformed + private void classPathChoseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_classPathChoseButtonActionPerformed + + JFileChooser chooser = new JFileChooser(); + + File dir = null; + if (!"".equals(xClassPath.getText())) { + dir = new File(xClassPath.getText()); + if (!dir.exists()) { + dir = null; + } + } + if (dir == null) { + dir = new File(System.getProperty("user.home")); + } + + chooser.setCurrentDirectory(dir); + + chooser.setDialogTitle("Chose Directory"); + chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + chooser.setAcceptAllFileFilterUsed(false); + + + int rc = chooser.showOpenDialog(null); + if ( rc == JFileChooser.APPROVE_OPTION){ + xClassPath.setText(chooser.getSelectedFile().getAbsolutePath()); + } + + + }//GEN-LAST:event_classPathChoseButtonActionPerformed + /** * @param args the command line arguments */ @@ -271,10 +345,13 @@ public class EditPreferencesDialog extends javax.swing.JDialog { // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton applyButton; private javax.swing.JButton cancelButton; + private javax.swing.JButton classPathChoseButton; private javax.swing.JCheckBox godmodeCheckBox; private javax.swing.JCheckBox jDevleopmentFeaturesCheckBox; private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; private javax.swing.JComboBox lafComboBox; private javax.swing.JButton okButton; + private javax.swing.JTextField xClassPath; // End of variables declaration//GEN-END:variables } diff --git a/src/gui/QuotePanel.form b/src/opensesim/gui/QuotePanel.form similarity index 100% rename from src/gui/QuotePanel.form rename to src/opensesim/gui/QuotePanel.form diff --git a/src/gui/QuotePanel.java b/src/opensesim/gui/QuotePanel.java similarity index 96% rename from src/gui/QuotePanel.java rename to src/opensesim/gui/QuotePanel.java index dfd18f5..a9b05a4 100644 --- a/src/gui/QuotePanel.java +++ b/src/opensesim/gui/QuotePanel.java @@ -23,9 +23,9 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui; -import sesim.Quote; +import opensesim.old_sesim.Quote; import java.awt.Color; import javax.swing.SwingUtilities; import java.util.*; @@ -34,7 +34,7 @@ import java.util.*; * * @author 7u83 <7u83@mail.ru> */ -public class QuotePanel extends javax.swing.JPanel implements sesim.Exchange.QuoteReceiver{ +public class QuotePanel extends javax.swing.JPanel implements opensesim.old_sesim.Exchange.QuoteReceiver{ /** * Creates new form QuotePanel diff --git a/src/gui/SeSimApplication.form b/src/opensesim/gui/SeSimApplication.form similarity index 90% rename from src/gui/SeSimApplication.form rename to src/opensesim/gui/SeSimApplication.form index 3521071..4189e3c 100644 --- a/src/gui/SeSimApplication.form +++ b/src/opensesim/gui/SeSimApplication.form @@ -34,7 +34,7 @@ - + @@ -141,8 +141,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -337,7 +371,7 @@ - + @@ -356,7 +390,7 @@ - + @@ -371,7 +405,7 @@ - + @@ -396,7 +430,7 @@ - + @@ -427,14 +461,14 @@ - + - + @@ -443,7 +477,7 @@ - + @@ -462,20 +496,13 @@ - + - - - - - - - diff --git a/src/gui/SeSimApplication.java b/src/opensesim/gui/SeSimApplication.java similarity index 86% rename from src/gui/SeSimApplication.java rename to src/opensesim/gui/SeSimApplication.java index 76df5c4..0712782 100644 --- a/src/gui/SeSimApplication.java +++ b/src/opensesim/gui/SeSimApplication.java @@ -23,10 +23,10 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui; -import chart.Help; -import chart.SuperDlg; +import opensesim.chart.Help; +import opensesim.chart.SuperDlg; import java.awt.Dialog; import java.awt.Frame; import java.awt.GraphicsDevice; @@ -38,22 +38,36 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.HashMap; import java.util.Scanner; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.prefs.Preferences; import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JOptionPane; +import javax.swing.LookAndFeel; import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER; +import javax.swing.UIManager; import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileNameExtensionFilter; +import opensesim.gui.AssetPairEditor.NewJDialog; +import opensesim.gui.exchangeeditor.ExchangeEditorDialog; +import opensesim.gui.exchangeeditor.ExchangeListDialog; import org.json.JSONArray; import org.json.JSONObject; -import sesim.AutoTraderInterface; -import sesim.Exchange; -import sesim.Scheduler; +import opensesim.old_sesim.AutoTraderInterface; +import opensesim.old_sesim.Exchange; +import opensesim.old_sesim.Scheduler; +import opensesim.util.IDGenerator.Id; +import opensesim.util.XClassLoader; /** * @@ -66,6 +80,9 @@ public class SeSimApplication extends javax.swing.JFrame { */ public SeSimApplication() { + Globals.setXClassLoader(); + Globals.setLookAndFeel(Globals.prefs.get(Globals.PrefKeys.LAF, "Nimbus")); + // Globals.setLookAndFeel("Metal"); initComponents(); // Get default screen and place our window @@ -87,7 +104,6 @@ public class SeSimApplication extends javax.swing.JFrame { } // this.chartSrollPane.setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_NEVER); - } AutoTraderInterface createTrader(Exchange se, long id, String name, double money, double shares, JSONObject cfg) { @@ -117,7 +133,15 @@ public class SeSimApplication extends javax.swing.JFrame { for (int i = 0; i < tlist.length(); i++) { JSONObject t = tlist.getJSONObject(i); String strategy_name = t.getString("Strategy"); - JSONObject strategy = Globals.getStrategy(strategy_name); + JSONObject strategy = null; + try { + strategy = Globals.getStrategy(strategy_name); + } catch (Exception ex) { + javax.swing.JOptionPane.showMessageDialog(chart, "Strategy not defined:\n\"" + strategy_name + " \"", "Error", + javax.swing.JOptionPane.ERROR_MESSAGE); + return; + } + String base = strategy.getString("base"); AutoTraderInterface ac = Globals.tloader.getAutoTraderInterface(base); @@ -172,22 +196,21 @@ public class SeSimApplication extends javax.swing.JFrame { jTextArea1 = new javax.swing.JTextArea(); jSplitPane1 = new javax.swing.JSplitPane(); jSplitPane2 = new javax.swing.JSplitPane(); - orderBookNew1 = new gui.orderbook.OrderBook(); + orderBookNew1 = new opensesim.gui.orderbook.OrderBook(); jPanel2 = new javax.swing.JPanel(); stopButton = new javax.swing.JButton(); runButton = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); accelSpinner = new javax.swing.JSpinner(); - clock = new gui.Clock(); + clock = new opensesim.gui.Clock(); jLabel1 = new javax.swing.JLabel(); jSplitPane3 = new javax.swing.JSplitPane(); jSplitPane4 = new javax.swing.JSplitPane(); - orderBooksHorizontal1 = new gui.orderbook.OrderBooksHorizontal(); - chart = new chart.MasterChart(); - quoteVertical1 = new gui.orderbook.QuoteVertical(); + orderBooksHorizontal1 = new opensesim.gui.orderbook.OrderBooksHorizontal(); + chart = new opensesim.chart.MasterChart(); + quoteVertical1 = new opensesim.gui.orderbook.QuoteVertical(); jSplitPane5 = new javax.swing.JSplitPane(); - statistics1 = new gui.Statistics(); - mMChart2 = new chart.MMChart(); + statistics1 = new opensesim.gui.Statistics(); menuBar = new javax.swing.JMenuBar(); fileMenu = new javax.swing.JMenu(); openMenuItem = new javax.swing.JMenuItem(); @@ -202,6 +225,9 @@ public class SeSimApplication extends javax.swing.JFrame { editMenu = new javax.swing.JMenu(); editExchangeMenuItem = new javax.swing.JMenuItem(); jSeparator1 = new javax.swing.JPopupMenu.Separator(); + assetsMenuItem = new javax.swing.JMenuItem(); + exchangesMenuItem = new javax.swing.JMenuItem(); + jMenuItem2 = new javax.swing.JMenuItem(); pasteMenuItem = new javax.swing.JMenuItem(); deleteMenuItem = new javax.swing.JMenuItem(); jSeparator2 = new javax.swing.JPopupMenu.Separator(); @@ -231,7 +257,7 @@ public class SeSimApplication extends javax.swing.JFrame { setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setMinimumSize(new java.awt.Dimension(640, 480)); - stopButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icons/stop.gif"))); // NOI18N + stopButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/opensesim/resources/icons/stop.gif"))); // NOI18N stopButton.setText("Stop"); stopButton.setFocusable(false); stopButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); @@ -243,7 +269,7 @@ public class SeSimApplication extends javax.swing.JFrame { }); runButton.setFont(runButton.getFont()); - runButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icons/run.gif"))); // NOI18N + runButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/opensesim/resources/icons/run.gif"))); // NOI18N runButton.setText("Run sim!"); runButton.setToolTipText("Run the simmulation"); runButton.setFocusable(false); @@ -255,7 +281,7 @@ public class SeSimApplication extends javax.swing.JFrame { } }); - jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icons/pause.gif"))); // NOI18N + jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/opensesim/resources/icons/pause.gif"))); // NOI18N jButton2.setText("Pause"); jButton2.setFocusable(false); jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); @@ -326,7 +352,6 @@ public class SeSimApplication extends javax.swing.JFrame { jSplitPane5.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); jSplitPane5.setTopComponent(statistics1); - jSplitPane5.setRightComponent(mMChart2); jSplitPane3.setLeftComponent(jSplitPane5); @@ -417,6 +442,34 @@ public class SeSimApplication extends javax.swing.JFrame { editMenu.add(editExchangeMenuItem); editMenu.add(jSeparator1); + assetsMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F2, 0)); + assetsMenuItem.setMnemonic('a'); + assetsMenuItem.setText("Assets ..."); + assetsMenuItem.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + assetsMenuItemActionPerformed(evt); + } + }); + editMenu.add(assetsMenuItem); + + exchangesMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F3, 0)); + exchangesMenuItem.setText("Exchanges ..."); + exchangesMenuItem.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + exchangesMenuItemActionPerformed(evt); + } + }); + editMenu.add(exchangesMenuItem); + + jMenuItem2.setText("Asset Pairs"); + jMenuItem2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jMenuItem2ActionPerformed(evt); + } + }); + editMenu.add(jMenuItem2); + + pasteMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, 0)); pasteMenuItem.setMnemonic('s'); pasteMenuItem.setText("Strategies ..."); pasteMenuItem.addActionListener(new java.awt.event.ActionListener() { @@ -533,7 +586,7 @@ public class SeSimApplication extends javax.swing.JFrame { }//GEN-LAST:event_exitMenuItemActionPerformed private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed - Dialog d = new gui.AboutDialog(this, rootPaneCheckingEnabled); + Dialog d = new opensesim.gui.misc.AboutDialog(this, rootPaneCheckingEnabled); d.setVisible(rootPaneCheckingEnabled); }//GEN-LAST:event_aboutMenuItemActionPerformed @@ -600,7 +653,7 @@ public class SeSimApplication extends javax.swing.JFrame { private void editPreferencesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editPreferencesActionPerformed Globals.LOGGER.info("Edit prefs..."); - Dialog d = new gui.EditPreferencesDialog(this, rootPaneCheckingEnabled); + Dialog d = new opensesim.gui.PreferencesEditor.EditPreferencesDialog(this, rootPaneCheckingEnabled); d.setVisible(rootPaneCheckingEnabled); }//GEN-LAST:event_editPreferencesActionPerformed @@ -745,7 +798,7 @@ public class SeSimApplication extends javax.swing.JFrame { }//GEN-LAST:event_editExchangeMenuItemActionPerformed private void resetToDefaults() { - InputStream is = getClass().getResourceAsStream("/resources/files/defaultcfg.json"); + InputStream is = getClass().getResourceAsStream("/opensesim/resources/files/defaultcfg.json"); String df = new Scanner(is, "UTF-8").useDelimiter("\\A").next(); try { @@ -799,7 +852,7 @@ public class SeSimApplication extends javax.swing.JFrame { }//GEN-LAST:event_stopButtonActionPerformed private void jCheckBoxMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxMenuItem1ActionPerformed - JDialog jd = new gui.orderbook.OrderBookDialog(this, false); + JDialog jd = new opensesim.gui.orderbook.OrderBookDialog(this, false); jd.setVisible(rootPaneCheckingEnabled); }//GEN-LAST:event_jCheckBoxMenuItem1ActionPerformed @@ -858,59 +911,72 @@ public class SeSimApplication extends javax.swing.JFrame { private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed //SuperDlg d = new SuperDlg(this, false); //d.setVisible(true); - + //Help hs = new Help(this,true); //hs.setVisible(true); - SeSimHelp h = new SeSimHelp(); - + h.setVisible(true); }//GEN-LAST:event_jMenuItem1ActionPerformed + private void assetsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_assetsMenuItemActionPerformed + opensesim.gui.AssetEditor.AssetListDialog dialog; + dialog = new opensesim.gui.AssetEditor.AssetListDialog(this,true); + dialog.setLocationRelativeTo(this); + dialog.setVisible(rootPaneCheckingEnabled); + dialog.dispose(); + }//GEN-LAST:event_assetsMenuItemActionPerformed + + private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed + JDialog dialog = new NewJDialog(this,true); + dialog.setVisible(true); + dialog.dispose(); + + }//GEN-LAST:event_jMenuItem2ActionPerformed + + private void exchangesMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exchangesMenuItemActionPerformed + + ExchangeListDialog.runDialog(this); + + }//GEN-LAST:event_exchangesMenuItemActionPerformed + /** * @param args the command line arguments * @throws java.lang.IllegalAccessException * @throws java.lang.InstantiationException */ public static void main(String args[]) throws IllegalAccessException, InstantiationException { - - - - GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + + // Initialize globals + Class c = opensesim.gui.SeSimApplication.class; + Globals.initGlobals(c); + + String world_source = Globals.prefs.get("world", "{}"); + JSONObject world = new org.json.JSONObject(world_source); + Globals.world.putConfig(world); + + + //Globals.installLookAndFeels(); - GraphicsDevice[] gs = ge.getScreenDevices(); - for (GraphicsDevice d : gs) { - System.out.printf("ID %s\n", d.getIDstring()); + // Globals.setLookAndFeel("Metal"); - } - //System.exit(0); + //JDialog.setDefaultLookAndFeelDecorated(true); + - //System.exit(0); - Globals.initGlobals(); - //System.exit(0); + + Globals.se = new Exchange(); - Class c = sesim.Exchange.class; - Globals.prefs = Preferences.userNodeForPackage(c); + Globals.prefs.put(Globals.PrefKeys.CURRENTFILE, ""); - Globals.setLookAndFeel(Globals.prefs.get("laf", "Nimbus")); - JDialog.setDefaultLookAndFeelDecorated(true); + java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { - - - - /* String x = new java.io.File(SeSimApplication.class.getProtectionDomain() - .getCodeSource() - .getLocation() - .getPath()).toString(); //.getName(); - */ -// System.out.printf("Creating Application\n"); new SeSimApplication().setVisible(true); } }); @@ -919,14 +985,16 @@ public class SeSimApplication extends javax.swing.JFrame { // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JMenuItem aboutMenuItem; private javax.swing.JSpinner accelSpinner; - private chart.MasterChart chart; + private javax.swing.JMenuItem assetsMenuItem; + private opensesim.chart.MasterChart chart; private javax.swing.JMenuItem clearMenuItem; - private gui.Clock clock; + private opensesim.gui.Clock clock; private javax.swing.JMenuItem closeMenuItem; private javax.swing.JMenuItem deleteMenuItem; private javax.swing.JMenuItem editExchangeMenuItem; private javax.swing.JMenu editMenu; private javax.swing.JMenuItem editPreferences; + private javax.swing.JMenuItem exchangesMenuItem; private javax.swing.JMenuItem exitMenuItem; private javax.swing.JMenu fileMenu; private javax.swing.JMenu helpMenu; @@ -934,6 +1002,7 @@ public class SeSimApplication extends javax.swing.JFrame { private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem1; private javax.swing.JLabel jLabel1; private javax.swing.JMenuItem jMenuItem1; + private javax.swing.JMenuItem jMenuItem2; private javax.swing.JPanel jPanel2; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JPopupMenu.Separator jSeparator1; @@ -946,13 +1015,12 @@ public class SeSimApplication extends javax.swing.JFrame { private javax.swing.JSplitPane jSplitPane4; private javax.swing.JSplitPane jSplitPane5; private javax.swing.JTextArea jTextArea1; - private chart.MMChart mMChart2; private javax.swing.JMenuBar menuBar; private javax.swing.JMenuItem openMenuItem; - private gui.orderbook.OrderBook orderBookNew1; - private gui.orderbook.OrderBooksHorizontal orderBooksHorizontal1; + private opensesim.gui.orderbook.OrderBook orderBookNew1; + private opensesim.gui.orderbook.OrderBooksHorizontal orderBooksHorizontal1; private javax.swing.JMenuItem pasteMenuItem; - private gui.orderbook.QuoteVertical quoteVertical1; + private opensesim.gui.orderbook.QuoteVertical quoteVertical1; private javax.swing.JMenuItem resetToDefaultsMenuItem; private javax.swing.JButton runButton; private javax.swing.JMenuItem saveAsMenuItem; @@ -961,7 +1029,7 @@ public class SeSimApplication extends javax.swing.JFrame { private javax.swing.JMenuItem simMenuPause; private javax.swing.JMenuItem simMenuStart; private javax.swing.JMenuItem simMenuStop; - private gui.Statistics statistics1; + private opensesim.gui.Statistics statistics1; private javax.swing.JButton stopButton; private javax.swing.JMenu viewMenu; private javax.swing.JCheckBoxMenuItem viewTraderListCheckBox; diff --git a/src/gui/SeSimHelp.form b/src/opensesim/gui/SeSimHelp.form similarity index 100% rename from src/gui/SeSimHelp.form rename to src/opensesim/gui/SeSimHelp.form diff --git a/src/gui/SeSimHelp.java b/src/opensesim/gui/SeSimHelp.java similarity index 98% rename from src/gui/SeSimHelp.java rename to src/opensesim/gui/SeSimHelp.java index 3b936e1..90bffab 100644 --- a/src/gui/SeSimHelp.java +++ b/src/opensesim/gui/SeSimHelp.java @@ -23,9 +23,9 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui; -import chart.Help; +import opensesim.chart.Help; import java.net.URL; import javax.help.HelpSet; import javax.help.JHelp; diff --git a/src/gui/Statistics.form b/src/opensesim/gui/Statistics.form similarity index 100% rename from src/gui/Statistics.form rename to src/opensesim/gui/Statistics.form diff --git a/src/gui/Statistics.java b/src/opensesim/gui/Statistics.java similarity index 99% rename from src/gui/Statistics.java rename to src/opensesim/gui/Statistics.java index d410f9b..46c96e0 100644 --- a/src/gui/Statistics.java +++ b/src/opensesim/gui/Statistics.java @@ -23,11 +23,11 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui; import java.util.Timer; import java.util.TimerTask; -import sesim.Exchange; +import opensesim.old_sesim.Exchange; /** * diff --git a/src/gui/StatisticsPanel.form b/src/opensesim/gui/StatisticsPanel.form similarity index 100% rename from src/gui/StatisticsPanel.form rename to src/opensesim/gui/StatisticsPanel.form diff --git a/src/gui/StatisticsPanel.java b/src/opensesim/gui/StatisticsPanel.java similarity index 98% rename from src/gui/StatisticsPanel.java rename to src/opensesim/gui/StatisticsPanel.java index 25b64a8..1d176c5 100644 --- a/src/gui/StatisticsPanel.java +++ b/src/opensesim/gui/StatisticsPanel.java @@ -23,11 +23,11 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui; import java.util.Timer; import java.util.TimerTask; -import sesim.Scheduler; +import opensesim.old_sesim.Scheduler; /** * diff --git a/src/gui/StrategySaveDialog.form b/src/opensesim/gui/StrategySaveDialog.form similarity index 100% rename from src/gui/StrategySaveDialog.form rename to src/opensesim/gui/StrategySaveDialog.form diff --git a/src/gui/StrategySaveDialog.java b/src/opensesim/gui/StrategySaveDialog.java similarity index 99% rename from src/gui/StrategySaveDialog.java rename to src/opensesim/gui/StrategySaveDialog.java index ebc15a7..ccb0725 100644 --- a/src/gui/StrategySaveDialog.java +++ b/src/opensesim/gui/StrategySaveDialog.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui; import java.awt.event.KeyEvent; diff --git a/src/gui/TestChartdialog.form b/src/opensesim/gui/TestChartdialog.form similarity index 100% rename from src/gui/TestChartdialog.form rename to src/opensesim/gui/TestChartdialog.form diff --git a/src/gui/TestChartdialog.java b/src/opensesim/gui/TestChartdialog.java similarity index 97% rename from src/gui/TestChartdialog.java rename to src/opensesim/gui/TestChartdialog.java index ecad82e..54ad717 100644 --- a/src/gui/TestChartdialog.java +++ b/src/opensesim/gui/TestChartdialog.java @@ -3,7 +3,7 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package gui; +package opensesim.gui; import java.awt.Cursor; @@ -32,7 +32,7 @@ public class TestChartdialog extends javax.swing.JDialog { private void initComponents() { jButton1 = new javax.swing.JButton(); - chart1 = new chart.Chart(); + chart1 = new opensesim.chart.Chart(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); @@ -118,7 +118,7 @@ public class TestChartdialog extends javax.swing.JDialog { } // Variables declaration - do not modify//GEN-BEGIN:variables - private chart.Chart chart1; + private opensesim.chart.Chart chart1; private javax.swing.JButton jButton1; // End of variables declaration//GEN-END:variables } diff --git a/src/gui/TraderListDialog.form b/src/opensesim/gui/TraderListDialog.form similarity index 100% rename from src/gui/TraderListDialog.form rename to src/opensesim/gui/TraderListDialog.form diff --git a/src/gui/TraderListDialog.java b/src/opensesim/gui/TraderListDialog.java similarity index 97% rename from src/gui/TraderListDialog.java rename to src/opensesim/gui/TraderListDialog.java index 2736b2e..d8a2084 100644 --- a/src/gui/TraderListDialog.java +++ b/src/opensesim/gui/TraderListDialog.java @@ -1,4 +1,4 @@ -package gui; +package opensesim.gui; import java.awt.Dialog; @@ -54,7 +54,7 @@ public class TraderListDialog extends javax.swing.JDialog { // //GEN-BEGIN:initComponents private void initComponents() { - traderListPanel22 = new gui.TraderListPanel(); + traderListPanel22 = new opensesim.gui.TraderListPanel(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Trader List"); @@ -117,6 +117,6 @@ public class TraderListDialog extends javax.swing.JDialog { } // Variables declaration - do not modify//GEN-BEGIN:variables - private gui.TraderListPanel traderListPanel22; + private opensesim.gui.TraderListPanel traderListPanel22; // End of variables declaration//GEN-END:variables } diff --git a/src/gui/TraderListPanel.form b/src/opensesim/gui/TraderListPanel.form similarity index 100% rename from src/gui/TraderListPanel.form rename to src/opensesim/gui/TraderListPanel.form diff --git a/src/gui/TraderListPanel.java b/src/opensesim/gui/TraderListPanel.java similarity index 97% rename from src/gui/TraderListPanel.java rename to src/opensesim/gui/TraderListPanel.java index bbb040b..c6ae928 100644 --- a/src/gui/TraderListPanel.java +++ b/src/opensesim/gui/TraderListPanel.java @@ -23,9 +23,9 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui; -import gui.tools.NummericCellRenderer; +import opensesim.gui.tools.NummericCellRenderer; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -38,9 +38,9 @@ import javax.swing.JTable; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableRowSorter; -import sesim.AutoTraderInterface; -import sesim.Exchange; -import sesim.Account; +import opensesim.old_sesim.AutoTraderInterface; +import opensesim.old_sesim.Exchange; +import opensesim.old_sesim.Account; /** * @@ -59,7 +59,7 @@ public class TraderListPanel extends javax.swing.JPanel { return; } - sesim.Quote q = Globals.se.getLastQuoete(); + opensesim.old_sesim.Quote q = Globals.se.getLastQuoete(); double price = q == null ? 0 : q.price; diff --git a/src/gui/WaitBox.form b/src/opensesim/gui/WaitBox.form similarity index 100% rename from src/gui/WaitBox.form rename to src/opensesim/gui/WaitBox.form diff --git a/src/gui/WaitBox.java b/src/opensesim/gui/WaitBox.java similarity index 99% rename from src/gui/WaitBox.java rename to src/opensesim/gui/WaitBox.java index 1d44847..3ad2faa 100644 --- a/src/gui/WaitBox.java +++ b/src/opensesim/gui/WaitBox.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui; /** * diff --git a/src/opensesim/gui/exchangeeditor/ExchangeEditorDialog.form b/src/opensesim/gui/exchangeeditor/ExchangeEditorDialog.form new file mode 100644 index 0000000..7433c2d --- /dev/null +++ b/src/opensesim/gui/exchangeeditor/ExchangeEditorDialog.form @@ -0,0 +1,67 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/opensesim/gui/exchangeeditor/ExchangeEditorDialog.java b/src/opensesim/gui/exchangeeditor/ExchangeEditorDialog.java new file mode 100644 index 0000000..1b0a405 --- /dev/null +++ b/src/opensesim/gui/exchangeeditor/ExchangeEditorDialog.java @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.gui.exchangeeditor; + +import java.awt.Dialog; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.JDialog; +import javax.swing.JFrame; +import opensesim.gui.EscDialog; +import opensesim.util.SeSimException; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class ExchangeEditorDialog extends EscDialog { + + /** + * Creates new form ExchangeEditorDialog + */ + public ExchangeEditorDialog(Dialog parent, boolean modal) { + super(parent, modal); + initComponents(); + } + + public static void runDialog(Dialog parent) { + + ExchangeEditorDialog dialog = new ExchangeEditorDialog(parent, true); + dialog.setLocationRelativeTo(parent); + dialog.setVisible(true); + try { + dialog.exchangeEditorPanel1.saveData(); + } catch (SeSimException ex) { + javax.swing.JOptionPane.showMessageDialog(parent, ex.getMessage(), + "Error Hello", + javax.swing.JOptionPane.ERROR_MESSAGE); + } + dialog.dispose(); + + } + + /** + * 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. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + exchangeEditorPanel1 = new opensesim.gui.exchangeeditor.ExchangeEditorPanel(); + jButton1 = new javax.swing.JButton(); + jButton2 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + + jButton1.setText("Ok"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + jButton2.setText("Cancel"); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jButton1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jButton2) + .addContainerGap()) + .addComponent(exchangeEditorPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(exchangeEditorPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jButton2) + .addComponent(jButton1)) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + setVisible(false); + }//GEN-LAST:event_jButton1ActionPerformed + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(ExchangeEditorDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(ExchangeEditorDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(ExchangeEditorDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(ExchangeEditorDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the dialog */ + /* java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + ExchangeEditorDialog dialog = new ExchangeEditorDialog(new javax.swing.JFrame(), true); + dialog.addWindowListener(new java.awt.event.WindowAdapter() { + @Override + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + }); + dialog.setVisible(true); + } + });*/ + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private opensesim.gui.exchangeeditor.ExchangeEditorPanel exchangeEditorPanel1; + private javax.swing.JButton jButton1; + private javax.swing.JButton jButton2; + // End of variables declaration//GEN-END:variables +} diff --git a/src/opensesim/gui/exchangeeditor/ExchangeEditorPanel.form b/src/opensesim/gui/exchangeeditor/ExchangeEditorPanel.form new file mode 100644 index 0000000..d3b7368 --- /dev/null +++ b/src/opensesim/gui/exchangeeditor/ExchangeEditorPanel.form @@ -0,0 +1,70 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/opensesim/gui/exchangeeditor/ExchangeEditorPanel.java b/src/opensesim/gui/exchangeeditor/ExchangeEditorPanel.java new file mode 100644 index 0000000..a007f47 --- /dev/null +++ b/src/opensesim/gui/exchangeeditor/ExchangeEditorPanel.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.gui.exchangeeditor; + +import opensesim.Exchange; +import opensesim.World; +import opensesim.gui.Globals; +import opensesim.util.SeSimException; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class ExchangeEditorPanel extends javax.swing.JPanel { + + World world; + /** + * Creates new form ExchangeEditorPanel + */ + public ExchangeEditorPanel() { + world = Globals.world; + initComponents(); + } + + public void saveData() throws SeSimException{ + Exchange ex = world.addExchange(symField.getText()); + ex.setName(nameField.getText()); + } + + /** + * 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. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jLabel1 = new javax.swing.JLabel(); + symField = new opensesim.gui.util.JTextFieldLimit(); + symField.setLimit(10); + jLabel2 = new javax.swing.JLabel(); + nameField = new javax.swing.JTextField(); + + jLabel1.setText("Symbol:"); + + jLabel2.setText("Name:"); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel2) + .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(nameField, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE) + .addComponent(symField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel1) + .addComponent(symField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel2) + .addComponent(nameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(35, Short.MAX_VALUE)) + ); + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JTextField nameField; + private opensesim.gui.util.JTextFieldLimit symField; + // End of variables declaration//GEN-END:variables +} diff --git a/src/opensesim/gui/exchangeeditor/ExchangeListDialog.form b/src/opensesim/gui/exchangeeditor/ExchangeListDialog.form new file mode 100644 index 0000000..e1c70c0 --- /dev/null +++ b/src/opensesim/gui/exchangeeditor/ExchangeListDialog.form @@ -0,0 +1,73 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/opensesim/gui/exchangeeditor/ExchangeListDialog.java b/src/opensesim/gui/exchangeeditor/ExchangeListDialog.java new file mode 100644 index 0000000..9291a85 --- /dev/null +++ b/src/opensesim/gui/exchangeeditor/ExchangeListDialog.java @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.gui.exchangeeditor; + +import java.awt.Dialog; +import java.awt.Window; +import javax.swing.JFrame; +import opensesim.gui.EscDialog; +import opensesim.util.SeSimException; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class ExchangeListDialog extends EscDialog { + + /** + * Creates new form ExchangeListDialog + */ + public ExchangeListDialog(Window parent, boolean modal) { + super(parent, modal); + initComponents(); + } + + public static void runDialog(Window parent) { + + ExchangeListDialog dialog = new ExchangeListDialog(parent, true); + dialog.setLocationRelativeTo(parent); + dialog.setVisible(true); +/* try { + dialog.exchangeListPanel1. + } catch (SeSimException ex) { + javax.swing.JOptionPane.showMessageDialog(parent, ex.getMessage(), + "Error Hello", + javax.swing.JOptionPane.ERROR_MESSAGE); + } +*/ dialog.dispose(); + + } + /** + * 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. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + exchangeListPanel1 = new opensesim.gui.exchangeeditor.ExchangeListPanel(); + jButton1 = new javax.swing.JButton(); + jButton2 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + + jButton1.setText("Done"); + + jButton2.setText("New ..."); + jButton2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton2ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(jButton2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jButton1)) + .addComponent(exchangeListPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE)) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(exchangeListPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jButton1) + .addComponent(jButton2)) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed + Dialog d = this; + ExchangeEditorDialog.runDialog(d); + }//GEN-LAST:event_jButton2ActionPerformed + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(ExchangeListDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(ExchangeListDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(ExchangeListDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(ExchangeListDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the dialog */ + /* java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + ExchangeListDialog dialog = new ExchangeListDialog(new javax.swing.JFrame(), true); + dialog.addWindowListener(new java.awt.event.WindowAdapter() { + @Override + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + }); + dialog.setVisible(true); + } + });*/ + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private opensesim.gui.exchangeeditor.ExchangeListPanel exchangeListPanel1; + private javax.swing.JButton jButton1; + private javax.swing.JButton jButton2; + // End of variables declaration//GEN-END:variables +} diff --git a/src/opensesim/gui/exchangeeditor/ExchangeListPanel.form b/src/opensesim/gui/exchangeeditor/ExchangeListPanel.form new file mode 100644 index 0000000..8d2c3e4 --- /dev/null +++ b/src/opensesim/gui/exchangeeditor/ExchangeListPanel.form @@ -0,0 +1,46 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/opensesim/gui/exchangeeditor/ExchangeListPanel.java b/src/opensesim/gui/exchangeeditor/ExchangeListPanel.java new file mode 100644 index 0000000..f701c10 --- /dev/null +++ b/src/opensesim/gui/exchangeeditor/ExchangeListPanel.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.gui.exchangeeditor; + +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableModel; +import opensesim.World; +import opensesim.gui.Globals; +import opensesim.Exchange; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class ExchangeListPanel extends javax.swing.JPanel { + + World world; + + /** + * Creates new form ExchangeList + */ + public ExchangeListPanel() { + world = Globals.world; + initComponents(); + reload(); + } + + final void reload() { + DefaultTableModel m = (DefaultTableModel) exchangeTable.getModel(); + + if (world == null) { + return; + } + m.setRowCount(0); + for (Exchange e : world.getExchangeCollection()) { + m.addRow(new Object[]{ + + e.getSymbol(), + e.getName() + + }); + + } + } + + private TableModel getModel() { + + class TModel extends DefaultTableModel { + + private TModel(Object[] object, int i) { + super(object, i); + } + + @Override + public boolean isCellEditable(int row, int column) { + //all cells false + return false; + } + } + + DefaultTableModel model = new TModel( + new Object[]{"Symbol", "Name"}, 0 + ); + + exchangeTable.setAutoCreateRowSorter(true); + exchangeTable.getTableHeader().setReorderingAllowed(false); + + return model; + + } + + /** + * 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. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jScrollPane2 = new javax.swing.JScrollPane(); + exchangeTable = new javax.swing.JTable(); + + exchangeTable.setModel(getModel()); + jScrollPane2.setViewportView(exchangeTable); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE) + ); + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JTable exchangeTable; + private javax.swing.JScrollPane jScrollPane2; + // End of variables declaration//GEN-END:variables +} diff --git a/src/gui/jp99.form b/src/opensesim/gui/jp99.form similarity index 97% rename from src/gui/jp99.form rename to src/opensesim/gui/jp99.form index 48abb80..34ebfb0 100644 --- a/src/gui/jp99.form +++ b/src/opensesim/gui/jp99.form @@ -38,7 +38,7 @@ - + diff --git a/src/gui/jp99.java b/src/opensesim/gui/jp99.java similarity index 94% rename from src/gui/jp99.java rename to src/opensesim/gui/jp99.java index b4065ef..96ea46d 100644 --- a/src/gui/jp99.java +++ b/src/opensesim/gui/jp99.java @@ -3,7 +3,7 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package gui; +package opensesim.gui; /** * @@ -28,7 +28,7 @@ public class jp99 extends javax.swing.JPanel { private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane(); - chart11 = new sesim.ChartPanel(); + chart11 = new opensesim.old_sesim.ChartPanel(); javax.swing.GroupLayout chart11Layout = new javax.swing.GroupLayout(chart11); chart11.setLayout(chart11Layout); @@ -63,7 +63,7 @@ public class jp99 extends javax.swing.JPanel { // Variables declaration - do not modify//GEN-BEGIN:variables - private sesim.ChartPanel chart11; + private opensesim.old_sesim.ChartPanel chart11; private javax.swing.JScrollPane jScrollPane1; // End of variables declaration//GEN-END:variables } diff --git a/src/gui/AboutDialog.form b/src/opensesim/gui/misc/AboutDialog.form similarity index 68% rename from src/gui/AboutDialog.form rename to src/opensesim/gui/misc/AboutDialog.form index 336d9b1..21d1cde 100644 --- a/src/gui/AboutDialog.form +++ b/src/opensesim/gui/misc/AboutDialog.form @@ -3,6 +3,7 @@
+ @@ -27,7 +28,7 @@ - + @@ -37,7 +38,7 @@ - + @@ -61,7 +62,7 @@ - + diff --git a/src/gui/AboutDialog.java b/src/opensesim/gui/misc/AboutDialog.java similarity index 80% rename from src/gui/AboutDialog.java rename to src/opensesim/gui/misc/AboutDialog.java index 35b6cd4..86dc7c0 100644 --- a/src/gui/AboutDialog.java +++ b/src/opensesim/gui/misc/AboutDialog.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui; +package opensesim.gui.misc; /** * @@ -54,11 +54,12 @@ public class AboutDialog extends javax.swing.JDialog { jButton1 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setTitle("About OpenSeSim"); setMinimumSize(new java.awt.Dimension(400, 300)); jTextPane1.setEditable(false); jTextPane1.setFont(jTextPane1.getFont()); - jTextPane1.setText("SeSim - Stock Exchange Simulator - Version 0.1\n\n\nCopyright (c) 2017, 7u83 <7u83@mail.ru>\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\n* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n\n* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"); + jTextPane1.setText("OpenSeSim - Open Source Stock Exchange Simulator - Version 0.1\n\n\nCopyright (c) 2017, 7u83 <7u83@mail.ru>\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\n* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n\n* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"); jScrollPane1.setViewportView(jTextPane1); jButton1.setMnemonic('c'); @@ -74,7 +75,7 @@ public class AboutDialog extends javax.swing.JDialog { layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addContainerGap(547, Short.MAX_VALUE) + .addContainerGap(549, Short.MAX_VALUE) .addComponent(jButton1) .addContainerGap()) .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) @@ -82,7 +83,7 @@ public class AboutDialog extends javax.swing.JDialog { layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 472, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 490, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) diff --git a/src/gui/orderbook/OrderBook.form b/src/opensesim/gui/orderbook/OrderBook.form similarity index 100% rename from src/gui/orderbook/OrderBook.form rename to src/opensesim/gui/orderbook/OrderBook.form diff --git a/src/gui/orderbook/OrderBook.java b/src/opensesim/gui/orderbook/OrderBook.java similarity index 96% rename from src/gui/orderbook/OrderBook.java rename to src/opensesim/gui/orderbook/OrderBook.java index bf35468..d840be2 100644 --- a/src/gui/orderbook/OrderBook.java +++ b/src/opensesim/gui/orderbook/OrderBook.java @@ -23,11 +23,11 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui.orderbook; +package opensesim.gui.orderbook; -import gui.Globals; -import gui.Globals.CfgListener; -import gui.tools.NummericCellRenderer; +import opensesim.gui.Globals; +import opensesim.gui.Globals.CfgListener; +import opensesim.gui.tools.NummericCellRenderer; import java.awt.Component; import java.text.DecimalFormat; import java.util.ArrayList; @@ -40,9 +40,9 @@ import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; import javax.swing.table.TableColumnModel; -import sesim.Exchange; -import sesim.Order; -import sesim.Order.OrderType; +import opensesim.old_sesim.Exchange; +import opensesim.old_sesim.Order; +import opensesim.old_sesim.Order.OrderType; /** * diff --git a/src/gui/orderbook/OrderBookDialog.form b/src/opensesim/gui/orderbook/OrderBookDialog.form similarity index 100% rename from src/gui/orderbook/OrderBookDialog.form rename to src/opensesim/gui/orderbook/OrderBookDialog.form diff --git a/src/gui/orderbook/OrderBookDialog.java b/src/opensesim/gui/orderbook/OrderBookDialog.java similarity index 97% rename from src/gui/orderbook/OrderBookDialog.java rename to src/opensesim/gui/orderbook/OrderBookDialog.java index 872b84d..f25a0e3 100644 --- a/src/gui/orderbook/OrderBookDialog.java +++ b/src/opensesim/gui/orderbook/OrderBookDialog.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui.orderbook; +package opensesim.gui.orderbook; /** * @@ -49,7 +49,7 @@ public class OrderBookDialog extends javax.swing.JDialog { // //GEN-BEGIN:initComponents private void initComponents() { - books = new gui.orderbook.OrderBooksHorizontal(); + books = new opensesim.gui.orderbook.OrderBooksHorizontal(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); @@ -116,6 +116,6 @@ public class OrderBookDialog extends javax.swing.JDialog { } // Variables declaration - do not modify//GEN-BEGIN:variables - private gui.orderbook.OrderBooksHorizontal books; + private opensesim.gui.orderbook.OrderBooksHorizontal books; // End of variables declaration//GEN-END:variables } diff --git a/src/gui/orderbook/OrderBooksHorizontal.form b/src/opensesim/gui/orderbook/OrderBooksHorizontal.form similarity index 95% rename from src/gui/orderbook/OrderBooksHorizontal.form rename to src/opensesim/gui/orderbook/OrderBooksHorizontal.form index 5f7d304..c06e60e 100644 --- a/src/gui/orderbook/OrderBooksHorizontal.form +++ b/src/opensesim/gui/orderbook/OrderBooksHorizontal.form @@ -48,7 +48,7 @@ - + @@ -61,7 +61,7 @@ - + @@ -95,7 +95,7 @@ - + diff --git a/src/gui/orderbook/OrderBooksHorizontal.java b/src/opensesim/gui/orderbook/OrderBooksHorizontal.java similarity index 92% rename from src/gui/orderbook/OrderBooksHorizontal.java rename to src/opensesim/gui/orderbook/OrderBooksHorizontal.java index 09bcdd9..f382351 100644 --- a/src/gui/orderbook/OrderBooksHorizontal.java +++ b/src/opensesim/gui/orderbook/OrderBooksHorizontal.java @@ -23,11 +23,11 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui.orderbook; +package opensesim.gui.orderbook; -import gui.Globals; -import sesim.Exchange; -import sesim.Order.OrderType; +import opensesim.gui.Globals; +import opensesim.old_sesim.Exchange; +import opensesim.old_sesim.Order.OrderType; /** * @@ -62,11 +62,11 @@ public class OrderBooksHorizontal extends javax.swing.JPanel { private void initComponents() { bidBookPanel = new javax.swing.JPanel(); - bidBook = new gui.orderbook.OrderBook(); + bidBook = new opensesim.gui.orderbook.OrderBook(); jLabel2 = new javax.swing.JLabel(); - quoteVertical2 = new gui.orderbook.QuoteVertical(); + quoteVertical2 = new opensesim.gui.orderbook.QuoteVertical(); askBookPanel = new javax.swing.JPanel(); - askBook = new gui.orderbook.OrderBook(); + askBook = new opensesim.gui.orderbook.OrderBook(); jLabel1 = new javax.swing.JLabel(); setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.LINE_AXIS)); @@ -131,12 +131,12 @@ public class OrderBooksHorizontal extends javax.swing.JPanel { // Variables declaration - do not modify//GEN-BEGIN:variables - private gui.orderbook.OrderBook askBook; + private opensesim.gui.orderbook.OrderBook askBook; private javax.swing.JPanel askBookPanel; - private gui.orderbook.OrderBook bidBook; + private opensesim.gui.orderbook.OrderBook bidBook; private javax.swing.JPanel bidBookPanel; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; - private gui.orderbook.QuoteVertical quoteVertical2; + private opensesim.gui.orderbook.QuoteVertical quoteVertical2; // End of variables declaration//GEN-END:variables } diff --git a/src/gui/orderbook/QuoteVertical.form b/src/opensesim/gui/orderbook/QuoteVertical.form similarity index 100% rename from src/gui/orderbook/QuoteVertical.form rename to src/opensesim/gui/orderbook/QuoteVertical.form diff --git a/src/gui/orderbook/QuoteVertical.java b/src/opensesim/gui/orderbook/QuoteVertical.java similarity index 97% rename from src/gui/orderbook/QuoteVertical.java rename to src/opensesim/gui/orderbook/QuoteVertical.java index 819309f..2ce4030 100644 --- a/src/gui/orderbook/QuoteVertical.java +++ b/src/opensesim/gui/orderbook/QuoteVertical.java @@ -23,12 +23,12 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui.orderbook; +package opensesim.gui.orderbook; -import gui.Globals; +import opensesim.gui.Globals; import java.text.DecimalFormat; -import sesim.Exchange.QuoteReceiver; -import sesim.Quote; +import opensesim.old_sesim.Exchange.QuoteReceiver; +import opensesim.old_sesim.Quote; /** * diff --git a/src/gui/orderbook/QutoesHorizontal.form b/src/opensesim/gui/orderbook/QutoesHorizontal.form similarity index 100% rename from src/gui/orderbook/QutoesHorizontal.form rename to src/opensesim/gui/orderbook/QutoesHorizontal.form diff --git a/src/gui/orderbook/QutoesHorizontal.java b/src/opensesim/gui/orderbook/QutoesHorizontal.java similarity index 98% rename from src/gui/orderbook/QutoesHorizontal.java rename to src/opensesim/gui/orderbook/QutoesHorizontal.java index c299029..82dfe42 100644 --- a/src/gui/orderbook/QutoesHorizontal.java +++ b/src/opensesim/gui/orderbook/QutoesHorizontal.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui.orderbook; +package opensesim.gui.orderbook; /** * diff --git a/src/gui/tools/NummericCellRenderer.java b/src/opensesim/gui/tools/NummericCellRenderer.java similarity index 98% rename from src/gui/tools/NummericCellRenderer.java rename to src/opensesim/gui/tools/NummericCellRenderer.java index 9cc6a72..d90aac9 100644 --- a/src/gui/tools/NummericCellRenderer.java +++ b/src/opensesim/gui/tools/NummericCellRenderer.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package gui.tools; +package opensesim.gui.tools; import java.awt.Component; import java.text.DecimalFormat; diff --git a/src/opensesim/gui/util/JTextFieldLimit.java b/src/opensesim/gui/util/JTextFieldLimit.java new file mode 100644 index 0000000..34e6d3d --- /dev/null +++ b/src/opensesim/gui/util/JTextFieldLimit.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.gui.util; + +import javax.swing.JTextField; +import javax.swing.text.AttributeSet; +import javax.swing.text.BadLocationException; +import javax.swing.text.PlainDocument; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class JTextFieldLimit extends JTextField { + + /* JTextFieldLimit() { + super(); + this.setDocument(new PlainDocumentLimit()); + setLimit(0); + } + */ + private int limit; + + + public final void setLimit(int limit){ + this.limit = limit; + String text = getText(); + setDocument(new PlainDocumentLimit()); + setText(text); + } + + public final int getLimit(){ + return limit; + } + + class PlainDocumentLimit extends PlainDocument { + + //private int limit; + + PlainDocumentLimit() { + super(); + + } + + @Override + public void insertString(int offset, String str, AttributeSet attr) throws BadLocationException { + if (str == null) { + return; + } + if ((getLength() + str.length()) <= limit || limit==0) { + super.insertString(offset, str, attr); + } + } + } + +} diff --git a/src/indicators/BaseIndicator.java b/src/opensesim/indicators/BaseIndicator.java similarity index 93% rename from src/indicators/BaseIndicator.java rename to src/opensesim/indicators/BaseIndicator.java index 17b2cbf..f4605cb 100644 --- a/src/indicators/BaseIndicator.java +++ b/src/opensesim/indicators/BaseIndicator.java @@ -23,11 +23,11 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package indicators; +package opensesim.indicators; import org.json.JSONObject; -import sesim.ConfigurableInterface; -import sesim.Indicator; +import opensesim.old_sesim.ConfigurableInterface; +import opensesim.old_sesim.Indicator; /** * diff --git a/src/indicators/RSIIndicator.java b/src/opensesim/indicators/RSIIndicator.java similarity index 98% rename from src/indicators/RSIIndicator.java rename to src/opensesim/indicators/RSIIndicator.java index e3d235b..16f40e9 100644 --- a/src/indicators/RSIIndicator.java +++ b/src/opensesim/indicators/RSIIndicator.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package indicators; +package opensesim.indicators; /** diff --git a/src/indicators/SMAIndicator.java b/src/opensesim/indicators/SMAIndicator.java similarity index 91% rename from src/indicators/SMAIndicator.java rename to src/opensesim/indicators/SMAIndicator.java index 74c5812..d715178 100644 --- a/src/indicators/SMAIndicator.java +++ b/src/opensesim/indicators/SMAIndicator.java @@ -23,11 +23,11 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package indicators; +package opensesim.indicators; import org.json.JSONObject; -import sesim.OHLCData; -import sesim.OHLCDataItem; +import opensesim.old_sesim.OHLCData; +import opensesim.old_sesim.OHLCDataItem; /** * @@ -93,7 +93,7 @@ public class SMAIndicator extends BaseIndicator { int i = parent.size() - 1; OHLCDataItem p = parent.get(i); float pr = this.getAt(i); - OHLCDataItem it = new sesim.OHLCDataItem(p.time, pr, 0); + OHLCDataItem it = new opensesim.old_sesim.OHLCDataItem(p.time, pr, 0); this.indicator.set(i, it); return; } @@ -101,7 +101,7 @@ public class SMAIndicator extends BaseIndicator { for (int i = indicator.size(); i < parent.size(); i++) { OHLCDataItem p = parent.get(i); float pr = this.getAt(i); - OHLCDataItem it = new sesim.OHLCDataItem(p.time, pr, 0); + OHLCDataItem it = new opensesim.old_sesim.OHLCDataItem(p.time, pr, 0); this.indicator.add(it); diff --git a/src/sesim/Account.java b/src/opensesim/old_sesim/Account.java similarity index 99% rename from src/sesim/Account.java rename to src/opensesim/old_sesim/Account.java index b171e86..d9619dd 100644 --- a/src/sesim/Account.java +++ b/src/opensesim/old_sesim/Account.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package sesim; +package opensesim.old_sesim; import java.util.concurrent.ConcurrentHashMap; diff --git a/src/sesim/AutoTraderBase.java b/src/opensesim/old_sesim/AutoTraderBase.java similarity index 97% rename from src/sesim/AutoTraderBase.java rename to src/opensesim/old_sesim/AutoTraderBase.java index 8db8d34..29e26ae 100644 --- a/src/sesim/AutoTraderBase.java +++ b/src/opensesim/old_sesim/AutoTraderBase.java @@ -23,10 +23,10 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package sesim; +package opensesim.old_sesim; import org.json.JSONObject; -import sesim.Scheduler.TimerTaskRunner; +import opensesim.old_sesim.Scheduler.TimerTaskRunner; /** * diff --git a/src/sesim/AutoTraderGui.java b/src/opensesim/old_sesim/AutoTraderGui.java similarity index 98% rename from src/sesim/AutoTraderGui.java rename to src/opensesim/old_sesim/AutoTraderGui.java index 926a579..798d409 100644 --- a/src/sesim/AutoTraderGui.java +++ b/src/opensesim/old_sesim/AutoTraderGui.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package sesim; +package opensesim.old_sesim; import javax.swing.JPanel; diff --git a/src/sesim/AutoTraderInterface.java b/src/opensesim/old_sesim/AutoTraderInterface.java similarity index 98% rename from src/sesim/AutoTraderInterface.java rename to src/opensesim/old_sesim/AutoTraderInterface.java index a1bf2ce..08eea61 100644 --- a/src/sesim/AutoTraderInterface.java +++ b/src/opensesim/old_sesim/AutoTraderInterface.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package sesim; +package opensesim.old_sesim; import javax.swing.JDialog; import org.json.JSONObject; diff --git a/src/sesim/AutoTraderLoader.java b/src/opensesim/old_sesim/AutoTraderLoader.java similarity index 98% rename from src/sesim/AutoTraderLoader.java rename to src/opensesim/old_sesim/AutoTraderLoader.java index 199fcc1..f919205 100644 --- a/src/sesim/AutoTraderLoader.java +++ b/src/opensesim/old_sesim/AutoTraderLoader.java @@ -23,9 +23,9 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package sesim; +package opensesim.old_sesim; -import gui.Globals; +import opensesim.gui.Globals; import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; diff --git a/src/sesim/ChartDef.java b/src/opensesim/old_sesim/ChartDef.java similarity index 98% rename from src/sesim/ChartDef.java rename to src/opensesim/old_sesim/ChartDef.java index 31a5c0f..1609a52 100644 --- a/src/sesim/ChartDef.java +++ b/src/opensesim/old_sesim/ChartDef.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package sesim; +package opensesim.old_sesim; import javax.swing.JScrollBar; diff --git a/src/sesim/ChartPainterInterface.java b/src/opensesim/old_sesim/ChartPainterInterface.java similarity index 98% rename from src/sesim/ChartPainterInterface.java rename to src/opensesim/old_sesim/ChartPainterInterface.java index 2d92393..eee3344 100644 --- a/src/sesim/ChartPainterInterface.java +++ b/src/opensesim/old_sesim/ChartPainterInterface.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package sesim; +package opensesim.old_sesim; import java.awt.Graphics2D; diff --git a/src/sesim/ChartPanel.form b/src/opensesim/old_sesim/ChartPanel.form similarity index 100% rename from src/sesim/ChartPanel.form rename to src/opensesim/old_sesim/ChartPanel.form diff --git a/src/sesim/ChartPanel.java b/src/opensesim/old_sesim/ChartPanel.java similarity index 97% rename from src/sesim/ChartPanel.java rename to src/opensesim/old_sesim/ChartPanel.java index f282b3b..a7f0bd2 100644 --- a/src/sesim/ChartPanel.java +++ b/src/opensesim/old_sesim/ChartPanel.java @@ -1,7 +1,7 @@ -package sesim; +package opensesim.old_sesim; -import chart.painter.ChartPainter; -import gui.Globals; +import opensesim.chart.painter.ChartPainter; +import opensesim.gui.Globals; import java.awt.Cursor; diff --git a/src/sesim/ConfigurableInterface.java b/src/opensesim/old_sesim/ConfigurableInterface.java similarity index 95% rename from src/sesim/ConfigurableInterface.java rename to src/opensesim/old_sesim/ConfigurableInterface.java index e31261d..1611129 100644 --- a/src/sesim/ConfigurableInterface.java +++ b/src/opensesim/old_sesim/ConfigurableInterface.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, tube + * Copyright (c) 2017, 7u83 <7u83@mail.ru> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,13 +23,13 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package sesim; +package opensesim.old_sesim; import org.json.JSONObject; /** * - * @author tube + * @author 7u83 */ public abstract interface ConfigurableInterface { diff --git a/src/sesim/Exchange.java b/src/opensesim/old_sesim/Exchange.java similarity index 99% rename from src/sesim/Exchange.java rename to src/opensesim/old_sesim/Exchange.java index ae450f9..d86ab2c 100644 --- a/src/sesim/Exchange.java +++ b/src/opensesim/old_sesim/Exchange.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package sesim; +package opensesim.old_sesim; import java.text.DecimalFormat; import java.util.*; @@ -35,11 +35,11 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.json.JSONArray; import org.json.JSONObject; -import sesim.Order.OrderStatus; -import sesim.Order.OrderType; +import opensesim.old_sesim.Order.OrderStatus; +import opensesim.old_sesim.Order.OrderType; /** - * @desc Echchange class + * @desc Exchange class * @author 7u83 */ public class Exchange { diff --git a/src/sesim/IDGenerator.java b/src/opensesim/old_sesim/IDGenerator.java similarity index 98% rename from src/sesim/IDGenerator.java rename to src/opensesim/old_sesim/IDGenerator.java index 4c6fa30..bf5ff57 100644 --- a/src/sesim/IDGenerator.java +++ b/src/opensesim/old_sesim/IDGenerator.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package sesim; +package opensesim.old_sesim; /** * Implementation of a simple ID generator to create uniqe IDs of type long diff --git a/src/sesim/Indicator.java b/src/opensesim/old_sesim/Indicator.java similarity index 98% rename from src/sesim/Indicator.java rename to src/opensesim/old_sesim/Indicator.java index ba38816..a4c447d 100644 --- a/src/sesim/Indicator.java +++ b/src/opensesim/old_sesim/Indicator.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package sesim; +package opensesim.old_sesim; /** * diff --git a/src/sesim/IndicatorLoader.java b/src/opensesim/old_sesim/IndicatorLoader.java similarity index 98% rename from src/sesim/IndicatorLoader.java rename to src/opensesim/old_sesim/IndicatorLoader.java index fbcecac..3d527e5 100644 --- a/src/sesim/IndicatorLoader.java +++ b/src/opensesim/old_sesim/IndicatorLoader.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package sesim; +package opensesim.old_sesim; import java.util.ArrayList; diff --git a/src/sesim/Locker.java b/src/opensesim/old_sesim/Locker.java similarity index 98% rename from src/sesim/Locker.java rename to src/opensesim/old_sesim/Locker.java index 22799e0..1ba0ae9 100644 --- a/src/sesim/Locker.java +++ b/src/opensesim/old_sesim/Locker.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package sesim; +package opensesim.old_sesim; import java.util.concurrent.Semaphore; diff --git a/src/sesim/Logger.java b/src/opensesim/old_sesim/Logger.java similarity index 93% rename from src/sesim/Logger.java rename to src/opensesim/old_sesim/Logger.java index ad0beae..36f12a6 100644 --- a/src/sesim/Logger.java +++ b/src/opensesim/old_sesim/Logger.java @@ -1,4 +1,4 @@ -package sesim; +package opensesim.old_sesim; public class Logger { diff --git a/src/sesim/MinMax.java b/src/opensesim/old_sesim/MinMax.java similarity index 98% rename from src/sesim/MinMax.java rename to src/opensesim/old_sesim/MinMax.java index 390b66f..9a52676 100644 --- a/src/sesim/MinMax.java +++ b/src/opensesim/old_sesim/MinMax.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package sesim; +package opensesim.old_sesim; /** * diff --git a/src/sesim/OHLCData.java b/src/opensesim/old_sesim/OHLCData.java similarity index 99% rename from src/sesim/OHLCData.java rename to src/opensesim/old_sesim/OHLCData.java index 0ec2ec8..9ce3a55 100644 --- a/src/sesim/OHLCData.java +++ b/src/opensesim/old_sesim/OHLCData.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package sesim; +package opensesim.old_sesim; import java.util.*; diff --git a/src/sesim/OHLCDataItem.java b/src/opensesim/old_sesim/OHLCDataItem.java similarity index 98% rename from src/sesim/OHLCDataItem.java rename to src/opensesim/old_sesim/OHLCDataItem.java index 28568fc..bd5f51d 100644 --- a/src/sesim/OHLCDataItem.java +++ b/src/opensesim/old_sesim/OHLCDataItem.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package sesim; +package opensesim.old_sesim; /** * diff --git a/src/sesim/OHLCDataProvider.java b/src/opensesim/old_sesim/OHLCDataProvider.java similarity index 98% rename from src/sesim/OHLCDataProvider.java rename to src/opensesim/old_sesim/OHLCDataProvider.java index 71f30cb..03378e9 100644 --- a/src/sesim/OHLCDataProvider.java +++ b/src/opensesim/old_sesim/OHLCDataProvider.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package sesim; +package opensesim.old_sesim; /** * diff --git a/src/sesim/Order.java b/src/opensesim/old_sesim/Order.java similarity index 99% rename from src/sesim/Order.java rename to src/opensesim/old_sesim/Order.java index fb23284..16c833a 100644 --- a/src/sesim/Order.java +++ b/src/opensesim/old_sesim/Order.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package sesim; +package opensesim.old_sesim; /** * diff --git a/src/sesim/Quote.java b/src/opensesim/old_sesim/Quote.java similarity index 98% rename from src/sesim/Quote.java rename to src/opensesim/old_sesim/Quote.java index 7e45132..e5507bb 100644 --- a/src/sesim/Quote.java +++ b/src/opensesim/old_sesim/Quote.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package sesim; +package opensesim.old_sesim; /** * diff --git a/src/sesim/Scheduler.java b/src/opensesim/old_sesim/Scheduler.java similarity index 99% rename from src/sesim/Scheduler.java rename to src/opensesim/old_sesim/Scheduler.java index abc4183..30b0f00 100644 --- a/src/sesim/Scheduler.java +++ b/src/opensesim/old_sesim/Scheduler.java @@ -23,10 +23,10 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package sesim; +package opensesim.old_sesim; //import static com.sun.org.apache.xalan.internal.lib.ExsltDatetime.date; -import gui.Globals; +import opensesim.gui.Globals; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Comparator; diff --git a/src/sesim/SeSimClassLoader.java b/src/opensesim/old_sesim/SeSimClassLoader.java similarity index 97% rename from src/sesim/SeSimClassLoader.java rename to src/opensesim/old_sesim/SeSimClassLoader.java index ac0f94c..2d3da23 100644 --- a/src/sesim/SeSimClassLoader.java +++ b/src/opensesim/old_sesim/SeSimClassLoader.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package sesim; +package opensesim.old_sesim; import java.io.File; import java.io.FileInputStream; @@ -109,7 +109,7 @@ public class SeSimClassLoader { * Create a new instance of specified class * * @param cls Class to create an instance of - * @return the instance, null if not successfull + * @return the instance, null if not successful */ public Object newInstance(Class cls) { try { @@ -121,7 +121,7 @@ public class SeSimClassLoader { /** * Check if a given class provides a certain interface and also if the class - * is not abstract, so it could be instanciated. + * is not abstract, so it could be instantiated. * * @param cls Class to check * @param iface Interface which the class should provide @@ -183,6 +183,8 @@ public class SeSimClassLoader { } catch (ClassNotFoundException ex) { return null; + } catch (NoClassDefFoundError e){ + return null; } } diff --git a/src/sesim/Stock.java b/src/opensesim/old_sesim/Stock.java similarity index 98% rename from src/sesim/Stock.java rename to src/opensesim/old_sesim/Stock.java index adbacf2..cabdd59 100644 --- a/src/sesim/Stock.java +++ b/src/opensesim/old_sesim/Stock.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package sesim; +package opensesim.old_sesim; import java.util.ArrayList; import java.util.HashMap; @@ -73,7 +73,7 @@ public class Stock { // protected ConcurrentLinkedQueue order_queue = new ConcurrentLinkedQueue(); /** - * Histrory of quotes + * History of quotes */ public TreeSet quoteHistory; diff --git a/src/resources/TOC.xml b/src/opensesim/resources/TOC.xml similarity index 85% rename from src/resources/TOC.xml rename to src/opensesim/resources/TOC.xml index a3e7080..7cf5208 100644 --- a/src/resources/TOC.xml +++ b/src/opensesim/resources/TOC.xml @@ -6,8 +6,9 @@ "http://java.sun.com/products/javahelp/toc_2_0.dtd"> - Introduction to JDE Online Help /> + text="OpenSeSim - Stock Exchange Simulator"> + + diff --git a/src/resources/files/defaultcfg.json b/src/opensesim/resources/files/defaultcfg.json similarity index 95% rename from src/resources/files/defaultcfg.json rename to src/opensesim/resources/files/defaultcfg.json index 40824d6..1800095 100644 --- a/src/resources/files/defaultcfg.json +++ b/src/opensesim/resources/files/defaultcfg.json @@ -54,7 +54,7 @@ -2, 2 ], - "base": "traders.RandomTraderA" + "base": "opensesim.traders.RandomTraderA" }}, "version": 0.1 } \ No newline at end of file diff --git a/src/resources/helpset.hs b/src/opensesim/resources/helpset.hs similarity index 98% rename from src/resources/helpset.hs rename to src/opensesim/resources/helpset.hs index e8ea281..35140fb 100644 --- a/src/resources/helpset.hs +++ b/src/opensesim/resources/helpset.hs @@ -16,7 +16,7 @@ TOC - + javax.help.TOCView TOC.xml diff --git a/src/resources/icons/pause.gif b/src/opensesim/resources/icons/pause.gif similarity index 100% rename from src/resources/icons/pause.gif rename to src/opensesim/resources/icons/pause.gif diff --git a/src/resources/icons/run.gif b/src/opensesim/resources/icons/run.gif similarity index 100% rename from src/resources/icons/run.gif rename to src/opensesim/resources/icons/run.gif diff --git a/src/resources/icons/stop.gif b/src/opensesim/resources/icons/stop.gif similarity index 100% rename from src/resources/icons/stop.gif rename to src/opensesim/resources/icons/stop.gif diff --git a/src/opensesim/sesim/AssetPair.java b/src/opensesim/sesim/AssetPair.java new file mode 100644 index 0000000..4faddc9 --- /dev/null +++ b/src/opensesim/sesim/AssetPair.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.sesim; + +import java.util.HashMap; +import java.util.SortedSet; +import java.util.TreeSet; +import opensesim.AbstractAsset; +import opensesim.sesim.Assets.BasicAsset; +import opensesim.sesim.interfaces.Asset; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class AssetPair { + + private final AbstractAsset asset; + private final AbstractAsset currency; + + public AbstractAsset getAsset() { + return asset; + } + + public AbstractAsset getCurrency() { + return currency; + } + + public String getSymbol() { + return asset.getSymbol() + "/" + currency.getSymbol(); + } + + public AssetPair(AbstractAsset asset, AbstractAsset currency) { + this.asset = asset; + this.currency = currency; + + } + + protected HashMap> order_books; + + public final void reset() { + order_books = new HashMap(); + + // Create an order book for each order type + for (Order.Type type : Order.Type.values()) { + // order_books.put(type, new TreeSet(new Exchange.OrderComparator(type))); + order_books.put(type, new TreeSet<>()); + } + + // quoteHistory = new TreeSet(); + // ohlc_data = new HashMap(); + } + + + + @Override + public boolean equals(Object o) { + AssetPair ap = (AssetPair)o; + if (ap.asset==asset && ap.currency==currency) + return true; + if (ap.asset==currency && ap.currency==asset) + return false; + return true; + } + + + +} diff --git a/src/opensesim/sesim/Assets/BasicAsset.java b/src/opensesim/sesim/Assets/BasicAsset.java new file mode 100644 index 0000000..3d38c82 --- /dev/null +++ b/src/opensesim/sesim/Assets/BasicAsset.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.sesim.Assets; + + +import javax.swing.JPanel; +import opensesim.AbstractAsset; + +/** + * Defines an asset + * + * @author 7u83 + */ +public class BasicAsset extends AbstractAsset { + + public String getTypeName() { + return "Basic from Abstract"; + } + + + public JPanel getEditGui() { + return null; + } + + + + + + + + + + + + + +} diff --git a/src/opensesim/sesim/Assets/CurrencyAsset.java b/src/opensesim/sesim/Assets/CurrencyAsset.java new file mode 100644 index 0000000..22975e2 --- /dev/null +++ b/src/opensesim/sesim/Assets/CurrencyAsset.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.sesim.Assets; + +import opensesim.AbstractAsset; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class CurrencyAsset extends AbstractAsset { + + @Override + public String getTypeName() { + return "Currency"; + } + + @Override + public boolean isCurrency() { + return true; + } + + @Override + public boolean isAsset(){ + return true; + } + +} diff --git a/src/opensesim/sesim/Assets/FurtureAsset.java b/src/opensesim/sesim/Assets/FurtureAsset.java new file mode 100644 index 0000000..d0e6675 --- /dev/null +++ b/src/opensesim/sesim/Assets/FurtureAsset.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.sesim.Assets; + +import javax.swing.JPanel; +import opensesim.AbstractAsset; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class FurtureAsset extends AbstractAsset{ + @Override + public String getTypeName(){ + return "Future"; + } + + public JPanel getEditGui(){ + return new FutureAssetEditGui(); + } + + @Override + public boolean isAsset() { + return true; + } +} diff --git a/src/opensesim/sesim/Assets/FutureAssetEditGui.form b/src/opensesim/sesim/Assets/FutureAssetEditGui.form new file mode 100644 index 0000000..5316d9a --- /dev/null +++ b/src/opensesim/sesim/Assets/FutureAssetEditGui.form @@ -0,0 +1,198 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/opensesim/sesim/Assets/FutureAssetEditGui.java b/src/opensesim/sesim/Assets/FutureAssetEditGui.java new file mode 100644 index 0000000..1622551 --- /dev/null +++ b/src/opensesim/sesim/Assets/FutureAssetEditGui.java @@ -0,0 +1,180 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.sesim.Assets; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class FutureAssetEditGui extends javax.swing.JPanel { + + /** + * Creates new form FutureAssetEditGui + */ + public FutureAssetEditGui() { + initComponents(); + } + + /** + * 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. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jLabel1 = new javax.swing.JLabel(); + jTextField1 = new javax.swing.JTextField(); + jTextField2 = new javax.swing.JTextField(); + jLabel2 = new javax.swing.JLabel(); + jComboBox1 = new javax.swing.JComboBox<>(); + jLabel3 = new javax.swing.JLabel(); + jLabel4 = new javax.swing.JLabel(); + jTextField3 = new javax.swing.JTextField(); + jComboBox2 = new javax.swing.JComboBox<>(); + jRadioButton1 = new javax.swing.JRadioButton(); + jScrollPane1 = new javax.swing.JScrollPane(); + jTextArea1 = new javax.swing.JTextArea(); + jPasswordField1 = new javax.swing.JPasswordField(); + jTextField4 = new javax.swing.JTextField(); + + jLabel1.setText("Duration:"); + + jLabel2.setText("Settlement:"); + + jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Cash Settlement", "Physical Delivery" })); + + jLabel3.setText("Underlying:"); + + jLabel4.setText("Contract size:"); + + jComboBox2.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); + + jRadioButton1.setText("jRadioButton1"); + + jTextArea1.setColumns(20); + jTextArea1.setRows(5); + jScrollPane1.setViewportView(jTextArea1); + + jPasswordField1.setText("jPasswordField1"); + + jTextField4.setText("jTextField4"); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) + .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE) + .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jTextField2) + .addComponent(jTextField1))) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jTextField3) + .addComponent(jComboBox1, 0, 520, Short.MAX_VALUE))) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(32, 32, 32) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap()) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(jRadioButton1) + .addGap(77, 77, 77)))) + .addGroup(layout.createSequentialGroup() + .addGap(50, 50, 50) + .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(0, 0, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(206, 206, 206)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel3) + .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel1) + .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel2) + .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(9, 9, 9) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel4) + .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(49, 49, 49) + .addComponent(jRadioButton1) + .addGap(52, 52, 52) + .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 75, Short.MAX_VALUE) + .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(73, 73, 73) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addContainerGap()) + ); + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JComboBox jComboBox1; + private javax.swing.JComboBox jComboBox2; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; + private javax.swing.JPasswordField jPasswordField1; + private javax.swing.JRadioButton jRadioButton1; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTextArea jTextArea1; + private javax.swing.JTextField jTextField1; + private javax.swing.JTextField jTextField2; + private javax.swing.JTextField jTextField3; + private javax.swing.JTextField jTextField4; + // End of variables declaration//GEN-END:variables +} diff --git a/src/opensesim/sesim/Assets/StockAssett.java b/src/opensesim/sesim/Assets/StockAssett.java new file mode 100644 index 0000000..df34184 --- /dev/null +++ b/src/opensesim/sesim/Assets/StockAssett.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.sesim.Assets; + +import opensesim.AbstractAsset; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class StockAssett extends AbstractAsset{ + + @Override + public String getTypeName() { + return "Stock"; + } + + @Override + public boolean isAsset() { + return true; + } + +} diff --git a/src/opensesim/sesim/Assets/WarrentAsset.java b/src/opensesim/sesim/Assets/WarrentAsset.java new file mode 100644 index 0000000..e74e8f5 --- /dev/null +++ b/src/opensesim/sesim/Assets/WarrentAsset.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.sesim.Assets; + +import opensesim.AbstractAsset; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class WarrentAsset extends AbstractAsset{ + @Override + public String getTypeName(){ + return "Warrent"; + } + + @Override + public boolean isAsset() { + return true; + } +} diff --git a/src/opensesim/sesim/Order.java b/src/opensesim/sesim/Order.java new file mode 100644 index 0000000..d0b2e49 --- /dev/null +++ b/src/opensesim/sesim/Order.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.sesim; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class Order implements Comparable{ + + @Override + public int compareTo(Object o) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + /** + * Order status + */ + public enum Status { + OPEN, PARTIALLY_EXECUTED, CLOSED, CANCELED + } + + /** + * Definition of order types + */ + public enum Type { + BUYLIMIT, SELLLIMIT, STOPLOSS, STOPBUY, BUY, SELL + } + + protected double limit; + protected double volume; + + public double getLimit() { + return limit; + } + + public double getVolume() { + return volume; + } + + AssetPair assetPair; + + +} diff --git a/src/opensesim/sesim/SeSimClassLoader.java b/src/opensesim/sesim/SeSimClassLoader.java new file mode 100644 index 0000000..0700956 --- /dev/null +++ b/src/opensesim/sesim/SeSimClassLoader.java @@ -0,0 +1,294 @@ +/* + * Copyright (c) 2017, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.sesim; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.lang.reflect.Modifier; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.jar.JarEntry; +import java.util.jar.JarInputStream; +import java.util.logging.Level; + +/** + * + * @author 7u83 <7u83@mail.ru> + * @param + */ +public class SeSimClassLoader { + + protected ArrayList default_pathlist; + private ArrayList> cache; + final Class class_type; + + /** + * Create a SeSimClassLoader object with an empty default path + * + * @param class_type + */ + public SeSimClassLoader(Class class_type) { + this(class_type, new ArrayList<>()); + } + + /** + * Create a SeSimClassLoader object with given default path + * + * @param class_type + * @param pathlist Default path to search classes for + */ + public SeSimClassLoader(Class class_type, ArrayList pathlist) { + this.class_type = class_type; + setDefaultPathList(pathlist); + } + + /** + * Set the path list where to search for classes + * + * @param pathlist List of paths + */ + public final void setDefaultPathList(ArrayList pathlist) { + this.default_pathlist = pathlist; + + } + + /** + * Get a list of all files in a given directory and its sub-directories. + * + * @param path Directory to list + * @return List of files + */ + public ArrayList listFiles(String path) { + + ArrayList files = new ArrayList<>(); + + File fp = new File(path); + if (!fp.isDirectory()) { + files.add(fp); + return files; + } + + File[] fList = new File(path).listFiles(); + + for (File file : fList) { + if (file.isFile()) { + files.add(file); + } else if (file.isDirectory()) { + files.addAll(listFiles(file.getAbsolutePath())); + } + } + return files; + } + + /** + * Create a new instance of specified class + * + * @param cls Class to create an instance of + * @return the instance, null if not successful + */ + public Object newInstance(Class cls) { + try { + return cls.newInstance(); + } catch (InstantiationException | IllegalAccessException ex) { + return null; + } + } + + /** + * Check if a given class provides a certain interface and also if the class + * is not abstract, so it could be instantiated. + * + * @param cls Class to check + * @param iface Interface which the class should provide + * @return true if it is an instance of insclass, otherwise false + */ + public boolean hasInterface(Class cls, Class iface) { + + if (Modifier.isAbstract(cls.getModifiers())) { + return false; + } + + do { + + for (Class i : cls.getInterfaces()) { + if (i == iface) { + return true; + } + } + + } while ((cls = cls.getSuperclass()) != null); + return false; + } + + private Class loadClass(String directory, String class_name) { + + if (class_name == null) { + return null; + } + + URL url; + try { + url = new File(directory).toURI().toURL(); + + } catch (MalformedURLException ex) { + return null; + } + URL[] urls = new URL[]{url}; + + ClassLoader cl; + cl = new URLClassLoader(urls); + + try { + Class cls; + cls = cl.loadClass(class_name); + if (cls == null) { + return null; + } + + if (class_type != null) { + if (!hasInterface(cls, class_type)) { + return null; + } + } + +/* if (newInstance(cls) == null) { + return null; + } +*/ + return (Class) cls; + + } catch (ClassNotFoundException ex) { + return null; + } catch (NoClassDefFoundError ex){ + return null; + } + + } + + /** + * + * @param pathlist + * @return + */ + public ArrayList> getInstalledClasses0(ArrayList pathlist) { + + ArrayList> result = new ArrayList<>(); + + for (String path : pathlist) { + + ArrayList files = listFiles(path); + + for (File file : files) { + + String fn = file.toString(); + + if (fn.toLowerCase().endsWith(".class")) { + + String class_name; + class_name = fn.substring(path.length()); + // in case we are under Windows, replace \ width / + class_name = class_name.replace("\\", "/"); + class_name = class_name.substring(1, class_name.length() - 6).replace('/', '.'); + + Class c = loadClass(path, class_name); + if (null == c) { + continue; + } + result.add(c); + } + + if (fn.toLowerCase().endsWith(".jar")) { + JarInputStream jarstream = null; + try { + File jarfile = new File(fn); + jarstream = new JarInputStream(new FileInputStream(jarfile)); + JarEntry jarentry; + + while ((jarentry = jarstream.getNextJarEntry()) != null) { + + String class_name = jarentry.getName(); + + if (class_name.endsWith(".class")) { + + class_name = class_name.substring(0, class_name.length() - 6).replace('/', '.'); + Class c = loadClass(path, class_name); + if (null == c) { + continue; + } + result.add(c); + } + } + } catch (IOException ex) { + + } finally { + try { + if (jarstream != null) { + jarstream.close(); + } + } catch (IOException ex) { + // java.util.logging.Logger.getLogger(AutoTraderLoader.class.getName()).log(Level.SEVERE, null, ex); + } + } + + } + + } + + } + return result; + } + + /** + * Get a list of all traders found in class path + * + * @param additional_pathlist + * @return List of installed Classes + */ + public ArrayList> getInstalledClasses(ArrayList additional_pathlist ) { + + if (cache != null) { + return cache; + } + + ArrayList pathlist; + pathlist = new ArrayList<>(); + + pathlist.addAll(default_pathlist); + pathlist.addAll(additional_pathlist); + + cache = getInstalledClasses0(pathlist); + + return cache; + + } + + public ArrayList> getInstalledClasses(){ + return getInstalledClasses(new ArrayList<>()); + } +} diff --git a/src/opensesim/sesim/interfaces/Asset.java b/src/opensesim/sesim/interfaces/Asset.java new file mode 100644 index 0000000..2ddc700 --- /dev/null +++ b/src/opensesim/sesim/interfaces/Asset.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.sesim.interfaces; + +import java.util.HashMap; +import javax.swing.JPanel; +import opensesim.World; +import opensesim.util.IDGenerator; +import opensesim.util.IDGenerator.Id; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public interface Asset extends Configurable { + + static HashMap assetsById = new HashMap<>(); + static HashMap assetsBySymbol = new HashMap<>(); + static IDGenerator assetIdGenerator = new IDGenerator(); + + public String getSymbol(); + + public Id getID(); + + public Id setID(Id id); + + public JPanel getEditGui(); + + /** + * Indicate if this asset can act as currency + * + * @return true if currency, false no. + */ + public boolean isCurrency(); + + public String getTypeName(); + + // public Asset(Id); +} diff --git a/src/opensesim/sesim/interfaces/Configurable.java b/src/opensesim/sesim/interfaces/Configurable.java new file mode 100644 index 0000000..20b037d --- /dev/null +++ b/src/opensesim/sesim/interfaces/Configurable.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.sesim.interfaces; + +import org.json.JSONObject; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public interface Configurable { + + /** + * Get current configuration as JSON object. + * + * @return JSONObject containing the configuration + */ + public abstract JSONObject getConfig(); + + /** + * Set the configuration by a JSON object. + * + * @param cfg the configuration + */ + public abstract void putConfig(JSONObject cfg); + + +} + + diff --git a/src/opensesim/sesim/interfaces/Exchange.java b/src/opensesim/sesim/interfaces/Exchange.java new file mode 100644 index 0000000..a16f729 --- /dev/null +++ b/src/opensesim/sesim/interfaces/Exchange.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2018, tohe + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.sesim.interfaces; + +/** + * + * @author tohe + */ +public interface Exchange { + static enum OrderType{ + + } + +}; diff --git a/src/opensesim/sesim/interfaces/FeeModel.java b/src/opensesim/sesim/interfaces/FeeModel.java new file mode 100644 index 0000000..70de692 --- /dev/null +++ b/src/opensesim/sesim/interfaces/FeeModel.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.sesim.interfaces; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public interface FeeModel { + double getTakerFee(double x); + +} diff --git a/src/opensesim/sesim/interfaces/Indicator.java b/src/opensesim/sesim/interfaces/Indicator.java new file mode 100644 index 0000000..d3f6ed5 --- /dev/null +++ b/src/opensesim/sesim/interfaces/Indicator.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.sesim.interfaces; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public interface Indicator extends Configurable{ + public String getName(); + public String getDescription(); +} diff --git a/src/opensesim/sesim/interfaces/Trader.java b/src/opensesim/sesim/interfaces/Trader.java new file mode 100644 index 0000000..d0c74f8 --- /dev/null +++ b/src/opensesim/sesim/interfaces/Trader.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.sesim.interfaces; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public interface Trader { + String getName(); + +} diff --git a/src/traders/ManTrader/AccountBalance.form b/src/opensesim/traders/ManTrader/AccountBalance.form similarity index 100% rename from src/traders/ManTrader/AccountBalance.form rename to src/opensesim/traders/ManTrader/AccountBalance.form diff --git a/src/traders/ManTrader/AccountBalance.java b/src/opensesim/traders/ManTrader/AccountBalance.java similarity index 98% rename from src/traders/ManTrader/AccountBalance.java rename to src/opensesim/traders/ManTrader/AccountBalance.java index e912243..e926151 100644 --- a/src/traders/ManTrader/AccountBalance.java +++ b/src/opensesim/traders/ManTrader/AccountBalance.java @@ -23,9 +23,9 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package traders.ManTrader; +package opensesim.traders.ManTrader; -import sesim.Account; +import opensesim.old_sesim.Account; /** * diff --git a/src/traders/ManTrader/CreateOrderDialog.form b/src/opensesim/traders/ManTrader/CreateOrderDialog.form similarity index 100% rename from src/traders/ManTrader/CreateOrderDialog.form rename to src/opensesim/traders/ManTrader/CreateOrderDialog.form diff --git a/src/traders/ManTrader/CreateOrderDialog.java b/src/opensesim/traders/ManTrader/CreateOrderDialog.java similarity index 98% rename from src/traders/ManTrader/CreateOrderDialog.java rename to src/opensesim/traders/ManTrader/CreateOrderDialog.java index 5e39f80..a662e02 100644 --- a/src/traders/ManTrader/CreateOrderDialog.java +++ b/src/opensesim/traders/ManTrader/CreateOrderDialog.java @@ -23,13 +23,12 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package traders.ManTrader; +package opensesim.traders.ManTrader; -import gui.Globals; - -import sesim.Account; -import sesim.Order.OrderType; -import sesim.Quote; +import opensesim.gui.Globals; +import opensesim.old_sesim.Account; +import opensesim.old_sesim.Order.OrderType; +import opensesim.old_sesim.Quote; /** * diff --git a/src/traders/ManTrader/ManTrader.java b/src/opensesim/traders/ManTrader/ManTrader.java similarity index 89% rename from src/traders/ManTrader/ManTrader.java rename to src/opensesim/traders/ManTrader/ManTrader.java index ece689b..0bb1242 100644 --- a/src/traders/ManTrader/ManTrader.java +++ b/src/opensesim/traders/ManTrader/ManTrader.java @@ -23,23 +23,21 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package traders.ManTrader; +package opensesim.traders.ManTrader; -import gui.Globals; -import gui.OpenOrdersList; +import opensesim.gui.Globals; +import opensesim.gui.OpenOrdersList; import javax.swing.JDialog; import org.json.JSONObject; -import sesim.AutoTraderBase; - -//import sesim.AutoTraderConfig; -import sesim.AutoTraderGui; -import sesim.AutoTraderInterface; -import sesim.Exchange; -import sesim.Exchange.AccountListener; -import sesim.Order.OrderStatus; -import sesim.Order; -import sesim.Account; +import opensesim.old_sesim.AutoTraderBase; +import opensesim.old_sesim.AutoTraderGui; +import opensesim.old_sesim.AutoTraderInterface; +import opensesim.old_sesim.Exchange; +import opensesim.old_sesim.Exchange.AccountListener; +import opensesim.old_sesim.Order.OrderStatus; +import opensesim.old_sesim.Order; +import opensesim.old_sesim.Account; /** * diff --git a/src/traders/ManTrader/ManTraderConsole.form b/src/opensesim/traders/ManTrader/ManTraderConsole.form similarity index 100% rename from src/traders/ManTrader/ManTraderConsole.form rename to src/opensesim/traders/ManTrader/ManTraderConsole.form diff --git a/src/traders/ManTrader/ManTraderConsole.java b/src/opensesim/traders/ManTrader/ManTraderConsole.java similarity index 97% rename from src/traders/ManTrader/ManTraderConsole.java rename to src/opensesim/traders/ManTrader/ManTraderConsole.java index 08c9f2f..432defa 100644 --- a/src/traders/ManTrader/ManTraderConsole.java +++ b/src/opensesim/traders/ManTrader/ManTraderConsole.java @@ -23,13 +23,12 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package traders.ManTrader; +package opensesim.traders.ManTrader; -import gui.OpenOrdersList; - -import sesim.Exchange; -import sesim.Order; -import sesim.Order.OrderType; +import opensesim.gui.OpenOrdersList; +import opensesim.old_sesim.Exchange; +import opensesim.old_sesim.Order; +import opensesim.old_sesim.Order.OrderType; /** * @@ -73,7 +72,7 @@ public class ManTraderConsole extends javax.swing.JPanel { moneyText = new javax.swing.JLabel(); stopLossButton = new javax.swing.JButton(); jTabbedPane1 = new javax.swing.JTabbedPane(); - ordersList = new gui.OpenOrdersList(); + ordersList = new opensesim.gui.OpenOrdersList(); limitSpinner.setModel(new javax.swing.SpinnerNumberModel(0.0d, 0.0d, null, 1.0d)); @@ -221,7 +220,7 @@ public class ManTraderConsole extends javax.swing.JPanel { private javax.swing.JTabbedPane jTabbedPane1; private javax.swing.JSpinner limitSpinner; private javax.swing.JLabel moneyText; - private gui.OpenOrdersList ordersList; + private opensesim.gui.OpenOrdersList ordersList; private javax.swing.JButton sellButton; private javax.swing.JButton stopLossButton; private javax.swing.JSpinner volumeSpinner; diff --git a/src/traders/ManTrader/ManTraderConsoleDialog.form b/src/opensesim/traders/ManTrader/ManTraderConsoleDialog.form similarity index 100% rename from src/traders/ManTrader/ManTraderConsoleDialog.form rename to src/opensesim/traders/ManTrader/ManTraderConsoleDialog.form diff --git a/src/traders/ManTrader/ManTraderConsoleDialog.java b/src/opensesim/traders/ManTrader/ManTraderConsoleDialog.java similarity index 94% rename from src/traders/ManTrader/ManTraderConsoleDialog.java rename to src/opensesim/traders/ManTrader/ManTraderConsoleDialog.java index 0542f6a..a046378 100644 --- a/src/traders/ManTrader/ManTraderConsoleDialog.java +++ b/src/opensesim/traders/ManTrader/ManTraderConsoleDialog.java @@ -23,10 +23,10 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package traders.ManTrader; +package opensesim.traders.ManTrader; import javax.swing.JPanel; -import sesim.Account; +import opensesim.old_sesim.Account; /** * @@ -48,7 +48,7 @@ public class ManTraderConsoleDialog extends javax.swing.JDialog { this.setLocationRelativeTo(parent); } - public gui.OpenOrdersList getOrderList(){ + public opensesim.gui.OpenOrdersList getOrderList(){ return this.ordersList; } @@ -72,8 +72,8 @@ public class ManTraderConsoleDialog extends javax.swing.JDialog { private void initComponents() { jTabbedPane1 = new javax.swing.JTabbedPane(); - ordersList = new gui.OpenOrdersList(); - accountBalance1 = new traders.ManTrader.AccountBalance(); + ordersList = new opensesim.gui.OpenOrdersList(); + accountBalance1 = new opensesim.traders.ManTrader.AccountBalance(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); @@ -149,8 +149,8 @@ public class ManTraderConsoleDialog extends javax.swing.JDialog { } // Variables declaration - do not modify//GEN-BEGIN:variables - private traders.ManTrader.AccountBalance accountBalance1; + private opensesim.traders.ManTrader.AccountBalance accountBalance1; private javax.swing.JTabbedPane jTabbedPane1; - private gui.OpenOrdersList ordersList; + private opensesim.gui.OpenOrdersList ordersList; // End of variables declaration//GEN-END:variables } diff --git a/src/traders/RandomTraderA.java b/src/opensesim/traders/RandomTraderA.java similarity index 95% rename from src/traders/RandomTraderA.java rename to src/opensesim/traders/RandomTraderA.java index b9f923c..1080c63 100644 --- a/src/traders/RandomTraderA.java +++ b/src/opensesim/traders/RandomTraderA.java @@ -23,24 +23,23 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package traders; +package opensesim.traders; -import gui.Globals; +import opensesim.gui.Globals; import java.util.Iterator; import java.util.Set; import javax.swing.JDialog; import org.json.JSONArray; import org.json.JSONObject; -import sesim.AutoTraderBase; -import sesim.AutoTraderGui; -import sesim.Exchange; -import sesim.Account; -import sesim.Exchange.AccountListener; - -import sesim.Order.OrderType; -import sesim.Order; -import sesim.Order.OrderStatus; -import sesim.Quote; +import opensesim.old_sesim.AutoTraderBase; +import opensesim.old_sesim.AutoTraderGui; +import opensesim.old_sesim.Exchange; +import opensesim.old_sesim.Account; +import opensesim.old_sesim.Exchange.AccountListener; +import opensesim.old_sesim.Order.OrderType; +import opensesim.old_sesim.Order; +import opensesim.old_sesim.Order.OrderStatus; +import opensesim.old_sesim.Quote; /** * @@ -60,6 +59,7 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener { public Long[] buy_wait = {10000L, 50000L}; public Long[] wait_after_buy = {0L, 0L}; + final String INITIAL_DELAY = "initla_delay"; final String SELL_VOLUME = "sell_volume"; final String BUY_VOLUME = "buy_volume"; @@ -86,7 +86,7 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener { public long timerTask() { intask = true; owait = null; - sesim.Account a = se.getAccount(account_id); + opensesim.old_sesim.Account a = se.getAccount(account_id); long rc = this.doTrade(); setStatus("Sleeping for %d ms", rc); intask = false; @@ -203,7 +203,7 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener { return null; } - sesim.Scheduler.TimerTaskDef timerTask; + opensesim.old_sesim.Scheduler.TimerTaskDef timerTask; @Override public void accountUpdated(Account a, Order o) { diff --git a/src/traders/RandomTraderB.java b/src/opensesim/traders/RandomTraderB.java similarity index 96% rename from src/traders/RandomTraderB.java rename to src/opensesim/traders/RandomTraderB.java index 222cba5..ad60c16 100644 --- a/src/traders/RandomTraderB.java +++ b/src/opensesim/traders/RandomTraderB.java @@ -23,9 +23,9 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package traders; +package opensesim.traders; -import gui.Globals; +import opensesim.gui.Globals; import java.util.Iterator; import java.util.Set; import javax.swing.JDialog; @@ -33,12 +33,12 @@ import org.json.JSONArray; import org.json.JSONObject; -import sesim.AutoTraderBase; -import sesim.AutoTraderGui; -import sesim.Account; -import sesim.Order; -import sesim.Order.OrderType; -import sesim.Quote; +import opensesim.old_sesim.AutoTraderBase; +import opensesim.old_sesim.AutoTraderGui; +import opensesim.old_sesim.Account; +import opensesim.old_sesim.Order; +import opensesim.old_sesim.Order.OrderType; +import opensesim.old_sesim.Quote; /** * @@ -76,7 +76,7 @@ public class RandomTraderB extends AutoTraderBase { @Override public long timerTask() { - sesim.Account a = se.getAccount(account_id); + opensesim.old_sesim.Account a = se.getAccount(account_id); long rc = this.doTrade(); return rc; diff --git a/src/traders/RandomTraderGuiA.form b/src/opensesim/traders/RandomTraderGuiA.form similarity index 100% rename from src/traders/RandomTraderGuiA.form rename to src/opensesim/traders/RandomTraderGuiA.form diff --git a/src/traders/RandomTraderGuiA.java b/src/opensesim/traders/RandomTraderGuiA.java similarity index 99% rename from src/traders/RandomTraderGuiA.java rename to src/opensesim/traders/RandomTraderGuiA.java index d2ca170..95309e2 100644 --- a/src/traders/RandomTraderGuiA.java +++ b/src/opensesim/traders/RandomTraderGuiA.java @@ -23,11 +23,11 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package traders; +package opensesim.traders; import javax.swing.JDialog; import org.json.JSONObject; -import sesim.AutoTraderGui; +import opensesim.old_sesim.AutoTraderGui; /** * diff --git a/src/opensesim/util/AssetVol.java b/src/opensesim/util/AssetVol.java new file mode 100644 index 0000000..00c92cd --- /dev/null +++ b/src/opensesim/util/AssetVol.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.util; + +import opensesim.AbstractAsset; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class AssetVol { + public AbstractAsset asset; + public double volume; + + public AssetVol(AbstractAsset asset, double volume){ + this.asset=asset; + this.volume=volume; + } +} diff --git a/src/opensesim/util/Files.java b/src/opensesim/util/Files.java new file mode 100644 index 0000000..feaeb46 --- /dev/null +++ b/src/opensesim/util/Files.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.util; + +import java.io.File; +import java.io.FilenameFilter; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class Files { + + /** + * Converts a list of file objects to a list of URL objects + * @param files list of file objects + * @return list of url objects + */ + static public ArrayList buildUrlList( ArrayList files){ + ArrayList urllist; + urllist = new ArrayList<>(); + URL url; + for (File file : files) { + try { + url = file.toURI().toURL(); + } catch (MalformedURLException ex) { + Logger.getLogger(XClassLoader.class.getName()).log(Level.SEVERE, null, ex); + continue; + } + urllist.add(url); + } + return urllist; + } + + /** + * Get a list of all files in a given directory and its sub-directories. + * The files are filtered by a filter. + * + * @param path Directory to list + * @param filter a Filter to filter files + * @return List of files + */ + public static ArrayList listFiles(String path, FilenameFilter filter) { + ArrayList files = new ArrayList<>(); + File fp = new File(path); + if (!fp.isDirectory()) { + files.add(fp); + return files; + } + File[] fList = new File(path).listFiles(filter); + for (File file : fList) { + if (file.isFile()) { + files.add(file); + } else if (file.isDirectory()) { + files.addAll(listFiles(file.getAbsolutePath(), filter)); + } + } + return files; + } + + /** + * Get a list of all files in a given directory and its sub-directories. + * @param path Path to list files in + * @return list of files + */ + public static ArrayList listFiles(String path) { + FilenameFilter f = new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + return true; + } + }; + return Files.listFiles(path, f); + } + + /** + * Get a list of all files in a given directory and its sub-directories, + * filtered by extension + + * @param path Path to list files in + * @param ext extension to filter + * @return list of files + */ + public static ArrayList listFiles(String path, String ext) { + FilenameFilter f; + f = (File dir, String name) -> name.toLowerCase().endsWith(ext) || dir.isDirectory(); + return Files.listFiles(path, f); + } +} diff --git a/src/opensesim/util/IDGenerator.java b/src/opensesim/util/IDGenerator.java new file mode 100644 index 0000000..8fc346a --- /dev/null +++ b/src/opensesim/util/IDGenerator.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.util; + +import java.util.Objects; + + + +/** + * Implementation of a simple ID generator to create uniqe IDs of type long + * + * @author 7u83 <7u83@mail.ru> + */ +public class IDGenerator { + + + public static class Id { + final Long value; + + public Id(String id) { + value =Long.parseLong(id); + } + + @Override + public boolean equals(Object o) { + if (o.getClass() != Id.class) + return false; + return Objects.equals(value, ((Id)o).value); + } + + @Override + public int hashCode() { + int hash = 3; + hash = 47 * hash + Objects.hashCode(this.value); + return hash; + } + + @Override + public String toString() { + return value.toString(); + } + + + } + + private Long next_id; + private Long start_id; + + /** + * Initialize the ID generator + * + * @param start ID value to start with + */ + public IDGenerator(String start) { + start_id=Long.parseLong(start); + reset(); + } + + /** + * Initialize ID Generator with start ID = 0 + */ + public IDGenerator() { + this("0"); + } + + /** + * Reset the ID generator + */ + public final void reset(){ + next_id = start_id; + } + + /** + * Get the next ID + * + * @return the next generated ID + */ + public synchronized Id getNext() { + return new Id((next_id++).toString()); + } +} diff --git a/src/opensesim/util/SeSimException.java b/src/opensesim/util/SeSimException.java new file mode 100644 index 0000000..052e190 --- /dev/null +++ b/src/opensesim/util/SeSimException.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.util; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class SeSimException extends Exception { + + public SeSimException(String msg) { + super(msg); + } + +} diff --git a/src/opensesim/util/XClassLoader.java b/src/opensesim/util/XClassLoader.java new file mode 100644 index 0000000..c32ee7f --- /dev/null +++ b/src/opensesim/util/XClassLoader.java @@ -0,0 +1,342 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.util; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Modifier; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.jar.JarEntry; +import java.util.jar.JarInputStream; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class XClassLoader { + + /** + * Build a list of urls for an additional class path + * + * @param xpath + * @return List + */ + public static ArrayList getXPathUrlList(String xpath) { + + ArrayList urllist = new ArrayList<>(); + URL url; + + if (xpath == null) + return urllist; + + // add xpath to load find classes stored under xpath + try { + url = new File(xpath).toURI().toURL(); + } catch (MalformedURLException ex) { + Logger.getLogger(XClassLoader.class.getName()).log(Level.SEVERE, null, ex); + return urllist; + } + + // add all .jar files + urllist.add(url); + ArrayList files; + files = Files.listFiles(xpath, ".jar"); + + urllist.addAll(opensesim.util.Files.buildUrlList(files)); + return urllist; + + } + + private static Class lClass(ArrayList urllist, Class check, String class_name) { + + URLClassLoader cl; + URL[] urls = urllist.toArray(new URL[urllist.size()]); + cl = new URLClassLoader(urls); + + Class cls; + try { + cls = cl.loadClass(class_name); + } catch (ClassNotFoundException ex) { + Logger.getLogger(XClassLoader.class.getName()).log(Level.SEVERE, null, ex); + return null; + } catch (NoClassDefFoundError e){ + return null; + } + + if (cls == null) { + return null; + } + + if (Modifier.isAbstract(cls.getModifiers())) { + return null; + } + + if (Modifier.isInterface(cls.getModifiers())) { + return null; + } + if (check.isAssignableFrom(cls)) { + return cls; + }; + + return null; + } + + public static ArrayList> getClassesList(ArrayList urllist, Class check) { + + ArrayList> class_list; + class_list = new ArrayList<>(); + + if (urllist==null) + return class_list; + + for (URL url : urllist) { + if (url.getProtocol().equals("file")) { + File f = new File(url.getFile()); + if (f.exists() && f.isDirectory()) { + + System.out.println(f.getAbsolutePath()); + + ArrayList classfilelist = Files.listFiles(f.getAbsolutePath(), ".class"); + for (File classfile : classfilelist) { + String class_name; + class_name = classfile.toString().substring(f.toString().length()); + // in case we are under Windows, replace \ with / + class_name = class_name.replace("\\", "/"); + class_name = class_name.substring(1, class_name.length() - 6).replace('/', '.'); + + System.out.println("Auqa"); + System.out.println(class_name); + + Class c = XClassLoader.lClass(urllist, check, class_name); + if (null != c) { + class_list.add(c); + } + + //java.util.logging.Logger.getLogger("opensesim").log(Level.SEVERE, ); + //Class c = checkClass(path, class_name); + } + continue; + } + } + + + JarInputStream jarstream; + try { + jarstream = new JarInputStream(url.openConnection().getInputStream()); + + } catch (IOException ex) { + Logger.getLogger(XClassLoader.class.getName()).log(Level.SEVERE, null, ex); + continue; + } + + JarEntry jarentry; + try { + while ((jarentry = jarstream.getNextJarEntry()) != null) { + + String class_name = jarentry.getName(); + + if (class_name.endsWith(".class")) { + + class_name = class_name.substring(0, class_name.length() - 6).replace('/', '.'); + Class c = XClassLoader.lClass(urllist, check, class_name); + if (null != c) { + class_list.add(c); + } + + } + } + } catch (IOException ex) { + Logger.getLogger(XClassLoader.class.getName()).log(Level.SEVERE, null, ex); + } + } + return class_list; + } + + /** + * + * @param pathlist + * @return + */ +/* public static ArrayList> getClasses(ArrayList pathlist) { + + ArrayList> result = new ArrayList<>(); + + for (String path : pathlist) { + + ArrayList files = Files.listFiles(path); + + for (File file : files) { + + if (!file.exists()) { + java.util.logging.Logger.getLogger("opensesim").log(Level.WARNING, + "File dos not exists: " + file.getAbsolutePath()); + continue; + } + + String fn = file.toString(); + + // handle file with .class extension + if (fn.toLowerCase().endsWith(".class")) { + + String class_name; + class_name = fn.substring(path.length()); + // in case we are under Windows, replace \ with / + class_name = class_name.replace("\\", "/"); + class_name = class_name.substring(1, class_name.length() - 6).replace('/', '.'); + + //java.util.logging.Logger.getLogger(XClassLoader.class.getName()).log(Level.SEVERE, null, null); + java.util.logging.Logger.getLogger("opensesim").log(Level.SEVERE, fn); + Class c = checkClass(path, class_name); + // if (null == c) { + // continue; + // } + // result.add(c); + } + + // handle file .jar extension + if (fn.toLowerCase().endsWith(".jar")) { + JarInputStream jarstream = null; + try { + File jarfile = new File(fn); + jarstream = new JarInputStream(new FileInputStream(jarfile)); + JarEntry jarentry; + + while ((jarentry = jarstream.getNextJarEntry()) != null) { + + String class_name = jarentry.getName(); + + if (class_name.endsWith(".class")) { + + class_name = class_name.substring(0, class_name.length() - 6).replace('/', '.'); + Class c = checkClass(fn, class_name); +// if (null == c) { +// continue; + // } + // result.add(c); + } + } + } catch (IOException ex) { + + } finally { + try { + if (jarstream != null) { + jarstream.close(); + } + } catch (IOException ex) { + // java.util.logging.Logger.getLogger(AutoTraderLoader.class.getName()).log(Level.SEVERE, null, ex); + } + } + + } + + } + + } + return result; + } + + public static ArrayList> getClasses(String path) { + ArrayList pathlist = new ArrayList(); + pathlist.add(path); + return getClasses(pathlist); + + } + +*/ + + +/* + private static Class checkClass(String directory, String class_name) { + + if (class_name == null) { + return null; + } + + URL url; + try { + url = new File(directory).toURI().toURL(); + + } catch (MalformedURLException ex) { + return null; + } + URL[] urls = new URL[]{url}; + + ClassLoader cl; + cl = new URLClassLoader(urls); + + try { + Class cls; + cls = cl.loadClass(class_name); + if (cls == null) { + return null; + } + + System.out.printf("ClassChecker: %s\n", class_name); + + String gn = cls.toGenericString(); + + ArrayList> res; + + Class xxx = javax.swing.LookAndFeel.class; + + if (Modifier.isAbstract(cls.getModifiers())) { + return null; + } + + if (Modifier.isInterface(cls.getModifiers())) { + return null; + } + + boolean rrr = xxx.isAssignableFrom(cls); + + if (rrr) { + System.out.print(class_name); + System.out.print("\n"); + //javax.swing.LookAndFeel laf; + + //UIManager.installLookAndFeel(class_name, class_name); + //UIManager.installLookAndFeel(class_name, class_name); + } + + //res.getClass().isAssignableFrom(cls); + + return (Class) cls; + + } catch (NoClassDefFoundError ex) { + return null; + } catch (ClassNotFoundException ex) { + Logger.getLogger(XClassLoader.class.getName()).log(Level.SEVERE, null, ex); + return null; + } + + } +*/ +} diff --git a/test/opensesim/sesim/AssetPairTest.java b/test/opensesim/sesim/AssetPairTest.java new file mode 100644 index 0000000..0b99943 --- /dev/null +++ b/test/opensesim/sesim/AssetPairTest.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.sesim; + +import opensesim.sesim.Assets.BasicAsset; +import opensesim.sesim.AssetPair; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class AssetPairTest { + + public AssetPairTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getAsset method, of class AssetPair. + */ + @Test + public void testGetAsset() { + System.out.println("getAsset"); + AssetPair instance = new AssetPair(null,null); + opensesim.sesim.interfaces.Asset expResult = null; + opensesim.sesim.interfaces.Asset result = instance.getAsset(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + //fail("The test case is a prototype."); + } + + + /** + * Test of getCurrency method, of class AssetPair. + */ + @Test + public void testGetCurrency() { + System.out.println("getCurrency"); + AssetPair instance = new AssetPair(null,null); + opensesim.sesim.interfaces.Asset expResult = null; + opensesim.sesim.interfaces.Asset result = instance.getCurrency(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + //fail("The test case is a prototype."); + } + + + /** + * Test of getSymbol method, of class AssetPair. + */ + @Test + public void testGetSymbol() { + System.out.println("getSymbol"); + + BasicAsset asset = new opensesim.sesim.Assets.BasicAsset("AAPL", "Apple", "Apple Inc."); + BasicAsset currency = new opensesim.sesim.Assets.BasicAsset("EUR", "Euro", "Euro desc"); + + AssetPair instance = new AssetPair(asset,currency); + + String expResult = "AAPL/EUR"; + String result = instance.getSymbol(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + //fail("The test case is a prototype."); + } + +} diff --git a/test/opensesim/sesim/AssetTest.java b/test/opensesim/sesim/AssetTest.java new file mode 100644 index 0000000..4f36149 --- /dev/null +++ b/test/opensesim/sesim/AssetTest.java @@ -0,0 +1,230 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.sesim; + +import opensesim.sesim.Assets.BasicAsset; +import org.json.JSONObject; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class AssetTest { + + public AssetTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getSymbol method, of class Asset. + */ + @Test + public void testGetSymbol() { + System.out.println("getSymbol"); + BasicAsset instance = new BasicAsset(); + String expResult = "EUR"; + instance.setSymbol(expResult); + String result = instance.getSymbol(); + assertEquals(expResult, result); + + } + + /** + * Test of getConfig method, of class Asset. + */ + @Test + public void testGetConfig() { + System.out.println("getConfig"); + BasicAsset instance = new BasicAsset(); + + int decimals = 17; + String symbol = "EUR"; + String description = "Eruo - Europaen currency"; + String name = "Euro"; + + instance.setDecimals(decimals); + instance.setName(name); + instance.setDescription(description); + instance.setSymbol(symbol); + + JSONObject result = instance.getConfig(); + + assertEquals(symbol, result.getString(BasicAsset.JSON_SYMBOL)); + assertEquals(name, result.getString(BasicAsset.JSON_NAME)); + assertEquals(description, result.getString(BasicAsset.JSON_DESCRIPTION)); + assertEquals(decimals, result.getInt(BasicAsset.JSON_DECIMALS)); + + } + + /** + * Test of putConfig method, of class Asset. + */ + @Test + public void testPutConfig() { + System.out.println("putConfig"); + + int decimals = 17; + String symbol = "EUR"; + String name = "Euro"; + String description = "Eruo - Europaen currency"; + + JSONObject cfg = new JSONObject(); + cfg.put(BasicAsset.JSON_SYMBOL, symbol); + cfg.put(BasicAsset.JSON_NAME, name); + cfg.put(BasicAsset.JSON_DESCRIPTION, description); + cfg.put(BasicAsset.JSON_DECIMALS, decimals); + + BasicAsset instance = new BasicAsset(); + instance.putConfig(cfg); + + assertEquals(symbol,instance.getSymbol()); + assertEquals(name,instance.getName()); + assertEquals(description,instance.getDescription()); + assertEquals(decimals,instance.getDecimals()); + + } + + /** + * Test of setSymbol method, of class Asset. + */ + @Test + public void testSetSymbol() { + System.out.println("setSymbol"); + String symbol = "EUR"; + BasicAsset instance = new BasicAsset(); + instance.setSymbol(symbol); + String result = instance.getSymbol(); + assertEquals(symbol, result); + + } + + /** + * Test of getName method, of class Asset. + */ + @Test + public void testGetName() { + System.out.println("getName"); + BasicAsset instance = new BasicAsset(); + String expResult = "Euro"; + instance.setName(expResult); + String result = instance.getName(); + assertEquals(expResult, result); + + } + + /** + * Test of setName method, of class Asset. + */ + @Test + public void testSetName() { + System.out.println("setName"); + String name = "Euro"; + BasicAsset instance = new BasicAsset(); + instance.setName(name); + String result = instance.getName(); + assertEquals(name, result); + + } + + /** + * Test of getDescription method, of class Asset. + */ + @Test + public void testGetDescription() { + System.out.println("getDescription"); + BasicAsset instance = new BasicAsset(); + String expResult = "Euro - European currency"; + instance.setDescription(expResult); + String result = instance.getDescription(); + assertEquals(expResult, result); + + } + + /** + * Test of setDescription method, of class Asset. + */ + @Test + public void testSetDescription() { + System.out.println("setDescription"); + String description = "Eruo - Eruopean currency"; + BasicAsset instance = new BasicAsset(); + instance.setDescription(description); + String result = instance.getDescription(); + assertEquals(description, result); + + } + + /** + * Test of getDecimals method, of class Asset. + */ + @Test + public void testGetDecimals() { + System.out.println("getDecimals"); + BasicAsset instance = new BasicAsset(); + int expResult = 7; + instance.setDecimals(expResult); + int result = instance.getDecimals(); + assertEquals(expResult, result); + + } + + /** + * Test of setDecimals method, of class Asset. + */ + @Test + public void testSetDecimals() { + System.out.println("setDecimals"); + int decimals; + decimals = 350; + BasicAsset instance = new BasicAsset(); + instance.setDecimals(decimals); + int result = instance.getDecimals(); + assertEquals(decimals, result); + + } + +} diff --git a/test/opensesim/sesim/ExchangeTest.java b/test/opensesim/sesim/ExchangeTest.java new file mode 100644 index 0000000..f16a39f --- /dev/null +++ b/test/opensesim/sesim/ExchangeTest.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2018, 7u83 <7u83@mail.ru> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.sesim; + +import opensesim.Exchange; +import opensesim.sesim.Assets.BasicAsset; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class ExchangeTest { + + public ExchangeTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of add method, of class Exchange. + */ + @Test + public void testAdd() { + System.out.println("add"); + BasicAsset a = new BasicAsset(); + a.setSymbol("EUR"); + Exchange instance = new Exchange(); + instance.add(a); + // TODO review the generated test code and remove the default call to fail. + //fail("The test case is a prototype."); + } + +} diff --git a/test/sesim/Test.java b/test/sesim/Test.java deleted file mode 100644 index 1e5cea9..0000000 --- a/test/sesim/Test.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (c) 2017, tobias - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package sesim; - -import java.io.File; -import java.io.IOException; -import java.io.RandomAccessFile; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; -import java.security.ProtectionDomain; -import java.util.ArrayList; -import java.util.SortedMap; -import java.util.TreeMap; -import java.lang.ClassLoader.*; -import java.util.Random; -import java.util.logging.Level; -import java.util.logging.Logger; -import sesim.Scheduler.TimerTaskRunner; - -/** - * - * @author tobias - */ -public class Test { - - static void tube() { - try { - System.out.printf("Hello %s\n", "args"); - if (0 == 0) { - return; - } - } finally { - System.out.printf("Always %s\n", "the end"); - } - System.out.print("haha\n"); - } - - static public String getFullClassName(String classFileName) throws IOException { - File file = new File(classFileName); - - FileChannel roChannel = new RandomAccessFile(file, "r").getChannel(); - ByteBuffer bb = roChannel.map(FileChannel.MapMode.READ_ONLY, 0, (int) roChannel.size()); - - String x = new String(); - - //x.getClass().getClassLoader().loadClass(x); - //Class clazz = defineClass((String)null, bb, (ProtectionDomain)null); - //return clazz.getName(); - return ""; - } - - /* static private void to(T n, Double o) { - if (Float == T) { - System.out.printf("Double ret %", o.floatValue()); - - n = (T) (Number) o.floatValue(); - } - - } - */ - static class Exer extends Thread { - - int value = 0; - - @Override - public void run() { - - while (true) { - try { - System.out.printf("Exer getting Exer Lock"); - synchronized (this) { - System.out.printf("Exer having Exer Lock wait 30000\n"); - this.wait(); - } - - } catch (InterruptedException ex) { - System.out.printf("Interrupted\n"); - } - - System.out.printf("Exer Value %d\n", value); - } - } - - } - - static class Runner extends Thread { - - } - static Scheduler s = new Scheduler(); - - static class MyTask implements TimerTaskRunner { - - long ctr = 0; - - @Override - public long timerTask() { - ctr++; - double r = 1; - for (int i = 0; i < 100000; i++) { - r = r + i * r; - r = r + 1.0; - } - synchronized (this) { - try { - wait(500); - } catch (InterruptedException ex) { - Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex); - } - } - System.out.printf("TimerTask %d %d %f\n", ctr, s.currentTimeMillis(), r); - - return 1000; - } - - @Override - public long getID() { - return 0; - } - - } - - /** - * @param args the command line arguments - */ - public static void main(String[] args) throws InterruptedException, MalformedURLException, InstantiationException, IllegalAccessException, IOException { - - double val = Math.log(12); - double rval = Math.exp(val); - - - System.out.printf("Result: %f, %f\n", val,rval); - - - - } - -}