...
This commit is contained in:
@ -25,7 +25,6 @@
|
||||
*/
|
||||
package gui;
|
||||
|
||||
import sesim.Exchange.*;
|
||||
import sesim.Order.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
@ -34,10 +34,10 @@ public class CandlestickDemo extends JFrame {
|
||||
|
||||
//Now create the chart and chart panel
|
||||
JFreeChart chart = new JFreeChart(stockSymbol, null, mainPlot, false);
|
||||
ChartPanel chartPanel = new ChartPanel(chart);
|
||||
chartPanel.setPreferredSize(new Dimension(600, 300));
|
||||
// ChartPanel chartPanel = new ChartPanel(chart);
|
||||
// chartPanel.setPreferredSize(new Dimension(600, 300));
|
||||
|
||||
this.add(chartPanel);
|
||||
// this.add(chartPanel);
|
||||
this.pack();
|
||||
}
|
||||
protected AbstractXYDataset getDataSet(String stockSymbol) {
|
||||
|
@ -74,7 +74,9 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
|
||||
DateAxis domainAxis = new DateAxis("Date");
|
||||
NumberAxis rangeAxis = new NumberAxis("Price");
|
||||
|
||||
CandlestickRenderer renderer = new CandlestickRenderer();
|
||||
|
||||
XYDataset dataset = getDataSet(stockSymbol);
|
||||
|
||||
XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);
|
||||
@ -87,8 +89,9 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
|
||||
//Now create the chart and chart panel
|
||||
JFreeChart chart = new JFreeChart(stockSymbol, null, mainPlot, false);
|
||||
|
||||
ChartPanel chartPanel = new ChartPanel(chart);
|
||||
|
||||
|
||||
chartPanel.setPreferredSize(new Dimension(500, 270));
|
||||
|
||||
add(chartPanel);
|
||||
@ -129,12 +132,11 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
double high = 0;
|
||||
double low = 0;
|
||||
double close = 0;
|
||||
double volume=0;
|
||||
double volume = 0;
|
||||
|
||||
Iterator<Quote> it = l.iterator();
|
||||
|
||||
Quote q;
|
||||
|
||||
|
||||
if (it.hasNext()) {
|
||||
q = it.next();
|
||||
@ -142,11 +144,9 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
high = q.price;
|
||||
low = q.price;
|
||||
volume = q.volume;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
q = new Quote();
|
||||
}
|
||||
|
||||
|
||||
while (it.hasNext() && q.time < last) {
|
||||
q = it.next();
|
||||
@ -178,13 +178,13 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
|
||||
SortedSet<Quote> h = MainWin.se.getQuoteHistory(ct - 60);
|
||||
|
||||
for (long i = (ct - 60)*1000; i < (ct + 10)*1000; i += 10*1000) {
|
||||
OHLCDataItem d = getOhlcData(i, i + 10*1000, h);
|
||||
for (long i = (ct - 60) * 1000; i < (ct + 10) * 1000; i += 10 * 1000) {
|
||||
OHLCDataItem d = getOhlcData(i, i + 10 * 1000, h);
|
||||
data.add(d);
|
||||
}
|
||||
|
||||
System.out.print(data.size() + "\n");
|
||||
// System.exit(0);
|
||||
// System.exit(0);
|
||||
|
||||
return data.toArray(new OHLCDataItem[data.size()]);
|
||||
|
||||
@ -255,8 +255,16 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
|
||||
@Override
|
||||
public void UpdateQuote(Quote q) {
|
||||
return;
|
||||
//q.print();
|
||||
|
||||
// q.print();
|
||||
long ct;
|
||||
ct = Exchange.getCurrentTimeSeconds(5);
|
||||
SortedSet<Quote> h = MainWin.se.getQuoteHistory(ct - 15);
|
||||
|
||||
System.out.print("Number of quotes" + ct + "\n");
|
||||
|
||||
System.out.print("Number of quotes:" + h.size() + "\n");
|
||||
|
||||
/* SortedSet h = MainWin.se.getQuoteHistory(60);
|
||||
System.out.print(
|
||||
"SortedSet size:"
|
||||
|
28
src/main/java/gui/ChartPanel.form
Normal file
28
src/main/java/gui/ChartPanel.form
Normal file
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
|
||||
<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">
|
||||
<EmptySpace min="0" pref="400" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
</Form>
|
46
src/main/java/gui/ChartPanel.java
Normal file
46
src/main/java/gui/ChartPanel.java
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package gui;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class ChartPanel extends javax.swing.JPanel {
|
||||
|
||||
/**
|
||||
* Creates new form ChartPanel
|
||||
*/
|
||||
public ChartPanel() {
|
||||
initComponents();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 400, Short.MAX_VALUE)
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 300, Short.MAX_VALUE)
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
130
src/main/java/gui/DTSCTest.java
Normal file
130
src/main/java/gui/DTSCTest.java
Normal file
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Random;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.Timer;
|
||||
import org.jfree.chart.ChartFactory;
|
||||
import org.jfree.chart.ChartPanel;
|
||||
import org.jfree.chart.JFreeChart;
|
||||
import org.jfree.chart.axis.ValueAxis;
|
||||
import org.jfree.chart.plot.XYPlot;
|
||||
import org.jfree.data.time.DynamicTimeSeriesCollection;
|
||||
import org.jfree.data.time.Second;
|
||||
import org.jfree.data.xy.XYDataset;
|
||||
import org.jfree.ui.ApplicationFrame;
|
||||
import org.jfree.ui.RefineryUtilities;
|
||||
|
||||
/**
|
||||
* @see http://stackoverflow.com/questions/5048852
|
||||
*/
|
||||
public class DTSCTest extends ApplicationFrame {
|
||||
|
||||
private static final String TITLE = "Dynamic Series";
|
||||
private static final String START = "Start";
|
||||
private static final String STOP = "Stop";
|
||||
private static final float MINMAX = 300;
|
||||
private static final int COUNT = 2 * 60;
|
||||
private static final int FAST = 100;
|
||||
private static final int SLOW = FAST * 5;
|
||||
private static final Random RANDOM = new Random();
|
||||
private Timer timer;
|
||||
|
||||
public DTSCTest(final String title) {
|
||||
super(title);
|
||||
final DynamicTimeSeriesCollection dataset
|
||||
= new DynamicTimeSeriesCollection(1, COUNT, new Second());
|
||||
dataset.setTimeBase(new Second(0, 0, 0, 1, 1, 2011));
|
||||
dataset.addSeries(gaussianData(), 0, "Gaussian data");
|
||||
JFreeChart chart = createChart(dataset);
|
||||
|
||||
final JButton run = new JButton(STOP);
|
||||
run.addActionListener((ActionEvent e) -> {
|
||||
String cmd = e.getActionCommand();
|
||||
if (STOP.equals(cmd)) {
|
||||
timer.stop();
|
||||
run.setText(START);
|
||||
} else {
|
||||
timer.start();
|
||||
run.setText(STOP);
|
||||
}
|
||||
});
|
||||
|
||||
final JComboBox combo = new JComboBox();
|
||||
combo.addItem("Fast");
|
||||
combo.addItem("Slow");
|
||||
combo.addActionListener((ActionEvent e) -> {
|
||||
if ("Fast".equals(combo.getSelectedItem())) {
|
||||
timer.setDelay(FAST);
|
||||
} else {
|
||||
timer.setDelay(SLOW);
|
||||
}
|
||||
});
|
||||
|
||||
this.add(new ChartPanel(chart), BorderLayout.CENTER);
|
||||
JPanel btnPanel = new JPanel(new FlowLayout());
|
||||
// btnPanel.add(run);
|
||||
// btnPanel.add(combo);
|
||||
this.add(btnPanel, BorderLayout.SOUTH);
|
||||
|
||||
timer = new Timer(FAST, new ActionListener() {
|
||||
|
||||
float[] newData = new float[1];
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
newData[0] = randomValue();
|
||||
dataset.advanceTime();
|
||||
dataset.appendData(newData);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private float randomValue() {
|
||||
return (float) (RANDOM.nextGaussian() * MINMAX / 3);
|
||||
}
|
||||
|
||||
private float[] gaussianData() {
|
||||
float[] a = new float[COUNT];
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
a[i] = randomValue();
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
private JFreeChart createChart(final XYDataset dataset) {
|
||||
final JFreeChart result = ChartFactory.createTimeSeriesChart(
|
||||
TITLE, "hh:mm:ss", "milliVolts", dataset, true, true, false);
|
||||
final XYPlot plot = result.getXYPlot();
|
||||
ValueAxis domain = plot.getDomainAxis();
|
||||
domain.setAutoRange(true);
|
||||
ValueAxis range = plot.getRangeAxis();
|
||||
range.setRange(-MINMAX, MINMAX);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
timer.start();
|
||||
}
|
||||
|
||||
public static void main(final String[] args) {
|
||||
EventQueue.invokeLater(() -> {
|
||||
DTSCTest demo = new DTSCTest(TITLE);
|
||||
demo.pack();
|
||||
RefineryUtilities.centerFrameOnScreen(demo);
|
||||
demo.setVisible(true);
|
||||
demo.start();
|
||||
});
|
||||
}
|
||||
}
|
@ -97,7 +97,7 @@ public abstract class OrderBook extends javax.swing.JPanel implements Exchange.B
|
||||
protected class OrderBookListModel extends AbstractTableModel {
|
||||
|
||||
private ArrayList list;
|
||||
private boolean desc = false;
|
||||
//private final boolean desc = false;
|
||||
|
||||
public OrderBookListModel() {
|
||||
// System.out.print("CREATING A NEW MODEL\n");
|
||||
|
@ -105,11 +105,48 @@ public class test {
|
||||
|
||||
return ts.tailSet(iter.next());
|
||||
}
|
||||
|
||||
|
||||
static abstract interface Rc {
|
||||
public abstract int inc(int x);
|
||||
// public abstract int dec(int x);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String args[]) {
|
||||
NoProblem p = new NoProblem();
|
||||
p.run();
|
||||
// NoProblem p = new NoProblem();
|
||||
// p.run();
|
||||
|
||||
Rc a = new Rc(){
|
||||
@Override
|
||||
public int inc(int x) {
|
||||
return x+1;
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public int dec(int x) {
|
||||
return x+1;
|
||||
}
|
||||
*/
|
||||
|
||||
};
|
||||
|
||||
|
||||
Rc l = (x) -> x+1;
|
||||
|
||||
|
||||
System.out.print("A:"
|
||||
+a.inc(17)
|
||||
+" "
|
||||
+l.inc(4)
|
||||
|
||||
);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user