Mouswheel is working
This commit is contained in:
parent
f7b56294e9
commit
d472935317
@ -1,4 +1,4 @@
|
||||
#Sat, 07 Oct 2017 07:36:14 +0200
|
||||
#Sat, 07 Oct 2017 09:35:06 +0200
|
||||
annotation.processing.enabled=true
|
||||
annotation.processing.enabled.in.editor=false
|
||||
annotation.processing.processors.list=
|
||||
|
@ -32,12 +32,12 @@ import javax.swing.JScrollBar;
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class ChartDef {
|
||||
// JScrollBar x_scrollbar=null;
|
||||
|
||||
|
||||
/**
|
||||
* width of an x unit in em
|
||||
*/
|
||||
public double x_unit_width=4.0;
|
||||
public double x_unit_width=1.0;
|
||||
|
||||
ChartDef(){
|
||||
|
||||
|
@ -5,19 +5,17 @@ import chart.painter.XLegendPainter;
|
||||
import gui.Globals;
|
||||
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Dimension;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import java.awt.event.AdjustmentEvent;
|
||||
import java.awt.event.AdjustmentListener;
|
||||
import java.awt.geom.AffineTransform;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import javax.swing.JScrollBar;
|
||||
import javax.swing.JViewport;
|
||||
import javax.swing.Scrollable;
|
||||
import sesim.Exchange.QuoteReceiver;
|
||||
|
||||
import sesim.OHLCData;
|
||||
import sesim.OHLCDataItem;
|
||||
import sesim.Quote;
|
||||
@ -29,6 +27,8 @@ import sesim.Quote;
|
||||
public class ChartPanel extends javax.swing.JPanel implements AdjustmentListener {
|
||||
|
||||
public JScrollBar x_scrollbar=null;
|
||||
ChartDef chartDef;
|
||||
|
||||
|
||||
/**
|
||||
* Creates new form Chart1
|
||||
@ -39,7 +39,11 @@ public class ChartPanel extends javax.swing.JPanel implements AdjustmentListener
|
||||
setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a horizontal scrollbar
|
||||
* @param x_scrollbar
|
||||
*/
|
||||
public void setXSCrollBar(JScrollBar x_scrollbar){
|
||||
if (this.x_scrollbar!=null)
|
||||
this.x_scrollbar.removeAdjustmentListener(this);
|
||||
@ -47,6 +51,10 @@ public class ChartPanel extends javax.swing.JPanel implements AdjustmentListener
|
||||
if (this.x_scrollbar!=null)
|
||||
this.x_scrollbar.addAdjustmentListener(this);
|
||||
}
|
||||
|
||||
public void setChartDef(ChartDef def){
|
||||
chartDef = def;
|
||||
}
|
||||
|
||||
private ArrayList<ChartPainter> chartPainters = new ArrayList<>();
|
||||
|
||||
@ -72,12 +80,12 @@ public class ChartPanel extends javax.swing.JPanel implements AdjustmentListener
|
||||
XLegendPainter p = new XLegendPainter();
|
||||
data = Globals.se.getOHLCdata(60000 * 60);
|
||||
|
||||
ChartDef def = new ChartDef();
|
||||
def.x_unit_width = 1.0;
|
||||
// ChartDef def = new ChartDef();
|
||||
// def.x_unit_width = 1.0;
|
||||
// def.x_scrollbar = x_scrollbar;
|
||||
|
||||
for (ChartPainter painter : chartPainters) {
|
||||
painter.drawChart((Graphics2D) g, this, def);
|
||||
painter.drawChart((Graphics2D) g, this, chartDef);
|
||||
}
|
||||
|
||||
}
|
||||
@ -119,7 +127,7 @@ public class ChartPanel extends javax.swing.JPanel implements AdjustmentListener
|
||||
|
||||
}//GEN-LAST:event_formMouseMoved
|
||||
|
||||
// @Override
|
||||
@Override
|
||||
public void adjustmentValueChanged(AdjustmentEvent e) {
|
||||
|
||||
this.repaint();
|
||||
|
@ -1,6 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
|
||||
<Events>
|
||||
<EventHandler event="mouseWheelMoved" listener="java.awt.event.MouseWheelListener" parameters="java.awt.event.MouseWheelEvent" handler="formMouseWheelMoved"/>
|
||||
</Events>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
@ -55,8 +58,8 @@
|
||||
<Properties>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="org.netbeans.modules.form.compat2.border.LineBorderInfo">
|
||||
<LineBorder roundedCorners="true">
|
||||
<Color PropertyName="color" blue="99" green="0" red="99" type="rgb"/>
|
||||
<LineBorder>
|
||||
<Color PropertyName="color" blue="cc" green="cc" red="cc" type="rgb"/>
|
||||
</LineBorder>
|
||||
</Border>
|
||||
</Property>
|
||||
@ -81,21 +84,19 @@
|
||||
<Container class="chart.ChartPanel" name="yLegend">
|
||||
<Properties>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="org.netbeans.modules.form.compat2.border.LineBorderInfo">
|
||||
<LineBorder roundedCorners="true"/>
|
||||
</Border>
|
||||
<Border info="null"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="95" max="32767" attributes="0"/>
|
||||
<EmptySpace min="0" pref="83" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="253" max="32767" attributes="0"/>
|
||||
<EmptySpace min="0" pref="326" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
@ -103,21 +104,19 @@
|
||||
<Container class="chart.ChartPanel" name="xLegend">
|
||||
<Properties>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="org.netbeans.modules.form.compat2.border.LineBorderInfo">
|
||||
<LineBorder roundedCorners="true"/>
|
||||
</Border>
|
||||
<Border info="null"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="520" max="32767" attributes="0"/>
|
||||
<EmptySpace min="0" pref="576" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="73" max="32767" attributes="0"/>
|
||||
<EmptySpace min="0" pref="61" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
@ -126,6 +125,9 @@
|
||||
<Properties>
|
||||
<Property name="orientation" type="int" value="0"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="adjustmentValueChanged" listener="java.awt.event.AdjustmentListener" parameters="java.awt.event.AdjustmentEvent" handler="xScrollBarAdjustmentValueChanged"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
|
@ -41,20 +41,27 @@ import sesim.Quote;
|
||||
*/
|
||||
public class MasterChart extends javax.swing.JPanel implements QuoteReceiver, ChartPainter.DataProvider {
|
||||
|
||||
private ChartDef chartDef;
|
||||
|
||||
/**
|
||||
* Creates new form MasterChart
|
||||
*/
|
||||
public MasterChart() {
|
||||
initComponents();
|
||||
|
||||
ChartDef def = new ChartDef();
|
||||
def.x_unit_width = 1.0;
|
||||
chartDef = new ChartDef();
|
||||
chartDef.x_unit_width = 3.0;
|
||||
|
||||
if (Globals.se == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Globals.se.addQuoteReceiver(this);
|
||||
|
||||
|
||||
this.chart.setChartDef(chartDef);
|
||||
this.xLegend.setChartDef(chartDef);
|
||||
this.yLegend.setChartDef(chartDef);
|
||||
|
||||
ChartPainter p = new CandleStickChartPainter();
|
||||
this.xScrollBar.setMaximum(0);
|
||||
@ -96,7 +103,13 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver, Ch
|
||||
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));
|
||||
addMouseWheelListener(new java.awt.event.MouseWheelListener() {
|
||||
public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
|
||||
formMouseWheelMoved(evt);
|
||||
}
|
||||
});
|
||||
|
||||
chart.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
|
||||
chart.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
|
||||
public void mouseMoved(java.awt.event.MouseEvent evt) {
|
||||
chartMouseMoved(evt);
|
||||
@ -114,33 +127,38 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver, Ch
|
||||
.addGap(0, 0, Short.MAX_VALUE)
|
||||
);
|
||||
|
||||
yLegend.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
|
||||
yLegend.setBorder(null);
|
||||
|
||||
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)
|
||||
.addGap(0, 83, Short.MAX_VALUE)
|
||||
);
|
||||
yLegendLayout.setVerticalGroup(
|
||||
yLegendLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 253, Short.MAX_VALUE)
|
||||
.addGap(0, 326, Short.MAX_VALUE)
|
||||
);
|
||||
|
||||
xLegend.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
|
||||
xLegend.setBorder(null);
|
||||
|
||||
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)
|
||||
.addGap(0, 576, Short.MAX_VALUE)
|
||||
);
|
||||
xLegendLayout.setVerticalGroup(
|
||||
xLegendLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 73, Short.MAX_VALUE)
|
||||
.addGap(0, 61, Short.MAX_VALUE)
|
||||
);
|
||||
|
||||
xScrollBar.setOrientation(javax.swing.JScrollBar.HORIZONTAL);
|
||||
xScrollBar.addAdjustmentListener(new java.awt.event.AdjustmentListener() {
|
||||
public void adjustmentValueChanged(java.awt.event.AdjustmentEvent evt) {
|
||||
xScrollBarAdjustmentValueChanged(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
@ -177,6 +195,25 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver, Ch
|
||||
|
||||
}//GEN-LAST:event_chartMouseMoved
|
||||
|
||||
private void formMouseWheelMoved(java.awt.event.MouseWheelEvent evt) {//GEN-FIRST:event_formMouseWheelMoved
|
||||
double n = evt.getPreciseWheelRotation() * (-1.0);
|
||||
|
||||
if (n < 0) {
|
||||
if (chartDef.x_unit_width > 0.3) {
|
||||
chartDef.x_unit_width += 0.1 * n;
|
||||
}
|
||||
} else {
|
||||
chartDef.x_unit_width += 0.1 * n;
|
||||
}
|
||||
|
||||
this.invalidate();
|
||||
this.repaint();
|
||||
}//GEN-LAST:event_formMouseWheelMoved
|
||||
|
||||
private void xScrollBarAdjustmentValueChanged(java.awt.event.AdjustmentEvent evt) {//GEN-FIRST:event_xScrollBarAdjustmentValueChanged
|
||||
repaint();
|
||||
}//GEN-LAST:event_xScrollBarAdjustmentValueChanged
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private chart.ChartPanel chart;
|
||||
|
Loading…
Reference in New Issue
Block a user