work on charts

This commit is contained in:
7u83 2017-09-30 08:03:48 +02:00
parent 92930d9417
commit 2ff7097661
7 changed files with 189 additions and 138 deletions

View File

@ -1,4 +1,4 @@
#Sun, 17 Sep 2017 23:52:04 +0200
#Fri, 29 Sep 2017 22:33:34 +0200
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processors.list=

View File

@ -504,7 +504,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab
p0 = 0;
}
JViewport vp = (JViewport) this.getParent();
Point pp = vp.getViewPosition();
// Point pp = vp.getViewPosition();
Point cp = vp.getViewPosition();
if (autoScroll && this.lastvpos != cp.x) {

View File

@ -7,6 +7,11 @@ import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.geom.AffineTransform;
import javax.swing.JScrollBar;
import javax.swing.JViewport;
import javax.swing.Scrollable;
import sesim.Exchange.QuoteReceiver;
import sesim.OHLCData;
@ -17,8 +22,10 @@ import sesim.Quote;
*
* @author 7u83 <7u83@mail.ru>
*/
public class Chart1 extends javax.swing.JPanel implements QuoteReceiver, Scrollable {
public class Chart1 extends javax.swing.JPanel implements QuoteReceiver, AdjustmentListener {
public JScrollBar xbar;
/**
* Creates new form Chart1
*/
@ -27,11 +34,15 @@ public class Chart1 extends javax.swing.JPanel implements QuoteReceiver, Scrolla
System.out.printf("Now cursor\n");
setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
if (Globals.se == null) {
return;
}
setSize(new Dimension(9000,500));
Globals.se.addQuoteReceiver(this);
}
@ -40,14 +51,27 @@ public class Chart1 extends javax.swing.JPanel implements QuoteReceiver, Scrolla
private void drawChart(Graphics2D g) {
JViewport vp = new JViewport();
// if (Globals.se==null)
// return;
Dimension d = new Dimension(200,200);
setPreferredSize(d);
g.setClip(10,10,800,200);
g.setColor(Color.red);
g.drawLine(0, 0, 8000, 610);
if (Globals.se==null)
return;
g.setColor(Color.red);
g.drawLine(0, 0, 7000, 610);
Dimension d = new Dimension(8000,200);
setPreferredSize(d);
revalidate();
@ -58,7 +82,7 @@ public class Chart1 extends javax.swing.JPanel implements QuoteReceiver, Scrolla
OHLCData data = Globals.se.getOHLCdata(60000);
/*
int first_bar = 0;
int last_bar = data.size();
@ -79,6 +103,7 @@ public class Chart1 extends javax.swing.JPanel implements QuoteReceiver, Scrolla
prev = di;
}
*/
}
@Override
@ -88,6 +113,7 @@ public class Chart1 extends javax.swing.JPanel implements QuoteReceiver, Scrolla
// Calculate the number of pixels for 1 em
em_width = g.getFontMetrics().stringWidth("M");
this.xbar.setMaximum(994000);
drawChart((Graphics2D)g);
@ -120,29 +146,12 @@ public class Chart1 extends javax.swing.JPanel implements QuoteReceiver, Scrolla
}
@Override
public Dimension getPreferredScrollableViewportSize() {
return this.getPreferredSize();
public void adjustmentValueChanged(AdjustmentEvent e) {
System.out.printf("Adjustemntlistener called %d\n",xbar.getValue());
}
@Override
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
return 1;
}
@Override
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
return 1;
}
@Override
public boolean getScrollableTracksViewportWidth() {
return true;
}
@Override
public boolean getScrollableTracksViewportHeight() {
return true;
}
// Variables declaration - do not modify//GEN-BEGIN:variables

View File

@ -21,54 +21,36 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" min="-2" pref="223" max="-2" attributes="0"/>
<EmptySpace pref="71" max="32767" attributes="0"/>
</Group>
<Component id="jScrollBar1" alignment="1" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="100" max="-2" attributes="0"/>
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="119" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace pref="47" max="32767" attributes="0"/>
<Component id="jScrollPane1" min="-2" pref="247" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<EmptySpace pref="189" max="32767" attributes="0"/>
<Component id="jScrollBar1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="63" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<Component class="javax.swing.JScrollBar" name="jScrollBar1">
<Properties>
<Property name="horizontalScrollBarPolicy" type="int" value="32"/>
<Property name="verticalScrollBarPolicy" type="int" value="22"/>
<Property name="orientation" type="int" value="0"/>
</Properties>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Container class="chart.Chart1" name="chart11">
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="217" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="241" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Container>
</SubComponents>
</Container>
</Component>
<Component class="javax.swing.JButton" name="jButton1">
<Properties>
<Property name="text" type="java.lang.String" value="jButton1"/>
</Properties>
</Component>
</SubComponents>
</Form>

View File

@ -25,11 +25,16 @@
*/
package chart;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Rectangle;
import javax.swing.Scrollable;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class ChartPanal extends javax.swing.JPanel {
public class ChartPanal extends javax.swing.JPanel implements Scrollable{
/**
* Creates new form ChartPanal
@ -37,6 +42,19 @@ public class ChartPanal extends javax.swing.JPanel {
public ChartPanal() {
initComponents();
}
@Override
public void paint(Graphics g) {
// Dimension psize = this.chart12.getPreferredSize();
// this.setPreferredSize(psize);
super.paint(g); //To change body of generated methods, choose Tools | Templates.
}
/**
* This method is called from within the constructor to initialize the form.
@ -47,52 +65,64 @@ public class ChartPanal extends javax.swing.JPanel {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
chart11 = new chart.Chart1();
jScrollBar1 = new javax.swing.JScrollBar();
jButton1 = new javax.swing.JButton();
setPreferredSize(new java.awt.Dimension(300, 300));
jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
jScrollBar1.setOrientation(javax.swing.JScrollBar.HORIZONTAL);
javax.swing.GroupLayout chart11Layout = new javax.swing.GroupLayout(chart11);
chart11.setLayout(chart11Layout);
chart11Layout.setHorizontalGroup(
chart11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 217, Short.MAX_VALUE)
);
chart11Layout.setVerticalGroup(
chart11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 241, Short.MAX_VALUE)
);
jScrollPane1.setViewportView(chart11);
jButton1.setText("jButton1");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(71, Short.MAX_VALUE)))
.addComponent(jScrollBar1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGap(100, 100, 100)
.addComponent(jButton1)
.addContainerGap(119, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(47, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap()))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(189, Short.MAX_VALUE)
.addComponent(jScrollBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)
.addGap(63, 63, 63))
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private chart.Chart1 chart11;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JButton jButton1;
private javax.swing.JScrollBar jScrollBar1;
// End of variables declaration//GEN-END:variables
@Override
public Dimension getPreferredScrollableViewportSize() {
return this.getPreferredSize();
}
@Override
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
return 1;
}
@Override
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
return 100;
}
@Override
public boolean getScrollableTracksViewportWidth() {
return false;
}
@Override
public boolean getScrollableTracksViewportHeight() {
return false;
}
}

View File

@ -3,6 +3,12 @@
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="2"/>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[800, 600]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[100, 100]"/>
</Property>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
@ -23,9 +29,13 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace pref="387" max="32767" attributes="0"/>
<Component id="jScrollPane1" min="-2" pref="123" max="-2" attributes="0"/>
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="chart11" alignment="1" pref="482" max="32767" attributes="0"/>
<Component id="jScrollBar1" alignment="1" pref="482" max="32767" attributes="0"/>
<Component id="jToolBar1" alignment="0" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
@ -33,38 +43,45 @@
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace pref="59" max="32767" attributes="0"/>
<Component id="jScrollPane1" min="-2" pref="254" max="-2" attributes="0"/>
<EmptySpace pref="120" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="chart11" min="-2" pref="157" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="53" max="-2" attributes="0"/>
<Component id="jToolBar1" min="-2" pref="25" max="-2" attributes="0"/>
<EmptySpace pref="89" max="32767" attributes="0"/>
<Component id="jScrollBar1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<Component class="javax.swing.JScrollBar" name="jScrollBar1">
<Properties>
<Property name="horizontalScrollBarPolicy" type="int" value="32"/>
<Property name="verticalScrollBarPolicy" type="int" value="22"/>
<Property name="orientation" type="int" value="0"/>
</Properties>
</Component>
<Container class="chart.Chart1" name="chart11">
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="157" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</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.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Container class="chart.Chart1" name="chart11">
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="102" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="233" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Container>
</SubComponents>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout"/>
</Container>
</SubComponents>
</Form>

View File

@ -38,6 +38,8 @@ public class ChartTestDialog extends javax.swing.JDialog {
super(parent, modal);
initComponents();
setLocationRelativeTo(parent);
this.chart11.xbar=this.jScrollBar1;
this.jScrollBar1.addAdjustmentListener(chart11);
}
/**
@ -49,42 +51,52 @@ public class ChartTestDialog extends javax.swing.JDialog {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
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));
setMinimumSize(new java.awt.Dimension(100, 100));
jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
jScrollBar1.setOrientation(javax.swing.JScrollBar.HORIZONTAL);
javax.swing.GroupLayout chart11Layout = new javax.swing.GroupLayout(chart11);
chart11.setLayout(chart11Layout);
chart11Layout.setHorizontalGroup(
chart11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 102, Short.MAX_VALUE)
.addGap(0, 0, Short.MAX_VALUE)
);
chart11Layout.setVerticalGroup(
chart11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 233, Short.MAX_VALUE)
.addGap(0, 157, Short.MAX_VALUE)
);
jScrollPane1.setViewportView(chart11);
jToolBar1.setFloatable(false);
jToolBar1.setRollover(true);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(387, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
.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))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(59, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(120, Short.MAX_VALUE))
.addContainerGap()
.addComponent(chart11, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(53, 53, 53)
.addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 89, Short.MAX_VALUE)
.addComponent(jScrollBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();
@ -134,6 +146,7 @@ public class ChartTestDialog extends javax.swing.JDialog {
// Variables declaration - do not modify//GEN-BEGIN:variables
private chart.Chart1 chart11;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollBar jScrollBar1;
private javax.swing.JToolBar jToolBar1;
// End of variables declaration//GEN-END:variables
}