Create JSONObject by annotations
This commit is contained in:
parent
044f23b338
commit
f9949fa5ad
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,6 @@ 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=b3520478
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48
|
||||
nbproject/build-impl.xml.data.CRC32=ce5e9408
|
||||
nbproject/build-impl.xml.script.CRC32=9fb4669e
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=3a2fa800@1.89.1.48
|
||||
|
@ -1,47 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
||||
|
||||
Copyright 1997-2013 Oracle and/or its affiliates. All rights reserved.
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
Oracle and Java are registered trademarks of Oracle and/or its affiliates.
|
||||
Other names may be trademarks of their respective owners.
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
|
||||
The contents of this file are subject to the terms of either the GNU
|
||||
General Public License Version 2 only ("GPL") or the Common
|
||||
Development and Distribution License("CDDL") (collectively, the
|
||||
"License"). You may not use this file except in compliance with the
|
||||
License. You can obtain a copy of the License at
|
||||
http://www.netbeans.org/cddl-gplv2.html
|
||||
or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
|
||||
specific language governing permissions and limitations under the
|
||||
License. When distributing the software, include this License Header
|
||||
Notice in each file and include the License file at
|
||||
nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
|
||||
particular file as subject to the "Classpath" exception as provided
|
||||
by Oracle in the GPL Version 2 section of the License file that
|
||||
accompanied this code. If applicable, add the following below the
|
||||
License Header, with the fields enclosed by brackets [] replaced by
|
||||
your own identifying information:
|
||||
"Portions Copyrighted [year] [name of copyright owner]"
|
||||
|
||||
Contributor(s):
|
||||
|
||||
The Original Software is NetBeans. The Initial Developer of the Original
|
||||
Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
|
||||
Microsystems, Inc. All Rights Reserved.
|
||||
|
||||
If you wish your version of this file to be governed by only the CDDL
|
||||
or only the GPL Version 2, indicate your decision by adding
|
||||
"[Contributor] elects to include this software in this distribution
|
||||
under the [CDDL or GPL Version 2] license." If you do not indicate a
|
||||
single choice of license, a recipient has the option to distribute
|
||||
your version of this file under either the CDDL, the GPL Version 2 or
|
||||
to extend the choice of license to its licensees as provided above.
|
||||
However, if you add GPL Version 2 code and therefore, elected the GPL
|
||||
Version 2 license, then the option applies only if the new code is
|
||||
made subject to such option by the copyright holder.
|
||||
-->
|
||||
|
||||
<project name="jnlp-impl" default="default" basedir=".." xmlns:jnlp="http://www.netbeans.org/ns/j2se-project/jnlp" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3">
|
||||
@ -866,18 +842,6 @@ made subject to such option by the copyright holder.
|
||||
description="Debug javaws project in IDE"/>
|
||||
|
||||
<target name="-init-debug-args">
|
||||
<property name="version-output" value="java version "${ant.java.version}"/>
|
||||
<condition property="have-jdk-older-than-1.4">
|
||||
<or>
|
||||
<contains string="${version-output}" substring="java version "1.0"/>
|
||||
<contains string="${version-output}" substring="java version "1.1"/>
|
||||
<contains string="${version-output}" substring="java version "1.2"/>
|
||||
<contains string="${version-output}" substring="java version "1.3"/>
|
||||
</or>
|
||||
</condition>
|
||||
<condition else="-Xdebug" property="debug-args-line" value="-Xdebug -Xnoagent -Djava.compiler=none">
|
||||
<istrue value="${have-jdk-older-than-1.4}"/>
|
||||
</condition>
|
||||
<condition else="dt_socket" property="debug-transport-by-os" value="dt_shmem">
|
||||
<os family="windows"/>
|
||||
</condition>
|
||||
@ -889,7 +853,7 @@ made subject to such option by the copyright holder.
|
||||
<target name="-debug-javaws-debuggee" depends="-init-debug-args,-init-platform,-check-webstart">
|
||||
<echo message="Executing ${jnlp.dest.dir}${file.separator}${jnlp.file} in debug mode using ${active.webstart.executable}"/>
|
||||
<exec executable="${active.webstart.executable}">
|
||||
<env key="JAVAWS_VM_ARGS" value="${debug-args-line} -Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
|
||||
<env key="JAVAWS_VM_ARGS" value="-agentlib:jdwp=transport=${debug-transport},address=${jpda.address}"/>
|
||||
<arg value="-wait"/>
|
||||
<arg file="${jnlp.dest.dir}${file.separator}${jnlp.file}"/>
|
||||
</exec>
|
||||
|
@ -1,23 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
||||
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
Copyright 1997-2013 Oracle and/or its affiliates. All rights reserved.
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Oracle and Java are registered trademarks of Oracle and/or its affiliates.
|
||||
Other names may be trademarks of their respective owners.
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
|
||||
The contents of this file are subject to the terms of either the GNU
|
||||
General Public License Version 2 only ("GPL") or the Common
|
||||
Development and Distribution License("CDDL") (collectively, the
|
||||
"License"). You may not use this file except in compliance with the
|
||||
License. You can obtain a copy of the License at
|
||||
http://www.netbeans.org/cddl-gplv2.html
|
||||
or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
|
||||
specific language governing permissions and limitations under the
|
||||
License. When distributing the software, include this License Header
|
||||
Notice in each file and include the License file at
|
||||
nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
|
||||
particular file as subject to the "Classpath" exception as provided
|
||||
by Oracle in the GPL Version 2 section of the License file that
|
||||
accompanied this code. If applicable, add the following below the
|
||||
License Header, with the fields enclosed by brackets [] replaced by
|
||||
your own identifying information:
|
||||
"Portions Copyrighted [year] [name of copyright owner]"
|
||||
|
||||
Contributor(s):
|
||||
|
||||
The Original Software is NetBeans. The Initial Developer of the Original
|
||||
Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
|
||||
Microsystems, Inc. All Rights Reserved.
|
||||
|
||||
If you wish your version of this file to be governed by only the CDDL
|
||||
or only the GPL Version 2, indicate your decision by adding
|
||||
"[Contributor] elects to include this software in this distribution
|
||||
under the [CDDL or GPL Version 2] license." If you do not indicate a
|
||||
single choice of license, a recipient has the option to distribute
|
||||
your version of this file under either the CDDL, the GPL Version 2 or
|
||||
to extend the choice of license to its licensees as provided above.
|
||||
However, if you add GPL Version 2 code and therefore, elected the GPL
|
||||
Version 2 license, then the option applies only if the new code is
|
||||
made subject to such option by the copyright holder.
|
||||
-->
|
||||
|
||||
<project name="jnlp-impl" default="default" basedir=".." xmlns:jnlp="http://www.netbeans.org/ns/j2se-project/jnlp" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3">
|
||||
@ -842,6 +866,18 @@
|
||||
description="Debug javaws project in IDE"/>
|
||||
|
||||
<target name="-init-debug-args">
|
||||
<property name="version-output" value="java version "${ant.java.version}"/>
|
||||
<condition property="have-jdk-older-than-1.4">
|
||||
<or>
|
||||
<contains string="${version-output}" substring="java version "1.0"/>
|
||||
<contains string="${version-output}" substring="java version "1.1"/>
|
||||
<contains string="${version-output}" substring="java version "1.2"/>
|
||||
<contains string="${version-output}" substring="java version "1.3"/>
|
||||
</or>
|
||||
</condition>
|
||||
<condition else="-Xdebug" property="debug-args-line" value="-Xdebug -Xnoagent -Djava.compiler=none">
|
||||
<istrue value="${have-jdk-older-than-1.4}"/>
|
||||
</condition>
|
||||
<condition else="dt_socket" property="debug-transport-by-os" value="dt_shmem">
|
||||
<os family="windows"/>
|
||||
</condition>
|
||||
@ -853,7 +889,7 @@
|
||||
<target name="-debug-javaws-debuggee" depends="-init-debug-args,-init-platform,-check-webstart">
|
||||
<echo message="Executing ${jnlp.dest.dir}${file.separator}${jnlp.file} in debug mode using ${active.webstart.executable}"/>
|
||||
<exec executable="${active.webstart.executable}">
|
||||
<env key="JAVAWS_VM_ARGS" value="-agentlib:jdwp=transport=${debug-transport},address=${jpda.address}"/>
|
||||
<env key="JAVAWS_VM_ARGS" value="${debug-args-line} -Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
|
||||
<arg value="-wait"/>
|
||||
<arg file="${jnlp.dest.dir}${file.separator}${jnlp.file}"/>
|
||||
</exec>
|
||||
|
@ -1,4 +1,4 @@
|
||||
#Fri, 30 Nov 2018 16:58:10 +0100
|
||||
#Sat, 01 Dec 2018 03:21:26 +0100
|
||||
annotation.processing.enabled=true
|
||||
annotation.processing.enabled.in.editor=false
|
||||
annotation.processing.processors.list=
|
||||
@ -63,6 +63,7 @@ javac.test.processorpath=${javac.test.classpath}
|
||||
javadoc.additionalparam=
|
||||
javadoc.author=false
|
||||
javadoc.encoding=${source.encoding}
|
||||
javadoc.html5=false
|
||||
javadoc.noindex=false
|
||||
javadoc.nonavbar=false
|
||||
javadoc.notree=false
|
||||
@ -71,6 +72,8 @@ javadoc.splitindex=true
|
||||
javadoc.use=true
|
||||
javadoc.version=false
|
||||
javadoc.windowtitle=
|
||||
jlink.launcher=false
|
||||
jlink.launcher.name=OpenSeSim
|
||||
jnlp.applet.height=300
|
||||
jnlp.applet.width=300
|
||||
jnlp.codebase.type=user
|
||||
@ -97,7 +100,7 @@ manifest.custom.permissions=
|
||||
manifest.file=manifest.mf
|
||||
meta.inf.dir=${src.dir}/META-INF
|
||||
mkdist.disabled=false
|
||||
platform.active=default_platform
|
||||
platform.active=JDK_1.11.0
|
||||
project.license=bsd
|
||||
run.classpath=${javac.classpath}\:${build.classes.dir}
|
||||
# Space-separated list of JVM arguments used when running the project.
|
||||
@ -111,4 +114,4 @@ source.encoding=UTF-8
|
||||
src.dir=src
|
||||
test.src.dir=test
|
||||
ivy.home=/usr/share/java
|
||||
ivy.classpath=lib/jackson-annotations-2.9.0.jar\:lib/jackson-annotations-2.9.7-javadoc.jar\:lib/jackson-annotations-2.9.7-sources.jar\:lib/jackson-annotations-2.9.7.jar\:lib/jackson-core-2.9.7-javadoc.jar\:lib/jackson-core-2.9.7-sources.jar\:lib/jackson-core-2.9.7.jar\:lib/jackson-databind-2.9.7-javadoc.jar\:lib/jackson-databind-2.9.7-sources.jar\:lib/jackson-databind-2.9.7.jar\:lib/javahelp-2.0.05-javadoc.jar\:lib/javahelp-2.0.05-sources.jar\:lib/javahelp-2.0.05.jar\:lib/json-20160810-javadoc.jar\:lib/json-20160810-sources.jar\:lib/json-20160810.jar
|
||||
ivy.classpath=lib/gson-2.8.5-javadoc.jar\:lib/gson-2.8.5-sources.jar\:lib/gson-2.8.5.jar\:lib/jackson-annotations-2.9.0.jar\:lib/jackson-core-2.9.7-javadoc.jar\:lib/jackson-core-2.9.7-sources.jar\:lib/jackson-core-2.9.7.jar\:lib/jackson-databind-2.9.7-javadoc.jar\:lib/jackson-databind-2.9.7-sources.jar\:lib/jackson-databind-2.9.7.jar\:lib/javahelp-2.0.05-javadoc.jar\:lib/javahelp-2.0.05-sources.jar\:lib/javahelp-2.0.05.jar\:lib/json-20160810-javadoc.jar\:lib/json-20160810-sources.jar\:lib/json-20160810.jar
|
||||
|
@ -10,6 +10,7 @@
|
||||
</buildExtensions>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<name>OpenSeSim</name>
|
||||
<explicit-platform explicit-source-supported="true"/>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
</source-roots>
|
||||
|
@ -25,25 +25,22 @@
|
||||
*/
|
||||
package opensesim.gui.AssetEditor;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.MapperFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import java.awt.Dialog;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.awt.Window;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import opensesim.AbstractAsset;
|
||||
import opensesim.World;
|
||||
|
||||
import opensesim.gui.EscDialog;
|
||||
import opensesim.gui.Globals;
|
||||
import opensesim.gui.util.Json;
|
||||
import opensesim.gui.util.Json.Export;
|
||||
import opensesim.util.IDGenerator.Id;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
@ -63,6 +60,12 @@ public class AssetEditorDialog extends EscDialog {
|
||||
world = Globals.world;
|
||||
}
|
||||
|
||||
public AssetEditorDialog(Window parent) {
|
||||
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
|
||||
@ -125,6 +128,10 @@ public class AssetEditorDialog extends EscDialog {
|
||||
|
||||
private Id newId = null;
|
||||
|
||||
@Export
|
||||
public String hallo = "hallo";
|
||||
|
||||
|
||||
public Id getCreatedId() {
|
||||
return newId;
|
||||
}
|
||||
@ -185,6 +192,47 @@ public class AssetEditorDialog extends EscDialog {
|
||||
|
||||
}//GEN-LAST:event_cancelButtonActionPerformed
|
||||
|
||||
static public boolean runDialog(Window parent, JSONObject o) {
|
||||
//JSONObject jo = new org.json.JSONObject(parent, new String[]{"getMyName"});
|
||||
//System.out.printf("PARENT: %s", jo.toString());
|
||||
// JSONObject.
|
||||
|
||||
|
||||
|
||||
|
||||
AssetEditorDialog d = new AssetEditorDialog(parent);
|
||||
d.assetEditorPanel.symField.setText("Hallo");
|
||||
//d.assetEditorPanel.symField.setText("Herr");
|
||||
JSONObject jo = Json.get(d.assetEditorPanel);
|
||||
|
||||
System.out.printf("Resulting JSONN %s\n", jo.toString(5));
|
||||
|
||||
//Class aClass = d.assetEditorPanel.getClass().getDeclaredFields();
|
||||
|
||||
Field[] fields = d.assetEditorPanel.getClass().getFields();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
for (Field f : fields) {
|
||||
|
||||
Export ex = f.getAnnotation(Export.class);
|
||||
System.out.printf("Fieldname: %s\n",f.getName());
|
||||
|
||||
|
||||
|
||||
if (ex == null){
|
||||
continue;
|
||||
}
|
||||
|
||||
System.out.printf("EX: %s\n", ex.getClass().getName());
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
static public Id runDialog(Dialog parent, AbstractAsset asset) {
|
||||
AssetEditorDialog dialog = new AssetEditorDialog(parent, asset);
|
||||
dialog.assetEditorPanel.initFields(asset);
|
||||
@ -215,7 +263,7 @@ public class AssetEditorDialog extends EscDialog {
|
||||
|
||||
return dialog.newId;
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
|
@ -25,7 +25,12 @@
|
||||
*/
|
||||
package opensesim.gui.AssetEditor;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonGetter;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.logging.Level;
|
||||
@ -37,6 +42,7 @@ import javax.swing.JPanel;
|
||||
import opensesim.AbstractAsset;
|
||||
import opensesim.gui.Globals;
|
||||
import opensesim.gui.util.JTextFieldLimit;
|
||||
import opensesim.gui.util.Json.Export;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -44,6 +50,10 @@ import opensesim.gui.util.JTextFieldLimit;
|
||||
*/
|
||||
public class AssetEditorPanel extends javax.swing.JPanel {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ArrayList<Class<AbstractAsset>> asset_types;
|
||||
|
||||
/**
|
||||
@ -58,6 +68,19 @@ public class AssetEditorPanel extends javax.swing.JPanel {
|
||||
AbstractAsset a1, a2;
|
||||
try {
|
||||
a1 = o1.newInstance();
|
||||
try {
|
||||
try {
|
||||
a1 = o1.getConstructor().newInstance(null);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
Logger.getLogger(AssetEditorPanel.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (InvocationTargetException ex) {
|
||||
Logger.getLogger(AssetEditorPanel.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
} catch (NoSuchMethodException ex) {
|
||||
Logger.getLogger(AssetEditorPanel.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (SecurityException ex) {
|
||||
Logger.getLogger(AssetEditorPanel.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
a2 = o2.newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException ex) {
|
||||
Logger.getLogger(AssetEditorPanel.class.getName()).log(Level.SEVERE, null, ex);
|
||||
@ -89,17 +112,22 @@ public class AssetEditorPanel extends javax.swing.JPanel {
|
||||
|
||||
}
|
||||
|
||||
@JsonGetter("name")
|
||||
|
||||
public String getNameField() {
|
||||
return nameField.getText();
|
||||
}
|
||||
@JsonGetter("sym")
|
||||
|
||||
|
||||
public String getSymField() {
|
||||
return symField.getText();
|
||||
}
|
||||
|
||||
@Export
|
||||
public String hallo = "hello";
|
||||
|
||||
public JDialog dialog;
|
||||
|
||||
|
||||
ComboBoxModel getComboBoxModel() {
|
||||
ArrayList vector = new ArrayList();
|
||||
|
||||
@ -116,7 +144,7 @@ public class AssetEditorPanel extends javax.swing.JPanel {
|
||||
|
||||
for (i = 0; i < asset_types.size(); i++) {
|
||||
AbstractAsset ait;
|
||||
Class <AbstractAsset> asset_type = asset_types.get(i);
|
||||
Class<AbstractAsset> asset_type = asset_types.get(i);
|
||||
try {
|
||||
|
||||
ait = asset_type.newInstance();
|
||||
@ -164,6 +192,12 @@ public class AssetEditorPanel extends javax.swing.JPanel {
|
||||
|
||||
jLabel2.setText("Type:");
|
||||
|
||||
symField.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
symFieldActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jLabel3.setText("Name:");
|
||||
|
||||
jLabel4.setText("Decimals:");
|
||||
@ -279,6 +313,10 @@ public class AssetEditorPanel extends javax.swing.JPanel {
|
||||
|
||||
}//GEN-LAST:event_assetTypesComboBoxActionPerformed
|
||||
|
||||
private void symFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_symFieldActionPerformed
|
||||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_symFieldActionPerformed
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
public javax.swing.JComboBox<String> assetTypesComboBox;
|
||||
@ -291,6 +329,7 @@ public class AssetEditorPanel extends javax.swing.JPanel {
|
||||
private javax.swing.JLabel jLabel4;
|
||||
private javax.swing.JLabel label;
|
||||
protected opensesim.gui.util.JTextFieldLimit nameField;
|
||||
protected opensesim.gui.util.JTextFieldLimit symField;
|
||||
@Export
|
||||
public opensesim.gui.util.JTextFieldLimit symField;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
|
36
src/opensesim/gui/AssetEditor/GuiSelectionList.java
Normal file
36
src/opensesim/gui/AssetEditor/GuiSelectionList.java
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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 org.json.JSONObject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public interface GuiSelectionList {
|
||||
JSONObject getSelectedObject();
|
||||
}
|
@ -25,6 +25,7 @@
|
||||
*/
|
||||
package opensesim.gui;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import opensesim.chart.Help;
|
||||
import opensesim.chart.SuperDlg;
|
||||
import java.awt.Dialog;
|
||||
@ -940,6 +941,20 @@ public class SeSimApplication extends javax.swing.JFrame {
|
||||
ExchangeListDialog.runDialog(this);
|
||||
|
||||
}//GEN-LAST:event_exchangesMenuItemActionPerformed
|
||||
public static class Pojo {
|
||||
|
||||
public String getSymbol() {
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String symbol = "EUR";
|
||||
public String name = "Euro";
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
@ -948,6 +963,29 @@ public class SeSimApplication extends javax.swing.JFrame {
|
||||
*/
|
||||
public static void main(String args[]) throws IllegalAccessException, InstantiationException {
|
||||
|
||||
|
||||
// testing
|
||||
|
||||
Pojo p = new Pojo();
|
||||
|
||||
Gson g = new Gson();
|
||||
String r = g.toJson(p);
|
||||
|
||||
System.out.printf("GSON: %s\n", r);
|
||||
|
||||
JSONObject o = new JSONObject(p,new String[]{"name","symbol"});
|
||||
System.out.printf("OJSON: %s\n", o.toString(8));
|
||||
|
||||
|
||||
|
||||
|
||||
// System.exit(0);
|
||||
|
||||
|
||||
// end testing
|
||||
|
||||
|
||||
|
||||
// Initialize globals
|
||||
Class<?> c = opensesim.gui.SeSimApplication.class;
|
||||
Globals.initGlobals(c);
|
||||
|
88
src/opensesim/gui/util/Json.java
Normal file
88
src/opensesim/gui/util/Json.java
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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 java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.JTextField;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class Json {
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.FIELD, ElementType.METHOD})
|
||||
public static @interface Export {
|
||||
|
||||
public String value() default "";
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.FIELD, ElementType.METHOD})
|
||||
public static @interface Import {
|
||||
|
||||
public String value() default "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static JSONObject get(Object o) {
|
||||
Field[] fields = o.getClass().getFields();
|
||||
JSONObject jo = new JSONObject();
|
||||
|
||||
for (Field f : fields) {
|
||||
|
||||
System.out.printf("CHECKFIELD %s\n", f.getName());
|
||||
Export ex = f.getAnnotation(Export.class);
|
||||
if (ex == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Class cls = f.getType();
|
||||
if (JTextField.class.isAssignableFrom(cls)){
|
||||
try {
|
||||
JTextField tf = (JTextField) f.get(o);
|
||||
jo.put(f.getName(), tf.getText());
|
||||
} catch (IllegalArgumentException | IllegalAccessException ex1) {
|
||||
Logger.getLogger(Json.class.getName()).log(Level.SEVERE, null, ex1);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.printf("EX: %s\n", ex.getClass().getName());
|
||||
|
||||
}
|
||||
|
||||
return jo;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user