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;
|
|
|
|
|
2017-10-04 10:05:32 +02:00
|
|
|
import chart.painter.CandleStickChartPainter;
|
|
|
|
import chart.painter.ChartPainter;
|
2017-10-05 20:57:37 +02:00
|
|
|
import chart.painter.XLegendPainter;
|
2017-10-04 10:05:32 +02:00
|
|
|
import chart.painter.ChartCrossPainter;
|
2017-10-23 07:29:42 +02:00
|
|
|
import chart.painter.LineChartPainter;
|
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;
|
2017-10-28 09:15:26 +02:00
|
|
|
import sesim.Indicator;
|
2017-10-03 12:35:12 +02:00
|
|
|
import sesim.OHLCData;
|
|
|
|
import sesim.Quote;
|
2017-10-28 09:15:26 +02:00
|
|
|
import sesim.SMAIndicator;
|
2017-10-03 12:35:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @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-07 09:36:41 +02:00
|
|
|
private ChartDef chartDef;
|
|
|
|
|
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-07 09:36:41 +02:00
|
|
|
chartDef = new ChartDef();
|
|
|
|
chartDef.x_unit_width = 3.0;
|
2017-10-03 15:50:18 +02:00
|
|
|
|
|
|
|
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);
|
2017-10-07 09:36:41 +02:00
|
|
|
|
|
|
|
|
2017-10-28 09:15:26 +02:00
|
|
|
Indicator in = new SMAIndicator(get());
|
|
|
|
|
|
|
|
|
2017-10-07 09:36:41 +02:00
|
|
|
this.chart.setChartDef(chartDef);
|
|
|
|
this.xLegend.setChartDef(chartDef);
|
|
|
|
this.yLegend.setChartDef(chartDef);
|
2017-10-03 15:50:18 +02:00
|
|
|
|
2017-10-23 07:29:42 +02:00
|
|
|
ChartPainter p = new LineChartPainter();
|
|
|
|
p.setDataProvider(this);
|
|
|
|
chart.addChartPainter(p);
|
|
|
|
|
2017-10-03 15:50:18 +02:00
|
|
|
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-28 09:15:26 +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();
|
|
|
|
|
2017-10-07 09:36:41 +02:00
|
|
|
addMouseWheelListener(new java.awt.event.MouseWheelListener() {
|
|
|
|
public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
|
|
|
|
formMouseWheelMoved(evt);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
chart.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
|
2017-10-03 12:35:12 +02:00
|
|
|
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)
|
|
|
|
);
|
|
|
|
|
2017-10-07 09:36:41 +02:00
|
|
|
yLegend.setBorder(null);
|
2017-10-03 12:35:12 +02:00
|
|
|
|
|
|
|
javax.swing.GroupLayout yLegendLayout = new javax.swing.GroupLayout(yLegend);
|
|
|
|
yLegend.setLayout(yLegendLayout);
|
|
|
|
yLegendLayout.setHorizontalGroup(
|
|
|
|
yLegendLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
2017-10-07 09:36:41 +02:00
|
|
|
.addGap(0, 83, Short.MAX_VALUE)
|
2017-10-03 12:35:12 +02:00
|
|
|
);
|
|
|
|
yLegendLayout.setVerticalGroup(
|
|
|
|
yLegendLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
2017-10-07 09:36:41 +02:00
|
|
|
.addGap(0, 326, Short.MAX_VALUE)
|
2017-10-03 12:35:12 +02:00
|
|
|
);
|
|
|
|
|
2017-10-07 09:36:41 +02:00
|
|
|
xLegend.setBorder(null);
|
2017-10-03 12:35:12 +02:00
|
|
|
|
|
|
|
javax.swing.GroupLayout xLegendLayout = new javax.swing.GroupLayout(xLegend);
|
|
|
|
xLegend.setLayout(xLegendLayout);
|
|
|
|
xLegendLayout.setHorizontalGroup(
|
|
|
|
xLegendLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
2017-10-07 09:36:41 +02:00
|
|
|
.addGap(0, 576, Short.MAX_VALUE)
|
2017-10-03 12:35:12 +02:00
|
|
|
);
|
|
|
|
xLegendLayout.setVerticalGroup(
|
|
|
|
xLegendLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
2017-10-07 09:36:41 +02:00
|
|
|
.addGap(0, 61, Short.MAX_VALUE)
|
2017-10-03 12:35:12 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
xScrollBar.setOrientation(javax.swing.JScrollBar.HORIZONTAL);
|
2017-10-07 09:36:41 +02:00
|
|
|
xScrollBar.addAdjustmentListener(new java.awt.event.AdjustmentListener() {
|
|
|
|
public void adjustmentValueChanged(java.awt.event.AdjustmentEvent evt) {
|
|
|
|
xScrollBarAdjustmentValueChanged(evt);
|
|
|
|
}
|
|
|
|
});
|
2017-10-03 12:35:12 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2017-10-07 09:36:41 +02:00
|
|
|
private void formMouseWheelMoved(java.awt.event.MouseWheelEvent evt) {//GEN-FIRST:event_formMouseWheelMoved
|
|
|
|
double n = evt.getPreciseWheelRotation() * (-1.0);
|
|
|
|
|
|
|
|
if (n < 0) {
|
|
|
|
if (chartDef.x_unit_width > 0.3) {
|
|
|
|
chartDef.x_unit_width += 0.1 * n;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
chartDef.x_unit_width += 0.1 * n;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.invalidate();
|
|
|
|
this.repaint();
|
|
|
|
}//GEN-LAST:event_formMouseWheelMoved
|
|
|
|
|
|
|
|
private void xScrollBarAdjustmentValueChanged(java.awt.event.AdjustmentEvent evt) {//GEN-FIRST:event_xScrollBarAdjustmentValueChanged
|
|
|
|
repaint();
|
|
|
|
}//GEN-LAST:event_xScrollBarAdjustmentValueChanged
|
|
|
|
|
2017-10-03 12:35:12 +02:00
|
|
|
|
|
|
|
// 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
|
|
|
}
|