better charts

This commit is contained in:
7u83 2017-12-24 10:32:29 +01:00
parent 6780f78e14
commit ab78a513a6
2 changed files with 100 additions and 38 deletions

View File

@ -1,4 +1,4 @@
#Wed, 20 Dec 2017 19:18:09 +0100 #Fri, 22 Dec 2017 23:54:42 +0100
annotation.processing.enabled=true annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false annotation.processing.enabled.in.editor=false
annotation.processing.processors.list= annotation.processing.processors.list=

View File

@ -25,14 +25,20 @@
*/ */
package chart; package chart;
import chart.painter.ChartPainter;
import chart.painter.XLegendPainter; import chart.painter.XLegendPainter;
import gui.Globals; import gui.Globals;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.border.Border; import javax.swing.border.Border;
import sesim.ChartDef;
import sesim.ChartPanel;
import sesim.OHLCData;
import sesim.Stock; import sesim.Stock;
/** /**
@ -51,42 +57,103 @@ public class MMChart extends javax.swing.JPanel {
initComponents(); initComponents();
setupLayout(); setupLayout();
} }
JPanel xLegend; ChartPanel xLegend;
JPanel yLegend; JPanel yLegend;
JPanel mainChart; JPanel mainChart;
private final 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);
}
final 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);
ChartPainter p;
OHLCData mydata = Globals.se.getOHLCdata(Globals.se.getDefaultStock(),60000 * 20);
// this.xScrollBar.setMaximum(0);
p = new XLegendPainter();
p.setOHLCData(mydata);
xLegend.addChartPainter(p);
}
final void setupMainChart(){
mainChart = new ChartPanel();
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);
}
ChartDef chartDef;
final void setupLayout() { final void setupLayout() {
this.removeAll(); removeAll();
Border redborder = javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0)); 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)); Border blueborder = javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 255));
GridBagLayout layout = new GridBagLayout();
yLegend = new JPanel();
java.awt.GridBagLayout layout = new java.awt.GridBagLayout();
setLayout(layout); setLayout(layout);
java.awt.GridBagConstraints gridBagConstraints; setupYLegend();
setupXLegend();
setupMainChart();
yLegend.setBorder(redborder);
yLegend.setPreferredSize(new Dimension(0,0));
gridBagConstraints = new java.awt.GridBagConstraints(); chartDef = new ChartDef();
gridBagConstraints.gridx = 1; chartDef.x_unit_width = 3.0;
gridBagConstraints.gridy = 0;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
add(yLegend, gridBagConstraints); java.awt.GridBagConstraints gbConstraints;
/* p = new JPanel(); mainChart = new JPanel();
mainChart.setPreferredSize(new Dimension(100, 40));
mainChart.setBackground(Color.blue);
/* p = new JPanel();
p.setPreferredSize(new Dimension(100,40)); p.setPreferredSize(new Dimension(100,40));
p.setBorder(redborder); p.setBorder(redborder);
p.setBackground(Color.yellow); p.setBackground(Color.yellow);
@ -113,12 +180,8 @@ public class MMChart extends javax.swing.JPanel {
add(xLegend, gridBagConstraints); add(xLegend, gridBagConstraints);
*/ */
// p.setLayout(layout);
// p.setLayout(layout);
} }
int em_width; int em_width;
@ -126,15 +189,14 @@ public class MMChart extends javax.swing.JPanel {
@Override @Override
public void paint(Graphics g) { public void paint(Graphics g) {
em_width = g.getFontMetrics().stringWidth("M"); em_width = g.getFontMetrics().stringWidth("M");
// this.removeAll(); // this.removeAll();
// repaint(); // repaint();
setupLayout(); setupLayout();
revalidate(); revalidate();
super.paint(g); //To change body of generated methods, choose Tools | Templates. super.paint(g); //To change body of generated methods, choose Tools | Templates.
} }
/** /**
* This method is called from within the constructor to initialize the form. * 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 * WARNING: Do NOT modify this code. The content of this method is always