Initial commit of multiasset branch
This commit is contained in:
42
src/opensesim/chart/Chart.form
Normal file
42
src/opensesim/chart/Chart.form
Normal file
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||
<Properties>
|
||||
<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"/>
|
||||
</Property>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[300, 300]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="2"/>
|
||||
</SyntheticProperties>
|
||||
<Events>
|
||||
<EventHandler event="mouseMoved" listener="java.awt.event.MouseMotionListener" parameters="java.awt.event.MouseEvent" handler="formMouseMoved"/>
|
||||
</Events>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="589" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
</Form>
|
623
src/opensesim/chart/Chart.java
Normal file
623
src/opensesim/chart/Chart.java
Normal file
@ -0,0 +1,623 @@
|
||||
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package opensesim.chart;
|
||||
|
||||
import opensesim.old_sesim.OHLCDataItem;
|
||||
import opensesim.old_sesim.OHLCData;
|
||||
import java.awt.*;
|
||||
import opensesim.old_sesim.Exchange.*;
|
||||
import opensesim.old_sesim.Quote;
|
||||
import opensesim.gui.Globals;
|
||||
import java.util.ArrayList;
|
||||
import javax.swing.JViewport;
|
||||
import javax.swing.Scrollable;
|
||||
import opensesim.old_sesim.MinMax;
|
||||
import opensesim.old_sesim.Scheduler;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollable {
|
||||
|
||||
private int em_height;
|
||||
private int em_width;
|
||||
|
||||
protected double x_legend_height = 6;
|
||||
|
||||
protected double x_unit_width = 1.0;
|
||||
|
||||
/**
|
||||
* width of y legend in em
|
||||
*/
|
||||
protected float yl_width = 10;
|
||||
|
||||
protected int num_bars = 4000;
|
||||
|
||||
protected Rectangle clip_bounds = new Rectangle();
|
||||
|
||||
private int first_bar, last_bar;
|
||||
|
||||
/**
|
||||
* Creates new form Chart
|
||||
*/
|
||||
public Chart() {
|
||||
if (Globals.se == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
initComponents();
|
||||
if (Globals.se == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Globals.se.addQuoteReceiver(this);
|
||||
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
class XLegendDef {
|
||||
|
||||
//int big_tick = 10;
|
||||
// long start;
|
||||
XLegendDef() {
|
||||
|
||||
}
|
||||
|
||||
String getAt(int unit) {
|
||||
|
||||
int fs = data.getFrameSize();
|
||||
return Scheduler.formatTimeMillis(0 + unit * fs);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void setXLegendHeight(int h) {
|
||||
this.x_legend_height = h;
|
||||
}
|
||||
|
||||
/**
|
||||
* Text Color of X-legend
|
||||
*/
|
||||
protected Color xl_color = null;
|
||||
|
||||
/**
|
||||
* Background color of X-legend
|
||||
*/
|
||||
protected Color xl_bgcolor = null;
|
||||
/**
|
||||
* Height of X-legend
|
||||
*/
|
||||
protected int xl_height;
|
||||
|
||||
/**
|
||||
* Draw the one and only one X legend
|
||||
*
|
||||
* @param g Graphics conext to draw
|
||||
* @param xld Definition
|
||||
*/
|
||||
void drawXLegend(Graphics2D g, XLegendDef xld) {
|
||||
|
||||
Color cur = g.getColor(); // save current color
|
||||
|
||||
// Caluclate with of y legend in pixels
|
||||
int yl_width_p = (int) (yl_width * em_width);
|
||||
|
||||
g.setClip(clip_bounds.x, clip_bounds.y, clip_bounds.width - yl_width_p, clip_bounds.height);
|
||||
|
||||
int y = clip_bounds.height - em_height * xl_height;
|
||||
|
||||
// Draw background
|
||||
if (this.xl_bgcolor != null) {
|
||||
|
||||
g.setColor(xl_bgcolor);
|
||||
g.fillRect(clip_bounds.x, y, clip_bounds.width, em_height * xl_height);
|
||||
g.drawRect(clip_bounds.y, y, clip_bounds.width, em_height * xl_height);
|
||||
g.setColor(cur);
|
||||
}
|
||||
|
||||
if (xl_color != null) {
|
||||
g.setColor(xl_color);
|
||||
}
|
||||
|
||||
g.drawLine(clip_bounds.x, y, clip_bounds.width, y);
|
||||
|
||||
Dimension dim = getSize();
|
||||
|
||||
int n;
|
||||
double x;
|
||||
|
||||
long big_tick = 1;
|
||||
|
||||
double btl, xxx;
|
||||
do {
|
||||
big_tick++;
|
||||
btl = em_width * big_tick * x_unit_width;
|
||||
xxx = 7 * em_width;
|
||||
|
||||
} while (btl < xxx);
|
||||
|
||||
for (n = 0, x = 0; x < dim.width; x += em_width * x_unit_width) {
|
||||
|
||||
if (n % big_tick == 1) {
|
||||
g.drawLine((int) x, y, (int) x, y + em_width);
|
||||
String text;
|
||||
text = xld.getAt(n);
|
||||
|
||||
int swidth = g.getFontMetrics().stringWidth(text);
|
||||
|
||||
g.drawString(text, (int) x - swidth / 2, y + em_height * 2);
|
||||
} else {
|
||||
g.drawLine((int) x, y, (int) x, y + em_width / 2);
|
||||
}
|
||||
|
||||
if (n % big_tick == 0) {
|
||||
|
||||
}
|
||||
|
||||
n += 1;
|
||||
}
|
||||
|
||||
g.setColor(cur);
|
||||
}
|
||||
|
||||
class RenderCtx {
|
||||
|
||||
Rectangle rect;
|
||||
//float scaling;
|
||||
float min;
|
||||
Graphics2D g;
|
||||
float iwidth;
|
||||
|
||||
float getY(float y) {
|
||||
|
||||
float ys = rect.height / c_mm.getDiff();
|
||||
if (c_mm.isLog()) {
|
||||
return rect.height + rect.y - ((float) Math.log(y) - c_mm.getMin()) * ys;
|
||||
}
|
||||
return (rect.height - ((y - c_mm.getMin()) * c_yscaling)) + rect.y;
|
||||
}
|
||||
|
||||
double getValAtY(float y) {
|
||||
float val = 0;
|
||||
|
||||
if (c_mm.isLog()) {
|
||||
float ys = rect.height / c_mm.getDiff();
|
||||
|
||||
return Math.exp((rect.height + rect.y) / ys + c_mm.getMin() - y / ys);
|
||||
|
||||
}
|
||||
|
||||
return (-(y - rect.y - rect.height)) / c_yscaling + c_mm.getMin();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void drawLineItem(RenderCtx ctx, int prevx, int x, OHLCDataItem prev, OHLCDataItem i) {
|
||||
Graphics2D g = ctx.g;
|
||||
if (prev == null) {
|
||||
prev = i;
|
||||
}
|
||||
int y1 = (int) ctx.getY(prev.close);
|
||||
int y2 = (int) ctx.getY(i.close);
|
||||
Color cur = g.getColor();
|
||||
g.setColor(Color.RED);
|
||||
g.drawLine(prevx, y1, x, y2);
|
||||
g.setColor(cur);
|
||||
}
|
||||
|
||||
private void drawCandleItem(RenderCtx ctx, int prevx, int x, OHLCDataItem prev, OHLCDataItem i) {
|
||||
|
||||
Graphics2D g = ctx.g;
|
||||
|
||||
if (i.open < i.close) {
|
||||
int xl = (int) (x + ctx.iwidth / 2);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawLine(xl, (int) ctx.getY(i.close), xl, (int) ctx.getY(i.high));
|
||||
g.drawLine(xl, (int) ctx.getY(i.low), xl, (int) ctx.getY(i.open));
|
||||
|
||||
float w = ctx.iwidth;
|
||||
float h = (int) (ctx.getY(i.open) - ctx.getY(i.close));
|
||||
|
||||
g.setColor(Color.GREEN);
|
||||
g.fillRect((int) (x), (int) ctx.getY(i.close), (int) w, (int) h);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect((int) (x), (int) ctx.getY(i.close), (int) w, (int) h);
|
||||
|
||||
} else {
|
||||
int xl = (int) (x + ctx.iwidth / 2);
|
||||
g.setColor(Color.RED);
|
||||
g.drawLine(xl, (int) ctx.getY(i.high), xl, (int) ctx.getY(i.close));
|
||||
g.drawLine(xl, (int) ctx.getY(i.open), xl, (int) ctx.getY(i.low));
|
||||
|
||||
float w = ctx.iwidth;
|
||||
float h = (int) (ctx.getY(i.close) - ctx.getY(i.open));
|
||||
|
||||
g.fillRect((int) (x), (int) ctx.getY(i.open), (int) w, (int) h);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect((int) (x), (int) ctx.getY(i.open), (int) w, (int) h);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void drawBarItem(RenderCtx ctx, int prevx, int x, OHLCDataItem prev, OHLCDataItem i) {
|
||||
Graphics2D g = ctx.g;
|
||||
g.setColor(Color.BLACK);
|
||||
|
||||
g.drawLine(x, (int) ctx.getY(0), x, (int) ctx.getY(i.volume));
|
||||
|
||||
Rectangle r = ctx.rect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Char types
|
||||
*/
|
||||
protected enum ChartType {
|
||||
CANDLESTICK,
|
||||
LINE,
|
||||
BAR,
|
||||
VOL,
|
||||
}
|
||||
|
||||
ChartType ct = ChartType.CANDLESTICK;
|
||||
|
||||
private void drawItem(RenderCtx ctx, int prevx, int x, OHLCDataItem prev, OHLCDataItem i) {
|
||||
switch (ct) {
|
||||
case CANDLESTICK:
|
||||
this.drawCandleItem(ctx, prevx, x, prev, i);
|
||||
break;
|
||||
case LINE:
|
||||
this.drawLineItem(ctx, prevx, x, prev, i);
|
||||
break;
|
||||
case VOL:
|
||||
this.drawBarItem(ctx, prevx, x, prev, i);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
float c_yscaling;
|
||||
|
||||
private void drawYLegend(RenderCtx ctx) {
|
||||
|
||||
Graphics2D g = ctx.g;
|
||||
|
||||
Rectangle dim;
|
||||
dim = this.clip_bounds;
|
||||
|
||||
// Dimension rv = this.getSize();
|
||||
int yw = (int) (this.yl_width * this.em_width);
|
||||
|
||||
g.drawLine(dim.width + dim.x - yw, 0, dim.width + dim.x - yw, dim.height);
|
||||
|
||||
float y1 = ctx.getY(c_mm.getMin(false));
|
||||
float y2 = ctx.getY(c_mm.getMax(false));
|
||||
float ydiff = y1 - y2;
|
||||
// System.out.printf("%s y1: %f, y2: %f, diff %f\n", Boolean.toString(c_mm.isLog()), y1, y2, ydiff);
|
||||
|
||||
for (int yp = (int) y2; yp < y1; yp += em_width * 5) {
|
||||
g.drawLine(dim.width + dim.x - yw, yp, dim.width + dim.x - yw + em_width, yp);
|
||||
double v1 = ctx.getValAtY(yp);
|
||||
g.drawString(String.format("%.2f", v1), dim.width + dim.x - yw + em_width * 1.5f, yp + c_font_height / 3);
|
||||
}
|
||||
|
||||
double v1, v2;
|
||||
v1 = ctx.getValAtY(y1);
|
||||
v2 = ctx.getValAtY(y2);
|
||||
|
||||
}
|
||||
|
||||
private MinMax c_mm = null;
|
||||
// private Rectangle c_rect;
|
||||
|
||||
void drawChart(RenderCtx ctx) {
|
||||
|
||||
c_yscaling = ctx.rect.height / c_mm.getDiff();
|
||||
|
||||
ctx.g.setClip(null);
|
||||
// ctx.g.setColor(Color.ORANGE);
|
||||
// ctx.g.setClip(ctx.rect.x, ctx.rect.y, ctx.rect.width, ctx.rect.height);
|
||||
// ctx.g.drawRect(ctx.rect.x, ctx.rect.y, ctx.rect.width, ctx.rect.height);
|
||||
this.drawYLegend(ctx);
|
||||
|
||||
/// ctx.g.setColor(Color.ORANGE);
|
||||
int yw = (int) (this.yl_width * this.em_width);
|
||||
|
||||
ctx.g.setClip(clip_bounds.x, clip_bounds.y, clip_bounds.width - yw, clip_bounds.height);
|
||||
// ctx.g.setClip(ctx.rect.x, ctx.rect.y, ctx.rect.width-yw, ctx.rect.height);
|
||||
|
||||
OHLCDataItem prev = null;
|
||||
for (int i = first_bar; i < last_bar && i < data.size(); i++) {
|
||||
OHLCDataItem di = data.get(i);
|
||||
int x = (int) (i * em_width * x_unit_width); //em_width;
|
||||
this.drawItem(ctx, (int) (x - em_width * x_unit_width), x, prev, di); //, ctx.scaling, data.getMin());
|
||||
|
||||
// myi++;
|
||||
prev = di;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
boolean autoScroll = true;
|
||||
int lastvpos = 0;
|
||||
|
||||
/**
|
||||
* definition for a sub-chart window
|
||||
*/
|
||||
public class SubChartDef {
|
||||
|
||||
/**
|
||||
* Height of sub-chart in percent
|
||||
*/
|
||||
public float height;
|
||||
|
||||
/**
|
||||
* top padding in em_height
|
||||
*/
|
||||
public float padding_top = 0;
|
||||
/**
|
||||
* bottom padding in em_height (not implemented yet)
|
||||
*/
|
||||
public float padding_bottom = 0;
|
||||
|
||||
public ChartType type;
|
||||
public OHLCData data;
|
||||
|
||||
public Color bgcolor = null;
|
||||
|
||||
/**
|
||||
* logarithmic scaling
|
||||
*/
|
||||
public boolean log = false;
|
||||
|
||||
}
|
||||
|
||||
protected OHLCData data;
|
||||
|
||||
ArrayList<SubChartDef> charts = new ArrayList<>();
|
||||
|
||||
protected void addChart(SubChartDef d) {
|
||||
|
||||
charts.add(d);
|
||||
|
||||
}
|
||||
|
||||
void drawAll(Graphics2D g) {
|
||||
int pwidth = (int) (em_width * x_unit_width * (num_bars + 1)) + clip_bounds.width;
|
||||
this.setPreferredSize(new Dimension(pwidth, gdim.height));
|
||||
this.revalidate();
|
||||
|
||||
int h1 = 0;
|
||||
|
||||
for (SubChartDef d : charts) {
|
||||
|
||||
if (d.data == null) {
|
||||
System.out.printf("Data is null\n");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
// calclulate the min/max values
|
||||
switch (d.type) {
|
||||
case VOL:
|
||||
c_mm = d.data.getVolMinMax(first_bar, last_bar);
|
||||
c_mm.setMin(0);
|
||||
break;
|
||||
default:
|
||||
c_mm = d.data.getMinMax(first_bar, last_bar);
|
||||
}
|
||||
|
||||
// Calculate the height for all sub-charts
|
||||
// this is the height of out panel minus the height of x-legend
|
||||
int chartwin_height = clip_bounds.height - xl_height * em_height;
|
||||
|
||||
// Caclulate the height of our sub-chart
|
||||
int subchartwin_height = (int) (chartwin_height * d.height);
|
||||
|
||||
// Draw background
|
||||
if (d.bgcolor != null) {
|
||||
Color cur = g.getColor();
|
||||
g.setColor(d.bgcolor);
|
||||
g.fillRect(clip_bounds.x, h1, clip_bounds.width, subchartwin_height);
|
||||
g.drawRect(clip_bounds.x, h1, clip_bounds.width, subchartwin_height);
|
||||
g.setColor(cur);
|
||||
}
|
||||
|
||||
// Caclulate the top padding
|
||||
int pad_top = (int) (subchartwin_height * d.padding_top);
|
||||
|
||||
RenderCtx ctx = new RenderCtx();
|
||||
|
||||
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.min = c_mm.getMin();
|
||||
ctx.g = g;
|
||||
ctx.iwidth = (float) ((x_unit_width * em_width) * 0.9f);
|
||||
|
||||
this.ct = d.type;
|
||||
// logs = false;
|
||||
c_mm.setLog(d.log);
|
||||
|
||||
drawChart(ctx);
|
||||
|
||||
h1 = h1 + subchartwin_height;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void setupSubCharts() {
|
||||
|
||||
}
|
||||
|
||||
private void draw(Graphics2D g) {
|
||||
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
if (data.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Point m = MouseInfo.getPointerInfo().getLocation() ;
|
||||
// g.drawLine(0, m.y, 1000, m.y);
|
||||
int pwidth = (int) (em_width * x_unit_width * (num_bars + 1)) + clip_bounds.width;
|
||||
|
||||
this.setPreferredSize(new Dimension(pwidth, gdim.height));
|
||||
this.revalidate();
|
||||
|
||||
int bww = (int) (data.size() * (this.x_unit_width * this.em_width));
|
||||
int p0 = pwidth - clip_bounds.width - (clip_bounds.width - (int) (13 * em_width));
|
||||
if (p0 < 0) {
|
||||
p0 = 0;
|
||||
}
|
||||
JViewport vp = (JViewport) this.getParent();
|
||||
// Point pp = vp.getViewPosition();
|
||||
Point cp = vp.getViewPosition();
|
||||
|
||||
if (autoScroll && this.lastvpos != cp.x) {
|
||||
autoScroll = false;
|
||||
}
|
||||
|
||||
if (!autoScroll && cp.x >= p0) {
|
||||
autoScroll = true;
|
||||
}
|
||||
|
||||
if (autoScroll) {
|
||||
vp.setViewPosition(new Point(p0, 0));
|
||||
lastvpos = p0;
|
||||
|
||||
}
|
||||
|
||||
this.charts = new ArrayList<>();
|
||||
setupSubCharts();
|
||||
|
||||
num_bars = data.size();
|
||||
|
||||
em_height = g.getFontMetrics().getHeight();
|
||||
em_width = g.getFontMetrics().stringWidth("M");
|
||||
|
||||
XLegendDef xld = new XLegendDef();
|
||||
this.drawXLegend(g, xld);
|
||||
|
||||
drawAll(g);
|
||||
|
||||
}
|
||||
|
||||
Dimension gdim;
|
||||
|
||||
Rectangle c_rect0;
|
||||
|
||||
|
||||
private float c_font_height;
|
||||
|
||||
@Override
|
||||
public final void paintComponent(Graphics g) {
|
||||
if (Globals.se == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
super.paintComponent(g);
|
||||
|
||||
// Calculate the number of pixels for 1 em
|
||||
em_width = g.getFontMetrics().stringWidth("M");
|
||||
|
||||
this.gdim = this.getParent().getSize(gdim);
|
||||
this.getParent().setPreferredSize(gdim);
|
||||
|
||||
//Object o = this.getParent();
|
||||
JViewport vp = (JViewport) this.getParent();
|
||||
|
||||
//this.clip_bounds=g.getClipBounds();
|
||||
this.clip_bounds = vp.getViewRect();
|
||||
|
||||
first_bar = (int) (clip_bounds.x / (this.x_unit_width * this.em_width));
|
||||
last_bar = 1 + (int) ((clip_bounds.x + clip_bounds.width - (this.yl_width * em_width)) / (this.x_unit_width * this.em_width));
|
||||
|
||||
// num_bars = data.size(); // + (int) (clip_bounds.width / (this.x_unit_width * this.em_width))+5;
|
||||
// num_bars=1;
|
||||
c_font_height = g.getFontMetrics().getHeight();
|
||||
|
||||
draw((Graphics2D) g);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
setBackground(java.awt.Color.white);
|
||||
setBorder(null);
|
||||
setOpaque(false);
|
||||
setPreferredSize(new java.awt.Dimension(300, 300));
|
||||
setRequestFocusEnabled(false);
|
||||
addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
|
||||
public void mouseMoved(java.awt.event.MouseEvent evt) {
|
||||
formMouseMoved(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 589, Short.MAX_VALUE)
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 300, Short.MAX_VALUE)
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void formMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseMoved
|
||||
|
||||
}//GEN-LAST:event_formMouseMoved
|
||||
|
||||
@Override
|
||||
public void UpdateQuote(Quote q) {
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
59
src/opensesim/chart/Help.form
Normal file
59
src/opensesim/chart/Help.form
Normal file
@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="2"/>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
|
||||
</SyntheticProperties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="400" max="32767" attributes="0"/>
|
||||
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace pref="153" max="32767" attributes="0"/>
|
||||
<Component id="jButton1" min="-2" pref="123" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="124" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</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="137" max="32767" attributes="0"/>
|
||||
<Component id="jButton1" min="-2" pref="49" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="114" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JButton" name="jButton1">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="jButton1"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
167
src/opensesim/chart/Help.java
Normal file
167
src/opensesim/chart/Help.java
Normal file
@ -0,0 +1,167 @@
|
||||
/*
|
||||
* 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 opensesim.chart;
|
||||
import java.net.URL;
|
||||
import java.util.Locale;
|
||||
import javax.help.*;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class Help extends javax.swing.JDialog {
|
||||
|
||||
/**
|
||||
* Creates new form Help
|
||||
*/
|
||||
public Help(java.awt.Frame parent, boolean modal) {
|
||||
super(parent, modal);
|
||||
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")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
jButton1 = new javax.swing.JButton();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
|
||||
|
||||
jButton1.setText("jButton1");
|
||||
jButton1.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton1ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 400, Short.MAX_VALUE)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addContainerGap(153, Short.MAX_VALUE)
|
||||
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap(124, 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(137, Short.MAX_VALUE)
|
||||
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap(114, Short.MAX_VALUE)))
|
||||
);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
|
||||
// Find the HelpSet file and create the HelpSet object:
|
||||
String helpHS = "resources/helpset.hs";
|
||||
ClassLoader cl = Help.class.getClassLoader();
|
||||
HelpSet hs;
|
||||
JHelp helpViewer = null;
|
||||
try {
|
||||
URL url = HelpSet.findHelpSet(null, helpHS); //, "xml", Locale.ENGLISH);
|
||||
// URL hsURL = HelpSet.findHelpSet(cl, helpHS);
|
||||
//hs = new HelpSet(null, hsURL);
|
||||
helpViewer = new JHelp(new HelpSet(cl, url));
|
||||
} catch (Exception ee) {
|
||||
// Say what the exception really is
|
||||
System.out.println( "HelpSet " + ee.getMessage());
|
||||
// System.out.println("HelpSet "+ helpHS +" not found")
|
||||
return;
|
||||
}
|
||||
|
||||
JFrame frame = new JFrame();
|
||||
frame.setTitle("SeSim Help");
|
||||
frame.setSize(800,600);
|
||||
frame.getContentPane().add(helpViewer);
|
||||
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
frame.setVisible(true);
|
||||
|
||||
|
||||
|
||||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_jButton1ActionPerformed
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
/* Set the Nimbus look and feel */
|
||||
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
|
||||
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
|
||||
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
|
||||
*/
|
||||
try {
|
||||
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
|
||||
if ("Nimbus".equals(info.getName())) {
|
||||
javax.swing.UIManager.setLookAndFeel(info.getClassName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException ex) {
|
||||
java.util.logging.Logger.getLogger(Help.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (InstantiationException ex) {
|
||||
java.util.logging.Logger.getLogger(Help.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (IllegalAccessException ex) {
|
||||
java.util.logging.Logger.getLogger(Help.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
|
||||
java.util.logging.Logger.getLogger(Help.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
/* Create and display the dialog */
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
Help dialog = new Help(new javax.swing.JFrame(), true);
|
||||
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(java.awt.event.WindowEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton jButton1;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
55
src/opensesim/chart/MChart.form
Normal file
55
src/opensesim/chart/MChart.form
Normal file
@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.8" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.PanelFormInfo">
|
||||
<Properties>
|
||||
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
|
||||
<Color id="Crosshair Cursor"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,115,0,0,2,127"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace min="-2" pref="149" max="-2" attributes="0"/>
|
||||
<Component id="jPanel1" min="-2" pref="100" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="390" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace min="-2" pref="97" max="-2" attributes="0"/>
|
||||
<Component id="jPanel1" min="-2" pref="100" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="174" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Container class="javax.swing.JPanel" name="jPanel1">
|
||||
<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/>
|
||||
</Border>
|
||||
</Property>
|
||||
</Properties>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout"/>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Form>
|
123
src/opensesim/chart/MChart.java
Normal file
123
src/opensesim/chart/MChart.java
Normal file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* 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 opensesim.chart;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.Border;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class MChart extends java.awt.Panel {
|
||||
|
||||
private javax.swing.JButton jButton1;
|
||||
private javax.swing.JToggleButton jToggleButton1;
|
||||
|
||||
/**
|
||||
* Creates new form MChart
|
||||
*/
|
||||
public MChart() {
|
||||
initComponents();
|
||||
/* java.awt.GridBagConstraints gridBagConstraints;
|
||||
|
||||
jButton1 = new javax.swing.JButton();
|
||||
jToggleButton1 = new javax.swing.JToggleButton();
|
||||
|
||||
java.awt.GridBagLayout layout = new java.awt.GridBagLayout();
|
||||
layout.columnWidths = new int[]{0, 5, 0, 5, 0};
|
||||
layout.rowHeights = new int[]{0};
|
||||
setLayout(layout);
|
||||
*/
|
||||
this.setupLeyout();
|
||||
|
||||
}
|
||||
|
||||
void setupLeyout() {
|
||||
Border border = javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0));
|
||||
|
||||
jButton1 = new javax.swing.JButton();
|
||||
jToggleButton1 = new javax.swing.JToggleButton();
|
||||
java.awt.GridBagLayout layout = new java.awt.GridBagLayout();
|
||||
setLayout(layout);
|
||||
java.awt.GridBagConstraints gridBagConstraints;
|
||||
jButton1.setText("jButton1");
|
||||
|
||||
JPanel p = new JPanel();
|
||||
//Border border;
|
||||
//border = javax.swing.border.LineBorder;
|
||||
|
||||
p.setBorder(border);
|
||||
|
||||
gridBagConstraints = new java.awt.GridBagConstraints();
|
||||
gridBagConstraints.gridx = 0;
|
||||
gridBagConstraints.gridy = 0;
|
||||
gridBagConstraints.gridwidth = 1;
|
||||
gridBagConstraints.gridheight = java.awt.GridBagConstraints.RELATIVE;
|
||||
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
|
||||
gridBagConstraints.weightx = 1.0;
|
||||
gridBagConstraints.weighty = 0.7;
|
||||
add(p, gridBagConstraints);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
jPanel1 = new javax.swing.JPanel();
|
||||
|
||||
setCursor(new java.awt.Cursor(java.awt.Cursor.CROSSHAIR_CURSOR));
|
||||
|
||||
jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(149, 149, 149)
|
||||
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap(390, Short.MAX_VALUE))
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(97, 97, 97)
|
||||
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap(174, Short.MAX_VALUE))
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JPanel jPanel1;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
33
src/opensesim/chart/MMChart.form
Normal file
33
src/opensesim/chart/MMChart.form
Normal file
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
|
||||
<NonVisualComponents>
|
||||
<Container class="javax.swing.JPopupMenu" name="popupMenu">
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
|
||||
<Property name="useNullLayout" type="boolean" value="true"/>
|
||||
</Layout>
|
||||
</Container>
|
||||
</NonVisualComponents>
|
||||
<Events>
|
||||
<EventHandler event="mouseMoved" listener="java.awt.event.MouseMotionListener" parameters="java.awt.event.MouseEvent" handler="formMouseMoved"/>
|
||||
<EventHandler event="mouseWheelMoved" listener="java.awt.event.MouseWheelListener" parameters="java.awt.event.MouseWheelEvent" handler="formMouseWheelMoved"/>
|
||||
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="formMouseClicked"/>
|
||||
</Events>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
|
||||
<Property name="useNullLayout" type="boolean" value="true"/>
|
||||
</Layout>
|
||||
</Form>
|
268
src/opensesim/chart/MMChart.java
Normal file
268
src/opensesim/chart/MMChart.java
Normal file
@ -0,0 +1,268 @@
|
||||
/*
|
||||
* 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 opensesim.chart;
|
||||
|
||||
import opensesim.chart.painter.ChartCrossPainter;
|
||||
import opensesim.chart.painter.ChartPainter;
|
||||
import opensesim.chart.painter.OHLCChartPainter;
|
||||
import opensesim.chart.painter.XLegendDetail;
|
||||
import opensesim.chart.painter.XLegendPainter;
|
||||
import opensesim.chart.painter.YLegendPainter;
|
||||
import opensesim.gui.Globals;
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.event.MouseListener;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.Border;
|
||||
import opensesim.old_sesim.ChartDef;
|
||||
import opensesim.old_sesim.ChartPanel;
|
||||
import opensesim.old_sesim.OHLCData;
|
||||
import opensesim.old_sesim.Stock;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class MMChart extends JPanel {
|
||||
|
||||
Stock stock;
|
||||
|
||||
/**
|
||||
* Creates new form MMChart
|
||||
*/
|
||||
public MMChart() {
|
||||
stock = Globals.se.getDefaultStock();
|
||||
initComponents();
|
||||
this.em_width = 10;
|
||||
setupLayout();
|
||||
|
||||
}
|
||||
|
||||
ChartPanel xLegend;
|
||||
ChartPanel yLegend;
|
||||
ChartPanel mainChart;
|
||||
|
||||
private int compression=60000;
|
||||
|
||||
|
||||
|
||||
|
||||
private void setupYLegend() {
|
||||
yLegend = new ChartPanel();
|
||||
Border redborder = javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0));
|
||||
yLegend.setBorder(redborder);
|
||||
yLegend.setPreferredSize(new Dimension(this.em_width * 10, 110));
|
||||
yLegend.setMinimumSize(new Dimension(em_width * 10, 110));
|
||||
|
||||
GridBagConstraints gbConstraints;
|
||||
gbConstraints = new java.awt.GridBagConstraints();
|
||||
gbConstraints.gridx = 1;
|
||||
gbConstraints.gridy = 0;
|
||||
gbConstraints.fill = GridBagConstraints.BOTH;
|
||||
gbConstraints.weightx = 0.0;
|
||||
gbConstraints.weighty = 1.0;
|
||||
|
||||
add(yLegend, gbConstraints);
|
||||
this.addMouseMotionListener(yLegend);
|
||||
|
||||
OHLCChartPainter ylp = new YLegendPainter(/*null*/);
|
||||
OHLCData mydata = stock.getOHLCdata(compression);
|
||||
|
||||
ylp.setOHLCData(mydata);
|
||||
yLegend.setChartDef(chartDef);
|
||||
yLegend.addChartPainter(ylp);
|
||||
|
||||
}
|
||||
|
||||
private void setupXLegend() {
|
||||
xLegend = new ChartPanel();
|
||||
// xLegend.setBackground(Color.blue);
|
||||
|
||||
xLegend.setPreferredSize(new Dimension(em_width * 2, em_width * 3));
|
||||
xLegend.setMinimumSize(new Dimension(em_width * 2, em_width * 3));
|
||||
|
||||
xLegend.setChartDef(chartDef);
|
||||
|
||||
GridBagConstraints gbConstraints;
|
||||
gbConstraints = new java.awt.GridBagConstraints();
|
||||
gbConstraints.gridx = 0;
|
||||
gbConstraints.gridy = 1;
|
||||
gbConstraints.fill = GridBagConstraints.BOTH;
|
||||
gbConstraints.weightx = 1.0;
|
||||
gbConstraints.weighty = 0.0;
|
||||
|
||||
add(xLegend, gbConstraints);
|
||||
|
||||
OHLCChartPainter p;
|
||||
OHLCData mydata = stock.getOHLCdata(compression);
|
||||
|
||||
// this.xScrollBar.setMaximum(0);
|
||||
p = new XLegendPainter();
|
||||
p.setOHLCData(mydata);
|
||||
xLegend.addChartPainter(p);
|
||||
|
||||
p = new XLegendDetail();
|
||||
p.setOHLCData(mydata);
|
||||
xLegend.addChartPainter(p);
|
||||
|
||||
ChartPainter p0;
|
||||
p0 = new ChartCrossPainter();
|
||||
xLegend.addChartPainter(p0);
|
||||
xLegend.setChartDef(chartDef);
|
||||
|
||||
}
|
||||
|
||||
private void addMouseMotionListener(JPanel panel) {
|
||||
panel.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
|
||||
@Override
|
||||
public void mouseMoved(java.awt.event.MouseEvent evt) {
|
||||
formMouseMoved(evt);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setupMainChart() {
|
||||
mainChart = new ChartPanel();
|
||||
mainChart.setDoubleBuffered(true);
|
||||
mainChart.setBackground(Color.green);
|
||||
|
||||
GridBagConstraints gbConstraints;
|
||||
gbConstraints = new java.awt.GridBagConstraints();
|
||||
gbConstraints.gridx = 0;
|
||||
gbConstraints.gridy = 0;
|
||||
gbConstraints.fill = GridBagConstraints.BOTH;
|
||||
gbConstraints.weightx = 1.0;
|
||||
gbConstraints.weighty = 1.0;
|
||||
|
||||
add(mainChart, gbConstraints);
|
||||
|
||||
ChartPainter p0;
|
||||
p0 = new ChartCrossPainter();
|
||||
mainChart.addChartPainter(p0);
|
||||
|
||||
this.addMouseMotionListener(mainChart);
|
||||
|
||||
|
||||
mainChart.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
|
||||
|
||||
}
|
||||
|
||||
ChartDef chartDef;
|
||||
|
||||
private void setupLayout() {
|
||||
removeAll();
|
||||
|
||||
Border redborder = javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0));
|
||||
Border blueborder = javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 255));
|
||||
|
||||
GridBagLayout layout = new GridBagLayout();
|
||||
setLayout(layout);
|
||||
|
||||
chartDef = new ChartDef();
|
||||
chartDef.x_unit_width = 3.0;
|
||||
|
||||
setupMainChart();
|
||||
chartDef.mainChart = mainChart;
|
||||
setupYLegend();
|
||||
setupXLegend();
|
||||
|
||||
java.awt.GridBagConstraints gbConstraints;
|
||||
|
||||
mainChart = new ChartPanel();
|
||||
mainChart.setPreferredSize(new Dimension(100, 40));
|
||||
mainChart.setBackground(Color.blue);
|
||||
}
|
||||
|
||||
int em_width;
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
em_width = g.getFontMetrics().stringWidth("M");
|
||||
// this.removeAll();
|
||||
|
||||
// repaint();
|
||||
// setupLayout();
|
||||
xLegend.setPreferredSize(new Dimension(em_width * 2, em_width * 3));
|
||||
xLegend.setMinimumSize(new Dimension(em_width * 2, em_width * 3));
|
||||
|
||||
revalidate();
|
||||
super.paint(g); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* 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")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
popupMenu = new javax.swing.JPopupMenu();
|
||||
|
||||
addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
|
||||
public void mouseMoved(java.awt.event.MouseEvent evt) {
|
||||
formMouseMoved(evt);
|
||||
}
|
||||
});
|
||||
addMouseWheelListener(new java.awt.event.MouseWheelListener() {
|
||||
public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
|
||||
formMouseWheelMoved(evt);
|
||||
}
|
||||
});
|
||||
addMouseListener(new java.awt.event.MouseAdapter() {
|
||||
public void mouseClicked(java.awt.event.MouseEvent evt) {
|
||||
formMouseClicked(evt);
|
||||
}
|
||||
});
|
||||
setLayout(null);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void formMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseMoved
|
||||
System.out.printf("Mouse Moved\n");
|
||||
// mainChart.repaint();
|
||||
// xLegend.revalidate();
|
||||
xLegend.repaint();
|
||||
}//GEN-LAST:event_formMouseMoved
|
||||
|
||||
private void formMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseClicked
|
||||
System.out.printf("The mouse was clicked\n");
|
||||
}//GEN-LAST:event_formMouseClicked
|
||||
|
||||
private void formMouseWheelMoved(java.awt.event.MouseWheelEvent evt) {//GEN-FIRST:event_formMouseWheelMoved
|
||||
System.out.printf("Wheel!!!\n");
|
||||
}//GEN-LAST:event_formMouseWheelMoved
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JPopupMenu popupMenu;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
145
src/opensesim/chart/MasterChart.form
Normal file
145
src/opensesim/chart/MasterChart.form
Normal file
@ -0,0 +1,145 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
|
||||
<NonVisualComponents>
|
||||
<Container class="javax.swing.JPopupMenu" name="ctxMenu">
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
|
||||
<Property name="useNullLayout" type="boolean" value="true"/>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Menu class="javax.swing.JMenu" name="jMenu1">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="jMenu1"/>
|
||||
</Properties>
|
||||
</Menu>
|
||||
<MenuItem class="javax.swing.JMenuItem" name="jMenuItem1">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="jMenuItem1"/>
|
||||
</Properties>
|
||||
</MenuItem>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</NonVisualComponents>
|
||||
<Events>
|
||||
<EventHandler event="mouseWheelMoved" listener="java.awt.event.MouseWheelListener" parameters="java.awt.event.MouseWheelEvent" handler="formMouseWheelMoved"/>
|
||||
<EventHandler event="mousePressed" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="formMousePressed"/>
|
||||
<EventHandler event="mouseReleased" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="formMouseReleased"/>
|
||||
</Events>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="xLegend" max="32767" attributes="0"/>
|
||||
<Component id="chart" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="yLegend" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="xScrollBar" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="chart" max="32767" attributes="0"/>
|
||||
<Component id="yLegend" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="xLegend" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="xScrollBar" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Container class="old_sesim.ChartPanel" name="chart">
|
||||
<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>
|
||||
<Color PropertyName="color" blue="cc" green="cc" red="cc" type="rgb"/>
|
||||
</LineBorder>
|
||||
</Border>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="mouseMoved" listener="java.awt.event.MouseMotionListener" parameters="java.awt.event.MouseEvent" handler="chartMouseMoved"/>
|
||||
<EventHandler event="mousePressed" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="chartMousePressed"/>
|
||||
</Events>
|
||||
|
||||
<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="317" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
</Container>
|
||||
<Container class="old_sesim.ChartPanel" name="yLegend">
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="95" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
</Container>
|
||||
<Container class="old_sesim.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/>
|
||||
</Border>
|
||||
</Property>
|
||||
</Properties>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="561" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="37" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
</Container>
|
||||
<Component class="javax.swing.JScrollBar" name="xScrollBar">
|
||||
<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>
|
396
src/opensesim/chart/MasterChart.java
Normal file
396
src/opensesim/chart/MasterChart.java
Normal file
@ -0,0 +1,396 @@
|
||||
/*
|
||||
* 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 opensesim.chart;
|
||||
|
||||
import opensesim.old_sesim.ChartDef;
|
||||
import opensesim.chart.painter.CandleStickChartPainter;
|
||||
import opensesim.chart.painter.ChartPainter;
|
||||
import opensesim.chart.painter.XLegendPainter;
|
||||
import opensesim.chart.painter.ChartCrossPainter;
|
||||
import opensesim.chart.painter.LineChartPainter;
|
||||
import opensesim.chart.painter.OHLCChartPainter;
|
||||
import opensesim.chart.painter.YLegendPainter;
|
||||
import opensesim.gui.Globals;
|
||||
import java.util.ArrayList;
|
||||
import opensesim.old_sesim.Exchange.QuoteReceiver;
|
||||
import opensesim.old_sesim.Indicator;
|
||||
import opensesim.old_sesim.MinMax;
|
||||
import opensesim.old_sesim.OHLCData;
|
||||
import opensesim.old_sesim.OHLCDataItem;
|
||||
import opensesim.old_sesim.Quote;
|
||||
import opensesim.indicators.SMAIndicator;
|
||||
import java.util.Objects;
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JRadioButtonMenuItem;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class MasterChart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
|
||||
private ChartDef chartDef;
|
||||
|
||||
class CompressionVal {
|
||||
|
||||
public final String text;
|
||||
public final Integer value;
|
||||
|
||||
CompressionVal(String text, Integer val) {
|
||||
this.text = text;
|
||||
this.value = val;
|
||||
}
|
||||
}
|
||||
|
||||
private final CompressionVal cvalues[] = {
|
||||
new CompressionVal("5 s", 5 * 1000),
|
||||
new CompressionVal("10 s", 10 * 1000),
|
||||
new CompressionVal("15 s", 15 * 1000),
|
||||
new CompressionVal("30 s", 30 * 1000),
|
||||
new CompressionVal("1 m", 1 * 60 * 1000),
|
||||
new CompressionVal("2 m", 2 * 60 * 1000),
|
||||
new CompressionVal("5 m", 5 * 60 * 1000),
|
||||
new CompressionVal("10 m", 10 * 60 * 1000),
|
||||
new CompressionVal("1 h", 1 * 3660 * 1000),
|
||||
new CompressionVal("2 h", 2 * 3660 * 1000),
|
||||
new CompressionVal("4 h", 4 * 3660 * 1000),
|
||||
new CompressionVal("1 d", 1 * 24 * 3660 * 1000),
|
||||
new CompressionVal("2 d", 2 * 24 * 3660 * 1000),
|
||||
new CompressionVal("3 d", 3 * 3660 * 1000),};
|
||||
|
||||
private void initCtxMenu() {
|
||||
ButtonGroup group = new ButtonGroup();
|
||||
for (int i = 0; i < this.cvalues.length; i++) {
|
||||
JRadioButtonMenuItem item = new JRadioButtonMenuItem(this.cvalues[i].text);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
SMAIndicator sma1, sma2;
|
||||
|
||||
class MyOHLCData extends OHLCData {
|
||||
|
||||
SMAIndicator sma;
|
||||
|
||||
MyOHLCData(SMAIndicator sma) {
|
||||
this.sma = sma;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return sma.getData().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OHLCDataItem get(int n) {
|
||||
return sma.getData().get(n);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MinMax getMinMax(int first, int last) {
|
||||
return mydata.getMinMax(first, last);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new form MasterChart
|
||||
*/
|
||||
public MasterChart() {
|
||||
initComponents();
|
||||
|
||||
chartDef = new ChartDef();
|
||||
chartDef.x_unit_width = 3.0;
|
||||
chartDef.mainChart=this.chart;
|
||||
|
||||
if (Globals.se == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Globals.se.addQuoteReceiver(this);
|
||||
|
||||
this.chart.setChartDef(chartDef);
|
||||
this.xLegend.setChartDef(chartDef);
|
||||
this.yLegend.setChartDef(chartDef);
|
||||
|
||||
// this.yLegend.addChartPainter(p);
|
||||
//this.yLegend.addChartPainter(pc);
|
||||
}
|
||||
OHLCData mydata;
|
||||
|
||||
public void reset() {
|
||||
this.chart.deleteAllChartPinters();
|
||||
this.xLegend.deleteAllChartPinters();
|
||||
this.yLegend.deleteAllChartPinters();
|
||||
|
||||
this.chart.setChartDef(chartDef);
|
||||
this.xLegend.setChartDef(chartDef);
|
||||
this.yLegend.setChartDef(chartDef);
|
||||
|
||||
OHLCChartPainter p;
|
||||
mydata = Globals.se.getOHLCdata(Globals.se.getDefaultStock(),60000*1);
|
||||
|
||||
this.xScrollBar.setMaximum(0);
|
||||
|
||||
p = new XLegendPainter();
|
||||
p.setOHLCData(mydata);
|
||||
|
||||
xLegend.addChartPainter(p);
|
||||
xLegend.setXSCrollBar(xScrollBar);
|
||||
|
||||
OHLCChartPainter pc = new CandleStickChartPainter();
|
||||
//pc.setDataProvider(this);
|
||||
pc.setOHLCData(mydata);
|
||||
|
||||
chart.addChartPainter(pc);
|
||||
chart.setXSCrollBar(xScrollBar);
|
||||
chart.addChartPainter(new ChartCrossPainter());
|
||||
|
||||
sma1 = new opensesim.indicators.SMAIndicator();
|
||||
sma1.setParent(mydata);
|
||||
|
||||
JSONObject co;
|
||||
co = new JSONObject("{\"len\": 60}");
|
||||
sma1.putConfig(co);
|
||||
MyOHLCData mysma1;
|
||||
mysma1 = new MyOHLCData(sma1);
|
||||
p = new LineChartPainter();
|
||||
p.setOHLCData(mysma1);
|
||||
|
||||
chart.addChartPainter(p);
|
||||
|
||||
sma2 = new opensesim.indicators.SMAIndicator();
|
||||
sma2.setParent(mydata);
|
||||
co = new JSONObject("{\"len\": 20}");
|
||||
sma2.putConfig(co);
|
||||
MyOHLCData mysma2;
|
||||
mysma2 = new MyOHLCData(sma2);
|
||||
p = new LineChartPainter();
|
||||
p.setOHLCData(mysma2);
|
||||
chart.addChartPainter(p);
|
||||
|
||||
OHLCChartPainter yp = new YLegendPainter(/*chart*/);
|
||||
// yp.setDataProvider(this);
|
||||
yp.setOHLCData(mydata);
|
||||
|
||||
this.yLegend.addChartPainter(yp);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
ctxMenu = new javax.swing.JPopupMenu();
|
||||
jMenu1 = new javax.swing.JMenu();
|
||||
jMenuItem1 = new javax.swing.JMenuItem();
|
||||
chart = new opensesim.old_sesim.ChartPanel();
|
||||
yLegend = new opensesim.old_sesim.ChartPanel();
|
||||
xLegend = new opensesim.old_sesim.ChartPanel();
|
||||
xScrollBar = new javax.swing.JScrollBar();
|
||||
|
||||
jMenu1.setText("jMenu1");
|
||||
ctxMenu.add(jMenu1);
|
||||
|
||||
jMenuItem1.setText("jMenuItem1");
|
||||
ctxMenu.add(jMenuItem1);
|
||||
|
||||
addMouseWheelListener(new java.awt.event.MouseWheelListener() {
|
||||
public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
|
||||
formMouseWheelMoved(evt);
|
||||
}
|
||||
});
|
||||
addMouseListener(new java.awt.event.MouseAdapter() {
|
||||
public void mousePressed(java.awt.event.MouseEvent evt) {
|
||||
formMousePressed(evt);
|
||||
}
|
||||
public void mouseReleased(java.awt.event.MouseEvent evt) {
|
||||
formMouseReleased(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);
|
||||
}
|
||||
});
|
||||
chart.addMouseListener(new java.awt.event.MouseAdapter() {
|
||||
public void mousePressed(java.awt.event.MouseEvent evt) {
|
||||
chartMousePressed(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, 317, Short.MAX_VALUE)
|
||||
);
|
||||
|
||||
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, 0, Short.MAX_VALUE)
|
||||
);
|
||||
|
||||
xLegend.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
|
||||
|
||||
javax.swing.GroupLayout xLegendLayout = new javax.swing.GroupLayout(xLegend);
|
||||
xLegend.setLayout(xLegendLayout);
|
||||
xLegendLayout.setHorizontalGroup(
|
||||
xLegendLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 561, Short.MAX_VALUE)
|
||||
);
|
||||
xLegendLayout.setVerticalGroup(
|
||||
xLegendLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 37, 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);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.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))
|
||||
.addComponent(xScrollBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(chart, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(yLegend, 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.RELATED)
|
||||
.addComponent(xScrollBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void xScrollBarAdjustmentValueChanged(java.awt.event.AdjustmentEvent evt) {//GEN-FIRST:event_xScrollBarAdjustmentValueChanged
|
||||
repaint();
|
||||
}//GEN-LAST:event_xScrollBarAdjustmentValueChanged
|
||||
|
||||
private void showCtxMenu(java.awt.event.MouseEvent evt) {
|
||||
|
||||
this.ctxMenu.setVisible(true);
|
||||
this.ctxMenu.show(this, evt.getX(), evt.getY());
|
||||
|
||||
invalidate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
||||
private void formMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMousePressed
|
||||
if (!evt.isPopupTrigger()) {
|
||||
return;
|
||||
}
|
||||
System.out.printf("ctx menu pressed\n");
|
||||
showCtxMenu(evt);
|
||||
}//GEN-LAST:event_formMousePressed
|
||||
|
||||
private void formMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseReleased
|
||||
formMousePressed(evt);
|
||||
}//GEN-LAST:event_formMouseReleased
|
||||
|
||||
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 chartMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_chartMouseMoved
|
||||
|
||||
}//GEN-LAST:event_chartMouseMoved
|
||||
|
||||
private void chartMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_chartMousePressed
|
||||
System.out.printf("Mauspress\n");
|
||||
this.formMousePressed(evt);
|
||||
}//GEN-LAST:event_chartMousePressed
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private opensesim.old_sesim.ChartPanel chart;
|
||||
private javax.swing.JPopupMenu ctxMenu;
|
||||
private javax.swing.JMenu jMenu1;
|
||||
private javax.swing.JMenuItem jMenuItem1;
|
||||
private opensesim.old_sesim.ChartPanel xLegend;
|
||||
private javax.swing.JScrollBar xScrollBar;
|
||||
private opensesim.old_sesim.ChartPanel yLegend;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
@Override
|
||||
public void UpdateQuote(Quote q) {
|
||||
if (sma1 != null) {
|
||||
sma1.update();
|
||||
}
|
||||
|
||||
if (sma2 != null) {
|
||||
sma2.update();
|
||||
}
|
||||
|
||||
int s = mydata.size();
|
||||
this.xScrollBar.setMaximum(s);
|
||||
repaint();
|
||||
}
|
||||
|
||||
}
|
50
src/opensesim/chart/NewPanel.form
Normal file
50
src/opensesim/chart/NewPanel.form
Normal file
@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.8" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.PanelFormInfo">
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JButton" name="jButton4">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="jButton4"/>
|
||||
</Properties>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
|
||||
<GridBagConstraints gridX="0" gridY="0" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="1.0" weightY="1.0"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="jButton5">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="jButton5"/>
|
||||
</Properties>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
|
||||
<GridBagConstraints gridX="1" gridY="0" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="jButton6">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="jButton6"/>
|
||||
</Properties>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
|
||||
<GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="1.0" weightY="1.0"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
88
src/opensesim/chart/NewPanel.java
Normal file
88
src/opensesim/chart/NewPanel.java
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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 opensesim.chart;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class NewPanel extends java.awt.Panel {
|
||||
|
||||
/**
|
||||
* Creates new form NewPanel
|
||||
*/
|
||||
public NewPanel() {
|
||||
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.
|
||||
*/
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
java.awt.GridBagConstraints gridBagConstraints;
|
||||
|
||||
jButton4 = new javax.swing.JButton();
|
||||
jButton5 = new javax.swing.JButton();
|
||||
jButton6 = new javax.swing.JButton();
|
||||
|
||||
setLayout(new java.awt.GridBagLayout());
|
||||
|
||||
jButton4.setText("jButton4");
|
||||
gridBagConstraints = new java.awt.GridBagConstraints();
|
||||
gridBagConstraints.gridx = 0;
|
||||
gridBagConstraints.gridy = 0;
|
||||
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
|
||||
gridBagConstraints.weightx = 1.0;
|
||||
gridBagConstraints.weighty = 1.0;
|
||||
add(jButton4, gridBagConstraints);
|
||||
|
||||
jButton5.setText("jButton5");
|
||||
gridBagConstraints = new java.awt.GridBagConstraints();
|
||||
gridBagConstraints.gridx = 1;
|
||||
gridBagConstraints.gridy = 0;
|
||||
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
|
||||
add(jButton5, gridBagConstraints);
|
||||
|
||||
jButton6.setText("jButton6");
|
||||
gridBagConstraints = new java.awt.GridBagConstraints();
|
||||
gridBagConstraints.gridx = 0;
|
||||
gridBagConstraints.gridy = 1;
|
||||
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
|
||||
gridBagConstraints.weightx = 1.0;
|
||||
gridBagConstraints.weighty = 1.0;
|
||||
add(jButton6, gridBagConstraints);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton jButton4;
|
||||
private javax.swing.JButton jButton5;
|
||||
private javax.swing.JButton jButton6;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
46
src/opensesim/chart/SuperDlg.form
Normal file
46
src/opensesim/chart/SuperDlg.form
Normal file
@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="2"/>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
|
||||
</SyntheticProperties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="masterChart1" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="masterChart1" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="chart.MasterChart" name="masterChart1">
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
121
src/opensesim/chart/SuperDlg.java
Normal file
121
src/opensesim/chart/SuperDlg.java
Normal file
@ -0,0 +1,121 @@
|
||||
/*
|
||||
* 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 opensesim.chart;
|
||||
import opensesim.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class SuperDlg extends javax.swing.JDialog {
|
||||
|
||||
/**
|
||||
* Creates new form SuperDlg
|
||||
*/
|
||||
public SuperDlg(java.awt.Frame parent, boolean modal) {
|
||||
super(parent, modal);
|
||||
initComponents();
|
||||
setLocationRelativeTo(parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
masterChart1 = new opensesim.chart.MasterChart();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
|
||||
|
||||
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()
|
||||
.addComponent(masterChart1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(masterChart1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
/* Set the Nimbus look and feel */
|
||||
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
|
||||
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
|
||||
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
|
||||
*/
|
||||
try {
|
||||
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
|
||||
if ("Nimbus".equals(info.getName())) {
|
||||
javax.swing.UIManager.setLookAndFeel(info.getClassName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException ex) {
|
||||
java.util.logging.Logger.getLogger(SuperDlg.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (InstantiationException ex) {
|
||||
java.util.logging.Logger.getLogger(SuperDlg.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (IllegalAccessException ex) {
|
||||
java.util.logging.Logger.getLogger(SuperDlg.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
|
||||
java.util.logging.Logger.getLogger(SuperDlg.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
/* Create and display the dialog */
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
SuperDlg dialog = new SuperDlg(new javax.swing.JFrame(), true);
|
||||
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(java.awt.event.WindowEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private opensesim.chart.MasterChart masterChart1;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
76
src/opensesim/chart/painter/CandleStickChartPainter.java
Normal file
76
src/opensesim/chart/painter/CandleStickChartPainter.java
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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 opensesim.chart.painter;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import javax.swing.JScrollBar;
|
||||
import opensesim.old_sesim.OHLCData;
|
||||
import opensesim.old_sesim.OHLCDataItem;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class CandleStickChartPainter extends OHLCChartPainter {
|
||||
|
||||
@Override
|
||||
protected void drawItem(Graphics2D g, int prevx, int x, OHLCDataItem prev, OHLCDataItem i) {
|
||||
|
||||
if (i.open < i.close) {
|
||||
int xl = (int) (x + iwidth / 2);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawLine(xl, (int) getY(i.close), xl, (int) getY(i.high));
|
||||
g.drawLine(xl, (int) getY(i.low), xl, (int) getY(i.open));
|
||||
|
||||
float w = iwidth;
|
||||
float h = (int) (getY(i.open) - getY(i.close));
|
||||
|
||||
g.setColor(Color.GREEN);
|
||||
g.fillRect((int) (x), (int) getY(i.close), (int) w, (int) h);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect((int) (x), (int) getY(i.close), (int) w, (int) h);
|
||||
|
||||
} else {
|
||||
int xl = (int) (x + iwidth / 2);
|
||||
g.setColor(Color.RED);
|
||||
g.drawLine(xl, (int) getY(i.high), xl, (int) getY(i.close));
|
||||
g.drawLine(xl, (int) getY(i.open), xl, (int) getY(i.low));
|
||||
|
||||
float w = iwidth;
|
||||
float h = (int) (getY(i.close) - getY(i.open));
|
||||
|
||||
g.fillRect((int) (x), (int) getY(i.open), (int) w, (int) h);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect((int) (x), (int) getY(i.open), (int) w, (int) h);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
62
src/opensesim/chart/painter/ChartCrossPainter.java
Normal file
62
src/opensesim/chart/painter/ChartCrossPainter.java
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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 opensesim.chart.painter;
|
||||
|
||||
import opensesim.old_sesim.ChartDef;
|
||||
import opensesim.old_sesim.ChartPanel;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import opensesim.old_sesim.OHLCDataItem;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class ChartCrossPainter extends OHLCChartPainter{
|
||||
|
||||
@Override
|
||||
public void drawChart(Graphics2D g, ChartPanel p, ChartDef def) {
|
||||
Point mp = p.mouse;
|
||||
if (mp==null)
|
||||
return;
|
||||
|
||||
if (!p.mouseEntered)
|
||||
return;
|
||||
|
||||
g.drawLine(0, p.mouse.y, p.getSize().width, p.mouse.y);
|
||||
g.drawLine(p.mouse.x, 0, p.mouse.x, p.getSize().height);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
void drawItem(Graphics2D g, int prevx, int x, OHLCDataItem prev, OHLCDataItem i) {
|
||||
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
|
||||
}
|
80
src/opensesim/chart/painter/ChartPainter.java
Normal file
80
src/opensesim/chart/painter/ChartPainter.java
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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 opensesim.chart.painter;
|
||||
|
||||
import opensesim.old_sesim.ChartDef;
|
||||
import opensesim.old_sesim.ChartPanel;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import opensesim.old_sesim.ChartPainterInterface;
|
||||
import opensesim.old_sesim.MinMax;
|
||||
import opensesim.old_sesim.OHLCData;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
abstract public class ChartPainter implements ChartPainterInterface{
|
||||
|
||||
protected int em_size;
|
||||
|
||||
|
||||
|
||||
/* public abstract interface DataProvider {
|
||||
|
||||
abstract OHLCData get();
|
||||
}
|
||||
|
||||
DataProvider dataProvider = null;
|
||||
|
||||
public void setDataProvider(DataProvider dataProvider) {
|
||||
this.dataProvider = dataProvider;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Init method scould be called before painting the chart
|
||||
*
|
||||
* @param g Graphics context
|
||||
*/
|
||||
protected final void init(Graphics2D g) {
|
||||
|
||||
// Calculate the number of pixels for 1 em
|
||||
em_size = g.getFontMetrics().stringWidth("M");
|
||||
|
||||
}
|
||||
|
||||
// protected float y_scaling;
|
||||
// protected int y_height;
|
||||
// protected float y_min;
|
||||
// protected float y_max;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
abstract public void drawChart(Graphics2D g, ChartPanel p, ChartDef def);
|
||||
|
||||
}
|
58
src/opensesim/chart/painter/LineChartPainter.java
Normal file
58
src/opensesim/chart/painter/LineChartPainter.java
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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 opensesim.chart.painter;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import opensesim.old_sesim.OHLCDataItem;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class LineChartPainter extends OHLCChartPainter{
|
||||
|
||||
protected float getVal(OHLCDataItem i){
|
||||
return i.getAverage();
|
||||
}
|
||||
|
||||
@Override
|
||||
void drawItem(Graphics2D g, int prevx, int x, OHLCDataItem prev, OHLCDataItem i) {
|
||||
|
||||
if (prev == null) {
|
||||
prev = i;
|
||||
}
|
||||
int y1 = (int) getY(getVal(prev));
|
||||
int y2 = (int) getY(getVal(i));
|
||||
Color cur = g.getColor();
|
||||
g.setColor(Color.RED);
|
||||
|
||||
g.drawLine(prevx, y1, x, y2);
|
||||
g.setColor(cur);
|
||||
}
|
||||
|
||||
|
||||
}
|
239
src/opensesim/chart/painter/OHLCChartPainter.java
Normal file
239
src/opensesim/chart/painter/OHLCChartPainter.java
Normal file
@ -0,0 +1,239 @@
|
||||
/*
|
||||
* 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 opensesim.chart.painter;
|
||||
|
||||
import opensesim.old_sesim.ChartDef;
|
||||
import opensesim.old_sesim.ChartPanel;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollBar;
|
||||
import opensesim.old_sesim.MinMax;
|
||||
import opensesim.old_sesim.OHLCData;
|
||||
import opensesim.old_sesim.OHLCDataItem;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public abstract class OHLCChartPainter extends ChartPainter {
|
||||
|
||||
protected float iwidth;
|
||||
|
||||
abstract void drawItem(Graphics2D g, int prevx, int x, OHLCDataItem prev, OHLCDataItem i);
|
||||
|
||||
protected OHLCData data;
|
||||
|
||||
public void setOHLCData(OHLCData data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
protected OHLCData getData() {
|
||||
return this.data;
|
||||
/*if (dataProvider == null) {
|
||||
return null;
|
||||
}
|
||||
return dataProvider.get();
|
||||
*/
|
||||
}
|
||||
|
||||
protected int getFirstBar(ChartPanel p) {
|
||||
if (p.x_scrollbar != null) {
|
||||
return p.x_scrollbar.getValue();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected long x2Time(ChartPanel p, ChartDef def, int x) {
|
||||
// int first_bar = getFirstBar(p);
|
||||
// OHLCDataItem d = data.get(first_bar);
|
||||
|
||||
long t = 0;
|
||||
|
||||
double xw = def.x_unit_width*em_size;
|
||||
|
||||
int fs = data.getFrameSize();
|
||||
|
||||
int xbar = (int)((float)x/(xw));
|
||||
int xrest = (int)((float)x%(xw));
|
||||
|
||||
|
||||
// System.out.printf("XBAR: %d %f\n",xbar,def.x_unit_width);
|
||||
|
||||
return xbar*fs + fs/(int)xw*xrest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of bars needed to fill the ChartPanel object
|
||||
* @param p ChartPanel object
|
||||
* @param def ChartDef
|
||||
* @return Number of bars
|
||||
*/
|
||||
protected int getBars(ChartPanel p, ChartDef def) {
|
||||
Dimension dim = p.getSize();
|
||||
return (int) (dim.width / (def.x_unit_width * em_size));
|
||||
}
|
||||
|
||||
protected float y_scaling;
|
||||
protected int y_height;
|
||||
protected float y_min;
|
||||
protected float y_max;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
protected float getRoundNumber(float n){
|
||||
|
||||
|
||||
|
||||
int ldist = em_size*2;
|
||||
int steps = y_height/ldist;
|
||||
|
||||
System.out.printf("Yheight: %d \n",y_height);
|
||||
|
||||
System.out.printf("Steps = %d, h: %d\n", steps, this.y_height);
|
||||
|
||||
float stepsize = (y_max - y_min) / steps;
|
||||
|
||||
|
||||
|
||||
// stepsize = 2;
|
||||
|
||||
// double minl10 = Math.log10(y_min);
|
||||
// double maxl10 = Math.log10(y_max);
|
||||
|
||||
double lo = Math.ceil(Math.log10(stepsize));
|
||||
double rss = Math.pow(10, lo);
|
||||
|
||||
|
||||
double st1 = 1/rss;
|
||||
|
||||
|
||||
|
||||
double dr = Math.ceil(y_min*st1)/st1;
|
||||
|
||||
|
||||
|
||||
|
||||
// double f = y_min
|
||||
|
||||
System.out.printf("Ste size %f %f %f %f %f\n",stepsize,lo, y_min, rss, dr);
|
||||
|
||||
|
||||
|
||||
|
||||
return (float)0.0;
|
||||
|
||||
}
|
||||
|
||||
void initGetY(MinMax minmax, Dimension dim) {
|
||||
y_height = dim.height;
|
||||
y_scaling = dim.height / minmax.getDiff();
|
||||
y_min = minmax.getMin();
|
||||
y_max = minmax.getMax();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
float getY(float y) {
|
||||
//c_yscaling = ctx.rect.height / c_mm.getDiff();
|
||||
// float ys = dim.height / mm.getDiff();
|
||||
/* if (minmax.isLog()) {
|
||||
// return rect.height + rect.y - ((float) Math.log(y) - c_mm.getMin()) * ys;
|
||||
}
|
||||
*/
|
||||
// return (dim.height - ((y - minmax.getMin()) * y_scaling));
|
||||
return (y_height - ((y - y_min) * y_scaling));
|
||||
|
||||
}
|
||||
|
||||
double getValAtY(float y) {
|
||||
float val = 0;
|
||||
|
||||
/* if (c_mm.isLog()) {
|
||||
float ys = rect.height / c_mm.getDiff();
|
||||
|
||||
return Math.exp((rect.height + rect.y) / ys + c_mm.getMin() - y / ys);
|
||||
|
||||
}
|
||||
*/
|
||||
return (-(y - y_height)) / y_scaling + y_min;
|
||||
|
||||
}
|
||||
|
||||
/* void initGetY(MinMax minmax, Dimension dim) {
|
||||
y_height = dim.height;
|
||||
y_scaling = dim.height / minmax.getDiff();
|
||||
y_min = minmax.getMin();
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void drawChart(Graphics2D g, ChartPanel p, ChartDef def) {
|
||||
OHLCData data = getData();
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
init(g);
|
||||
|
||||
iwidth = (float) ((def.x_unit_width * em_size) * 0.9f);
|
||||
|
||||
int first_bar = getFirstBar(p);
|
||||
|
||||
Dimension dim = p.getSize();
|
||||
//int bars = (int) (dim.width / (def.x_unit_width * em_size));
|
||||
int bars = this.getBars(p, def);
|
||||
|
||||
int last_bar = first_bar + bars + 1;
|
||||
|
||||
MinMax minmax = data.getMinMax(first_bar, last_bar);
|
||||
|
||||
this.initGetY(minmax, dim);
|
||||
|
||||
// y_scaling = dim.height / minmax.getDiff();
|
||||
OHLCDataItem prevd = null;
|
||||
int prevx;
|
||||
|
||||
if (data.size() > 0 && first_bar < data.size()) {
|
||||
prevd = data.get(first_bar);
|
||||
}
|
||||
|
||||
for (int b = first_bar, n = 0; b < last_bar && b < data.size(); b++, n++) {
|
||||
OHLCDataItem d = data.get(b);
|
||||
|
||||
int x = (int) (n * em_size * def.x_unit_width); //em_width;
|
||||
drawItem(g, (int) (x - em_size * def.x_unit_width), x, prevd, d);
|
||||
prevd = d;
|
||||
|
||||
//this.drawCandleItem(g, (int)((n-1)*def.x_unit_width*em_size), (int)(n*def.x_unit_width*em_size), prevd, d);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
91
src/opensesim/chart/painter/XLegendDetail.java
Normal file
91
src/opensesim/chart/painter/XLegendDetail.java
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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 opensesim.chart.painter;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import opensesim.old_sesim.ChartDef;
|
||||
import opensesim.old_sesim.ChartPanel;
|
||||
import opensesim.old_sesim.Scheduler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class XLegendDetail extends XLegendPainter {
|
||||
|
||||
public XLegendDetail() {
|
||||
|
||||
}
|
||||
|
||||
static int ctr = 0;
|
||||
|
||||
@Override
|
||||
public void drawChart(Graphics2D g, ChartPanel p, ChartDef def) {
|
||||
// System.out.printf("Xlegend Deatil drawchart called %d\n",ctr);
|
||||
// ctr++;
|
||||
|
||||
init(g);
|
||||
if (def == null) {
|
||||
return;
|
||||
}
|
||||
if (def.mainChart == null) {
|
||||
return;
|
||||
}
|
||||
if (def.mainChart.mouse == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (def.mainChart.mouseEntered!=true){
|
||||
return;
|
||||
}
|
||||
|
||||
Point mouse = def.mainChart.mouse;
|
||||
|
||||
int x = def.mainChart.mouse.x;
|
||||
|
||||
long t = this.x2Time(p, def, x);
|
||||
System.out.printf("CFR: %s\n", Scheduler.formatTimeMillis(t));
|
||||
|
||||
g.drawLine(mouse.x, 0, mouse.x, p.getSize().height);
|
||||
|
||||
String ts = Scheduler.formatTimeMillis(t);
|
||||
int sw = g.getFontMetrics().stringWidth(ts);
|
||||
Color old = g.getColor();
|
||||
g.setColor(g.getBackground());
|
||||
|
||||
int rd = (sw) + em_size;
|
||||
g.fillRect(x - rd / 2, em_size, rd, em_size * 2);
|
||||
g.setColor(old);
|
||||
g.drawRect(x - rd / 2, em_size, rd, em_size * 2);
|
||||
g.drawString(ts, (int) x - sw / 2, 0 + em_size * 3);
|
||||
|
||||
System.out.printf("Detail Mous X: %d\n", x);
|
||||
// super.drawChart(g, p, def); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
}
|
96
src/opensesim/chart/painter/XLegendPainter.java
Normal file
96
src/opensesim/chart/painter/XLegendPainter.java
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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 opensesim.chart.painter;
|
||||
|
||||
import opensesim.old_sesim.ChartDef;
|
||||
import opensesim.old_sesim.ChartPanel;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import opensesim.old_sesim.OHLCData;
|
||||
import opensesim.old_sesim.OHLCDataItem;
|
||||
|
||||
/**
|
||||
* Paints an x-legend for OHLC charts
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class XLegendPainter extends OHLCChartPainter {
|
||||
|
||||
private String getTimeStrAt(OHLCData data, int unit) {
|
||||
|
||||
int fs = data.getFrameSize();
|
||||
return opensesim.old_sesim.Scheduler.formatTimeMillis(0 + (long) unit * (long) fs);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawChart(Graphics2D g, ChartPanel p, ChartDef def) {
|
||||
|
||||
init(g);
|
||||
int caption_tick = 10;
|
||||
int long_tick = 5;
|
||||
|
||||
Dimension size = p.getSize();
|
||||
|
||||
int first_bar = getFirstBar(p);
|
||||
|
||||
double ticksize = em_size * def.x_unit_width;
|
||||
String text = getTimeStrAt(data, first_bar);
|
||||
int swidth = g.getFontMetrics().stringWidth(text);
|
||||
|
||||
caption_tick = swidth * 2 / ((int) ticksize);
|
||||
caption_tick = (caption_tick / 5) * 5 + 5;
|
||||
|
||||
int n;
|
||||
double x;
|
||||
int y = 0;
|
||||
|
||||
for (n = first_bar, x = 0; x < size.width+em_size*3; x += ticksize) {
|
||||
|
||||
if (n % long_tick == 0) {
|
||||
g.drawLine((int) x, y, (int) x, y + em_size);
|
||||
} else {
|
||||
g.drawLine((int) x, y, (int) x, y + em_size / 2);
|
||||
}
|
||||
|
||||
if (n % caption_tick == 0) {
|
||||
|
||||
text = getTimeStrAt(data, n);
|
||||
|
||||
swidth = g.getFontMetrics().stringWidth(text);
|
||||
g.drawString(text, (int) x - swidth / 2, y + em_size * 3);
|
||||
|
||||
}
|
||||
n += 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
void drawItem(Graphics2D g, int prevx, int x, OHLCDataItem prev, OHLCDataItem i) {
|
||||
}
|
||||
|
||||
}
|
155
src/opensesim/chart/painter/YLegendPainter.java
Normal file
155
src/opensesim/chart/painter/YLegendPainter.java
Normal file
@ -0,0 +1,155 @@
|
||||
/*
|
||||
* 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 opensesim.chart.painter;
|
||||
|
||||
import opensesim.chart.Chart;
|
||||
import java.awt.Color;
|
||||
import opensesim.old_sesim.ChartDef;
|
||||
import opensesim.old_sesim.ChartPanel;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import opensesim.old_sesim.MinMax;
|
||||
import opensesim.old_sesim.OHLCData;
|
||||
import opensesim.old_sesim.OHLCDataItem;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class YLegendPainter extends OHLCChartPainter {
|
||||
|
||||
ChartPanel master;
|
||||
|
||||
public YLegendPainter(/*ChartPanel master*/) {
|
||||
// this.master=master;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawChart(Graphics2D g, ChartPanel p, ChartDef def) {
|
||||
init(g);
|
||||
this.master = def.mainChart;
|
||||
|
||||
OHLCData da = getData();
|
||||
|
||||
Dimension dim = def.mainChart.getSize();
|
||||
int first_bar = getFirstBar(master);
|
||||
int last_bar = first_bar + getBars(master, def);
|
||||
MinMax minmax = this.getData().getMinMax(first_bar, last_bar);
|
||||
|
||||
this.initGetY(minmax, dim);
|
||||
|
||||
// calculate the number of captionable bars
|
||||
int ldist = em_size * 2;
|
||||
int steps = y_height / ldist;
|
||||
|
||||
// distance between bars
|
||||
float stepsize = (y_max - y_min) / steps;
|
||||
|
||||
// round stepsize to power of 10
|
||||
float stepsize10 = (float) Math.pow(10, Math.ceil(Math.log10(stepsize)));
|
||||
|
||||
// build inverse of stepsize
|
||||
float stepsize10i = 1 / stepsize10;
|
||||
|
||||
// calculate the first y value
|
||||
float firstyv = (float) Math.ceil(y_min * stepsize10i) / stepsize10i;
|
||||
|
||||
float y1 = getY(minmax.getMin(false));
|
||||
float y2 = getY(minmax.getMax(false));
|
||||
|
||||
int c_font_height = g.getFontMetrics().getHeight();
|
||||
|
||||
float lastyv = firstyv-stepsize10;
|
||||
for (float yv = firstyv; yv < minmax.getMax(false); yv += stepsize10) {
|
||||
float y;
|
||||
|
||||
float ministep = stepsize10/10.0f;
|
||||
|
||||
|
||||
for (float yv10 = lastyv+ministep; yv10 < yv; yv10 += ministep) {
|
||||
y = this.getY(yv10);
|
||||
Color oc = g.getColor();
|
||||
g.setColor(Color.RED);
|
||||
g.drawLine(0, (int) y, em_size/2, (int) y);
|
||||
g.setColor(oc);
|
||||
|
||||
}
|
||||
|
||||
y = this.getY(yv);
|
||||
|
||||
g.drawLine(0, (int) y, em_size, (int) y);
|
||||
g.drawString(String.format("%.2f", yv), em_size * 1.5f, y + c_font_height / 3);
|
||||
lastyv = yv;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
void drawItem(Graphics2D g, int prevx, int x, OHLCDataItem prev, OHLCDataItem i) {
|
||||
return;
|
||||
}
|
||||
|
||||
public void drawChart_old(Graphics2D g, ChartPanel p, ChartDef def) {
|
||||
init(g);
|
||||
this.master = def.mainChart;
|
||||
|
||||
OHLCData da = getData();
|
||||
|
||||
Dimension dim = def.mainChart.getSize();
|
||||
int first_bar = getFirstBar(master);
|
||||
int last_bar = first_bar + getBars(master, def);
|
||||
MinMax minmax = this.getData().getMinMax(first_bar, last_bar);
|
||||
|
||||
this.initGetY(minmax, dim);
|
||||
|
||||
this.getRoundNumber(90);
|
||||
|
||||
//Rectangle dim;
|
||||
// dim = p.getSize();
|
||||
// dim = this.clip_bounds;
|
||||
// Dimension rv = this.getSize();
|
||||
// int yw = (int) (this.yl_width * em_size);
|
||||
// g.drawLine(dim.width + dim.x - yw, 0, dim.width + dim.x - yw, dim.height);
|
||||
float y1 = getY(minmax.getMin(false));
|
||||
float y2 = getY(minmax.getMax(false));
|
||||
float ydiff = y1 - y2;
|
||||
// System.out.printf("%s y1: %f, y2: %f, diff %f\n", Boolean.toString(c_mm.isLog()), y1, y2, ydiff);
|
||||
int c_font_height = g.getFontMetrics().getHeight();
|
||||
|
||||
for (int yp = (int) y2; yp < y1; yp += em_size * 3) {
|
||||
g.drawLine(0, yp, em_size, yp);
|
||||
double v1 = getValAtY(yp);
|
||||
g.drawString(String.format("%.2f", v1), em_size * 1.5f, yp + c_font_height / 3);
|
||||
}
|
||||
|
||||
double v1, v2;
|
||||
// v1 = ctx.getValAtY(y1);
|
||||
// v2 = ctx.getValAtY(y2);
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user