/* * 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 chart.painter.CandleStickChartPainter; import chart.painter.ChartPainter; import chart.painter.XLegendChartPainter; import chart.painter.ChartCrossPainter; import gui.Globals; import sesim.Exchange.QuoteReceiver; import sesim.OHLCData; import sesim.Quote; /** * * @author 7u83 <7u83@mail.ru> */ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver, ChartPainter.DataProvider { /** * Creates new form MasterChart */ public MasterChart() { initComponents(); ChartDef def = new ChartDef(); def.x_unit_width = 1.0; if (Globals.se == null) { return; } Globals.se.addQuoteReceiver(this); ChartPainter p = new CandleStickChartPainter(); this.xScrollBar.setMaximum(0); p = new XLegendChartPainter(); p.setDataProvider(this); xLegend.addChartPainter(p); xLegend.setXSCrollBar(xScrollBar); p = new CandleStickChartPainter(); p.setDataProvider(this); chart.addChartPainter(p); chart.setXSCrollBar(xScrollBar); p = new ChartCrossPainter(); this.chart.addChartPainter(p); } /** * 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() { chart = new chart.ChartPanel(); yLegend = new chart.ChartPanel(); xLegend = new chart.ChartPanel(); xScrollBar = new javax.swing.JScrollBar(); chart.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(153, 0, 153), 1, true)); chart.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() { public void mouseMoved(java.awt.event.MouseEvent evt) { chartMouseMoved(evt); } }); javax.swing.GroupLayout chartLayout = new javax.swing.GroupLayout(chart); chart.setLayout(chartLayout); chartLayout.setHorizontalGroup( chartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 0, Short.MAX_VALUE) ); chartLayout.setVerticalGroup( chartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 0, Short.MAX_VALUE) ); yLegend.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true)); javax.swing.GroupLayout yLegendLayout = new javax.swing.GroupLayout(yLegend); yLegend.setLayout(yLegendLayout); yLegendLayout.setHorizontalGroup( yLegendLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 95, Short.MAX_VALUE) ); yLegendLayout.setVerticalGroup( yLegendLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 253, Short.MAX_VALUE) ); xLegend.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true)); javax.swing.GroupLayout xLegendLayout = new javax.swing.GroupLayout(xLegend); xLegend.setLayout(xLegendLayout); xLegendLayout.setHorizontalGroup( xLegendLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 520, Short.MAX_VALUE) ); xLegendLayout.setVerticalGroup( xLegendLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 73, Short.MAX_VALUE) ); xScrollBar.setOrientation(javax.swing.JScrollBar.HORIZONTAL); 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() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(xScrollBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(xLegend, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(chart, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(yLegend, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(yLegend, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(chart, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(xLegend, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(xScrollBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) ); }// //GEN-END:initComponents private void chartMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_chartMouseMoved }//GEN-LAST:event_chartMouseMoved // Variables declaration - do not modify//GEN-BEGIN:variables private chart.ChartPanel chart; private chart.ChartPanel xLegend; private javax.swing.JScrollBar xScrollBar; private chart.ChartPanel yLegend; // End of variables declaration//GEN-END:variables @Override public void UpdateQuote(Quote q) { OHLCData data = this.get(); int s = data.size(); this.xScrollBar.setMaximum(s); repaint(); } @Override public OHLCData get() { return Globals.se.getOHLCdata(60000 * 60); } }