OpenSeSim/src/chart/ChartPanel.java

132 lines
3.5 KiB
Java
Raw Normal View History

2017-10-02 21:45:20 +02:00
package chart;
import chart.painter.ChartPainter;
import chart.painter.XLegendChartPainter;
2017-10-02 21:45:20 +02:00
import gui.Globals;
2017-10-02 21:45:20 +02:00
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
2017-10-03 08:05:46 +02:00
import java.awt.Point;
2017-10-02 21:45:20 +02:00
import java.awt.Rectangle;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.geom.AffineTransform;
import java.util.ArrayList;
import javax.swing.JScrollBar;
import javax.swing.JViewport;
import javax.swing.Scrollable;
import sesim.Exchange.QuoteReceiver;
import sesim.OHLCData;
import sesim.OHLCDataItem;
import sesim.Quote;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
2017-10-03 15:50:18 +02:00
public class ChartPanel extends javax.swing.JPanel implements AdjustmentListener {
2017-10-02 21:45:20 +02:00
2017-10-03 15:50:18 +02:00
public JScrollBar x_scrollbar=null;
2017-10-02 21:45:20 +02:00
/**
* Creates new form Chart1
*/
public ChartPanel() {
initComponents();
setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
}
2017-10-03 15:50:18 +02:00
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);
}
2017-10-03 12:35:12 +02:00
private ArrayList<ChartPainter> chartPainters = new ArrayList<>();
2017-10-02 21:45:20 +02:00
/**
2017-10-03 12:35:12 +02:00
*
* @param p
2017-10-02 21:45:20 +02:00
*/
2017-10-03 12:35:12 +02:00
public void addChartPainter(ChartPainter p) {
2017-10-02 21:45:20 +02:00
chartPainters.add(p);
}
OHLCData data;
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
2017-10-03 12:35:12 +02:00
if (Globals.se == null) {
return;
}
2017-10-02 21:45:20 +02:00
2017-10-03 15:50:18 +02:00
//this.x_scrollbar.setMaximum(994000);
2017-10-02 21:45:20 +02:00
XLegendChartPainter p = new XLegendChartPainter();
2017-10-03 12:35:12 +02:00
data = Globals.se.getOHLCdata(60000 * 60);
2017-10-02 21:45:20 +02:00
ChartDef def = new ChartDef();
def.x_unit_width = 1.0;
2017-10-03 15:50:18 +02:00
// def.x_scrollbar = x_scrollbar;
2017-10-03 12:35:12 +02:00
for (ChartPainter painter : chartPainters) {
2017-10-03 15:50:18 +02:00
painter.drawChart((Graphics2D) g, this, def);
2017-10-02 21:45:20 +02:00
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
2017-10-03 08:05:46 +02:00
addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseMoved(java.awt.event.MouseEvent evt) {
formMouseMoved(evt);
}
});
2017-10-02 21:45:20 +02:00
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 498, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 341, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
public Point mouse = null;
2017-10-03 12:35:12 +02:00
2017-10-03 08:05:46 +02:00
private void formMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseMoved
2017-10-03 12:35:12 +02:00
2017-10-03 08:05:46 +02:00
Point p = evt.getPoint();
mouse = p;
repaint();
2017-10-03 12:35:12 +02:00
}//GEN-LAST:event_formMouseMoved
2017-10-02 21:45:20 +02:00
2017-10-03 12:35:12 +02:00
// @Override
2017-10-02 21:45:20 +02:00
public void adjustmentValueChanged(AdjustmentEvent e) {
this.repaint();
}
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}