From 0952c7b591d517b80311047bfba6b94765d35cc9 Mon Sep 17 00:00:00 2001 From: 7u83 <7u83@maiol.ru> Date: Mon, 9 Jan 2017 08:25:29 +0100 Subject: [PATCH] Interface improved --- src/main/java/chart/Chart.java | 146 +++++++++++++++++++----------- src/main/java/chart/OHLCData.java | 47 +++++++--- 2 files changed, 125 insertions(+), 68 deletions(-) diff --git a/src/main/java/chart/Chart.java b/src/main/java/chart/Chart.java index cc28e1b..0ca687e 100644 --- a/src/main/java/chart/Chart.java +++ b/src/main/java/chart/Chart.java @@ -14,79 +14,115 @@ import gui.MainWin; * * @author 7u83 <7u83@mail.ru> */ -public class Chart extends javax.swing.JPanel implements QuoteReceiver{ +public class Chart extends javax.swing.JPanel implements QuoteReceiver { /** * Creates new form Chart */ public Chart() { initComponents(); - + if (MainWin.se == null) { + return; + } + MainWin.se.addQuoteReceiver(this); //Graphics g = this.getGraphics(); //g.drawString("Hello world", 0, 0); } - - int item_width=10; - int items=350; - - + + int item_width = 10; + int items = 350; + long ntime = -1; + OHLCData data; - - OHLCDataItem current=null; - - private void realTimeAdd(long time,float price,float volume){ - if (current==null){ - current=new OHLCDataItem(price,price,price,price,volume); + OHLCDataItem current = null; + + long rasterTime(long time) { + + long rt = time / 5000; + return rt * 5000; + + } + + private void realTimeAdd(long time, float price, float volume) { + + /* System.out.print("Diff:" + +(ntime-time) + +"\n" + ); + */ + if (time > ntime) { + + System.out.print("new raster ----------------------------------\n"); + current = null; + ntime = rasterTime(time) + 5000; + // System.out.print(ntime+"\n"); + // System.out.print((time)+"\n"); + // System.exit(0); + } + + if (current == null) { + current = new OHLCDataItem(price, price, price, price, volume); + return; + } + + boolean rc = current.update(price, volume); + + if (rc) { + System.out.print("Updated -" + + " High:" + + current.high + + " Low:" + + current.low + + " Volume" + + current.volume + + "(" + + time + + ")" + + "\n" + ); + } + + } + + private void getData() { + + } + + private void draw(Graphics2D g) { + this.getSize(); + + int pwidth = item_width * items; + + this.setPreferredSize(new Dimension(pwidth, 400)); + + g.setColor(Color.RED); + g.drawLine(0,0,100,100); + + for (int i = 0; i < items; i++) { + int x = i * this.item_width; + g.drawLine(x, 0, x, 50); + + } + + + + if (this.current == null) { return; } - boolean rc = current.update(price,volume); - if (rc){ - System.out.print("Updated -" - +" High:" - +current.high - +" Low:" - +current.low - +" Volume" - +current.volume - +"\n" - - ); - } - + g.setColor(Color.BLUE); + g.drawLine(0, 0, 100, (int) ((this.current.close-80.0)*80.0)); + } - - - private void getData(){ - - } - - private void draw(Graphics2D g){ - this.getSize(); - - int pwidth = item_width*items; - - this.setPreferredSize(new Dimension(pwidth,400)); - - for (int i=0; i */ -public class OHLCData extends ArrayList { - +public class OHLCData { //extends ArrayList { + float max; - - long start_time; + + long time_start; long time_step; - - public float getMax(){ + + public float getMax() { return max; } - @Override - public boolean add (OHLCDataItem o){ - super.add(o); - - return true; - } - + + long rasterTime(long time) { + + long rt = time / 5000; + return rt * 5000; + + } + + ArrayList data = new ArrayList<>(); + + + private void updateMinMax(float price){ + // if (price>max) + } + + private long ntime = 0; + + boolean realTimeAdd(long time, float price, float volume) { + if (time > ntime) { + ntime = rasterTime(time) + 5000; + data.add(new OHLCDataItem(price, price, price, price, volume)); + return true; + } + + OHLCDataItem d = data.get(data.size() - 1); + boolean rc = d.update(price, volume); + return rc; + } }