diff --git a/src/main/java/chart/Chart.form b/src/main/java/chart/Chart.form index 5559af3..235ed37 100644 --- a/src/main/java/chart/Chart.form +++ b/src/main/java/chart/Chart.form @@ -13,6 +13,12 @@ + + + + + + @@ -23,6 +29,7 @@ + @@ -47,7 +54,7 @@ - + diff --git a/src/main/java/chart/Chart.java b/src/main/java/chart/Chart.java index d378d4b..74a8c22 100644 --- a/src/main/java/chart/Chart.java +++ b/src/main/java/chart/Chart.java @@ -18,8 +18,11 @@ import java.util.ArrayList; import java.util.Date; import java.util.Iterator; import javax.swing.JMenuItem; +import javax.swing.JScrollPane; +import javax.swing.JViewport; import javax.swing.Scrollable; import sesim.MinMax; +import sesim.Scheduler; /** * @@ -27,11 +30,25 @@ import sesim.MinMax; */ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollable { + class ChartDef { + + } + + + protected int em_size = 1; - protected float bar_width = 0.8f; - protected float bar_width_em = 1; - protected float y_legend_width = 8; + + protected float bar_width = 2.0f; + + + public void setBarWidth(float bw){ + bar_width=bw; + } + + + //protected float bar_width_em = 1; + protected float y_legend_width = 10; protected int num_bars = 4000; @@ -44,12 +61,19 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab // data = new OHLCData(60000*30); //data = new OHLCData(60000*30); //data = Globals.se.getOHLCdata(60000 * 30); + this.setCompression(10000); } + + /** * Creates new form Chart */ public Chart() { + if (Globals.se==null){ + return; + } + initComponents(); initChart(); initCtxMenu(); @@ -59,6 +83,10 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab } Globals.se.addQuoteReceiver(this); + +// scrollPane=new JScrollPane(); + // scrollPane.setViewportView(this); + } @@ -101,12 +129,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab OHLCData data; - OHLCDataItem current = null; - - //void drawCandle(Graphics2D g, OHLCData d, int x, int y) { -// - // } @Override public Dimension getPreferredScrollableViewportSize() { return this.getPreferredSize(); @@ -135,7 +158,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab class XLegendDef { double unit_width = 1; - int big_tick = 10; + int big_tick = 8; long start; XLegendDef() { @@ -143,11 +166,11 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab } String getAt(int unit) { - Date date = new Date(/*sesim.Scheduler.timeStart*/0 + unit * 5000); -// DateFormat formatter = new SimpleDateFormat("HH:mm:ss:SSS"); - DateFormat formatter = new SimpleDateFormat("HH:mm:ss"); - String dateFormatted = formatter.format(date); - return dateFormatted; + + int fs = data.getFrameSize(); + return Scheduler.formatTimeMillis(0+unit*fs); + + } } @@ -158,15 +181,10 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab void drawXLegend(Graphics2D g, XLegendDef xld) { - //XLegendDef xld = new XLegendDef(); g = (Graphics2D) g.create(); - int xl_height = 30; - Dimension dim = this.getSize(); - - int em_height = g.getFontMetrics().getHeight(); - int em_width = g.getFontMetrics().stringWidth("M"); - + + Dimension dim = getSize(); int y = dim.height - em_height * 3; g.drawLine(0, y, dim.width, y); @@ -174,18 +192,18 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab int n; double x; - for (n = 0, x = 0; x < dim.width; x += em_width * xld.unit_width) { + for (n = 0, x = 0; x < dim.width; x += em_size * xld.unit_width) { if (n % xld.big_tick == 0) { - g.drawLine((int) x, y, (int) x, y + em_height); + g.drawLine((int) x, y, (int) x, y + em_size); } else { - g.drawLine((int) x, y, (int) x, y + em_height / 2); + g.drawLine((int) x, y, (int) x, y + em_size / 2); } if (n % xld.big_tick == 0) { - String text = "Hello"; - + String text; text = xld.getAt(n); + int swidth = g.getFontMetrics().stringWidth(text); g.drawString(text, (int) x - swidth / 2, y + em_height * 2); @@ -320,13 +338,26 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab private void drawYLegend(Graphics2D g) { + // g.setClip(null); +System.out.printf("Drawing legend\n"); Dimension dim0 = this.getSize(); Rectangle dim = g.getClipBounds(); + dim = this.clip_bounds; + + + + Dimension rv = this.getSize(); + System.out.printf("W: %d,%d\n",rv.width,rv.height ); + + int yw = (int) (this.y_legend_width * this.em_size); -// System.out.printf("MinMax: %f %f\n", c_mm.min, c_mm.max); + + g.setColor(Color.BLUE); g.drawLine(dim.width + dim.x - yw, 0, dim.width + dim.x - yw, dim.height); + g.setColor(Color.YELLOW); +System.out.printf("Dim: %d %d %d %d\n", dim.x,dim.y,dim.width,dim.height); // float yscale = gdim.height / c_mm.getDiff(); c_yscaling = c_rect.height / c_mm.getDiff(); @@ -352,6 +383,10 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab private MinMax c_mm = null; private Rectangle c_rect; + + private int em_height; + private int em_width; + private void draw(Graphics2D g) { if (data == null) { @@ -369,12 +404,15 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab c_mm.min /= 1.5; //-= c_mm.min/ 2.0f; c_mm.max *= 1.2; //+= c_mm.max / 10.0f; + em_height = g.getFontMetrics().getHeight(); + em_width = g.getFontMetrics().stringWidth("M"); + + + OHLCDataItem di0 = data.get(0); XLegendDef xld = new XLegendDef(); this.drawXLegend(g, xld); - int em_height = g.getFontMetrics().getHeight(); - int em_width = g.getFontMetrics().stringWidth("M"); //this.getSize(); int pwidth = em_width * num_bars; @@ -429,30 +467,54 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab */ } - protected void initEmSize(Graphics g) { - - em_size = g.getFontMetrics().stringWidth("M"); - - } - + private float c_font_height; @Override public final void paintComponent(Graphics g) { super.paintComponent(g); - this.initEmSize(g); + // Calculate the number of pixels for 1 em + em_size = g.getFontMetrics().stringWidth("M"); + + this.gdim = this.getParent().getSize(gdim); this.getParent().setPreferredSize(gdim); - this.clip_bounds = g.getClipBounds(this.clip_bounds); + Object o = this.getParent(); + + JViewport vp = (JViewport) this.getParent(); + vp.getExtentSize(); + + + + this.clip_bounds=g.getClipBounds(); + + Dimension r = vp.getExtentSize(); + + System.out.printf("Repainting called %d %d %d %d\n", r.width,r.height,clip_bounds.width,clip_bounds.height); + + clip_bounds.width=r.width; + clip_bounds.height=r.height; + clip_bounds.x=0; + clip_bounds.y=0; + Point vvp = vp.getViewPosition(); + clip_bounds.x=vvp.x; + clip_bounds.y=vvp.y; + + this.clip_bounds=vp.getViewRect(); + + // System.out.printf("X:%d %d\n",gdim.width,gdim.height); first_bar = (int) (clip_bounds.x / (this.bar_width * this.em_size)); last_bar = 1 + (int) ((clip_bounds.x + clip_bounds.width - (this.y_legend_width * em_size)) / (this.bar_width * this.em_size)); + c_font_height = g.getFontMetrics().getHeight(); + System.out.printf("First %d, last %d\n", first_bar,last_bar); + draw((Graphics2D) g); } @@ -467,12 +529,18 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab ctxMenu = new javax.swing.JPopupMenu(); compMenu = new javax.swing.JMenu(); + jCheckBoxMenuItem1 = new javax.swing.JCheckBoxMenuItem(); compMenu.setText("Compression"); ctxMenu.add(compMenu); + jCheckBoxMenuItem1.setSelected(true); + jCheckBoxMenuItem1.setText("jCheckBoxMenuItem1"); + ctxMenu.add(jCheckBoxMenuItem1); + setBackground(java.awt.Color.white); setBorder(null); + setDoubleBuffered(false); setOpaque(false); setPreferredSize(new java.awt.Dimension(300, 300)); setRequestFocusEnabled(false); @@ -486,7 +554,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 300, Short.MAX_VALUE) + .addGap(0, 589, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -500,16 +568,24 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab return; }; + this.invalidate(); + + this.ctxMenu.setVisible(true); this.ctxMenu.show(this, evt.getX(), evt.getY()); + + this.invalidate(); + this.repaint(); }//GEN-LAST:event_formMousePressed void setCompression(int timeFrame) { data = Globals.se.getOHLCdata(timeFrame); + invalidate(); repaint(); } - + + @Override public void UpdateQuote(Quote q) { // System.out.print("Quote Received\n"); @@ -524,5 +600,6 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JMenu compMenu; private javax.swing.JPopupMenu ctxMenu; + private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem1; // End of variables declaration//GEN-END:variables } diff --git a/src/main/java/chart/FullChart.form b/src/main/java/chart/FullChart.form index 8487e7d..4060794 100644 --- a/src/main/java/chart/FullChart.form +++ b/src/main/java/chart/FullChart.form @@ -16,38 +16,13 @@ - - - - - + - - - - - + - - - - - - - - - - - - - - - - - diff --git a/src/main/java/chart/FullChart.java b/src/main/java/chart/FullChart.java index 01720f6..33d6b44 100644 --- a/src/main/java/chart/FullChart.java +++ b/src/main/java/chart/FullChart.java @@ -427,39 +427,19 @@ public class FullChart extends javax.swing.JPanel { // //GEN-BEGIN:initComponents private void initComponents() { - chart2 = new chart.Chart(); - - javax.swing.GroupLayout chart2Layout = new javax.swing.GroupLayout(chart2); - chart2.setLayout(chart2Layout); - chart2Layout.setHorizontalGroup( - chart2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 617, Short.MAX_VALUE) - ); - chart2Layout.setVerticalGroup( - chart2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 300, Short.MAX_VALUE) - ); - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addContainerGap() - .addComponent(chart2, javax.swing.GroupLayout.DEFAULT_SIZE, 617, Short.MAX_VALUE) - .addContainerGap()) + .addGap(0, 629, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addContainerGap(27, Short.MAX_VALUE) - .addComponent(chart2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) + .addGap(0, 333, Short.MAX_VALUE) ); }// //GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables - private chart.Chart chart2; // End of variables declaration//GEN-END:variables } diff --git a/src/main/java/chart/NewJPanel1.form b/src/main/java/chart/NewJPanel1.form new file mode 100644 index 0000000..4d3875d --- /dev/null +++ b/src/main/java/chart/NewJPanel1.form @@ -0,0 +1,41 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/main/java/chart/NewJPanel1.java b/src/main/java/chart/NewJPanel1.java new file mode 100644 index 0000000..c646a91 --- /dev/null +++ b/src/main/java/chart/NewJPanel1.java @@ -0,0 +1,73 @@ +/* + * 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; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class NewJPanel1 extends javax.swing.JPanel { + + /** + * Creates new form NewJPanel1 + */ + public NewJPanel1() { + initComponents(); + } + + /** + * 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") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jScrollPane1 = new javax.swing.JScrollPane(); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 294, Short.MAX_VALUE) + .addContainerGap()) + ); + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JScrollPane jScrollPane1; + // End of variables declaration//GEN-END:variables +} diff --git a/src/main/java/gui/NewMDIApplication.form b/src/main/java/gui/NewMDIApplication.form index 07f0c54..9b523a0 100644 --- a/src/main/java/gui/NewMDIApplication.form +++ b/src/main/java/gui/NewMDIApplication.form @@ -276,7 +276,7 @@ - + @@ -297,7 +297,7 @@ - + @@ -453,16 +453,21 @@ + + + + + - + - + diff --git a/src/main/java/gui/NewMDIApplication.java b/src/main/java/gui/NewMDIApplication.java index a55321b..c8508a0 100644 --- a/src/main/java/gui/NewMDIApplication.java +++ b/src/main/java/gui/NewMDIApplication.java @@ -258,7 +258,7 @@ public class NewMDIApplication extends javax.swing.JFrame { .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(stopButton, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 484, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 545, Short.MAX_VALUE) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(clock, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() @@ -291,15 +291,17 @@ public class NewMDIApplication extends javax.swing.JFrame { jSplitPane4.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); jSplitPane4.setBottomComponent(orderBooksHorizontal1); + chart.setPreferredSize(new java.awt.Dimension(892, 410)); + javax.swing.GroupLayout chartLayout = new javax.swing.GroupLayout(chart); chart.setLayout(chartLayout); chartLayout.setHorizontalGroup( chartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 300, Short.MAX_VALUE) + .addGap(0, 892, Short.MAX_VALUE) ); chartLayout.setVerticalGroup( chartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 300, Short.MAX_VALUE) + .addGap(0, 410, Short.MAX_VALUE) ); jChartScrollPane.setViewportView(chart); diff --git a/src/main/java/sesim/OHLCData.java b/src/main/java/sesim/OHLCData.java index 06d1834..abb29cd 100644 --- a/src/main/java/sesim/OHLCData.java +++ b/src/main/java/sesim/OHLCData.java @@ -31,7 +31,7 @@ import java.util.*; * * @author 7u83 <7u83@mail.ru> */ -public class OHLCData { //extends ArrayList { +public class OHLCData { private float max=0; private float min=0; @@ -39,6 +39,7 @@ public class OHLCData { //extends ArrayList { private int frame_size=60000; int max_size=100; + public OHLCData(){ @@ -49,9 +50,6 @@ public class OHLCData { //extends ArrayList { this.frame_size=frame_size; } - // long time_start; - // long time_step; - public float getMax() { return max; }