Interface improved

This commit is contained in:
7u83 2017-01-09 08:25:29 +01:00
parent d1e84ccbb2
commit 0952c7b591
2 changed files with 125 additions and 68 deletions

View File

@ -21,6 +21,9 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver{
*/ */
public Chart() { public Chart() {
initComponents(); initComponents();
if (MainWin.se == null) {
return;
}
MainWin.se.addQuoteReceiver(this); MainWin.se.addQuoteReceiver(this);
@ -30,20 +33,43 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver{
int item_width = 10; int item_width = 10;
int items = 350; int items = 350;
long ntime = -1;
OHLCData data; OHLCData data;
OHLCDataItem current = null; OHLCDataItem current = null;
long rasterTime(long time) {
long rt = time / 5000;
return rt * 5000;
}
private void realTimeAdd(long time, float price, float volume) { 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) { if (current == null) {
current = new OHLCDataItem(price, price, price, price, volume); current = new OHLCDataItem(price, price, price, price, volume);
return; return;
} }
boolean rc = current.update(price, volume); boolean rc = current.update(price, volume);
if (rc) { if (rc) {
System.out.print("Updated -" System.out.print("Updated -"
+ " High:" + " High:"
@ -52,15 +78,15 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver{
+ current.low + current.low
+ " Volume" + " Volume"
+ current.volume + current.volume
+ "("
+ time
+ ")"
+ "\n" + "\n"
); );
} }
} }
private void getData() { private void getData() {
} }
@ -72,17 +98,27 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver{
this.setPreferredSize(new Dimension(pwidth, 400)); this.setPreferredSize(new Dimension(pwidth, 400));
g.setColor(Color.RED);
g.drawLine(0,0,100,100);
for (int i = 0; i < items; i++) { for (int i = 0; i < items; i++) {
int x = i * this.item_width; int x = i * this.item_width;
g.drawLine(x, 0, x, 50); g.drawLine(x, 0, x, 50);
} }
if (this.current == null) {
return;
} }
g.setColor(Color.BLUE);
g.drawLine(0, 0, 100, (int) ((this.current.close-80.0)*80.0));
}
@Override @Override
public void paintComponent(Graphics go) { public void paintComponent(Graphics go) {
super.paintComponent(go); super.paintComponent(go);
@ -102,9 +138,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver{
//g.drawString("Hello world", 810, 10); //g.drawString("Hello world", 810, 10);
//g.drawLine(0, 0, d.width, d.height); //g.drawLine(0, 0, d.width, d.height);
//this.setPreferredSize(new Dimension(2000,4000)); //this.setPreferredSize(new Dimension(2000,4000));
draw(g); draw(g);
} }
@ -138,6 +172,8 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver{
public void UpdateQuote(Quote q) { public void UpdateQuote(Quote q) {
// System.out.print("Quote Received\n"); // System.out.print("Quote Received\n");
this.realTimeAdd(q.time, (float) q.price, q.volume); this.realTimeAdd(q.time, (float) q.price, q.volume);
// this.invalidate();
this.repaint();
} }

View File

@ -31,23 +31,44 @@ import java.util.*;
* *
* @author 7u83 <7u83@mail.ru> * @author 7u83 <7u83@mail.ru>
*/ */
public class OHLCData extends ArrayList <OHLCDataItem> { public class OHLCData { //extends ArrayList <OHLCDataItem> {
float max; float max;
long start_time; long time_start;
long time_step; long time_step;
public float getMax() { public float getMax() {
return max; return max;
} }
@Override
public boolean add (OHLCDataItem o){
super.add(o);
long rasterTime(long time) {
long rt = time / 5000;
return rt * 5000;
}
ArrayList<OHLCDataItem> 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; return true;
} }
OHLCDataItem d = data.get(data.size() - 1);
boolean rc = d.update(price, volume);
return rc;
}
} }