From caeb2c4060cae87724ce487be03bd829b30a93fa Mon Sep 17 00:00:00 2001 From: 7u83 <7u83@mail.ru> Date: Sun, 1 Oct 2017 11:36:35 +0200 Subject: [PATCH] next generation x legend --- nbproject/project.properties | 2 +- src/chart/Chart.form | 10 +++--- src/chart/Chart.java | 4 +-- src/chart/Chart1.java | 65 ++++++++++++++-------------------- src/chart/ChartDef.java | 37 +++++++++++++++++++ src/chart/ChartPainter.java | 49 +++++++++++++++++++++---- src/chart/ChartTestDialog.form | 21 +++-------- src/chart/ChartTestDialog.java | 18 +++------- 8 files changed, 124 insertions(+), 82 deletions(-) create mode 100644 src/chart/ChartDef.java diff --git a/nbproject/project.properties b/nbproject/project.properties index f1a8e7a..131608d 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,4 +1,4 @@ -#Sat, 30 Sep 2017 21:57:38 +0200 +#Sun, 01 Oct 2017 11:14:27 +0200 annotation.processing.enabled=true annotation.processing.enabled.in.editor=false annotation.processing.processors.list= diff --git a/src/chart/Chart.form b/src/chart/Chart.form index 4ba1efd..0f3dfd9 100644 --- a/src/chart/Chart.form +++ b/src/chart/Chart.form @@ -1,19 +1,17 @@ -
+ - - - - - + + + diff --git a/src/chart/Chart.java b/src/chart/Chart.java index 6bcb85c..1af1f08 100644 --- a/src/chart/Chart.java +++ b/src/chart/Chart.java @@ -193,7 +193,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab class RenderCtx { Rectangle rect; - float scaling; + //float scaling; float min; Graphics2D g; float iwidth; @@ -461,7 +461,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab RenderCtx ctx = new RenderCtx(); ctx.rect = new Rectangle(0, h1 + pad_top, pwidth, subchartwin_height - pad_top); - ctx.scaling = (float) ctx.rect.height / (c_mm.getMax() - c_mm.getMin()); +// ctx.scaling = (float) ctx.rect.height / (c_mm.getMax() - c_mm.getMin()); ctx.min = c_mm.getMin(); ctx.g = g; ctx.iwidth = (float) ((x_unit_width * em_width) * 0.9f); diff --git a/src/chart/Chart1.java b/src/chart/Chart1.java index 08e8ea7..d2f0ca1 100644 --- a/src/chart/Chart1.java +++ b/src/chart/Chart1.java @@ -25,7 +25,7 @@ import sesim.Quote; public class Chart1 extends javax.swing.JPanel implements QuoteReceiver, AdjustmentListener { public JScrollBar xbar; - + /** * Creates new form Chart1 */ @@ -34,16 +34,12 @@ public class Chart1 extends javax.swing.JPanel implements QuoteReceiver, Adjustm System.out.printf("Now cursor\n"); setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); - - if (Globals.se == null) { return; } - - - setSize(new Dimension(9000,500)); + setSize(new Dimension(9000, 500)); Globals.se.addQuoteReceiver(this); } @@ -51,38 +47,27 @@ public class Chart1 extends javax.swing.JPanel implements QuoteReceiver, Adjustm private void drawChart(Graphics2D g) { - - JViewport vp = new JViewport(); - - - - // if (Globals.se==null) -// return; - Dimension d = new Dimension(200,200); + // if (Globals.se==null) +// return; + Dimension d = new Dimension(200, 200); setPreferredSize(d); - - g.setClip(10,10,800,200); + g.setClip(10, 10, 800, 200); g.setColor(Color.red); g.drawLine(0, 0, 8000, 610); - - if (Globals.se==null) + + if (Globals.se == null) { return; - - - + } + revalidate(); - - - System.out.printf("Setting pref size\n" ); - - - - + + System.out.printf("Setting pref size\n"); + OHLCData data = Globals.se.getOHLCdata(60000); -/* + /* int first_bar = 0; int last_bar = data.size(); @@ -103,8 +88,9 @@ public class Chart1 extends javax.swing.JPanel implements QuoteReceiver, Adjustm prev = di; } - */ + */ } + OHLCData data; @Override protected void paintComponent(Graphics g) { @@ -113,12 +99,12 @@ public class Chart1 extends javax.swing.JPanel implements QuoteReceiver, Adjustm // Calculate the number of pixels for 1 em em_width = g.getFontMetrics().stringWidth("M"); - this.xbar.setMaximum(994000); - + //this.xbar.setMaximum(994000); + ChartPainter p = new ChartPainter(); - p.drawChart((Graphics2D)g, xbar, getSize()); - - + data = Globals.se.getOHLCdata(60000); + p.drawChart((Graphics2D) g, xbar, data, this); + //drawChart((Graphics2D)g); } @@ -145,17 +131,20 @@ public class Chart1 extends javax.swing.JPanel implements QuoteReceiver, Adjustm @Override public void UpdateQuote(Quote q) { + + int s = data.size(); + System.out.printf("Data size %d",s); + xbar.setMaximum(data.size()); repaint(); } @Override public void adjustmentValueChanged(AdjustmentEvent e) { - System.out.printf("Adjustemntlistener called %d\n",xbar.getValue()); + System.out.printf("Adjustemntlistener called %d\n", xbar.getValue()); + this.repaint(); } - - // Variables declaration - do not modify//GEN-BEGIN:variables // End of variables declaration//GEN-END:variables diff --git a/src/chart/ChartDef.java b/src/chart/ChartDef.java new file mode 100644 index 0000000..c7dace9 --- /dev/null +++ b/src/chart/ChartDef.java @@ -0,0 +1,37 @@ +/* + * 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; + +import javax.swing.JScrollBar; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class ChartDef { + JScrollBar scrollbar; + +} diff --git a/src/chart/ChartPainter.java b/src/chart/ChartPainter.java index e121d26..766dec6 100644 --- a/src/chart/ChartPainter.java +++ b/src/chart/ChartPainter.java @@ -29,6 +29,7 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics2D; import javax.swing.JScrollBar; +import sesim.OHLCData; /** * @@ -39,18 +40,54 @@ public class ChartPainter { int em_width; protected final void init(Graphics2D g) { - + // Calculate the number of pixels for 1 em em_width = g.getFontMetrics().stringWidth("M"); - + } - public void drawChart(Graphics2D g, JScrollBar sb, Dimension size) { - init (g); + int big_tick = 10; + int y = 0; + + String getAt(OHLCData data, int unit) { + + int fs = data.getFrameSize(); + return sesim.Scheduler.formatTimeMillis(0 + unit * fs); + + } + + public void drawChart(Graphics2D g, JScrollBar sb, OHLCData data, Chart1 p) { + init(g); g.setColor(Color.MAGENTA); - g.drawLine(0, 0, size.width, 100); - g.setBackground(Color.yellow); + Dimension size = p.getSize(); + //g.drawLine(0, 0, size.width, 100); + System.out.printf("SIZE %d %d\n",size.width,size.height); + + + + int n; + int x; + for (n = 0, x = 0; x < size.width; x += em_width * 1.0) { + if (n % big_tick == 1) { + g.drawLine((int) x, y, (int) x, y + em_width); + String text; + text = getAt(data,n); + + int swidth = g.getFontMetrics().stringWidth(text); + g.drawString(text, (int) x - swidth / 2, y + em_width * 2); + + } else { + g.drawLine((int) x, y, (int) x, y + em_width / 2); + } + + if (n % big_tick == 0) { + + } + + n += 1; + } + } } diff --git a/src/chart/ChartTestDialog.form b/src/chart/ChartTestDialog.form index 6b83bd1..fc701b5 100644 --- a/src/chart/ChartTestDialog.form +++ b/src/chart/ChartTestDialog.form @@ -32,9 +32,8 @@ - - - + + @@ -44,10 +43,8 @@ - - - - + + @@ -70,18 +67,10 @@ - + - - - - - - - - diff --git a/src/chart/ChartTestDialog.java b/src/chart/ChartTestDialog.java index b61e0c6..a9ce203 100644 --- a/src/chart/ChartTestDialog.java +++ b/src/chart/ChartTestDialog.java @@ -53,7 +53,6 @@ public class ChartTestDialog extends javax.swing.JDialog { jScrollBar1 = new javax.swing.JScrollBar(); chart11 = new chart.Chart1(); - jToolBar1 = new javax.swing.JToolBar(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setMaximumSize(new java.awt.Dimension(800, 600)); @@ -69,12 +68,9 @@ public class ChartTestDialog extends javax.swing.JDialog { ); chart11Layout.setVerticalGroup( chart11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 198, Short.MAX_VALUE) + .addGap(0, 318, Short.MAX_VALUE) ); - jToolBar1.setFloatable(false); - jToolBar1.setRollover(true); - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( @@ -82,19 +78,16 @@ public class ChartTestDialog extends javax.swing.JDialog { .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(chart11, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 482, Short.MAX_VALUE) - .addComponent(jScrollBar1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 482, Short.MAX_VALUE) - .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(jScrollBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 586, Short.MAX_VALUE) + .addComponent(chart11, javax.swing.GroupLayout.DEFAULT_SIZE, 586, Short.MAX_VALUE)) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() - .addComponent(chart11, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(chart11, javax.swing.GroupLayout.DEFAULT_SIZE, 318, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) ); @@ -147,6 +140,5 @@ public class ChartTestDialog extends javax.swing.JDialog { // Variables declaration - do not modify//GEN-BEGIN:variables private chart.Chart1 chart11; private javax.swing.JScrollBar jScrollBar1; - private javax.swing.JToolBar jToolBar1; // End of variables declaration//GEN-END:variables }