So. Now we build our editor around a world object.
Yes! We do!
This commit is contained in:
parent
03fbd9cd25
commit
160dcb6b21
34
src/opensesim/gui/AdmInterface.java
Normal file
34
src/opensesim/gui/AdmInterface.java
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tohe
|
||||
*/
|
||||
public interface AdmInterface {
|
||||
|
||||
}
|
@ -27,13 +27,13 @@
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||
<Component id="okButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="cancelButton" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="assetEditorPanel" alignment="0" pref="527" max="32767" attributes="0"/>
|
||||
<Component id="assetEditorPanel" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
@ -43,8 +43,8 @@
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="assetEditorPanel" pref="138" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="assetEditorPanel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="73" max="32767" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="cancelButton" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="okButton" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
|
@ -27,18 +27,14 @@ package opensesim.gui.AssetEditor;
|
||||
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Window;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import opensesim.world.AbstractAsset;
|
||||
import opensesim.world.World;
|
||||
|
||||
import opensesim.gui.util.EscDialog;
|
||||
import opensesim.gui.Globals;
|
||||
import opensesim.gui.util.Json;
|
||||
import opensesim.gui.util.Json.Export;
|
||||
|
||||
import org.json.JSONException;
|
||||
import opensesim.world.World;
|
||||
import opensesim.world.WorldAdm;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
@ -47,7 +43,7 @@ import org.json.JSONObject;
|
||||
*/
|
||||
public class AssetEditorDialog extends EscDialog {
|
||||
|
||||
|
||||
WorldAdm worldadm;
|
||||
|
||||
|
||||
/**
|
||||
@ -103,20 +99,20 @@ public class AssetEditorDialog extends EscDialog {
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addGroup(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))
|
||||
.addComponent(assetEditorPanel, 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(assetEditorPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(assetEditorPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 73, Short.MAX_VALUE)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(cancelButton)
|
||||
.addComponent(okButton))
|
||||
@ -129,12 +125,23 @@ public class AssetEditorDialog extends EscDialog {
|
||||
|
||||
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
|
||||
|
||||
if (assetEditorPanel.save(worldadm)){
|
||||
dispose();
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
|
||||
/*
|
||||
JSONObject result = Json.get(assetEditorPanel);
|
||||
System.out.printf("JSON: %s\n", result.toString(5));
|
||||
JSONObject all = Globals.getAssets();
|
||||
all.put(result.getString("symbol"), result);
|
||||
Globals.putAssets(all);
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* if (this.asset == null) {
|
||||
try {
|
||||
int selected = this.assetEditorPanel.assetTypesComboBox.getSelectedIndex();
|
||||
@ -179,7 +186,7 @@ public class AssetEditorDialog extends EscDialog {
|
||||
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
|
||||
|
||||
@ -189,9 +196,12 @@ public class AssetEditorDialog extends EscDialog {
|
||||
|
||||
}//GEN-LAST:event_cancelButtonActionPerformed
|
||||
|
||||
static public boolean runDialog(Window parent, JSONObject o, JSONObject all) {
|
||||
static public boolean runDialog(Window parent, WorldAdm worldadm, JSONObject o, JSONObject old) {
|
||||
|
||||
AssetEditorDialog d = new AssetEditorDialog(parent);
|
||||
d.worldadm = worldadm;
|
||||
|
||||
|
||||
if (o!=null)
|
||||
Json.put(d.assetEditorPanel, o);
|
||||
d.pack();
|
||||
|
@ -35,8 +35,14 @@ import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import opensesim.world.AbstractAsset;
|
||||
import opensesim.gui.Globals;
|
||||
import static opensesim.gui.Globals.world;
|
||||
import opensesim.gui.util.Json;
|
||||
import opensesim.gui.util.Json.Export;
|
||||
import opensesim.gui.util.Json.Import;
|
||||
import opensesim.util.SeSimException;
|
||||
import opensesim.world.World;
|
||||
import opensesim.world.WorldAdm;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -69,7 +75,7 @@ public class AssetEditorPanel extends javax.swing.JPanel {
|
||||
|
||||
}
|
||||
|
||||
public String getNameField() {
|
||||
/* public String getNameField() {
|
||||
return nameField.getText();
|
||||
}
|
||||
|
||||
@ -80,7 +86,7 @@ public class AssetEditorPanel extends javax.swing.JPanel {
|
||||
public void putType(String type) {
|
||||
System.out.printf("Here we have a type: %s\n", type);
|
||||
}
|
||||
|
||||
*/
|
||||
public JDialog dialog;
|
||||
|
||||
ComboBoxModel getComboBoxModel() {
|
||||
@ -213,24 +219,28 @@ public class AssetEditorPanel extends javax.swing.JPanel {
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
@Export
|
||||
public String getDeecimals(){
|
||||
public String getDeecimals() {
|
||||
return decimalsField.getValue().toString();
|
||||
}
|
||||
|
||||
|
||||
@Import
|
||||
public void setDecimals(String d){
|
||||
public void setDecimals(String d) {
|
||||
decimalsField.setValue(Integer.parseInt(d));
|
||||
}
|
||||
|
||||
@Export("type")
|
||||
|
||||
@Export(World.JKEYS.ASSET_TYPE)
|
||||
public String getType() {
|
||||
int selected = assetTypesComboBox.getSelectedIndex();
|
||||
return asset_types.get(selected).getName();
|
||||
//return asset_types.get(selected).getName();
|
||||
return this.type;
|
||||
}
|
||||
|
||||
@Import("type")
|
||||
String type;
|
||||
|
||||
@Import(World.JKEYS.ASSET_TYPE)
|
||||
public void setType(String type) {
|
||||
|
||||
this.type=type;
|
||||
|
||||
Class<AbstractAsset> ac = (Class<AbstractAsset>) Globals.getClassByName(type);
|
||||
if (ac == null) {
|
||||
return;
|
||||
@ -239,13 +249,8 @@ public class AssetEditorPanel extends javax.swing.JPanel {
|
||||
AbstractAsset a;
|
||||
|
||||
try {
|
||||
try {
|
||||
a = ac.getConstructor().newInstance();
|
||||
} catch (NoSuchMethodException | SecurityException ex) {
|
||||
Logger.getLogger(AssetEditorPanel.class.getName()).log(Level.SEVERE, null, ex);
|
||||
return;
|
||||
}
|
||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
|
||||
a = ac.getConstructor(World.class, JSONObject.class).newInstance(null, null);
|
||||
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
|
||||
Logger.getLogger(AssetEditorPanel.class.getName()).log(Level.SEVERE, null, ex);
|
||||
return;
|
||||
}
|
||||
@ -268,15 +273,38 @@ public class AssetEditorPanel extends javax.swing.JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean save(WorldAdm worldadm ){
|
||||
JSONObject jo = Json.get(this);
|
||||
|
||||
if (jo.getString(World.JKEYS.ASSET_SYMBOL).length()==0){
|
||||
javax.swing.JOptionPane.showMessageDialog(this, "Symbol must not be empty.",
|
||||
"Error",
|
||||
javax.swing.JOptionPane.ERROR_MESSAGE);
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
worldadm.world.createAsset(worldadm.masterKey, jo);
|
||||
} catch (SeSimException ex) {
|
||||
javax.swing.JOptionPane.showMessageDialog(this, ex.getMessage(),
|
||||
"Error",
|
||||
javax.swing.JOptionPane.ERROR_MESSAGE);
|
||||
return false;
|
||||
}
|
||||
|
||||
System.out.printf("JO: %s\n",jo);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void assetTypesComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_assetTypesComboBoxActionPerformed
|
||||
|
||||
int i = this.assetTypesComboBox.getSelectedIndex();
|
||||
setType(asset_types.get(i).getName());
|
||||
//this.pack();
|
||||
revalidate();
|
||||
repaint();
|
||||
|
||||
return;
|
||||
|
||||
}//GEN-LAST:event_assetTypesComboBoxActionPerformed
|
||||
|
@ -28,7 +28,7 @@
|
||||
<Group type="102" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace min="0" pref="250" max="32767" attributes="0"/>
|
||||
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||
<Component id="jButton3" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="editButton" min="-2" max="-2" attributes="0"/>
|
||||
@ -98,6 +98,9 @@
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="opensesim.gui.AssetEditor.AssetListPanel" name="assetListPanel">
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new opensesim.gui.AssetEditor.AssetListPanel(worldadm)"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
|
@ -25,9 +25,12 @@
|
||||
*/
|
||||
package opensesim.gui.AssetEditor;
|
||||
|
||||
import java.awt.Window;
|
||||
import java.awt.event.MouseEvent;
|
||||
import opensesim.gui.Globals;
|
||||
import opensesim.gui.util.EscDialog;
|
||||
import opensesim.world.World;
|
||||
import opensesim.world.WorldAdm;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
@ -37,10 +40,12 @@ import org.json.JSONObject;
|
||||
*/
|
||||
public class AssetListDialog extends EscDialog {
|
||||
|
||||
WorldAdm worldadm;
|
||||
|
||||
/**
|
||||
* Creates new form EditAssetsDialog
|
||||
*/
|
||||
public AssetListDialog(java.awt.Frame parent, boolean modal) {
|
||||
public AssetListDialog(Window parent, boolean modal) {
|
||||
super(parent, modal);
|
||||
initComponents();
|
||||
|
||||
@ -54,10 +59,29 @@ public class AssetListDialog extends EscDialog {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
this.assetListPanel.assetTable.addMouseListener(l);
|
||||
}
|
||||
|
||||
public AssetListDialog(WorldAdm worldadm, Window parent, boolean modal) {
|
||||
super(parent, modal);
|
||||
this.worldadm = worldadm;
|
||||
|
||||
initComponents();
|
||||
|
||||
java.awt.event.MouseAdapter l = new java.awt.event.MouseAdapter() {
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.getClickCount() == 2) {
|
||||
doEdit();
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
this.assetListPanel.assetTable.addMouseListener(l);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -71,7 +95,7 @@ public class AssetListDialog extends EscDialog {
|
||||
newButton = new javax.swing.JButton();
|
||||
jButton3 = new javax.swing.JButton();
|
||||
editButton = new javax.swing.JButton();
|
||||
assetListPanel = new opensesim.gui.AssetEditor.AssetListPanel();
|
||||
assetListPanel = new opensesim.gui.AssetEditor.AssetListPanel(worldadm);
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
|
||||
setTitle("Edit Assets");
|
||||
@ -113,7 +137,7 @@ public class AssetListDialog extends EscDialog {
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(0, 250, Short.MAX_VALUE)
|
||||
.addGap(0, 0, Short.MAX_VALUE)
|
||||
.addComponent(jButton3)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(editButton)
|
||||
@ -149,8 +173,9 @@ public class AssetListDialog extends EscDialog {
|
||||
return;
|
||||
}
|
||||
JSONObject o = new JSONObject();
|
||||
o.put("type", type);
|
||||
AssetEditorDialog.runDialog(this, o, o);
|
||||
o.put(World.JKEYS.ASSET_TYPE, type);
|
||||
|
||||
AssetEditorDialog.runDialog(this, worldadm, o, null);
|
||||
assetListPanel.reload();
|
||||
|
||||
}//GEN-LAST:event_newButtonActionPerformed
|
||||
@ -161,7 +186,7 @@ public class AssetListDialog extends EscDialog {
|
||||
|
||||
private void doEdit() {
|
||||
JSONObject o = assetListPanel.getSelectedObject();
|
||||
AssetEditorDialog.runDialog(this, o, o);
|
||||
// AssetEditorDialog.runDialog(this, o, o);
|
||||
assetListPanel.reload();
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
package opensesim.gui.AssetEditor;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Collection;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
@ -33,15 +34,16 @@ import javax.swing.table.TableModel;
|
||||
import opensesim.world.AbstractAsset;
|
||||
import opensesim.world.World;
|
||||
import opensesim.gui.Globals;
|
||||
import opensesim.world.WorldAdm;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class AssetListPanel extends javax.swing.JPanel implements GuiSelectionList{
|
||||
public class AssetListPanel extends javax.swing.JPanel implements GuiSelectionList {
|
||||
|
||||
World world;
|
||||
WorldAdm worldadm;
|
||||
|
||||
JSONObject json_set;
|
||||
|
||||
@ -49,7 +51,7 @@ public class AssetListPanel extends javax.swing.JPanel implements GuiSelectionLi
|
||||
* Creates new form AssetList
|
||||
*/
|
||||
public AssetListPanel() {
|
||||
world = Globals.world;
|
||||
|
||||
initComponents();
|
||||
|
||||
if (Globals.prefs == null) {
|
||||
@ -58,9 +60,9 @@ public class AssetListPanel extends javax.swing.JPanel implements GuiSelectionLi
|
||||
|
||||
json_set = new JSONObject(Globals.prefs.get("myassets", "{"
|
||||
+ "EUR:{name:Euro,decimals:8,type:opensesim.sesim.Assets.FurtureAsset}}"));
|
||||
|
||||
|
||||
json_set = Globals.getAssets();
|
||||
reload();
|
||||
// reload();
|
||||
|
||||
assetTable.setRowSelectionAllowed(true);
|
||||
|
||||
@ -69,6 +71,13 @@ public class AssetListPanel extends javax.swing.JPanel implements GuiSelectionLi
|
||||
assetTable.getColumnModel().getColumn(2).setPreferredWidth(80);
|
||||
}
|
||||
|
||||
public AssetListPanel(WorldAdm worldadm) {
|
||||
|
||||
this();
|
||||
this.worldadm = worldadm;
|
||||
reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getSelectedObject() {
|
||||
int row = assetTable.getSelectedRow();
|
||||
@ -77,7 +86,7 @@ public class AssetListPanel extends javax.swing.JPanel implements GuiSelectionLi
|
||||
}
|
||||
|
||||
final void reload() {
|
||||
json_set = Globals.getAssets();
|
||||
/* json_set = Globals.getAssets();
|
||||
DefaultTableModel m = (DefaultTableModel) assetTable.getModel();
|
||||
|
||||
|
||||
@ -98,7 +107,10 @@ public class AssetListPanel extends javax.swing.JPanel implements GuiSelectionLi
|
||||
Logger.getLogger(AssetListPanel.class.getName()).log(Level.SEVERE, null, ex);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
m.addRow(new Object[]{
|
||||
|
||||
@ -107,6 +119,35 @@ public class AssetListPanel extends javax.swing.JPanel implements GuiSelectionLi
|
||||
type_name
|
||||
});
|
||||
|
||||
}*/
|
||||
|
||||
Collection<AbstractAsset> assets;
|
||||
assets = worldadm.world.getAssetCollection();
|
||||
DefaultTableModel m = (DefaultTableModel) assetTable.getModel();
|
||||
m.setRowCount(0);
|
||||
for (AbstractAsset asset : assets) {
|
||||
JSONObject o;
|
||||
o = asset.getJson();
|
||||
if (o == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Class<AbstractAsset> a = Globals.getClassByName(o.optString("type"));
|
||||
String type_name;
|
||||
|
||||
try {
|
||||
type_name = a.getConstructor(World.class, JSONObject.class).newInstance(null, null).getTypeName();
|
||||
|
||||
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
|
||||
Logger.getLogger(AssetListPanel.class.getName()).log(Level.SEVERE, null, ex);
|
||||
continue;
|
||||
}
|
||||
m.addRow(new Object[]{
|
||||
o.opt("symbol"),
|
||||
o.opt("name"),
|
||||
type_name
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -144,7 +185,6 @@ public class AssetListPanel extends javax.swing.JPanel implements GuiSelectionLi
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
@ -26,6 +26,8 @@
|
||||
package opensesim.gui.AssetEditor;
|
||||
|
||||
import java.awt.Window;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@ -34,6 +36,8 @@ import javax.swing.DefaultComboBoxModel;
|
||||
import opensesim.world.AbstractAsset;
|
||||
import opensesim.gui.Globals;
|
||||
import opensesim.gui.util.EscDialog;
|
||||
import opensesim.world.World;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -61,10 +65,16 @@ public class SelectAssetTypeDialog extends EscDialog {
|
||||
System.out.printf("ACL: %s\n", asset_type.getName());
|
||||
|
||||
try {
|
||||
ait = asset_type.newInstance();
|
||||
Constructor<AbstractAsset> c;
|
||||
c = asset_type.getConstructor(World.class,JSONObject.class);
|
||||
ait = c.newInstance(null,null);
|
||||
|
||||
//ait = asset_type.getConstructor<AbstractAsset>(World.class,JSONObject.class).
|
||||
vector.add(i, ait.getTypeName());
|
||||
} catch (InstantiationException | IllegalAccessException | ClassCastException ex) {
|
||||
Logger.getLogger(AssetEditorPanel.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException ex) {
|
||||
Logger.getLogger(SelectAssetTypeDialog.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
return new DefaultComboBoxModel(vector.toArray());
|
||||
|
@ -211,6 +211,11 @@ public class Globals {
|
||||
|
||||
static public ArrayList<Class<AbstractAsset>> getAvailableAssetsTypes(boolean sort) {
|
||||
|
||||
// if class_cache is not initialized return an empty list
|
||||
if (class_cache == null){
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
Collection<Class> asset_types_raw;
|
||||
asset_types_raw = class_cache.getClassCollection(AbstractAsset.class);
|
||||
|
||||
@ -230,8 +235,8 @@ public class Globals {
|
||||
|
||||
try {
|
||||
// a1 = o1.newInstance();
|
||||
a1 = o1.getConstructor().newInstance();
|
||||
a2 = o2.getConstructor().newInstance();
|
||||
a1 = o1.getConstructor(World.class,JSONObject.class).newInstance(null,null);
|
||||
a2 = o2.getConstructor(World.class,JSONObject.class).newInstance(null,null);
|
||||
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException ex) {
|
||||
Logger.getLogger(AssetEditorPanel.class.getName()).log(Level.SEVERE, null, ex);
|
||||
return 0;
|
||||
|
@ -70,13 +70,17 @@ import opensesim.old_sesim.Scheduler;
|
||||
|
||||
import opensesim.util.XClassLoader;
|
||||
import opensesim.world.World;
|
||||
import opensesim.world.WorldAdm;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class SeSimApplication extends javax.swing.JFrame {
|
||||
|
||||
|
||||
WorldAdm worldadm;
|
||||
|
||||
/**
|
||||
* Creates new form NewMDIApplication
|
||||
*/
|
||||
@ -86,6 +90,11 @@ public class SeSimApplication extends javax.swing.JFrame {
|
||||
Globals.setLookAndFeel(Globals.prefs.get(Globals.PrefKeys.LAF, "Nimbus"));
|
||||
// Globals.setLookAndFeel("Metal");
|
||||
initComponents();
|
||||
|
||||
|
||||
worldadm = new WorldAdm();
|
||||
|
||||
|
||||
|
||||
// Get default screen and place our window
|
||||
// to the center of this screen
|
||||
@ -929,11 +938,14 @@ public class SeSimApplication extends javax.swing.JFrame {
|
||||
}//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 = new opensesim.gui.AssetEditor.AssetListDialog(worldadm,this,true);
|
||||
dialog.setLocationRelativeTo(this);
|
||||
dialog.setVisible(rootPaneCheckingEnabled);
|
||||
dialog.dispose();
|
||||
dialog.dispose();
|
||||
}//GEN-LAST:event_assetsMenuItemActionPerformed
|
||||
|
||||
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
|
||||
@ -970,6 +982,11 @@ public class SeSimApplication extends javax.swing.JFrame {
|
||||
*/
|
||||
public static void main(String args[]) throws IllegalAccessException, InstantiationException {
|
||||
|
||||
|
||||
|
||||
|
||||
//opensesim.world.World.MasterApi mapi = new opensesim.world.World.MasterApi();
|
||||
|
||||
|
||||
// testing
|
||||
|
||||
|
@ -160,18 +160,19 @@ public abstract class AbstractAsset {
|
||||
return null;
|
||||
}
|
||||
*/
|
||||
/* public JSONObject getConfig() {
|
||||
public JSONObject getJson() {
|
||||
JSONObject cfg = new JSONObject();
|
||||
cfg.put(AbstractAsset.JSON_ID,id.toString());
|
||||
cfg.put(AbstractAsset.JSON_CLASS, this.getClass().getName());
|
||||
cfg.put(World.JKEYS.ASSET_TYPE, 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;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public void putConfig(JSONObject cfg) {
|
||||
symbol = cfg.optString(AbstractAsset.JSON_SYMBOL);
|
||||
decimals = cfg.optInt(AbstractAsset.JSON_DECIMALS, AbstractAsset.DECIMALS_DEFAULT);
|
||||
|
49
src/opensesim/world/WorldAdm.java
Normal file
49
src/opensesim/world/WorldAdm.java
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.world;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tohe
|
||||
*/
|
||||
public class WorldAdm {
|
||||
public World world;
|
||||
public long masterKey;
|
||||
public WorldAdm(){
|
||||
masterKey = 123456;
|
||||
world = new World(masterKey);
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public long getMasterKey() {
|
||||
return masterKey;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user