From fdf09d651d70df7a4596982e779426fadbb861f6 Mon Sep 17 00:00:00 2001
From: 7u83 <7u83@mail.ru>
Date: Sat, 1 Dec 2018 22:36:57 +0100
Subject: [PATCH] New dialog to select asset type before creation
---
.../gui/AssetEditor/AssetEditorDialog.java | 5 +-
.../gui/AssetEditor/AssetEditorPanel.form | 1 +
.../gui/AssetEditor/AssetEditorPanel.java | 112 ++++-----
.../gui/AssetEditor/AssetListDialog.java | 58 +----
.../gui/AssetEditor/AssetListPanel.java | 3 +-
.../AssetEditor/SelectAssetTypeDialog.form | 97 ++++++++
.../AssetEditor/SelectAssetTypeDialog.java | 212 ++++++++++++++++++
.../gui/AssetPairEditor/NewJDialog.java | 2 +-
src/opensesim/gui/EditExchangeDialog.java | 1 +
src/opensesim/gui/Globals.java | 61 +++--
src/opensesim/gui/NewStrategyDialog.java | 1 +
.../EditPreferencesDialog.java | 2 +-
src/opensesim/gui/TraderListPanel.java | 2 +-
.../exchangeeditor/ExchangeEditorDialog.java | 2 +-
.../exchangeeditor/ExchangeListDialog.java | 2 +-
src/opensesim/gui/orderbook/OrderBook.java | 2 +-
src/opensesim/gui/{ => util}/EscDialog.form | 0
src/opensesim/gui/{ => util}/EscDialog.java | 2 +-
src/opensesim/gui/util/Misc.java | 43 ++++
.../{tools => util}/NummericCellRenderer.java | 2 +-
src/opensesim/util/XClassLoader.java | 4 +
21 files changed, 467 insertions(+), 147 deletions(-)
create mode 100644 src/opensesim/gui/AssetEditor/SelectAssetTypeDialog.form
create mode 100644 src/opensesim/gui/AssetEditor/SelectAssetTypeDialog.java
rename src/opensesim/gui/{ => util}/EscDialog.form (100%)
rename src/opensesim/gui/{ => util}/EscDialog.java (99%)
create mode 100644 src/opensesim/gui/util/Misc.java
rename src/opensesim/gui/{tools => util}/NummericCellRenderer.java (98%)
diff --git a/src/opensesim/gui/AssetEditor/AssetEditorDialog.java b/src/opensesim/gui/AssetEditor/AssetEditorDialog.java
index c159f4c..b42e6b0 100644
--- a/src/opensesim/gui/AssetEditor/AssetEditorDialog.java
+++ b/src/opensesim/gui/AssetEditor/AssetEditorDialog.java
@@ -33,7 +33,7 @@ import java.lang.reflect.Field;
import opensesim.AbstractAsset;
import opensesim.World;
-import opensesim.gui.EscDialog;
+import opensesim.gui.util.EscDialog;
import opensesim.gui.Globals;
import opensesim.gui.util.Json;
import opensesim.gui.util.Json.Export;
@@ -197,7 +197,8 @@ public class AssetEditorDialog extends EscDialog {
AssetEditorDialog d = new AssetEditorDialog(parent);
if (o!=null)
Json.put(d.assetEditorPanel, o);
-
+ d.pack();
+ d.revalidate();
d.setLocationRelativeTo(parent);
d.setVisible(true);
d.dispose();
diff --git a/src/opensesim/gui/AssetEditor/AssetEditorPanel.form b/src/opensesim/gui/AssetEditor/AssetEditorPanel.form
index d685c9c..078828b 100644
--- a/src/opensesim/gui/AssetEditor/AssetEditorPanel.form
+++ b/src/opensesim/gui/AssetEditor/AssetEditorPanel.form
@@ -86,6 +86,7 @@
+
diff --git a/src/opensesim/gui/AssetEditor/AssetEditorPanel.java b/src/opensesim/gui/AssetEditor/AssetEditorPanel.java
index a10a212..86d3719 100644
--- a/src/opensesim/gui/AssetEditor/AssetEditorPanel.java
+++ b/src/opensesim/gui/AssetEditor/AssetEditorPanel.java
@@ -25,7 +25,6 @@
*/
package opensesim.gui.AssetEditor;
-
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -51,10 +50,6 @@ import opensesim.gui.util.Json.Import;
*/
public class AssetEditorPanel extends javax.swing.JPanel {
-
-
-
-
ArrayList> asset_types;
/**
@@ -62,40 +57,8 @@ public class AssetEditorPanel extends javax.swing.JPanel {
*/
public AssetEditorPanel() {
super();
- asset_types = Globals.getAvailableAssetsTypes();
- asset_types.sort(new Comparator>() {
- @Override
- public int compare(Class o1, Class o2) {
- 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);
- return 0;
- }
+ asset_types = Globals.getAvailableAssetsTypes(true);
- String t1, t2;
- t1 = a1.getTypeName();
- t2 = a2.getTypeName();
-
- return t1.compareToIgnoreCase(t2);
- }
-
- });
initComponents();
symField.setLimit(Globals.MAX.SYMLEN);
@@ -113,56 +76,38 @@ public class AssetEditorPanel extends javax.swing.JPanel {
}
-
public String getNameField() {
return nameField.getText();
}
-
public String getSymField() {
return symField.getText();
}
-
+
@Export
public String hallo = "hello";
-
- @Import("type")
- public void putType(String type){
+
+ public void putType(String type) {
System.out.printf("Here we have a type: %s\n", type);
}
-
- public JDialog dialog;
+ public JDialog dialog;
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 {
+ System.out.printf("ACL: %s\n", asset_type.getName());
+ try {
ait = 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());
}
@@ -190,6 +135,7 @@ public class AssetEditorPanel extends javax.swing.JPanel {
jLabel1.setText("Symbol:");
assetTypesComboBox.setModel(getComboBoxModel());
+ assetTypesComboBox.setEnabled(false);
assetTypesComboBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
assetTypesComboBoxActionPerformed(evt);
@@ -290,13 +236,27 @@ public class AssetEditorPanel extends javax.swing.JPanel {
);
}// //GEN-END:initComponents
- private void assetTypesComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_assetTypesComboBoxActionPerformed
+ @Import("type")
+ public void setType(String type) {
+ System.out.printf("Here we have a type: %s\n", type);
+
+ Class ac = (Class) Globals.getClassByName(type);
+ if (ac == null) {
+ return;
+ }
+
+ System.out.printf("ACNAME: %s\n", ac.getName());
- int i = this.assetTypesComboBox.getSelectedIndex();
AbstractAsset a;
+
try {
- a = (AbstractAsset) asset_types.get(i).newInstance();
- } catch (InstantiationException | IllegalAccessException ex) {
+ 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) {
Logger.getLogger(AssetEditorPanel.class.getName()).log(Level.SEVERE, null, ex);
return;
}
@@ -305,7 +265,6 @@ public class AssetEditorPanel extends javax.swing.JPanel {
guiPanel.removeAll();
if (gui != null) {
-
guiPanel.add(gui, java.awt.BorderLayout.CENTER);
gui.setVisible(true);
@@ -313,9 +272,24 @@ public class AssetEditorPanel extends javax.swing.JPanel {
guiPanel.add(defaultGuiPanel, java.awt.BorderLayout.CENTER);
}
- dialog.pack();
- dialog.revalidate();
+ for (int i = 0; i < asset_types.size(); i++) {
+ if (asset_types.get(i).getName().equals(type)) {
+ assetTypesComboBox.setSelectedIndex(i);
+ }
+ }
+ }
+
+
+ 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
diff --git a/src/opensesim/gui/AssetEditor/AssetListDialog.java b/src/opensesim/gui/AssetEditor/AssetListDialog.java
index bb2710b..f7133f8 100644
--- a/src/opensesim/gui/AssetEditor/AssetListDialog.java
+++ b/src/opensesim/gui/AssetEditor/AssetListDialog.java
@@ -32,7 +32,7 @@ import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
-import opensesim.gui.EscDialog;
+import opensesim.gui.util.EscDialog;
import opensesim.sesim.Assets.BasicAsset;
import opensesim.util.IDGenerator.Id;
import org.json.JSONObject;
@@ -43,10 +43,6 @@ import org.json.JSONObject;
*/
public class AssetListDialog extends EscDialog {
- String getMyName(){
- return "Miau!";
- }
-
/**
* Creates new form EditAssetsDialog
*/
@@ -149,50 +145,14 @@ public class AssetListDialog extends EscDialog {
}// //GEN-END:initComponents
private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newButtonActionPerformed
-
- //AssetEditorDialog.runDialog(this, null);
+ String type = SelectAssetTypeDialog.runDialog(this);
+ if (type==null)
+ return;
+ JSONObject o = new JSONObject();
+ o.put("type", type);
+ AssetEditorDialog.runDialog(this, o, o);
this.assetListPanel.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
@@ -201,8 +161,8 @@ public class AssetListDialog extends EscDialog {
private void doEdit() {
JSONObject o = assetListPanel.getSelectedObject();
- System.out.printf("JON: %s",o.toString(4));
- AssetEditorDialog.runDialog(this, o,null);
+ System.out.printf("JON: %s", o.toString(4));
+ AssetEditorDialog.runDialog(this, o, null);
}
private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editButtonActionPerformed
diff --git a/src/opensesim/gui/AssetEditor/AssetListPanel.java b/src/opensesim/gui/AssetEditor/AssetListPanel.java
index 2383b26..33b7805 100644
--- a/src/opensesim/gui/AssetEditor/AssetListPanel.java
+++ b/src/opensesim/gui/AssetEditor/AssetListPanel.java
@@ -52,7 +52,8 @@ public class AssetListPanel extends javax.swing.JPanel implements GuiSelectionLi
return;
}
- json_set = new JSONObject(Globals.prefs.get("myassets", "{EUR:{name:Euro,decimals:8,type:Curreny}}"));
+ json_set = new JSONObject(Globals.prefs.get("myassets", "{"
+ + "EUR:{name:Euro,decimals:8,type:opensesim.sesim.Assets.FurtureAsset}}"));
reload();
assetTable.setRowSelectionAllowed(true);
diff --git a/src/opensesim/gui/AssetEditor/SelectAssetTypeDialog.form b/src/opensesim/gui/AssetEditor/SelectAssetTypeDialog.form
new file mode 100644
index 0000000..f25c782
--- /dev/null
+++ b/src/opensesim/gui/AssetEditor/SelectAssetTypeDialog.form
@@ -0,0 +1,97 @@
+
+
+
diff --git a/src/opensesim/gui/AssetEditor/SelectAssetTypeDialog.java b/src/opensesim/gui/AssetEditor/SelectAssetTypeDialog.java
new file mode 100644
index 0000000..85a4a2e
--- /dev/null
+++ b/src/opensesim/gui/AssetEditor/SelectAssetTypeDialog.java
@@ -0,0 +1,212 @@
+/*
+ * 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.Window;
+import java.util.ArrayList;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.swing.ComboBoxModel;
+import javax.swing.DefaultComboBoxModel;
+import opensesim.AbstractAsset;
+import opensesim.gui.Globals;
+import opensesim.gui.util.EscDialog;
+
+/**
+ *
+ * @author 7u83 <7u83@mail.ru>
+ */
+public class SelectAssetTypeDialog extends EscDialog {
+
+ ArrayList>asset_types;
+ /**
+ * Creates new form SelectAssetTypeDialog
+ */
+ public SelectAssetTypeDialog(Window parent, boolean modal) {
+ super(parent, modal);
+ asset_types = Globals.getAvailableAssetsTypes(true);
+ initComponents();
+
+ }
+
+ ComboBoxModel getComboBoxModel() {
+ ArrayList vector = new ArrayList();
+ int i;
+ for (i = 0; i < asset_types.size(); i++) {
+ AbstractAsset ait;
+ Class asset_type = asset_types.get(i);
+ System.out.printf("ACL: %s\n", asset_type.getName());
+
+ try {
+ ait = asset_type.newInstance();
+ vector.add(i, 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() {
+
+ cancelButton = new javax.swing.JButton();
+ okButton = new javax.swing.JButton();
+ assetTypeComboBox = new javax.swing.JComboBox<>();
+ jLabel1 = new javax.swing.JLabel();
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ setTitle("Select Asset Type to create");
+
+ cancelButton.setText("Cancel");
+ cancelButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ cancelButtonActionPerformed(evt);
+ }
+ });
+
+ okButton.setText("Create ...");
+ okButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ okButtonActionPerformed(evt);
+ }
+ });
+
+ assetTypeComboBox.setModel(getComboBoxModel());
+
+ jLabel1.setText("Type:");
+
+ 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, 158, Short.MAX_VALUE)
+ .addComponent(okButton)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(cancelButton))
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(jLabel1)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(assetTypeComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
+ .addContainerGap())
+ );
+ layout.setVerticalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addContainerGap()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(assetTypeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(jLabel1))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(cancelButton)
+ .addComponent(okButton))
+ .addContainerGap())
+ );
+
+ pack();
+ }// //GEN-END:initComponents
+
+ String selected = null;
+
+ private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
+ int i = this.assetTypeComboBox.getSelectedIndex();
+ selected = asset_types.get(i).getName();
+ dispose();
+ }//GEN-LAST:event_okButtonActionPerformed
+
+ private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
+ dispose();
+ }//GEN-LAST:event_cancelButtonActionPerformed
+
+
+ public static String runDialog(Window parent){
+ SelectAssetTypeDialog dialog;
+ dialog = new SelectAssetTypeDialog(parent,true);
+ dialog.setLocationRelativeTo(parent);
+ dialog.setVisible(true);
+ return dialog.selected;
+ }
+
+ /**
+ * @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(SelectAssetTypeDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (InstantiationException ex) {
+ java.util.logging.Logger.getLogger(SelectAssetTypeDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (IllegalAccessException ex) {
+ java.util.logging.Logger.getLogger(SelectAssetTypeDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (javax.swing.UnsupportedLookAndFeelException ex) {
+ java.util.logging.Logger.getLogger(SelectAssetTypeDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ }
+ //
+
+ /* Create and display the dialog */
+ java.awt.EventQueue.invokeLater(new Runnable() {
+ public void run() {
+ SelectAssetTypeDialog dialog = new SelectAssetTypeDialog(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 javax.swing.JComboBox assetTypeComboBox;
+ private javax.swing.JButton cancelButton;
+ private javax.swing.JLabel jLabel1;
+ private javax.swing.JButton okButton;
+ // End of variables declaration//GEN-END:variables
+}
diff --git a/src/opensesim/gui/AssetPairEditor/NewJDialog.java b/src/opensesim/gui/AssetPairEditor/NewJDialog.java
index 76c66a2..8816991 100644
--- a/src/opensesim/gui/AssetPairEditor/NewJDialog.java
+++ b/src/opensesim/gui/AssetPairEditor/NewJDialog.java
@@ -26,7 +26,7 @@
package opensesim.gui.AssetPairEditor;
import opensesim.World;
-import opensesim.gui.EscDialog;
+import opensesim.gui.util.EscDialog;
import opensesim.gui.Globals;
/**
diff --git a/src/opensesim/gui/EditExchangeDialog.java b/src/opensesim/gui/EditExchangeDialog.java
index faa22cd..86e288a 100644
--- a/src/opensesim/gui/EditExchangeDialog.java
+++ b/src/opensesim/gui/EditExchangeDialog.java
@@ -25,6 +25,7 @@
*/
package opensesim.gui;
+import opensesim.gui.util.EscDialog;
import org.json.JSONObject;
/**
diff --git a/src/opensesim/gui/Globals.java b/src/opensesim/gui/Globals.java
index e35194c..ef3efa4 100644
--- a/src/opensesim/gui/Globals.java
+++ b/src/opensesim/gui/Globals.java
@@ -29,13 +29,14 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
+import java.lang.reflect.InvocationTargetException;
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;
import java.util.Collection;
+import java.util.Comparator;
import java.util.Iterator;
import java.util.TreeMap;
import java.util.logging.Level;
@@ -45,19 +46,14 @@ 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 opensesim.gui.AssetEditor.AssetEditorPanel;
import org.json.JSONArray;
import org.json.JSONObject;
-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;
import opensesim.util.XClassLoader.ClassCache;
/**
@@ -118,7 +114,7 @@ public class Globals {
public static final class MAX {
- public static final int SYMLEN = 6;
+ public static final int SYMLEN = 16;
public static final int NAMELEN = 64;
}
@@ -211,24 +207,53 @@ public class Globals {
}
- static public ArrayList> getAvailableAssetsTypes() {
-// ArrayList asset_types_raw;
-// ClassLoader old = setXClassLoader();
- // asset_types_raw = opensesim.util.XClassLoader.getClassesList(urllist, AbstractAsset.class);
- // unsetXClassLoader(old);
+ static public ArrayList> getAvailableAssetsTypes(boolean sort) {
+
Collection asset_types_raw;
asset_types_raw = class_cache.getClassCollection(AbstractAsset.class);
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));
- }
+ asset_types_raw.forEach((a) -> {
+ asset_types.add(a);
+ });
+
+ if (!sort)
+ return asset_types;
+
+ asset_types.sort(new Comparator>() {
+ @Override
+ public int compare(Class o1, Class o2) {
+ AbstractAsset a1, a2;
+
+ try {
+ // a1 = o1.newInstance();
+ a1 = o1.getConstructor().newInstance();
+ a2 = o2.getConstructor().newInstance();
+ } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException ex) {
+ Logger.getLogger(AssetEditorPanel.class.getName()).log(Level.SEVERE, null, ex);
+ return 0;
+ }
+
+ String t1, t2;
+ t1 = a1.getTypeName();
+ t2 = a2.getTypeName();
+
+ return t1.compareToIgnoreCase(t2);
+ }
+
+ });
return asset_types;
}
+ static public ArrayList> getAvailableAssetsTypes() {
+ return getAvailableAssetsTypes(false);
+ }
+
+ static public Class getClassByName(String name) {
+ return class_cache.getClassByName(name);
+ }
+
static public void installLookAndFeels() {
Collection lafs;
// lafs = opensesim.util.XClassLoader.getClassesList(urllist, LookAndFeel.class);
diff --git a/src/opensesim/gui/NewStrategyDialog.java b/src/opensesim/gui/NewStrategyDialog.java
index cac027f..9fb1faa 100644
--- a/src/opensesim/gui/NewStrategyDialog.java
+++ b/src/opensesim/gui/NewStrategyDialog.java
@@ -25,6 +25,7 @@
*/
package opensesim.gui;
+import opensesim.gui.util.EscDialog;
import java.util.ArrayList;
/**
diff --git a/src/opensesim/gui/PreferencesEditor/EditPreferencesDialog.java b/src/opensesim/gui/PreferencesEditor/EditPreferencesDialog.java
index da3117a..5930907 100644
--- a/src/opensesim/gui/PreferencesEditor/EditPreferencesDialog.java
+++ b/src/opensesim/gui/PreferencesEditor/EditPreferencesDialog.java
@@ -43,7 +43,7 @@ import javax.swing.UnsupportedLookAndFeelException;
*
* @author 7u83 <7u83@mail.ru>
*/
-public class EditPreferencesDialog extends opensesim.gui.EscDialog {
+public class EditPreferencesDialog extends opensesim.gui.util.EscDialog {
UIManager.LookAndFeelInfo[] lafInfo;
diff --git a/src/opensesim/gui/TraderListPanel.java b/src/opensesim/gui/TraderListPanel.java
index c6ae928..e081fac 100644
--- a/src/opensesim/gui/TraderListPanel.java
+++ b/src/opensesim/gui/TraderListPanel.java
@@ -25,7 +25,7 @@
*/
package opensesim.gui;
-import opensesim.gui.tools.NummericCellRenderer;
+import opensesim.gui.util.NummericCellRenderer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
diff --git a/src/opensesim/gui/exchangeeditor/ExchangeEditorDialog.java b/src/opensesim/gui/exchangeeditor/ExchangeEditorDialog.java
index 1b0a405..d287e4e 100644
--- a/src/opensesim/gui/exchangeeditor/ExchangeEditorDialog.java
+++ b/src/opensesim/gui/exchangeeditor/ExchangeEditorDialog.java
@@ -30,7 +30,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDialog;
import javax.swing.JFrame;
-import opensesim.gui.EscDialog;
+import opensesim.gui.util.EscDialog;
import opensesim.util.SeSimException;
/**
diff --git a/src/opensesim/gui/exchangeeditor/ExchangeListDialog.java b/src/opensesim/gui/exchangeeditor/ExchangeListDialog.java
index 9291a85..4f9848b 100644
--- a/src/opensesim/gui/exchangeeditor/ExchangeListDialog.java
+++ b/src/opensesim/gui/exchangeeditor/ExchangeListDialog.java
@@ -28,7 +28,7 @@ package opensesim.gui.exchangeeditor;
import java.awt.Dialog;
import java.awt.Window;
import javax.swing.JFrame;
-import opensesim.gui.EscDialog;
+import opensesim.gui.util.EscDialog;
import opensesim.util.SeSimException;
/**
diff --git a/src/opensesim/gui/orderbook/OrderBook.java b/src/opensesim/gui/orderbook/OrderBook.java
index d840be2..7ecc1aa 100644
--- a/src/opensesim/gui/orderbook/OrderBook.java
+++ b/src/opensesim/gui/orderbook/OrderBook.java
@@ -27,7 +27,7 @@ package opensesim.gui.orderbook;
import opensesim.gui.Globals;
import opensesim.gui.Globals.CfgListener;
-import opensesim.gui.tools.NummericCellRenderer;
+import opensesim.gui.util.NummericCellRenderer;
import java.awt.Component;
import java.text.DecimalFormat;
import java.util.ArrayList;
diff --git a/src/opensesim/gui/EscDialog.form b/src/opensesim/gui/util/EscDialog.form
similarity index 100%
rename from src/opensesim/gui/EscDialog.form
rename to src/opensesim/gui/util/EscDialog.form
diff --git a/src/opensesim/gui/EscDialog.java b/src/opensesim/gui/util/EscDialog.java
similarity index 99%
rename from src/opensesim/gui/EscDialog.java
rename to src/opensesim/gui/util/EscDialog.java
index 831d3a9..eb1f270 100644
--- a/src/opensesim/gui/EscDialog.java
+++ b/src/opensesim/gui/util/EscDialog.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 opensesim.gui;
+package opensesim.gui.util;
import java.awt.Dialog;
import java.awt.event.ActionEvent;
diff --git a/src/opensesim/gui/util/Misc.java b/src/opensesim/gui/util/Misc.java
new file mode 100644
index 0000000..fa837d2
--- /dev/null
+++ b/src/opensesim/gui/util/Misc.java
@@ -0,0 +1,43 @@
+/*
+ * 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.JComboBox;
+
+/**
+ *
+ * @author 7u83 <7u83@mail.ru>
+ */
+public class Misc {
+
+ public class AssetTypeComboBox extends JComboBox
+ {
+ AssetTypeComboBox(){
+ super();
+ }
+ }
+
+}
diff --git a/src/opensesim/gui/tools/NummericCellRenderer.java b/src/opensesim/gui/util/NummericCellRenderer.java
similarity index 98%
rename from src/opensesim/gui/tools/NummericCellRenderer.java
rename to src/opensesim/gui/util/NummericCellRenderer.java
index d90aac9..7555c46 100644
--- a/src/opensesim/gui/tools/NummericCellRenderer.java
+++ b/src/opensesim/gui/util/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 opensesim.gui.tools;
+package opensesim.gui.util;
import java.awt.Component;
import java.text.DecimalFormat;
diff --git a/src/opensesim/util/XClassLoader.java b/src/opensesim/util/XClassLoader.java
index 2936c51..5a852c0 100644
--- a/src/opensesim/util/XClassLoader.java
+++ b/src/opensesim/util/XClassLoader.java
@@ -222,6 +222,10 @@ public class XClassLoader {
return Collections.unmodifiableCollection(h);
}
+ public Class getClassByName(String name){
+ return byName.get(name);
+ }
+
}
}