next generation x legend

This commit is contained in:
7u83 2017-10-01 11:36:35 +02:00
parent 254846c356
commit caeb2c4060
8 changed files with 124 additions and 82 deletions

View File

@ -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=true
annotation.processing.enabled.in.editor=false annotation.processing.enabled.in.editor=false
annotation.processing.processors.list= annotation.processing.processors.list=

View File

@ -1,19 +1,17 @@
<?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.JFrameFormInfo">
<Properties> <Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor"> <Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="ff" id="white" palette="1" red="ff" type="palette"/> <Color blue="ff" green="ff" id="white" palette="1" red="ff" type="palette"/>
</Property> </Property>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="null"/>
</Property>
<Property name="opaque" type="boolean" value="false"/>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor"> <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[300, 300]"/> <Dimension value="[300, 300]"/>
</Property> </Property>
<Property name="requestFocusEnabled" type="boolean" value="false"/>
</Properties> </Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="2"/>
</SyntheticProperties>
<Events> <Events>
<EventHandler event="mouseMoved" listener="java.awt.event.MouseMotionListener" parameters="java.awt.event.MouseEvent" handler="formMouseMoved"/> <EventHandler event="mouseMoved" listener="java.awt.event.MouseMotionListener" parameters="java.awt.event.MouseEvent" handler="formMouseMoved"/>
</Events> </Events>

View File

@ -193,7 +193,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
class RenderCtx { class RenderCtx {
Rectangle rect; Rectangle rect;
float scaling; //float scaling;
float min; float min;
Graphics2D g; Graphics2D g;
float iwidth; float iwidth;
@ -461,7 +461,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
RenderCtx ctx = new RenderCtx(); RenderCtx ctx = new RenderCtx();
ctx.rect = new Rectangle(0, h1 + pad_top, pwidth, subchartwin_height - pad_top); 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.min = c_mm.getMin();
ctx.g = g; ctx.g = g;
ctx.iwidth = (float) ((x_unit_width * em_width) * 0.9f); ctx.iwidth = (float) ((x_unit_width * em_width) * 0.9f);

View File

@ -35,15 +35,11 @@ public class Chart1 extends javax.swing.JPanel implements QuoteReceiver, Adjustm
setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
if (Globals.se == null) { if (Globals.se == null) {
return; return;
} }
setSize(new Dimension(9000, 500));
setSize(new Dimension(9000,500));
Globals.se.addQuoteReceiver(this); Globals.se.addQuoteReceiver(this);
} }
@ -51,38 +47,27 @@ public class Chart1 extends javax.swing.JPanel implements QuoteReceiver, Adjustm
private void drawChart(Graphics2D g) { private void drawChart(Graphics2D g) {
JViewport vp = new JViewport(); JViewport vp = new JViewport();
// if (Globals.se==null)
// if (Globals.se==null)
// return; // return;
Dimension d = new Dimension(200, 200);
Dimension d = new Dimension(200,200);
setPreferredSize(d); setPreferredSize(d);
g.setClip(10, 10, 800, 200);
g.setClip(10,10,800,200);
g.setColor(Color.red); g.setColor(Color.red);
g.drawLine(0, 0, 8000, 610); g.drawLine(0, 0, 8000, 610);
if (Globals.se==null) if (Globals.se == null) {
return; return;
}
revalidate(); revalidate();
System.out.printf("Setting pref size\n");
System.out.printf("Setting pref size\n" );
OHLCData data = Globals.se.getOHLCdata(60000); OHLCData data = Globals.se.getOHLCdata(60000);
/* /*
int first_bar = 0; int first_bar = 0;
int last_bar = data.size(); int last_bar = data.size();
@ -103,8 +88,9 @@ public class Chart1 extends javax.swing.JPanel implements QuoteReceiver, Adjustm
prev = di; prev = di;
} }
*/ */
} }
OHLCData data;
@Override @Override
protected void paintComponent(Graphics g) { protected void paintComponent(Graphics g) {
@ -113,11 +99,11 @@ public class Chart1 extends javax.swing.JPanel implements QuoteReceiver, Adjustm
// Calculate the number of pixels for 1 em // Calculate the number of pixels for 1 em
em_width = g.getFontMetrics().stringWidth("M"); em_width = g.getFontMetrics().stringWidth("M");
this.xbar.setMaximum(994000); //this.xbar.setMaximum(994000);
ChartPainter p = new ChartPainter(); 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); //drawChart((Graphics2D)g);
} }
@ -145,18 +131,21 @@ public class Chart1 extends javax.swing.JPanel implements QuoteReceiver, Adjustm
@Override @Override
public void UpdateQuote(Quote q) { public void UpdateQuote(Quote q) {
int s = data.size();
System.out.printf("Data size %d",s);
xbar.setMaximum(data.size());
repaint(); repaint();
} }
@Override @Override
public void adjustmentValueChanged(AdjustmentEvent e) { 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(); this.repaint();
} }
// 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
} }

37
src/chart/ChartDef.java Normal file
View File

@ -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;
}

View File

@ -29,6 +29,7 @@ import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import javax.swing.JScrollBar; import javax.swing.JScrollBar;
import sesim.OHLCData;
/** /**
* *
@ -45,11 +46,47 @@ public class ChartPainter {
} }
public void drawChart(Graphics2D g, JScrollBar sb, Dimension size) { int big_tick = 10;
init (g); 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.setColor(Color.MAGENTA);
g.drawLine(0, 0, size.width, 100); Dimension size = p.getSize();
g.setBackground(Color.yellow); //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;
}
} }

View File

@ -32,9 +32,8 @@
<Group type="102" attributes="0"> <Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Component id="chart11" alignment="1" pref="482" max="32767" attributes="0"/> <Component id="jScrollBar1" pref="586" max="32767" attributes="0"/>
<Component id="jScrollBar1" alignment="1" pref="482" max="32767" attributes="0"/> <Component id="chart11" pref="586" max="32767" attributes="0"/>
<Component id="jToolBar1" alignment="0" max="32767" attributes="0"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
</Group> </Group>
@ -44,10 +43,8 @@
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0"> <Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="chart11" min="-2" pref="198" max="-2" attributes="0"/> <Component id="chart11" pref="318" max="32767" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="jToolBar1" pref="102" max="32767" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="jScrollBar1" min="-2" max="-2" attributes="0"/> <Component id="jScrollBar1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
</Group> </Group>
@ -70,18 +67,10 @@
</DimensionLayout> </DimensionLayout>
<DimensionLayout dim="1"> <DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="198" max="32767" attributes="0"/> <EmptySpace min="0" pref="318" max="32767" attributes="0"/>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
</Layout> </Layout>
</Container> </Container>
<Container class="javax.swing.JToolBar" name="jToolBar1">
<Properties>
<Property name="floatable" type="boolean" value="false"/>
<Property name="rollover" type="boolean" value="true"/>
</Properties>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout"/>
</Container>
</SubComponents> </SubComponents>
</Form> </Form>

View File

@ -53,7 +53,6 @@ public class ChartTestDialog extends javax.swing.JDialog {
jScrollBar1 = new javax.swing.JScrollBar(); jScrollBar1 = new javax.swing.JScrollBar();
chart11 = new chart.Chart1(); chart11 = new chart.Chart1();
jToolBar1 = new javax.swing.JToolBar();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setMaximumSize(new java.awt.Dimension(800, 600)); setMaximumSize(new java.awt.Dimension(800, 600));
@ -69,12 +68,9 @@ public class ChartTestDialog extends javax.swing.JDialog {
); );
chart11Layout.setVerticalGroup( chart11Layout.setVerticalGroup(
chart11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 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()); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout); getContentPane().setLayout(layout);
layout.setHorizontalGroup( layout.setHorizontalGroup(
@ -82,19 +78,16 @@ public class ChartTestDialog extends javax.swing.JDialog {
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addContainerGap() .addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .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.DEFAULT_SIZE, 586, Short.MAX_VALUE)
.addComponent(jScrollBar1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 482, Short.MAX_VALUE) .addComponent(chart11, javax.swing.GroupLayout.DEFAULT_SIZE, 586, Short.MAX_VALUE))
.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap()) .addContainerGap())
); );
layout.setVerticalGroup( layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap() .addContainerGap()
.addComponent(chart11, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(chart11, javax.swing.GroupLayout.DEFAULT_SIZE, 318, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jScrollBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap()) .addContainerGap())
); );
@ -147,6 +140,5 @@ public class ChartTestDialog extends javax.swing.JDialog {
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private chart.Chart1 chart11; private chart.Chart1 chart11;
private javax.swing.JScrollBar jScrollBar1; private javax.swing.JScrollBar jScrollBar1;
private javax.swing.JToolBar jToolBar1;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
} }