Initial commit of multiasset branch

This commit is contained in:
2018-11-30 12:27:41 +01:00
parent 45684a9d0e
commit bb18f7cf03
205 changed files with 8656 additions and 2750 deletions

View File

@ -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;
}
}

View File

@ -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<URL> buildUrlList( ArrayList<File> files){
ArrayList<URL> 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<File> listFiles(String path, FilenameFilter filter) {
ArrayList<File> 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<File> 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<File> listFiles(String path, String ext) {
FilenameFilter f;
f = (File dir, String name) -> name.toLowerCase().endsWith(ext) || dir.isDirectory();
return Files.listFiles(path, f);
}
}

View File

@ -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());
}
}

View File

@ -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);
}
}

View File

@ -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<URL> getXPathUrlList(String xpath) {
ArrayList<URL> 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<File> files;
files = Files.listFiles(xpath, ".jar");
urllist.addAll(opensesim.util.Files.buildUrlList(files));
return urllist;
}
private static Class<?> lClass(ArrayList<URL> 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<Class<?>> getClassesList(ArrayList<URL> urllist, Class<?> check) {
ArrayList<Class<?>> 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<File> 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<Class<?>> getClasses(ArrayList<String> pathlist) {
ArrayList<Class<?>> result = new ArrayList<>();
for (String path : pathlist) {
ArrayList<File> 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<Class<?>> getClasses(String path) {
ArrayList<String> 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<Class<UIManager.LookAndFeelInfo>> 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;
}
}
*/
}