From 95f563aa0eafb0891e85c081db89ce7b179705b4 Mon Sep 17 00:00:00 2001 From: 7u83 <7u83@mail.ru> Date: Fri, 6 Oct 2017 07:21:03 +0200 Subject: [PATCH] YLegend ... --- nbproject/project.properties | 2 +- src/chart/MasterChart.java | 16 +++-- src/chart/painter/ChartPainter.java | 6 ++ src/chart/painter/OHLCChartPainter.java | 3 +- src/chart/painter/YLegendPainter.java | 85 +++++++++++++++++++++++++ 5 files changed, 104 insertions(+), 8 deletions(-) create mode 100644 src/chart/painter/YLegendPainter.java diff --git a/nbproject/project.properties b/nbproject/project.properties index 929c8e9..2d706e7 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,4 +1,4 @@ -#Wed, 04 Oct 2017 11:09:53 +0200 +#Thu, 05 Oct 2017 22:01:54 +0200 annotation.processing.enabled=true annotation.processing.enabled.in.editor=false annotation.processing.processors.list= diff --git a/src/chart/MasterChart.java b/src/chart/MasterChart.java index 9db51df..605be42 100644 --- a/src/chart/MasterChart.java +++ b/src/chart/MasterChart.java @@ -29,6 +29,7 @@ import chart.painter.CandleStickChartPainter; import chart.painter.ChartPainter; import chart.painter.XLegendPainter; import chart.painter.ChartCrossPainter; +import chart.painter.YLegendPainter; import gui.Globals; import sesim.Exchange.QuoteReceiver; import sesim.OHLCData; @@ -64,14 +65,19 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver, Ch xLegend.addChartPainter(p); xLegend.setXSCrollBar(xScrollBar); - p = new CandleStickChartPainter(); - p.setDataProvider(this); + ChartPainter pc = new CandleStickChartPainter(); + pc.setDataProvider(this); - chart.addChartPainter(p); + chart.addChartPainter(pc); chart.setXSCrollBar(xScrollBar); - p = new ChartCrossPainter(); - this.chart.addChartPainter(p); + ChartPainter yp = new YLegendPainter(chart); + yp.setDataProvider(this); + + this.chart.addChartPainter(yp); + + this.yLegend.addChartPainter(p); + this.yLegend.addChartPainter(pc); } diff --git a/src/chart/painter/ChartPainter.java b/src/chart/painter/ChartPainter.java index 35d7178..39321fa 100644 --- a/src/chart/painter/ChartPainter.java +++ b/src/chart/painter/ChartPainter.java @@ -27,6 +27,7 @@ package chart.painter; import chart.ChartDef; import chart.ChartPanel; +import java.awt.Dimension; import java.awt.Graphics2D; import sesim.OHLCData; @@ -61,6 +62,11 @@ abstract public class ChartPainter { } return 0; } + + protected int getBars(ChartPanel p, ChartDef def){ + Dimension dim = p.getSize(); + return (int) (dim.width / (def.x_unit_width * em_size)); + } /** * Init method scould be called before painting the chart diff --git a/src/chart/painter/OHLCChartPainter.java b/src/chart/painter/OHLCChartPainter.java index e692f5c..9506ed8 100644 --- a/src/chart/painter/OHLCChartPainter.java +++ b/src/chart/painter/OHLCChartPainter.java @@ -27,7 +27,6 @@ package chart.painter; import chart.ChartDef; import chart.ChartPanel; -import chart.painter.ChartPainter; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics2D; @@ -36,7 +35,7 @@ import javax.swing.JScrollBar; import sesim.MinMax; import sesim.OHLCData; import sesim.OHLCDataItem; -import static sun.awt.geom.Curve.prev; + /** * diff --git a/src/chart/painter/YLegendPainter.java b/src/chart/painter/YLegendPainter.java new file mode 100644 index 0000000..2ffa633 --- /dev/null +++ b/src/chart/painter/YLegendPainter.java @@ -0,0 +1,85 @@ +/* + * 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 chart.Chart; +import chart.ChartDef; +import chart.ChartPanel; +import java.awt.Dimension; +import java.awt.Graphics2D; +import java.awt.Rectangle; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class YLegendPainter extends ChartPainter { + + ChartPanel master; + + public YLegendPainter (ChartPanel master){ + this.master=master; + } + + @Override + public void drawChart(Graphics2D g, ChartPanel p, ChartDef def) { + init(g); + + Dimension dim = master.getSize(); + int first_bar = getFirstBar(master); + int bars = getBars(master,def); + + //Rectangle dim; + // dim = p.getSize(); + // dim = this.clip_bounds; + + // Dimension rv = this.getSize(); +// int yw = (int) (this.yl_width * em_size); + +// g.drawLine(dim.width + dim.x - yw, 0, dim.width + dim.x - yw, dim.height); + +/* + float y1 = ctx.getY(mm.getMin(false)); + float y2 = ctx.getY(c_mm.getMax(false)); + float ydiff = y1 - y2; +// System.out.printf("%s y1: %f, y2: %f, diff %f\n", Boolean.toString(c_mm.isLog()), y1, y2, ydiff); + + for (int yp = (int) y2; yp < y1; yp += em_width * 5) { + g.drawLine(dim.width + dim.x - yw, yp, dim.width + dim.x - yw + em_width, yp); + double v1 = ctx.getValAtY(yp); + g.drawString(String.format("%.2f", v1), dim.width + dim.x - yw + em_width * 1.5f, yp + c_font_height / 3); + } + + double v1, v2; + v1 = ctx.getValAtY(y1); + v2 = ctx.getValAtY(y2); +*/ + + } + + + +}