Interface improved
This commit is contained in:
parent
d1e84ccbb2
commit
0952c7b591
@ -21,6 +21,9 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver{
|
||||
*/
|
||||
public Chart() {
|
||||
initComponents();
|
||||
if (MainWin.se == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
MainWin.se.addQuoteReceiver(this);
|
||||
|
||||
@ -30,20 +33,43 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver{
|
||||
|
||||
int item_width = 10;
|
||||
int items = 350;
|
||||
|
||||
long ntime = -1;
|
||||
|
||||
OHLCData data;
|
||||
|
||||
|
||||
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:"
|
||||
@ -52,15 +78,15 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver{
|
||||
+ current.low
|
||||
+ " Volume"
|
||||
+ current.volume
|
||||
+ "("
|
||||
+ time
|
||||
+ ")"
|
||||
+ "\n"
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void getData() {
|
||||
|
||||
}
|
||||
@ -72,17 +98,27 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver{
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
g.setColor(Color.BLUE);
|
||||
g.drawLine(0, 0, 100, (int) ((this.current.close-80.0)*80.0));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics go) {
|
||||
super.paintComponent(go);
|
||||
@ -102,9 +138,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver{
|
||||
|
||||
//g.drawString("Hello world", 810, 10);
|
||||
//g.drawLine(0, 0, d.width, d.height);
|
||||
|
||||
//this.setPreferredSize(new Dimension(2000,4000));
|
||||
|
||||
draw(g);
|
||||
}
|
||||
|
||||
@ -138,6 +172,8 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver{
|
||||
public void UpdateQuote(Quote q) {
|
||||
// System.out.print("Quote Received\n");
|
||||
this.realTimeAdd(q.time, (float) q.price, q.volume);
|
||||
// this.invalidate();
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,23 +31,44 @@ import java.util.*;
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class OHLCData extends ArrayList <OHLCDataItem> {
|
||||
public class OHLCData { //extends ArrayList <OHLCDataItem> {
|
||||
|
||||
float max;
|
||||
|
||||
long start_time;
|
||||
long time_start;
|
||||
long time_step;
|
||||
|
||||
public float getMax() {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
OHLCDataItem d = data.get(data.size() - 1);
|
||||
boolean rc = d.update(price, volume);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user