diff --git a/nbproject/project.properties b/nbproject/project.properties index 7be2369..4e86927 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,4 +1,4 @@ -#Tue, 03 Oct 2017 12:34:23 +0200 +#Tue, 03 Oct 2017 15:28:04 +0200 annotation.processing.enabled=true annotation.processing.enabled.in.editor=false annotation.processing.processors.list= diff --git a/src/chart/ChartCrossPainter.java b/src/chart/ChartCrossPainter.java index 34d665e..25d8f23 100644 --- a/src/chart/ChartCrossPainter.java +++ b/src/chart/ChartCrossPainter.java @@ -38,7 +38,7 @@ import sesim.OHLCData; public class ChartCrossPainter extends ChartPainter{ @Override - public void drawChart(Graphics2D g, JScrollBar sb, OHLCData data, ChartPanel p, ChartDef def) { + public void drawChart(Graphics2D g, ChartPanel p, ChartDef def) { Point mp = p.mouse; if (mp==null) return; @@ -48,4 +48,5 @@ public class ChartCrossPainter extends ChartPainter{ } + } diff --git a/src/chart/ChartDef.java b/src/chart/ChartDef.java index a98431d..51bbd19 100644 --- a/src/chart/ChartDef.java +++ b/src/chart/ChartDef.java @@ -32,7 +32,7 @@ import javax.swing.JScrollBar; * @author 7u83 <7u83@mail.ru> */ public class ChartDef { - JScrollBar x_scrollbar=null; + // JScrollBar x_scrollbar=null; /** * width of an x unit in em diff --git a/src/chart/ChartPainter.java b/src/chart/ChartPainter.java index b51a286..c434a8a 100644 --- a/src/chart/ChartPainter.java +++ b/src/chart/ChartPainter.java @@ -39,6 +39,30 @@ import sesim.OHLCData; abstract public class ChartPainter { int em_size; + //OHLCData data=null; + + public abstract interface DataProvider { + abstract OHLCData get(); + } + + DataProvider dataProvider=null; + + public void setDataProvider(DataProvider dataProvider){ + this.dataProvider = dataProvider; + } + + protected OHLCData getData(){ + 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 final void init(Graphics2D g) { @@ -50,6 +74,6 @@ abstract public class ChartPainter { int big_tick = 10; int y = 0; - abstract public void drawChart(Graphics2D g, JScrollBar sb, OHLCData data, ChartPanel p, ChartDef def); + abstract public void drawChart(Graphics2D g, ChartPanel p, ChartDef def); } diff --git a/src/chart/ChartPanel.java b/src/chart/ChartPanel.java index a6c76e1..3aa3e18 100644 --- a/src/chart/ChartPanel.java +++ b/src/chart/ChartPanel.java @@ -24,9 +24,9 @@ import sesim.Quote; * * @author 7u83 <7u83@mail.ru> */ -public class ChartPanel extends javax.swing.JPanel /*implements AdjustmentListener*/ { +public class ChartPanel extends javax.swing.JPanel implements AdjustmentListener { - public JScrollBar xbar; + public JScrollBar x_scrollbar=null; /** * Creates new form Chart1 @@ -37,6 +37,14 @@ public class ChartPanel extends javax.swing.JPanel /*implements AdjustmentListen setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); } + + public void setXSCrollBar(JScrollBar x_scrollbar){ + if (this.x_scrollbar!=null) + this.x_scrollbar.removeAdjustmentListener(this); + this.x_scrollbar=x_scrollbar; + if (this.x_scrollbar!=null) + this.x_scrollbar.addAdjustmentListener(this); + } private ArrayList chartPainters = new ArrayList<>(); @@ -58,16 +66,16 @@ public class ChartPanel extends javax.swing.JPanel /*implements AdjustmentListen return; } - //this.xbar.setMaximum(994000); + //this.x_scrollbar.setMaximum(994000); XLegendChartPainter p = new XLegendChartPainter(); data = Globals.se.getOHLCdata(60000 * 60); ChartDef def = new ChartDef(); def.x_unit_width = 1.0; - def.x_scrollbar = xbar; +// def.x_scrollbar = x_scrollbar; for (ChartPainter painter : chartPainters) { - painter.drawChart((Graphics2D) g, xbar, data, this, def); + painter.drawChart((Graphics2D) g, this, def); } } diff --git a/src/chart/LineChartPainter.java b/src/chart/LineChartPainter.java index 26f815d..b2f11ed 100644 --- a/src/chart/LineChartPainter.java +++ b/src/chart/LineChartPainter.java @@ -52,4 +52,5 @@ public class LineChartPainter extends OHLCChartPainter{ g.setColor(cur); } + } diff --git a/src/chart/MasterChart.java b/src/chart/MasterChart.java index d47808a..0522be3 100644 --- a/src/chart/MasterChart.java +++ b/src/chart/MasterChart.java @@ -34,30 +34,44 @@ import sesim.Quote; * * @author 7u83 <7u83@mail.ru> */ -public class MasterChart extends javax.swing.JPanel implements QuoteReceiver{ +public class MasterChart extends javax.swing.JPanel implements QuoteReceiver, ChartPainter.DataProvider { + + //OHLCData data; - OHLCData data; - /** * Creates new form MasterChart */ public MasterChart() { initComponents(); - + ChartDef def = new ChartDef(); - def.x_unit_width=1.0; - def.x_scrollbar=xScrollBar; - - if (Globals.se==null) + def.x_unit_width = 1.0; + + + if (Globals.se == null) { return; - - data = Globals.se.getOHLCdata(60000); - - ChartPainter p = new CandleStickChartPainter(); + } + + // data = Globals.se.getOHLCdata(60000*60); + Globals.se.addQuoteReceiver(this); + + ChartPainter p = new CandleStickChartPainter(); //this.chart.addChartPainter(p); + this.xScrollBar.setMaximum(0); + p = new XLegendChartPainter(); + p.setDataProvider(this); + xLegend.addChartPainter(p); + xLegend.setXSCrollBar(xScrollBar); + + p = new CandleStickChartPainter(); + p.setDataProvider(this); + + + chart.addChartPainter(p); + chart.setXSCrollBar(xScrollBar); p = new ChartCrossPainter(); this.chart.addChartPainter(p); @@ -169,6 +183,15 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver{ @Override public void UpdateQuote(Quote q) { + OHLCData data = this.get(); + int s = data.size(); + this.xScrollBar.setMaximum(s); repaint(); } + + @Override + public OHLCData get() { + return Globals.se.getOHLCdata(60000*60); + + } } diff --git a/src/chart/OHLCChartPainter.java b/src/chart/OHLCChartPainter.java index bdbe64b..0140f61 100644 --- a/src/chart/OHLCChartPainter.java +++ b/src/chart/OHLCChartPainter.java @@ -61,12 +61,18 @@ public abstract class OHLCChartPainter extends ChartPainter { @Override - public void drawChart(Graphics2D g, JScrollBar sb, OHLCData data, ChartPanel p, ChartDef def) { + public void drawChart(Graphics2D g, ChartPanel p, ChartDef def) { + OHLCData data = getData(); + if (data==null) + return; + init(g); iwidth = (float) ((def.x_unit_width * em_size) * 0.9f); - int first_bar = def.x_scrollbar.getValue(); + int first_bar = getFirstBar(p); + + dim = p.getSize(); int bars = (int) (dim.width / (def.x_unit_width * em_size)); @@ -79,11 +85,13 @@ public abstract class OHLCChartPainter extends ChartPainter { OHLCDataItem prevd = null; int prevx; +System.out.printf("Firstbar %d - %d",first_bar,last_bar); + if (data.size() > 0 && first_bar < data.size()) { prevd = data.get(first_bar); } - prevd=null; + for (int b = first_bar, n = 0; b < last_bar && b < data.size(); b++, n++) { OHLCDataItem d = data.get(b); diff --git a/src/chart/XLegendChartPainter.java b/src/chart/XLegendChartPainter.java index cc47047..e6b6146 100644 --- a/src/chart/XLegendChartPainter.java +++ b/src/chart/XLegendChartPainter.java @@ -44,25 +44,23 @@ public class XLegendChartPainter extends ChartPainter { return sesim.Scheduler.formatTimeMillis(0 + unit * fs); } - - public void drawChart(Graphics2D g, JScrollBar sb, OHLCData data, ChartPanel p, ChartDef def) + + + @Override + public void drawChart(Graphics2D g, ChartPanel p, ChartDef def) { + OHLCData data = getData(); + if (data ==null) + return; + init(g); g.setColor(Color.black); Dimension size = p.getSize(); - //g.drawLine(0, 0, size.width, 100); - - System.out.printf("SIZE %d %d\n", size.width, size.height); int bars = (int) (size.width / (def.x_unit_width * em_size)); - System.out.printf("Units = %d\n", bars); - int first_bar; - if (def.x_scrollbar!=null) - first_bar = def.x_scrollbar.getValue(); - else - first_bar=0; + int first_bar = getFirstBar(p); int n; int x;