Moved all OHLC stuff from ChartPainter to OHLCChartPainter
This commit is contained in:
parent
ab78a513a6
commit
5324d61d4c
@ -1,4 +1,4 @@
|
|||||||
#Fri, 22 Dec 2017 23:54:42 +0100
|
#Tue, 26 Dec 2017 09:36:37 +0100
|
||||||
annotation.processing.enabled=true
|
annotation.processing.enabled=true
|
||||||
annotation.processing.enabled.in.editor=false
|
annotation.processing.enabled.in.editor=false
|
||||||
annotation.processing.processors.list=
|
annotation.processing.processors.list=
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
package chart;
|
package chart;
|
||||||
|
|
||||||
import chart.painter.ChartPainter;
|
import chart.painter.ChartPainter;
|
||||||
|
import chart.painter.OHLCChartPainter;
|
||||||
import chart.painter.XLegendPainter;
|
import chart.painter.XLegendPainter;
|
||||||
import gui.Globals;
|
import gui.Globals;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
@ -68,7 +69,7 @@ public class MMChart extends javax.swing.JPanel {
|
|||||||
Border redborder = javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0));
|
Border redborder = javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0));
|
||||||
yLegend.setBorder(redborder);
|
yLegend.setBorder(redborder);
|
||||||
yLegend.setPreferredSize(new Dimension(this.em_width * 10, 110));
|
yLegend.setPreferredSize(new Dimension(this.em_width * 10, 110));
|
||||||
yLegend.setMinimumSize(new Dimension(em_width*10,110));
|
yLegend.setMinimumSize(new Dimension(em_width * 10, 110));
|
||||||
|
|
||||||
GridBagConstraints gbConstraints;
|
GridBagConstraints gbConstraints;
|
||||||
gbConstraints = new java.awt.GridBagConstraints();
|
gbConstraints = new java.awt.GridBagConstraints();
|
||||||
@ -85,13 +86,11 @@ public class MMChart extends javax.swing.JPanel {
|
|||||||
xLegend = new ChartPanel();
|
xLegend = new ChartPanel();
|
||||||
// xLegend.setBackground(Color.blue);
|
// xLegend.setBackground(Color.blue);
|
||||||
|
|
||||||
xLegend.setPreferredSize(new Dimension(em_width*2,em_width*3));
|
xLegend.setPreferredSize(new Dimension(em_width * 2, em_width * 3));
|
||||||
xLegend.setMinimumSize(new Dimension(em_width*2,em_width*3));
|
xLegend.setMinimumSize(new Dimension(em_width * 2, em_width * 3));
|
||||||
|
|
||||||
xLegend.setChartDef(chartDef);
|
xLegend.setChartDef(chartDef);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GridBagConstraints gbConstraints;
|
GridBagConstraints gbConstraints;
|
||||||
gbConstraints = new java.awt.GridBagConstraints();
|
gbConstraints = new java.awt.GridBagConstraints();
|
||||||
gbConstraints.gridx = 0;
|
gbConstraints.gridx = 0;
|
||||||
@ -100,20 +99,19 @@ public class MMChart extends javax.swing.JPanel {
|
|||||||
gbConstraints.weightx = 1.0;
|
gbConstraints.weightx = 1.0;
|
||||||
gbConstraints.weighty = 0.0;
|
gbConstraints.weighty = 0.0;
|
||||||
|
|
||||||
add(xLegend,gbConstraints);
|
add(xLegend, gbConstraints);
|
||||||
|
|
||||||
ChartPainter p;
|
OHLCChartPainter p;
|
||||||
OHLCData mydata = Globals.se.getOHLCdata(Globals.se.getDefaultStock(),60000 * 20);
|
OHLCData mydata = Globals.se.getOHLCdata(Globals.se.getDefaultStock(), 60000 * 20);
|
||||||
|
|
||||||
// this.xScrollBar.setMaximum(0);
|
// this.xScrollBar.setMaximum(0);
|
||||||
|
|
||||||
p = new XLegendPainter();
|
p = new XLegendPainter();
|
||||||
p.setOHLCData(mydata);
|
p.setOHLCData(mydata);
|
||||||
xLegend.addChartPainter(p);
|
xLegend.addChartPainter(p);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final void setupMainChart(){
|
final void setupMainChart() {
|
||||||
mainChart = new ChartPanel();
|
mainChart = new ChartPanel();
|
||||||
mainChart.setBackground(Color.green);
|
mainChart.setBackground(Color.green);
|
||||||
|
|
||||||
@ -125,7 +123,7 @@ public class MMChart extends javax.swing.JPanel {
|
|||||||
gbConstraints.weightx = 1.0;
|
gbConstraints.weightx = 1.0;
|
||||||
gbConstraints.weighty = 1.0;
|
gbConstraints.weighty = 1.0;
|
||||||
|
|
||||||
add(mainChart,gbConstraints);
|
add(mainChart, gbConstraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
ChartDef chartDef;
|
ChartDef chartDef;
|
||||||
@ -143,7 +141,6 @@ public class MMChart extends javax.swing.JPanel {
|
|||||||
setupXLegend();
|
setupXLegend();
|
||||||
setupMainChart();
|
setupMainChart();
|
||||||
|
|
||||||
|
|
||||||
chartDef = new ChartDef();
|
chartDef = new ChartDef();
|
||||||
chartDef.x_unit_width = 3.0;
|
chartDef.x_unit_width = 3.0;
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ import chart.painter.ChartPainter;
|
|||||||
import chart.painter.XLegendPainter;
|
import chart.painter.XLegendPainter;
|
||||||
import chart.painter.ChartCrossPainter;
|
import chart.painter.ChartCrossPainter;
|
||||||
import chart.painter.LineChartPainter;
|
import chart.painter.LineChartPainter;
|
||||||
|
import chart.painter.OHLCChartPainter;
|
||||||
import chart.painter.YLegendPainter;
|
import chart.painter.YLegendPainter;
|
||||||
import gui.Globals;
|
import gui.Globals;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -149,7 +150,7 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver {
|
|||||||
this.xLegend.setChartDef(chartDef);
|
this.xLegend.setChartDef(chartDef);
|
||||||
this.yLegend.setChartDef(chartDef);
|
this.yLegend.setChartDef(chartDef);
|
||||||
|
|
||||||
ChartPainter p;
|
OHLCChartPainter p;
|
||||||
mydata = Globals.se.getOHLCdata(Globals.se.getDefaultStock(),60000 * 20);
|
mydata = Globals.se.getOHLCdata(Globals.se.getDefaultStock(),60000 * 20);
|
||||||
|
|
||||||
this.xScrollBar.setMaximum(0);
|
this.xScrollBar.setMaximum(0);
|
||||||
@ -160,7 +161,7 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver {
|
|||||||
xLegend.addChartPainter(p);
|
xLegend.addChartPainter(p);
|
||||||
xLegend.setXSCrollBar(xScrollBar);
|
xLegend.setXSCrollBar(xScrollBar);
|
||||||
|
|
||||||
ChartPainter pc = new CandleStickChartPainter();
|
OHLCChartPainter pc = new CandleStickChartPainter();
|
||||||
//pc.setDataProvider(this);
|
//pc.setDataProvider(this);
|
||||||
pc.setOHLCData(mydata);
|
pc.setOHLCData(mydata);
|
||||||
|
|
||||||
@ -191,7 +192,7 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver {
|
|||||||
p.setOHLCData(mysma2);
|
p.setOHLCData(mysma2);
|
||||||
chart.addChartPainter(p);
|
chart.addChartPainter(p);
|
||||||
|
|
||||||
ChartPainter yp = new YLegendPainter(chart);
|
OHLCChartPainter yp = new YLegendPainter(chart);
|
||||||
// yp.setDataProvider(this);
|
// yp.setDataProvider(this);
|
||||||
yp.setOHLCData(mydata);
|
yp.setOHLCData(mydata);
|
||||||
|
|
||||||
|
@ -43,6 +43,9 @@ public class ChartCrossPainter extends ChartPainter{
|
|||||||
if (mp==null)
|
if (mp==null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!p.mouseEntered)
|
||||||
|
return;
|
||||||
|
|
||||||
g.drawLine(0, p.mouse.y, p.getSize().width, p.mouse.y);
|
g.drawLine(0, p.mouse.y, p.getSize().width, p.mouse.y);
|
||||||
g.drawLine(p.mouse.x, 0, p.mouse.x, p.getSize().height);
|
g.drawLine(p.mouse.x, 0, p.mouse.x, p.getSize().height);
|
||||||
|
|
||||||
|
@ -42,11 +42,6 @@ abstract public class ChartPainter implements ChartPainterInterface{
|
|||||||
protected int em_size;
|
protected int em_size;
|
||||||
|
|
||||||
|
|
||||||
protected OHLCData data;
|
|
||||||
|
|
||||||
public void setOHLCData(OHLCData data){
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* public abstract interface DataProvider {
|
/* public abstract interface DataProvider {
|
||||||
|
|
||||||
@ -59,26 +54,6 @@ abstract public class ChartPainter implements ChartPainterInterface{
|
|||||||
this.dataProvider = dataProvider;
|
this.dataProvider = dataProvider;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
protected OHLCData getData() {
|
|
||||||
return this.data;
|
|
||||||
/*if (dataProvider == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return dataProvider.get();
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getFirstBar(ChartPanel p) {
|
|
||||||
if (p.x_scrollbar != null) {
|
|
||||||
return p.x_scrollbar.getValue();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getBars(ChartPanel p, ChartDef def) {
|
|
||||||
Dimension dim = p.getSize();
|
|
||||||
return (int) (dim.width / (def.x_unit_width * em_size));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init method scould be called before painting the chart
|
* Init method scould be called before painting the chart
|
||||||
|
@ -49,7 +49,68 @@ public abstract class OHLCChartPainter extends ChartPainter {
|
|||||||
|
|
||||||
abstract void drawItem(Graphics2D g, int prevx, int x, OHLCDataItem prev, OHLCDataItem i);
|
abstract void drawItem(Graphics2D g, int prevx, int x, OHLCDataItem prev, OHLCDataItem i);
|
||||||
|
|
||||||
|
protected OHLCData data;
|
||||||
|
|
||||||
|
public void setOHLCData(OHLCData data){
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected OHLCData getData() {
|
||||||
|
return this.data;
|
||||||
|
/*if (dataProvider == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return dataProvider.get();
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getFirstBar(ChartPanel p) {
|
||||||
|
if (p.x_scrollbar != null) {
|
||||||
|
return p.x_scrollbar.getValue();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getBars(ChartPanel p, ChartDef def) {
|
||||||
|
Dimension dim = p.getSize();
|
||||||
|
return (int) (dim.width / (def.x_unit_width * em_size));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected float y_scaling;
|
||||||
|
protected int y_height;
|
||||||
|
protected float y_min;
|
||||||
|
|
||||||
|
float getY(float y) {
|
||||||
|
//c_yscaling = ctx.rect.height / c_mm.getDiff();
|
||||||
|
// float ys = dim.height / mm.getDiff();
|
||||||
|
/* if (minmax.isLog()) {
|
||||||
|
// return rect.height + rect.y - ((float) Math.log(y) - c_mm.getMin()) * ys;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
// return (dim.height - ((y - minmax.getMin()) * y_scaling));
|
||||||
|
return (y_height - ((y - y_min) * y_scaling));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
double getValAtY(float y) {
|
||||||
|
float val = 0;
|
||||||
|
|
||||||
|
/* if (c_mm.isLog()) {
|
||||||
|
float ys = rect.height / c_mm.getDiff();
|
||||||
|
|
||||||
|
return Math.exp((rect.height + rect.y) / ys + c_mm.getMin() - y / ys);
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return (-(y - y_height)) / y_scaling + y_min;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void initGetY(MinMax minmax, Dimension dim) {
|
||||||
|
y_height = dim.height;
|
||||||
|
y_scaling = dim.height / minmax.getDiff();
|
||||||
|
y_min = minmax.getMin();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -33,12 +33,13 @@ import java.awt.Graphics2D;
|
|||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JScrollBar;
|
import javax.swing.JScrollBar;
|
||||||
import sesim.OHLCData;
|
import sesim.OHLCData;
|
||||||
|
import sesim.OHLCDataItem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author 7u83 <7u83@mail.ru>
|
* @author 7u83 <7u83@mail.ru>
|
||||||
*/
|
*/
|
||||||
public class XLegendPainter extends ChartPainter {
|
public class XLegendPainter extends OHLCChartPainter {
|
||||||
|
|
||||||
private String getTimeStrAt(OHLCData data, int unit) {
|
private String getTimeStrAt(OHLCData data, int unit) {
|
||||||
|
|
||||||
@ -91,4 +92,9 @@ public class XLegendPainter extends ChartPainter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void drawItem(Graphics2D g, int prevx, int x, OHLCDataItem prev, OHLCDataItem i) {
|
||||||
|
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ import sesim.OHLCDataItem;
|
|||||||
*
|
*
|
||||||
* @author 7u83 <7u83@mail.ru>
|
* @author 7u83 <7u83@mail.ru>
|
||||||
*/
|
*/
|
||||||
public class YLegendPainter extends ChartPainter {
|
public class YLegendPainter extends OHLCChartPainter {
|
||||||
|
|
||||||
ChartPanel master;
|
ChartPanel master;
|
||||||
|
|
||||||
@ -87,6 +87,11 @@ public class YLegendPainter extends ChartPainter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void drawItem(Graphics2D g, int prevx, int x, OHLCDataItem prev, OHLCDataItem i) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user