OpenSeSim/src/chart/MasterChart.java

202 lines
8.4 KiB
Java
Raw Normal View History

2017-10-03 12:35:12 +02:00
/*
* Copyright (c) 2017, 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 chart;
import chart.painter.CandleStickChartPainter;
import chart.painter.ChartPainter;
2017-10-05 20:57:37 +02:00
import chart.painter.XLegendPainter;
import chart.painter.ChartCrossPainter;
2017-10-06 07:21:03 +02:00
import chart.painter.YLegendPainter;
2017-10-03 12:35:12 +02:00
import gui.Globals;
import sesim.Exchange.QuoteReceiver;
import sesim.OHLCData;
import sesim.Quote;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
2017-10-03 15:50:18 +02:00
public class MasterChart extends javax.swing.JPanel implements QuoteReceiver, ChartPainter.DataProvider {
2017-10-03 12:35:12 +02:00
/**
* Creates new form MasterChart
*/
public MasterChart() {
initComponents();
2017-10-03 15:50:18 +02:00
2017-10-03 12:35:12 +02:00
ChartDef def = new ChartDef();
2017-10-03 15:50:18 +02:00
def.x_unit_width = 1.0;
if (Globals.se == null) {
2017-10-03 12:35:12 +02:00
return;
2017-10-03 15:50:18 +02:00
}
Globals.se.addQuoteReceiver(this);
ChartPainter p = new CandleStickChartPainter();
this.xScrollBar.setMaximum(0);
2017-10-03 15:51:42 +02:00
2017-10-05 20:57:37 +02:00
p = new XLegendPainter();
2017-10-03 15:50:18 +02:00
p.setDataProvider(this);
2017-10-03 15:51:42 +02:00
2017-10-03 12:35:12 +02:00
xLegend.addChartPainter(p);
2017-10-03 15:50:18 +02:00
xLegend.setXSCrollBar(xScrollBar);
2017-10-06 07:21:03 +02:00
ChartPainter pc = new CandleStickChartPainter();
pc.setDataProvider(this);
2017-10-03 15:51:42 +02:00
2017-10-06 07:21:03 +02:00
chart.addChartPainter(pc);
2017-10-03 15:50:18 +02:00
chart.setXSCrollBar(xScrollBar);
2017-10-07 02:40:22 +02:00
chart.addChartPainter(new ChartCrossPainter());
2017-10-03 15:51:42 +02:00
2017-10-06 07:21:03 +02:00
ChartPainter yp = new YLegendPainter(chart);
yp.setDataProvider(this);
2017-10-07 02:40:22 +02:00
this.yLegend.addChartPainter(yp);
2017-10-06 07:21:03 +02:00
2017-10-07 02:40:22 +02:00
// this.yLegend.addChartPainter(p);
//this.yLegend.addChartPainter(pc);
2017-10-03 12:35:12 +02:00
}
/**
* 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() {
chart = new chart.ChartPanel();
yLegend = new chart.ChartPanel();
xLegend = new chart.ChartPanel();
xScrollBar = new javax.swing.JScrollBar();
chart.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(153, 0, 153), 1, true));
chart.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseMoved(java.awt.event.MouseEvent evt) {
chartMouseMoved(evt);
}
});
javax.swing.GroupLayout chartLayout = new javax.swing.GroupLayout(chart);
chart.setLayout(chartLayout);
chartLayout.setHorizontalGroup(
chartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 0, Short.MAX_VALUE)
);
chartLayout.setVerticalGroup(
chartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 0, Short.MAX_VALUE)
);
yLegend.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
javax.swing.GroupLayout yLegendLayout = new javax.swing.GroupLayout(yLegend);
yLegend.setLayout(yLegendLayout);
yLegendLayout.setHorizontalGroup(
yLegendLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 95, Short.MAX_VALUE)
);
yLegendLayout.setVerticalGroup(
yLegendLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 253, Short.MAX_VALUE)
);
xLegend.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
javax.swing.GroupLayout xLegendLayout = new javax.swing.GroupLayout(xLegend);
xLegend.setLayout(xLegendLayout);
xLegendLayout.setHorizontalGroup(
xLegendLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 520, Short.MAX_VALUE)
);
xLegendLayout.setVerticalGroup(
xLegendLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 73, Short.MAX_VALUE)
);
xScrollBar.setOrientation(javax.swing.JScrollBar.HORIZONTAL);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(xScrollBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(xLegend, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(chart, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(yLegend, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(yLegend, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(chart, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(xLegend, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(xScrollBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
private void chartMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_chartMouseMoved
2017-10-03 15:51:42 +02:00
2017-10-03 12:35:12 +02:00
}//GEN-LAST:event_chartMouseMoved
// Variables declaration - do not modify//GEN-BEGIN:variables
private chart.ChartPanel chart;
private chart.ChartPanel xLegend;
private javax.swing.JScrollBar xScrollBar;
private chart.ChartPanel yLegend;
// End of variables declaration//GEN-END:variables
@Override
public void UpdateQuote(Quote q) {
2017-10-03 15:50:18 +02:00
OHLCData data = this.get();
int s = data.size();
this.xScrollBar.setMaximum(s);
2017-10-03 12:35:12 +02:00
repaint();
}
2017-10-03 15:50:18 +02:00
@Override
public OHLCData get() {
2017-10-03 15:51:42 +02:00
return Globals.se.getOHLCdata(60000 * 60);
2017-10-03 15:50:18 +02:00
}
2017-10-03 12:35:12 +02:00
}