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.in.editor=false
|
||||
annotation.processing.processors.list=
|
||||
|
@ -26,6 +26,7 @@
|
||||
package chart;
|
||||
|
||||
import chart.painter.ChartPainter;
|
||||
import chart.painter.OHLCChartPainter;
|
||||
import chart.painter.XLegendPainter;
|
||||
import gui.Globals;
|
||||
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));
|
||||
yLegend.setBorder(redborder);
|
||||
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;
|
||||
gbConstraints = new java.awt.GridBagConstraints();
|
||||
@ -83,15 +84,13 @@ public class MMChart extends javax.swing.JPanel {
|
||||
|
||||
final void setupXLegend() {
|
||||
xLegend = new ChartPanel();
|
||||
// xLegend.setBackground(Color.blue);
|
||||
|
||||
xLegend.setPreferredSize(new Dimension(em_width*2,em_width*3));
|
||||
xLegend.setMinimumSize(new Dimension(em_width*2,em_width*3));
|
||||
|
||||
// xLegend.setBackground(Color.blue);
|
||||
|
||||
xLegend.setPreferredSize(new Dimension(em_width * 2, em_width * 3));
|
||||
xLegend.setMinimumSize(new Dimension(em_width * 2, em_width * 3));
|
||||
|
||||
xLegend.setChartDef(chartDef);
|
||||
|
||||
|
||||
|
||||
|
||||
GridBagConstraints gbConstraints;
|
||||
gbConstraints = new java.awt.GridBagConstraints();
|
||||
gbConstraints.gridx = 0;
|
||||
@ -99,24 +98,23 @@ public class MMChart extends javax.swing.JPanel {
|
||||
gbConstraints.fill = GridBagConstraints.BOTH;
|
||||
gbConstraints.weightx = 1.0;
|
||||
gbConstraints.weighty = 0.0;
|
||||
|
||||
add(xLegend,gbConstraints);
|
||||
|
||||
ChartPainter p;
|
||||
OHLCData mydata = Globals.se.getOHLCdata(Globals.se.getDefaultStock(),60000 * 20);
|
||||
|
||||
// this.xScrollBar.setMaximum(0);
|
||||
add(xLegend, gbConstraints);
|
||||
|
||||
OHLCChartPainter p;
|
||||
OHLCData mydata = Globals.se.getOHLCdata(Globals.se.getDefaultStock(), 60000 * 20);
|
||||
|
||||
// this.xScrollBar.setMaximum(0);
|
||||
p = new XLegendPainter();
|
||||
p.setOHLCData(mydata);
|
||||
xLegend.addChartPainter(p);
|
||||
|
||||
|
||||
}
|
||||
|
||||
final void setupMainChart(){
|
||||
|
||||
final void setupMainChart() {
|
||||
mainChart = new ChartPanel();
|
||||
mainChart.setBackground(Color.green);
|
||||
|
||||
|
||||
GridBagConstraints gbConstraints;
|
||||
gbConstraints = new java.awt.GridBagConstraints();
|
||||
gbConstraints.gridx = 0;
|
||||
@ -124,10 +122,10 @@ public class MMChart extends javax.swing.JPanel {
|
||||
gbConstraints.fill = GridBagConstraints.BOTH;
|
||||
gbConstraints.weightx = 1.0;
|
||||
gbConstraints.weighty = 1.0;
|
||||
|
||||
add(mainChart,gbConstraints);
|
||||
|
||||
add(mainChart, gbConstraints);
|
||||
}
|
||||
|
||||
|
||||
ChartDef chartDef;
|
||||
|
||||
final void setupLayout() {
|
||||
@ -142,9 +140,8 @@ public class MMChart extends javax.swing.JPanel {
|
||||
setupYLegend();
|
||||
setupXLegend();
|
||||
setupMainChart();
|
||||
|
||||
|
||||
chartDef = new ChartDef();
|
||||
|
||||
chartDef = new ChartDef();
|
||||
chartDef.x_unit_width = 3.0;
|
||||
|
||||
java.awt.GridBagConstraints gbConstraints;
|
||||
|
@ -31,6 +31,7 @@ import chart.painter.ChartPainter;
|
||||
import chart.painter.XLegendPainter;
|
||||
import chart.painter.ChartCrossPainter;
|
||||
import chart.painter.LineChartPainter;
|
||||
import chart.painter.OHLCChartPainter;
|
||||
import chart.painter.YLegendPainter;
|
||||
import gui.Globals;
|
||||
import java.util.ArrayList;
|
||||
@ -149,7 +150,7 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
this.xLegend.setChartDef(chartDef);
|
||||
this.yLegend.setChartDef(chartDef);
|
||||
|
||||
ChartPainter p;
|
||||
OHLCChartPainter p;
|
||||
mydata = Globals.se.getOHLCdata(Globals.se.getDefaultStock(),60000 * 20);
|
||||
|
||||
this.xScrollBar.setMaximum(0);
|
||||
@ -160,7 +161,7 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
xLegend.addChartPainter(p);
|
||||
xLegend.setXSCrollBar(xScrollBar);
|
||||
|
||||
ChartPainter pc = new CandleStickChartPainter();
|
||||
OHLCChartPainter pc = new CandleStickChartPainter();
|
||||
//pc.setDataProvider(this);
|
||||
pc.setOHLCData(mydata);
|
||||
|
||||
@ -191,7 +192,7 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
p.setOHLCData(mysma2);
|
||||
chart.addChartPainter(p);
|
||||
|
||||
ChartPainter yp = new YLegendPainter(chart);
|
||||
OHLCChartPainter yp = new YLegendPainter(chart);
|
||||
// yp.setDataProvider(this);
|
||||
yp.setOHLCData(mydata);
|
||||
|
||||
|
@ -43,6 +43,9 @@ public class ChartCrossPainter extends ChartPainter{
|
||||
if (mp==null)
|
||||
return;
|
||||
|
||||
if (!p.mouseEntered)
|
||||
return;
|
||||
|
||||
g.drawLine(0, p.mouse.y, p.getSize().width, p.mouse.y);
|
||||
g.drawLine(p.mouse.x, 0, p.mouse.x, p.getSize().height);
|
||||
|
||||
|
@ -42,12 +42,7 @@ abstract public class ChartPainter implements ChartPainterInterface{
|
||||
protected int em_size;
|
||||
|
||||
|
||||
protected OHLCData data;
|
||||
|
||||
public void setOHLCData(OHLCData data){
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
|
||||
/* public abstract interface DataProvider {
|
||||
|
||||
abstract OHLCData get();
|
||||
@ -59,26 +54,6 @@ abstract public class ChartPainter implements ChartPainterInterface{
|
||||
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
|
||||
|
@ -49,9 +49,70 @@ public abstract class OHLCChartPainter extends ChartPainter {
|
||||
|
||||
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
|
||||
public void drawChart(Graphics2D g, ChartPanel p, ChartDef def) {
|
||||
OHLCData data = getData();
|
||||
|
@ -33,12 +33,13 @@ import java.awt.Graphics2D;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollBar;
|
||||
import sesim.OHLCData;
|
||||
import sesim.OHLCDataItem;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class XLegendPainter extends ChartPainter {
|
||||
public class XLegendPainter extends OHLCChartPainter {
|
||||
|
||||
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>
|
||||
*/
|
||||
public class YLegendPainter extends ChartPainter {
|
||||
public class YLegendPainter extends OHLCChartPainter {
|
||||
|
||||
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