New dialog to select asset type before creation
This commit is contained in:
parent
1a7012ef66
commit
fdf09d651d
@ -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();
|
||||
|
@ -86,6 +86,7 @@
|
||||
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="getComboBoxModel()" type="code"/>
|
||||
</Property>
|
||||
<Property name="enabled" type="boolean" value="false"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="assetTypesComboBoxActionPerformed"/>
|
||||
|
@ -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<Class<AbstractAsset>> 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<Class<AbstractAsset>>() {
|
||||
@Override
|
||||
public int compare(Class<AbstractAsset> o1, Class<AbstractAsset> 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<AbstractAsset> 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 {
|
||||
);
|
||||
}// </editor-fold>//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<AbstractAsset> ac = (Class<AbstractAsset>) 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
|
||||
|
||||
|
@ -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 {
|
||||
}// </editor-fold>//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
|
||||
|
@ -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);
|
||||
|
97
src/opensesim/gui/AssetEditor/SelectAssetTypeDialog.form
Normal file
97
src/opensesim/gui/AssetEditor/SelectAssetTypeDialog.form
Normal file
@ -0,0 +1,97 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="2"/>
|
||||
<Property name="title" type="java.lang.String" value="Select Asset Type to create"/>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
|
||||
</SyntheticProperties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace min="0" pref="158" 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>
|
||||
<Group type="102" attributes="0">
|
||||
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="assetTypeComboBox" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="assetTypeComboBox" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace pref="31" 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"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JButton" name="cancelButton">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Cancel"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cancelButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="okButton">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Create ..."/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="okButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JComboBox" name="assetTypeComboBox">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="getComboBoxModel()" type="code"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<String>"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="jLabel1">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Type:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
212
src/opensesim/gui/AssetEditor/SelectAssetTypeDialog.java
Normal file
212
src/opensesim/gui/AssetEditor/SelectAssetTypeDialog.java
Normal file
@ -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<Class<AbstractAsset>>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<AbstractAsset> 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")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//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();
|
||||
}// </editor-fold>//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 */
|
||||
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
|
||||
/* 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);
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
/* 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<String> assetTypeComboBox;
|
||||
private javax.swing.JButton cancelButton;
|
||||
private javax.swing.JLabel jLabel1;
|
||||
private javax.swing.JButton okButton;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
@ -26,7 +26,7 @@
|
||||
package opensesim.gui.AssetPairEditor;
|
||||
|
||||
import opensesim.World;
|
||||
import opensesim.gui.EscDialog;
|
||||
import opensesim.gui.util.EscDialog;
|
||||
import opensesim.gui.Globals;
|
||||
|
||||
/**
|
||||
|
@ -25,6 +25,7 @@
|
||||
*/
|
||||
package opensesim.gui;
|
||||
|
||||
import opensesim.gui.util.EscDialog;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
|
@ -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<Class<AbstractAsset>> getAvailableAssetsTypes() {
|
||||
// ArrayList<Class> asset_types_raw;
|
||||
// ClassLoader old = setXClassLoader();
|
||||
// asset_types_raw = opensesim.util.XClassLoader.getClassesList(urllist, AbstractAsset.class);
|
||||
// unsetXClassLoader(old);
|
||||
static public ArrayList<Class<AbstractAsset>> getAvailableAssetsTypes(boolean sort) {
|
||||
|
||||
Collection<Class> asset_types_raw;
|
||||
asset_types_raw = class_cache.getClassCollection(AbstractAsset.class);
|
||||
|
||||
ArrayList<Class<AbstractAsset>> asset_types = new ArrayList<>();
|
||||
for (Class a : asset_types_raw) {
|
||||
Class<AbstractAsset> 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<Class<AbstractAsset>>() {
|
||||
@Override
|
||||
public int compare(Class<AbstractAsset> o1, Class<AbstractAsset> 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<Class<AbstractAsset>> getAvailableAssetsTypes() {
|
||||
return getAvailableAssetsTypes(false);
|
||||
}
|
||||
|
||||
static public Class getClassByName(String name) {
|
||||
return class_cache.getClassByName(name);
|
||||
}
|
||||
|
||||
static public void installLookAndFeels() {
|
||||
Collection<Class> lafs;
|
||||
// lafs = opensesim.util.XClassLoader.getClassesList(urllist, LookAndFeel.class);
|
||||
|
@ -25,6 +25,7 @@
|
||||
*/
|
||||
package opensesim.gui;
|
||||
|
||||
import opensesim.gui.util.EscDialog;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
@ -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;
|
43
src/opensesim/gui/util/Misc.java
Normal file
43
src/opensesim/gui/util/Misc.java
Normal file
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
@ -222,6 +222,10 @@ public class XClassLoader {
|
||||
return Collections.unmodifiableCollection(h);
|
||||
}
|
||||
|
||||
public Class getClassByName(String name){
|
||||
return byName.get(name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user