some work
This commit is contained in:
parent
54d499cd18
commit
16468c4b3d
@ -1,4 +1,4 @@
|
|||||||
#Thu, 28 Dec 2017 10:07:33 +0100
|
#Tue, 02 Jan 2018 00:55:00 +0100
|
||||||
annotation.processing.enabled=true
|
annotation.processing.enabled=true
|
||||||
annotation.processing.enabled.in.editor=false
|
annotation.processing.enabled.in.editor=false
|
||||||
annotation.processing.processors.list=
|
annotation.processing.processors.list=
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
|
||||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
|
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
|
||||||
|
<Events>
|
||||||
|
<EventHandler event="mouseMoved" listener="java.awt.event.MouseMotionListener" parameters="java.awt.event.MouseEvent" handler="formMouseMoved"/>
|
||||||
|
</Events>
|
||||||
<AuxValues>
|
<AuxValues>
|
||||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||||
|
@ -25,8 +25,10 @@
|
|||||||
*/
|
*/
|
||||||
package chart;
|
package chart;
|
||||||
|
|
||||||
|
import chart.painter.ChartCrossPainter;
|
||||||
import chart.painter.ChartPainter;
|
import chart.painter.ChartPainter;
|
||||||
import chart.painter.OHLCChartPainter;
|
import chart.painter.OHLCChartPainter;
|
||||||
|
import chart.painter.XLegendDetail;
|
||||||
import chart.painter.XLegendPainter;
|
import chart.painter.XLegendPainter;
|
||||||
import gui.Globals;
|
import gui.Globals;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
@ -34,6 +36,7 @@ import java.awt.Dimension;
|
|||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.GridBagConstraints;
|
import java.awt.GridBagConstraints;
|
||||||
import java.awt.GridBagLayout;
|
import java.awt.GridBagLayout;
|
||||||
|
import java.awt.event.MouseListener;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
@ -56,14 +59,14 @@ public class MMChart extends javax.swing.JPanel {
|
|||||||
public MMChart() {
|
public MMChart() {
|
||||||
stock = Globals.se.getDefaultStock();
|
stock = Globals.se.getDefaultStock();
|
||||||
initComponents();
|
initComponents();
|
||||||
this.em_width=10;
|
this.em_width = 10;
|
||||||
setupLayout();
|
setupLayout();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ChartPanel xLegend;
|
ChartPanel xLegend;
|
||||||
JPanel yLegend;
|
JPanel yLegend;
|
||||||
JPanel mainChart;
|
ChartPanel mainChart;
|
||||||
|
|
||||||
private void setupYLegend() {
|
private void setupYLegend() {
|
||||||
yLegend = new ChartPanel();
|
yLegend = new ChartPanel();
|
||||||
@ -81,6 +84,7 @@ public class MMChart extends javax.swing.JPanel {
|
|||||||
gbConstraints.weighty = 1.0;
|
gbConstraints.weighty = 1.0;
|
||||||
|
|
||||||
add(yLegend, gbConstraints);
|
add(yLegend, gbConstraints);
|
||||||
|
this.addMouseMotionListener(yLegend);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupXLegend() {
|
private void setupXLegend() {
|
||||||
@ -104,14 +108,29 @@ public class MMChart extends javax.swing.JPanel {
|
|||||||
|
|
||||||
OHLCChartPainter p;
|
OHLCChartPainter p;
|
||||||
OHLCData mydata = stock.getOHLCdata(60000);
|
OHLCData mydata = stock.getOHLCdata(60000);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// this.xScrollBar.setMaximum(0);
|
// this.xScrollBar.setMaximum(0);
|
||||||
p = new XLegendPainter();
|
p = new XLegendPainter();
|
||||||
p.setOHLCData(mydata);
|
p.setOHLCData(mydata);
|
||||||
xLegend.addChartPainter(p);
|
xLegend.addChartPainter(p);
|
||||||
|
|
||||||
|
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() {
|
||||||
|
public void mouseMoved(java.awt.event.MouseEvent evt) {
|
||||||
|
formMouseMoved(evt);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupMainChart() {
|
private void setupMainChart() {
|
||||||
@ -128,11 +147,13 @@ public class MMChart extends javax.swing.JPanel {
|
|||||||
gbConstraints.weighty = 1.0;
|
gbConstraints.weighty = 1.0;
|
||||||
|
|
||||||
add(mainChart, gbConstraints);
|
add(mainChart, gbConstraints);
|
||||||
|
|
||||||
|
ChartPainter p0;
|
||||||
|
p0 = new ChartCrossPainter();
|
||||||
|
mainChart.addChartPainter(p0);
|
||||||
|
|
||||||
|
this.addMouseMotionListener(mainChart);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ChartDef chartDef;
|
ChartDef chartDef;
|
||||||
@ -146,18 +167,17 @@ public class MMChart extends javax.swing.JPanel {
|
|||||||
GridBagLayout layout = new GridBagLayout();
|
GridBagLayout layout = new GridBagLayout();
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
chartDef = new ChartDef();
|
chartDef = new ChartDef();
|
||||||
chartDef.x_unit_width = 3.0;
|
chartDef.x_unit_width = 3.0;
|
||||||
|
|
||||||
|
setupMainChart();
|
||||||
|
chartDef.mainChart = mainChart;
|
||||||
setupYLegend();
|
setupYLegend();
|
||||||
setupXLegend();
|
setupXLegend();
|
||||||
setupMainChart();
|
|
||||||
|
|
||||||
|
|
||||||
java.awt.GridBagConstraints gbConstraints;
|
java.awt.GridBagConstraints gbConstraints;
|
||||||
|
|
||||||
mainChart = new JPanel();
|
mainChart = new ChartPanel();
|
||||||
mainChart.setPreferredSize(new Dimension(100, 40));
|
mainChart.setPreferredSize(new Dimension(100, 40));
|
||||||
mainChart.setBackground(Color.blue);
|
mainChart.setBackground(Color.blue);
|
||||||
}
|
}
|
||||||
@ -170,10 +190,10 @@ public class MMChart extends javax.swing.JPanel {
|
|||||||
// this.removeAll();
|
// this.removeAll();
|
||||||
|
|
||||||
// repaint();
|
// repaint();
|
||||||
// setupLayout();
|
// setupLayout();
|
||||||
xLegend.setPreferredSize(new Dimension(em_width * 2, em_width * 3));
|
xLegend.setPreferredSize(new Dimension(em_width * 2, em_width * 3));
|
||||||
xLegend.setMinimumSize(new Dimension(em_width * 2, em_width * 3));
|
xLegend.setMinimumSize(new Dimension(em_width * 2, em_width * 3));
|
||||||
|
|
||||||
revalidate();
|
revalidate();
|
||||||
super.paint(g); //To change body of generated methods, choose Tools | Templates.
|
super.paint(g); //To change body of generated methods, choose Tools | Templates.
|
||||||
}
|
}
|
||||||
@ -187,9 +207,21 @@ public class MMChart extends javax.swing.JPanel {
|
|||||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||||
private void initComponents() {
|
private void initComponents() {
|
||||||
|
|
||||||
|
addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
|
||||||
|
public void mouseMoved(java.awt.event.MouseEvent evt) {
|
||||||
|
formMouseMoved(evt);
|
||||||
|
}
|
||||||
|
});
|
||||||
setLayout(null);
|
setLayout(null);
|
||||||
}// </editor-fold>//GEN-END:initComponents
|
}// </editor-fold>//GEN-END:initComponents
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
// End of variables declaration//GEN-END:variables
|
// End of variables declaration//GEN-END:variables
|
||||||
|
@ -151,7 +151,7 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver {
|
|||||||
this.yLegend.setChartDef(chartDef);
|
this.yLegend.setChartDef(chartDef);
|
||||||
|
|
||||||
OHLCChartPainter p;
|
OHLCChartPainter p;
|
||||||
mydata = Globals.se.getOHLCdata(Globals.se.getDefaultStock(),60000);
|
mydata = Globals.se.getOHLCdata(Globals.se.getDefaultStock(),60000*4);
|
||||||
|
|
||||||
this.xScrollBar.setMaximum(0);
|
this.xScrollBar.setMaximum(0);
|
||||||
|
|
||||||
|
@ -29,13 +29,14 @@ import sesim.ChartDef;
|
|||||||
import sesim.ChartPanel;
|
import sesim.ChartPanel;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
|
import sesim.OHLCDataItem;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author 7u83 <7u83@mail.ru>
|
* @author 7u83 <7u83@mail.ru>
|
||||||
*/
|
*/
|
||||||
public class ChartCrossPainter extends ChartPainter{
|
public class ChartCrossPainter extends OHLCChartPainter{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawChart(Graphics2D g, ChartPanel p, ChartDef def) {
|
public void drawChart(Graphics2D g, ChartPanel p, ChartDef def) {
|
||||||
@ -49,6 +50,12 @@ public class ChartCrossPainter extends ChartPainter{
|
|||||||
g.drawLine(0, p.mouse.y, p.getSize().width, p.mouse.y);
|
g.drawLine(0, p.mouse.y, p.getSize().width, p.mouse.y);
|
||||||
g.drawLine(p.mouse.x, 0, p.mouse.x, p.getSize().height);
|
g.drawLine(p.mouse.x, 0, p.mouse.x, p.getSize().height);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void drawItem(Graphics2D g, int prevx, int x, OHLCDataItem prev, OHLCDataItem i) {
|
||||||
|
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,7 +36,6 @@ import sesim.MinMax;
|
|||||||
import sesim.OHLCData;
|
import sesim.OHLCData;
|
||||||
import sesim.OHLCDataItem;
|
import sesim.OHLCDataItem;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author 7u83 <7u83@mail.ru>
|
* @author 7u83 <7u83@mail.ru>
|
||||||
@ -45,23 +44,21 @@ public abstract class OHLCChartPainter extends ChartPainter {
|
|||||||
|
|
||||||
protected float iwidth;
|
protected float iwidth;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
abstract void drawItem(Graphics2D g, int prevx, int x, OHLCDataItem prev, OHLCDataItem i);
|
abstract void drawItem(Graphics2D g, int prevx, int x, OHLCDataItem prev, OHLCDataItem i);
|
||||||
|
|
||||||
protected OHLCData data;
|
protected OHLCData data;
|
||||||
|
|
||||||
public void setOHLCData(OHLCData data){
|
public void setOHLCData(OHLCData data) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected OHLCData getData() {
|
protected OHLCData getData() {
|
||||||
return this.data;
|
return this.data;
|
||||||
/*if (dataProvider == null) {
|
/*if (dataProvider == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return dataProvider.get();
|
return dataProvider.get();
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getFirstBar(ChartPanel p) {
|
protected int getFirstBar(ChartPanel p) {
|
||||||
@ -71,6 +68,25 @@ public abstract class OHLCChartPainter extends ChartPainter {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected int x2Time(ChartPanel p, ChartDef def, int x) {
|
||||||
|
// int first_bar = getFirstBar(p);
|
||||||
|
// OHLCDataItem d = data.get(first_bar);
|
||||||
|
|
||||||
|
long t = 0;
|
||||||
|
|
||||||
|
int xbar = (int)((float)x/def.x_unit_width);
|
||||||
|
|
||||||
|
System.out.printf("XBAR: %d\n",xbar);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of bars needed to fill the ChartPanel object
|
||||||
|
* @param p ChartPanel object
|
||||||
|
* @param def ChartDef
|
||||||
|
* @return Number of bars
|
||||||
|
*/
|
||||||
protected int getBars(ChartPanel p, ChartDef def) {
|
protected int getBars(ChartPanel p, ChartDef def) {
|
||||||
Dimension dim = p.getSize();
|
Dimension dim = p.getSize();
|
||||||
return (int) (dim.width / (def.x_unit_width * em_size));
|
return (int) (dim.width / (def.x_unit_width * em_size));
|
||||||
@ -102,7 +118,7 @@ public abstract class OHLCChartPainter extends ChartPainter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
return (-(y - y_height)) / y_scaling + y_min;
|
return (-(y - y_height)) / y_scaling + y_min;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,45 +128,36 @@ public abstract class OHLCChartPainter extends ChartPainter {
|
|||||||
y_min = minmax.getMin();
|
y_min = minmax.getMin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawChart(Graphics2D g, ChartPanel p, ChartDef def) {
|
public void drawChart(Graphics2D g, ChartPanel p, ChartDef def) {
|
||||||
OHLCData data = getData();
|
OHLCData data = getData();
|
||||||
if (data==null)
|
if (data == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
init(g);
|
init(g);
|
||||||
|
|
||||||
iwidth = (float) ((def.x_unit_width * em_size) * 0.9f);
|
iwidth = (float) ((def.x_unit_width * em_size) * 0.9f);
|
||||||
|
|
||||||
int first_bar = getFirstBar(p);
|
int first_bar = getFirstBar(p);
|
||||||
|
|
||||||
|
|
||||||
Dimension dim = p.getSize();
|
Dimension dim = p.getSize();
|
||||||
//int bars = (int) (dim.width / (def.x_unit_width * em_size));
|
//int bars = (int) (dim.width / (def.x_unit_width * em_size));
|
||||||
int bars = this.getBars(p, def);
|
int bars = this.getBars(p, def);
|
||||||
|
|
||||||
|
int last_bar = first_bar + bars + 1;
|
||||||
int last_bar = first_bar + bars+1;
|
|
||||||
|
|
||||||
MinMax minmax = data.getMinMax(first_bar, last_bar);
|
MinMax minmax = data.getMinMax(first_bar, last_bar);
|
||||||
|
|
||||||
this.initGetY(minmax, dim);
|
|
||||||
|
|
||||||
// y_scaling = dim.height / minmax.getDiff();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
this.initGetY(minmax, dim);
|
||||||
|
|
||||||
|
// y_scaling = dim.height / minmax.getDiff();
|
||||||
OHLCDataItem prevd = null;
|
OHLCDataItem prevd = null;
|
||||||
int prevx;
|
int prevx;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (data.size() > 0 && first_bar < data.size()) {
|
if (data.size() > 0 && first_bar < data.size()) {
|
||||||
prevd = data.get(first_bar);
|
prevd = data.get(first_bar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (int b = first_bar, n = 0; b < last_bar && b < data.size(); b++, n++) {
|
for (int b = first_bar, n = 0; b < last_bar && b < data.size(); b++, n++) {
|
||||||
OHLCDataItem d = data.get(b);
|
OHLCDataItem d = data.get(b);
|
||||||
|
70
src/chart/painter/XLegendDetail.java
Normal file
70
src/chart/painter/XLegendDetail.java
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* 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.painter;
|
||||||
|
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Point;
|
||||||
|
import sesim.ChartDef;
|
||||||
|
import sesim.ChartPanel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author 7u83 <7u83@mail.ru>
|
||||||
|
*/
|
||||||
|
public class XLegendDetail extends XLegendPainter{
|
||||||
|
public XLegendDetail(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ctr=0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawChart(Graphics2D g, ChartPanel p, ChartDef def) {
|
||||||
|
// System.out.printf("Xlegend Deatil drawchart called %d\n",ctr);
|
||||||
|
// ctr++;
|
||||||
|
|
||||||
|
init (g);
|
||||||
|
if (def==null)
|
||||||
|
return;
|
||||||
|
if (def.mainChart==null)
|
||||||
|
return;
|
||||||
|
if (def.mainChart.mouse == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Point mouse = def.mainChart.mouse;
|
||||||
|
|
||||||
|
int x = def.mainChart.mouse.x;
|
||||||
|
|
||||||
|
this.x2Time(p, def, x);
|
||||||
|
|
||||||
|
g.drawLine(mouse.x, 0, mouse.x, p.getSize().height);
|
||||||
|
|
||||||
|
System.out.printf("Detail Mous X: %d\n",x);
|
||||||
|
// super.drawChart(g, p, def); //To change body of generated methods, choose Tools | Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -39,6 +39,9 @@ public class ChartDef {
|
|||||||
*/
|
*/
|
||||||
public double x_unit_width=1.0;
|
public double x_unit_width=1.0;
|
||||||
|
|
||||||
|
public ChartPanel mainChart;
|
||||||
|
public ChartPanel xLegend;
|
||||||
|
|
||||||
public ChartDef(){
|
public ChartDef(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user