2017-12-10 09:33:25 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017, 7u83 <7u83@mail.ru>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
package chart;
|
|
|
|
|
2018-01-02 00:55:54 +01:00
|
|
|
import chart.painter.ChartCrossPainter;
|
2017-12-24 10:32:29 +01:00
|
|
|
import chart.painter.ChartPainter;
|
2017-12-26 09:37:26 +01:00
|
|
|
import chart.painter.OHLCChartPainter;
|
2018-01-02 00:55:54 +01:00
|
|
|
import chart.painter.XLegendDetail;
|
2017-12-17 20:10:20 +01:00
|
|
|
import chart.painter.XLegendPainter;
|
2018-01-07 23:35:19 +01:00
|
|
|
import chart.painter.YLegendPainter;
|
2017-12-17 20:10:20 +01:00
|
|
|
import gui.Globals;
|
2017-12-10 09:33:25 +01:00
|
|
|
import java.awt.Color;
|
2018-01-23 01:36:25 +01:00
|
|
|
import java.awt.Cursor;
|
2017-12-10 09:33:25 +01:00
|
|
|
import java.awt.Dimension;
|
2017-12-20 19:18:26 +01:00
|
|
|
import java.awt.Graphics;
|
2017-12-24 10:32:29 +01:00
|
|
|
import java.awt.GridBagConstraints;
|
|
|
|
import java.awt.GridBagLayout;
|
2018-01-02 00:55:54 +01:00
|
|
|
import java.awt.event.MouseListener;
|
2017-12-10 09:33:25 +01:00
|
|
|
import javax.swing.JButton;
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
import javax.swing.border.Border;
|
2017-12-24 10:32:29 +01:00
|
|
|
import sesim.ChartDef;
|
|
|
|
import sesim.ChartPanel;
|
|
|
|
import sesim.OHLCData;
|
2017-12-17 20:10:20 +01:00
|
|
|
import sesim.Stock;
|
2017-12-10 09:33:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author 7u83 <7u83@mail.ru>
|
|
|
|
*/
|
2018-01-23 01:36:25 +01:00
|
|
|
public class MMChart extends JPanel {
|
2017-12-24 10:32:29 +01:00
|
|
|
|
2017-12-17 20:10:20 +01:00
|
|
|
Stock stock;
|
2017-12-10 09:33:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates new form MMChart
|
|
|
|
*/
|
|
|
|
public MMChart() {
|
2017-12-17 20:10:20 +01:00
|
|
|
stock = Globals.se.getDefaultStock();
|
2017-12-10 09:33:25 +01:00
|
|
|
initComponents();
|
2018-01-02 00:55:54 +01:00
|
|
|
this.em_width = 10;
|
2017-12-10 09:33:25 +01:00
|
|
|
setupLayout();
|
2017-12-24 10:32:29 +01:00
|
|
|
|
2017-12-10 09:33:25 +01:00
|
|
|
}
|
2017-12-24 10:32:29 +01:00
|
|
|
|
|
|
|
ChartPanel xLegend;
|
2018-01-07 23:35:19 +01:00
|
|
|
ChartPanel yLegend;
|
2018-01-02 00:55:54 +01:00
|
|
|
ChartPanel mainChart;
|
2018-01-23 01:36:25 +01:00
|
|
|
|
|
|
|
private int compression=60000;
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-12-24 10:32:29 +01:00
|
|
|
|
2017-12-26 10:16:29 +01:00
|
|
|
private void setupYLegend() {
|
2017-12-24 10:32:29 +01:00
|
|
|
yLegend = new ChartPanel();
|
|
|
|
Border redborder = javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0));
|
|
|
|
yLegend.setBorder(redborder);
|
|
|
|
yLegend.setPreferredSize(new Dimension(this.em_width * 10, 110));
|
2017-12-26 09:37:26 +01:00
|
|
|
yLegend.setMinimumSize(new Dimension(em_width * 10, 110));
|
2017-12-24 10:32:29 +01:00
|
|
|
|
|
|
|
GridBagConstraints gbConstraints;
|
|
|
|
gbConstraints = new java.awt.GridBagConstraints();
|
|
|
|
gbConstraints.gridx = 1;
|
|
|
|
gbConstraints.gridy = 0;
|
|
|
|
gbConstraints.fill = GridBagConstraints.BOTH;
|
|
|
|
gbConstraints.weightx = 0.0;
|
|
|
|
gbConstraints.weighty = 1.0;
|
|
|
|
|
|
|
|
add(yLegend, gbConstraints);
|
2018-01-02 00:55:54 +01:00
|
|
|
this.addMouseMotionListener(yLegend);
|
2018-01-07 23:35:19 +01:00
|
|
|
|
|
|
|
OHLCChartPainter ylp = new YLegendPainter(/*null*/);
|
2018-01-23 01:36:25 +01:00
|
|
|
OHLCData mydata = stock.getOHLCdata(compression);
|
2018-01-07 23:35:19 +01:00
|
|
|
|
|
|
|
ylp.setOHLCData(mydata);
|
|
|
|
yLegend.setChartDef(chartDef);
|
|
|
|
yLegend.addChartPainter(ylp);
|
|
|
|
|
2017-12-24 10:32:29 +01:00
|
|
|
}
|
|
|
|
|
2017-12-26 10:16:29 +01:00
|
|
|
private void setupXLegend() {
|
2017-12-24 10:32:29 +01:00
|
|
|
xLegend = new ChartPanel();
|
2017-12-26 09:37:26 +01:00
|
|
|
// xLegend.setBackground(Color.blue);
|
|
|
|
|
|
|
|
xLegend.setPreferredSize(new Dimension(em_width * 2, em_width * 3));
|
|
|
|
xLegend.setMinimumSize(new Dimension(em_width * 2, em_width * 3));
|
|
|
|
|
2017-12-24 10:32:29 +01:00
|
|
|
xLegend.setChartDef(chartDef);
|
2017-12-26 09:37:26 +01:00
|
|
|
|
2017-12-24 10:32:29 +01:00
|
|
|
GridBagConstraints gbConstraints;
|
|
|
|
gbConstraints = new java.awt.GridBagConstraints();
|
|
|
|
gbConstraints.gridx = 0;
|
|
|
|
gbConstraints.gridy = 1;
|
|
|
|
gbConstraints.fill = GridBagConstraints.BOTH;
|
|
|
|
gbConstraints.weightx = 1.0;
|
|
|
|
gbConstraints.weighty = 0.0;
|
|
|
|
|
2017-12-26 09:37:26 +01:00
|
|
|
add(xLegend, gbConstraints);
|
2017-12-24 10:32:29 +01:00
|
|
|
|
2017-12-26 09:37:26 +01:00
|
|
|
OHLCChartPainter p;
|
2018-01-23 01:36:25 +01:00
|
|
|
OHLCData mydata = stock.getOHLCdata(compression);
|
2017-12-26 09:37:26 +01:00
|
|
|
|
|
|
|
// this.xScrollBar.setMaximum(0);
|
2017-12-24 10:32:29 +01:00
|
|
|
p = new XLegendPainter();
|
|
|
|
p.setOHLCData(mydata);
|
|
|
|
xLegend.addChartPainter(p);
|
2017-12-26 09:37:26 +01:00
|
|
|
|
2018-01-02 00:55:54 +01:00
|
|
|
p = new XLegendDetail();
|
|
|
|
p.setOHLCData(mydata);
|
|
|
|
xLegend.addChartPainter(p);
|
|
|
|
|
|
|
|
ChartPainter p0;
|
|
|
|
p0 = new ChartCrossPainter();
|
|
|
|
xLegend.addChartPainter(p0);
|
|
|
|
xLegend.setChartDef(chartDef);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void addMouseMotionListener(JPanel panel) {
|
|
|
|
panel.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
|
2018-01-23 01:36:25 +01:00
|
|
|
@Override
|
2018-01-02 00:55:54 +01:00
|
|
|
public void mouseMoved(java.awt.event.MouseEvent evt) {
|
|
|
|
formMouseMoved(evt);
|
|
|
|
}
|
|
|
|
});
|
2017-12-24 10:32:29 +01:00
|
|
|
}
|
2017-12-26 09:37:26 +01:00
|
|
|
|
2017-12-26 10:16:29 +01:00
|
|
|
private void setupMainChart() {
|
2017-12-24 10:32:29 +01:00
|
|
|
mainChart = new ChartPanel();
|
2017-12-28 09:00:17 +01:00
|
|
|
mainChart.setDoubleBuffered(true);
|
2017-12-24 10:32:29 +01:00
|
|
|
mainChart.setBackground(Color.green);
|
2017-12-26 09:37:26 +01:00
|
|
|
|
2017-12-24 10:32:29 +01:00
|
|
|
GridBagConstraints gbConstraints;
|
|
|
|
gbConstraints = new java.awt.GridBagConstraints();
|
|
|
|
gbConstraints.gridx = 0;
|
|
|
|
gbConstraints.gridy = 0;
|
|
|
|
gbConstraints.fill = GridBagConstraints.BOTH;
|
|
|
|
gbConstraints.weightx = 1.0;
|
|
|
|
gbConstraints.weighty = 1.0;
|
2017-12-26 09:37:26 +01:00
|
|
|
|
|
|
|
add(mainChart, gbConstraints);
|
2018-01-02 00:55:54 +01:00
|
|
|
|
|
|
|
ChartPainter p0;
|
|
|
|
p0 = new ChartCrossPainter();
|
|
|
|
mainChart.addChartPainter(p0);
|
2017-12-26 10:16:29 +01:00
|
|
|
|
2018-01-02 00:55:54 +01:00
|
|
|
this.addMouseMotionListener(mainChart);
|
2018-01-23 01:36:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
mainChart.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
|
2018-01-02 00:55:54 +01:00
|
|
|
|
2017-12-24 10:32:29 +01:00
|
|
|
}
|
2017-12-26 09:37:26 +01:00
|
|
|
|
2017-12-24 10:32:29 +01:00
|
|
|
ChartDef chartDef;
|
|
|
|
|
2017-12-26 10:16:29 +01:00
|
|
|
private void setupLayout() {
|
2017-12-24 10:32:29 +01:00
|
|
|
removeAll();
|
|
|
|
|
2017-12-10 09:33:25 +01:00
|
|
|
Border redborder = javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0));
|
|
|
|
Border blueborder = javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 255));
|
|
|
|
|
2017-12-24 10:32:29 +01:00
|
|
|
GridBagLayout layout = new GridBagLayout();
|
2017-12-10 09:33:25 +01:00
|
|
|
setLayout(layout);
|
|
|
|
|
2018-01-02 00:55:54 +01:00
|
|
|
chartDef = new ChartDef();
|
2017-12-28 09:00:17 +01:00
|
|
|
chartDef.x_unit_width = 3.0;
|
|
|
|
|
2018-01-02 00:55:54 +01:00
|
|
|
setupMainChart();
|
|
|
|
chartDef.mainChart = mainChart;
|
2017-12-24 10:32:29 +01:00
|
|
|
setupYLegend();
|
|
|
|
setupXLegend();
|
|
|
|
|
|
|
|
java.awt.GridBagConstraints gbConstraints;
|
2017-12-10 09:33:25 +01:00
|
|
|
|
2018-01-02 00:55:54 +01:00
|
|
|
mainChart = new ChartPanel();
|
2017-12-24 10:32:29 +01:00
|
|
|
mainChart.setPreferredSize(new Dimension(100, 40));
|
|
|
|
mainChart.setBackground(Color.blue);
|
2017-12-10 09:33:25 +01:00
|
|
|
}
|
2017-12-24 10:32:29 +01:00
|
|
|
|
2017-12-20 19:18:26 +01:00
|
|
|
int em_width;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void paint(Graphics g) {
|
|
|
|
em_width = g.getFontMetrics().stringWidth("M");
|
2017-12-24 10:32:29 +01:00
|
|
|
// this.removeAll();
|
2017-12-20 19:18:26 +01:00
|
|
|
|
2017-12-24 10:32:29 +01:00
|
|
|
// repaint();
|
2018-01-02 00:55:54 +01:00
|
|
|
// setupLayout();
|
|
|
|
xLegend.setPreferredSize(new Dimension(em_width * 2, em_width * 3));
|
|
|
|
xLegend.setMinimumSize(new Dimension(em_width * 2, em_width * 3));
|
|
|
|
|
2017-12-24 10:32:29 +01:00
|
|
|
revalidate();
|
2017-12-20 19:18:26 +01:00
|
|
|
super.paint(g); //To change body of generated methods, choose Tools | Templates.
|
|
|
|
}
|
2017-12-24 10:32:29 +01:00
|
|
|
|
2017-12-10 09:33:25 +01: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() {
|
|
|
|
|
2018-01-23 01:36:25 +01:00
|
|
|
popupMenu = new javax.swing.JPopupMenu();
|
|
|
|
|
2018-01-02 00:55:54 +01:00
|
|
|
addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
|
|
|
|
public void mouseMoved(java.awt.event.MouseEvent evt) {
|
|
|
|
formMouseMoved(evt);
|
|
|
|
}
|
|
|
|
});
|
2018-01-23 01:36:25 +01:00
|
|
|
addMouseWheelListener(new java.awt.event.MouseWheelListener() {
|
|
|
|
public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
|
|
|
|
formMouseWheelMoved(evt);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
addMouseListener(new java.awt.event.MouseAdapter() {
|
|
|
|
public void mouseClicked(java.awt.event.MouseEvent evt) {
|
|
|
|
formMouseClicked(evt);
|
|
|
|
}
|
|
|
|
});
|
2017-12-10 09:33:25 +01:00
|
|
|
setLayout(null);
|
|
|
|
}// </editor-fold>//GEN-END:initComponents
|
|
|
|
|
2018-01-02 00:55:54 +01:00
|
|
|
private void formMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseMoved
|
|
|
|
System.out.printf("Mouse Moved\n");
|
|
|
|
// mainChart.repaint();
|
|
|
|
// xLegend.revalidate();
|
|
|
|
xLegend.repaint();
|
|
|
|
}//GEN-LAST:event_formMouseMoved
|
|
|
|
|
2018-01-23 01:36:25 +01:00
|
|
|
private void formMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseClicked
|
|
|
|
System.out.printf("The mouse was clicked\n");
|
|
|
|
}//GEN-LAST:event_formMouseClicked
|
|
|
|
|
|
|
|
private void formMouseWheelMoved(java.awt.event.MouseWheelEvent evt) {//GEN-FIRST:event_formMouseWheelMoved
|
|
|
|
System.out.printf("Wheel!!!\n");
|
|
|
|
}//GEN-LAST:event_formMouseWheelMoved
|
|
|
|
|
2017-12-10 09:33:25 +01:00
|
|
|
|
|
|
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
2018-01-23 01:36:25 +01:00
|
|
|
private javax.swing.JPopupMenu popupMenu;
|
2017-12-10 09:33:25 +01:00
|
|
|
// End of variables declaration//GEN-END:variables
|
|
|
|
}
|