Added a chart - beta
This commit is contained in:
parent
c1d3f9e4ec
commit
b0f9fabf52
@ -48,11 +48,102 @@ import SeSim.Exchange;
|
|||||||
*/
|
*/
|
||||||
public class Chart extends javax.swing.JPanel implements Exchange.QuoteReceiver {
|
public class Chart extends javax.swing.JPanel implements Exchange.QuoteReceiver {
|
||||||
|
|
||||||
|
SeSim.Exchange se;
|
||||||
|
|
||||||
|
private DefaultHighLowDataset createDataset() {
|
||||||
|
|
||||||
|
System.out.print("Making Data");
|
||||||
|
int s = se.quoteHistory.size();
|
||||||
|
System.out.print(("SIZE"));
|
||||||
|
System.out.println(s);
|
||||||
|
|
||||||
|
int serice = 115;
|
||||||
|
|
||||||
|
Date[] date = new Date[serice];
|
||||||
|
double[] high = new double[serice];
|
||||||
|
double[] low = new double[serice];
|
||||||
|
double[] open = new double[serice];
|
||||||
|
double[] close = new double[serice];
|
||||||
|
double[] volume = new double[serice];
|
||||||
|
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.set(2008, 5, 1);
|
||||||
|
|
||||||
|
for (int i = 0; i < serice; i++) {
|
||||||
|
date[i] = createData(2008, 8, i + 1);
|
||||||
|
high[i] = 30 + Math.round(10) + new Double(Math.random() * 20.0);
|
||||||
|
low[i] = 30 + Math.round(10) + new Double(Math.random() * 20.0);
|
||||||
|
open[i] = 10 + Math.round(10) + new Double(Math.random() * 20.0);
|
||||||
|
close[i] = 10 + Math.round(10) + new Double(Math.random() * 20.0);
|
||||||
|
volume[i] = 10.0 + new Double(Math.random() * 20.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
DefaultHighLowDataset data = new DefaultHighLowDataset("", date, high,
|
||||||
|
low, open, close, volume);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Date createData(int year, int month, int date) {
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.set(year, month - 1, date);
|
||||||
|
return calendar.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
private JFreeChart createChart(final DefaultHighLowDataset dataset) {
|
||||||
|
// final JFreeChart chart = ChartFactory.createCandlestickChart(
|
||||||
|
//"Candlestick Demo", "Time", "Price", dataset, false);
|
||||||
|
|
||||||
|
// final JFreeChart chart = ChartFactory.createCandlestickChart(
|
||||||
|
// "Candlestick Demo", "Time", "Price", dataset, false);
|
||||||
|
final JFreeChart chart = ChartFactory.createXYLineChart(
|
||||||
|
"Hallo", "X acse", "yachse", dataset,
|
||||||
|
PlotOrientation.VERTICAL,
|
||||||
|
true, // include legend
|
||||||
|
true, // tooltips
|
||||||
|
false // urls;
|
||||||
|
);
|
||||||
|
|
||||||
|
//"Candlestick Demo", "Time", "Price", dataset, false);
|
||||||
|
return chart;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new form Chart
|
* Creates new form Chart
|
||||||
*/
|
*/
|
||||||
public Chart() {
|
public Chart() {
|
||||||
initComponents();
|
initComponents();
|
||||||
|
|
||||||
|
this.se = MainWin.se;
|
||||||
|
if (this.se == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final DefaultHighLowDataset dataset = createDataset();
|
||||||
|
final JFreeChart chart = createChart(dataset);
|
||||||
|
|
||||||
|
final ChartPanel chartPanel = new ChartPanel(chart);
|
||||||
|
chartPanel.setPreferredSize(new java.awt.Dimension(800, 350));
|
||||||
|
// setContentPane(chartPanel);
|
||||||
|
initChart(chartPanel);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initChart(ChartPanel chart) {
|
||||||
|
|
||||||
|
// orderBook1 = new Gui.OrderBook();
|
||||||
|
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||||
|
this.setLayout(layout);
|
||||||
|
layout.setHorizontalGroup(
|
||||||
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
|
.addComponent(chart, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
|
||||||
|
);
|
||||||
|
layout.setVerticalGroup(
|
||||||
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
|
.addGroup(layout.createSequentialGroup()
|
||||||
|
.addContainerGap()
|
||||||
|
.addComponent(chart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
|
.addContainerGap(16, Short.MAX_VALUE))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,7 +168,6 @@ public class Chart extends javax.swing.JPanel implements Exchange.QuoteReceiver
|
|||||||
}// </editor-fold>//GEN-END:initComponents
|
}// </editor-fold>//GEN-END:initComponents
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
||||||
public void UpdateQuote(Exchange.Quote q) {
|
public void UpdateQuote(Exchange.Quote q) {
|
||||||
System.out.print("Quote received");
|
System.out.print("Quote received");
|
||||||
System.out.println(q.price);
|
System.out.println(q.price);
|
||||||
|
@ -75,7 +75,7 @@
|
|||||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||||
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,-66,0,0,2,72"/>
|
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,2,93,0,0,2,-69"/>
|
||||||
</AuxValues>
|
</AuxValues>
|
||||||
|
|
||||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
|
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
|
||||||
@ -114,25 +114,12 @@
|
|||||||
</Constraint>
|
</Constraint>
|
||||||
</Constraints>
|
</Constraints>
|
||||||
</Component>
|
</Component>
|
||||||
<Container class="Gui.Chart" name="chart1">
|
<Component class="Gui.Chart" name="chart2">
|
||||||
<Constraints>
|
<Constraints>
|
||||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
||||||
<BorderConstraints direction="Center"/>
|
<BorderConstraints direction="Center"/>
|
||||||
</Constraint>
|
</Constraint>
|
||||||
</Constraints>
|
</Constraints>
|
||||||
|
</Component>
|
||||||
<Layout>
|
|
||||||
<DimensionLayout dim="0">
|
|
||||||
<Group type="103" groupAlignment="0" attributes="0">
|
|
||||||
<EmptySpace min="0" pref="273" max="32767" attributes="0"/>
|
|
||||||
</Group>
|
|
||||||
</DimensionLayout>
|
|
||||||
<DimensionLayout dim="1">
|
|
||||||
<Group type="103" groupAlignment="0" attributes="0">
|
|
||||||
<EmptySpace min="0" pref="151" max="32767" attributes="0"/>
|
|
||||||
</Group>
|
|
||||||
</DimensionLayout>
|
|
||||||
</Layout>
|
|
||||||
</Container>
|
|
||||||
</SubComponents>
|
</SubComponents>
|
||||||
</Form>
|
</Form>
|
||||||
|
@ -41,7 +41,7 @@ public class MainWin extends javax.swing.JFrame {
|
|||||||
jLabel2 = new javax.swing.JLabel();
|
jLabel2 = new javax.swing.JLabel();
|
||||||
orderBook1 = new Gui.OrderBook();
|
orderBook1 = new Gui.OrderBook();
|
||||||
controlPanel2 = new Gui.ControlPanel();
|
controlPanel2 = new Gui.ControlPanel();
|
||||||
chart1 = new Gui.Chart();
|
chart2 = new Gui.Chart();
|
||||||
MainMenu = new javax.swing.JMenuBar();
|
MainMenu = new javax.swing.JMenuBar();
|
||||||
FileMenu = new javax.swing.JMenu();
|
FileMenu = new javax.swing.JMenu();
|
||||||
FileNew = new javax.swing.JMenuItem();
|
FileNew = new javax.swing.JMenuItem();
|
||||||
@ -67,19 +67,7 @@ public class MainWin extends javax.swing.JFrame {
|
|||||||
getContentPane().add(jLabel2, java.awt.BorderLayout.CENTER);
|
getContentPane().add(jLabel2, java.awt.BorderLayout.CENTER);
|
||||||
getContentPane().add(orderBook1, java.awt.BorderLayout.PAGE_END);
|
getContentPane().add(orderBook1, java.awt.BorderLayout.PAGE_END);
|
||||||
getContentPane().add(controlPanel2, java.awt.BorderLayout.LINE_END);
|
getContentPane().add(controlPanel2, java.awt.BorderLayout.LINE_END);
|
||||||
|
getContentPane().add(chart2, java.awt.BorderLayout.CENTER);
|
||||||
javax.swing.GroupLayout chart1Layout = new javax.swing.GroupLayout(chart1);
|
|
||||||
chart1.setLayout(chart1Layout);
|
|
||||||
chart1Layout.setHorizontalGroup(
|
|
||||||
chart1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
||||||
.addGap(0, 273, Short.MAX_VALUE)
|
|
||||||
);
|
|
||||||
chart1Layout.setVerticalGroup(
|
|
||||||
chart1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
||||||
.addGap(0, 151, Short.MAX_VALUE)
|
|
||||||
);
|
|
||||||
|
|
||||||
getContentPane().add(chart1, java.awt.BorderLayout.CENTER);
|
|
||||||
|
|
||||||
FileMenu.setBackground(new java.awt.Color(254, 203, 1));
|
FileMenu.setBackground(new java.awt.Color(254, 203, 1));
|
||||||
FileMenu.setText("File");
|
FileMenu.setText("File");
|
||||||
@ -202,7 +190,7 @@ public class MainWin extends javax.swing.JFrame {
|
|||||||
private javax.swing.JMenuItem FileNew;
|
private javax.swing.JMenuItem FileNew;
|
||||||
private javax.swing.JMenuItem FileRun;
|
private javax.swing.JMenuItem FileRun;
|
||||||
private javax.swing.JMenuBar MainMenu;
|
private javax.swing.JMenuBar MainMenu;
|
||||||
private Gui.Chart chart1;
|
private Gui.Chart chart2;
|
||||||
private Gui.ControlPanel controlPanel2;
|
private Gui.ControlPanel controlPanel2;
|
||||||
private javax.swing.JButton jButton1;
|
private javax.swing.JButton jButton1;
|
||||||
private javax.swing.JLabel jLabel1;
|
private javax.swing.JLabel jLabel1;
|
||||||
|
@ -6,6 +6,18 @@ import java.util.concurrent.*;
|
|||||||
import SeSim.Order.OrderStatus;
|
import SeSim.Order.OrderStatus;
|
||||||
|
|
||||||
public class Exchange extends Thread {
|
public class Exchange extends Thread {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Histrory of all quotes
|
||||||
|
*/
|
||||||
|
public ArrayList<Quote> quoteHistory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
public Exchange() {
|
||||||
|
this.quoteHistory = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
// Class to describe an executed order
|
// Class to describe an executed order
|
||||||
public class Quote {
|
public class Quote {
|
||||||
@ -42,7 +54,7 @@ public class Exchange extends Thread {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Quote> quoteHistory = new ArrayList<>();
|
|
||||||
|
|
||||||
// long time = 0;
|
// long time = 0;
|
||||||
double price = 12.9;
|
double price = 12.9;
|
||||||
|
Loading…
Reference in New Issue
Block a user