package com.teechart;
|
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseListener;
|
import java.util.ArrayList;
|
|
import javax.swing.JMenuItem;
|
import javax.swing.JPopupMenu;
|
|
import com.dev.ntm.BattTestData;
|
import com.steema.teechart.DateTime;
|
import com.steema.teechart.TChart;
|
import com.steema.teechart.drawing.Color;
|
import com.steema.teechart.events.SeriesMouseEvent;
|
import com.steema.teechart.events.SeriesMouseListener;
|
import com.steema.teechart.events.TextResolver;
|
import com.steema.teechart.legend.LegendStyle;
|
import com.steema.teechart.styles.Line;
|
import com.steema.teechart.styles.MarksStyle;
|
import com.steema.teechart.styles.PointerStyle;
|
import com.steema.teechart.tools.MarksTip;
|
import com.steema.teechart.tools.MarksTipMouseAction;
|
|
/******************************* Tee Line Chart For MonCap **************************************/
|
public class TMultMonCapLineChart extends TChart
|
{
|
private static final long serialVersionUID = 1L;
|
|
public static final byte LineType_GroupVol = 0;
|
public static final byte LineType_BattCurr = 1;
|
public static final byte LineType_MonVol = 2;
|
public static final byte LineType_MonCap = 3;
|
public static final byte LineType_MonTmp = 4;
|
public static final byte LineType_MonRes = 5;
|
public static final byte LineType_MonSer = 6;
|
public static final byte LineType_MonConnRes = 7;
|
public static final byte LineType_MonSer_Percent = 8;
|
|
public static final Color[] Line_Color = new Color[]{
|
Color.aqua, Color.bisque, Color.blue, Color.darkGray, Color.fuchsia,
|
Color.gold,Color.green, Color.greenYellow, Color.lightYellow, Color.olive,
|
Color.orange, Color.pink, Color.red, Color.silver, Color.skyBlue,
|
Color.teal, Color.white, Color.yellow};
|
|
private ArrayList<Line> al_LineSer;
|
private byte m_LineType;
|
private String m_LeftAxalValueFormat = "#";
|
private MarksTip tooltip1;
|
private boolean m_ShowChartMarks = true;
|
|
public double maxValue = 0;
|
public double minValue = 0;
|
|
String serial_title = "";
|
private Line m_SelectedLine = null;
|
private SeriesMouseListener m_SeriesMouseListener = null;
|
|
public TMultMonCapLineChart(byte line_type)
|
{
|
m_LineType = line_type;
|
al_LineSer = new ArrayList<Line>();
|
|
this.getChart().getTitle().setVisible(false);
|
this.getLegend().setVisible(true);
|
this.getLegend().setColor(Color.transparent);
|
this.getLegend().setLegendStyle(LegendStyle.SERIES);
|
this.getLegend().setFontSeriesColor(true);
|
this.getAspect().setView3D(false);
|
this.getPanel().setMarginLeft(0.2);
|
this.getPanel().setMarginRight(1);
|
this.getPanel().setMarginTop(2);
|
this.getPanel().setMarginBottom(2);
|
this.getPanel().setColor(Color.BLACK);
|
this.getAxes().getLeft().getLabels().getFont().setColor(Color.GRAY);
|
this.getAxes().getLeft().getGrid().setColor(Color.fromArgb(50, 50, 50));
|
this.getAxes().getLeft().getAxisPen().setColor(Color.GRAY);
|
this.getAxes().getBottom().getAxisPen().setColor(Color.GRAY);
|
this.getAxes().getBottom().getLabels().getFont().setColor(Color.GRAY);
|
this.getAxes().getBottom().getLabels().setDateTimeFormat("YYYY-MM-dd HH:mm");
|
this.getAxes().getBottom().getGrid().setVisible(false);
|
|
this.addMouseListener(new MouseListener(){
|
|
@Override
|
public void mouseClicked(MouseEvent e) {
|
if(e.getButton() == MouseEvent.BUTTON3)
|
{
|
JPopupMenu popupMenu = new JPopupMenu();
|
JMenuItem it_showhide_mark = new JMenuItem("ÏÔʾ/Òþ²Ø ÊýÖµ±êÇ©");
|
it_showhide_mark.addActionListener(new ActionListener(){
|
@Override
|
public void actionPerformed(ActionEvent arg0) {
|
m_ShowChartMarks = !m_ShowChartMarks;
|
for(int n=0; n<al_LineSer.size(); n++)
|
al_LineSer.get(n).getMarks().setVisible(m_ShowChartMarks);
|
}
|
});
|
JMenuItem it_showhide_legend = new JMenuItem("ÏÔʾ/Òþ²Ø ͼÀý");
|
it_showhide_legend.addActionListener(new ActionListener(){
|
@Override
|
public void actionPerformed(ActionEvent arg0) {
|
boolean vs = TMultMonCapLineChart.this.getLegend().getVisible();
|
TMultMonCapLineChart.this.getLegend().setVisible(!vs);
|
}
|
});
|
|
popupMenu.add(it_showhide_mark);
|
popupMenu.add(it_showhide_legend);
|
|
popupMenu.show(e.getComponent(), e.getX(), e.getY());
|
}
|
}
|
|
@Override
|
public void mouseEntered(MouseEvent e) {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void mouseExited(MouseEvent e) {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void mousePressed(MouseEvent e) {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void mouseReleased(MouseEvent e) {
|
// TODO Auto-generated method stub
|
|
}});
|
|
tooltip1 = new MarksTip(this.getChart());
|
tooltip1.setMouseDelay(50);
|
tooltip1.setMouseAction(MarksTipMouseAction.MOVE);
|
tooltip1.setStyle(MarksStyle.XY);
|
tooltip1.setToolTipResolver(new TextResolver(){
|
|
@Override
|
public String getText(Object arg0, String arg1) {
|
// TODO Auto-generated method stub
|
return serial_title + arg1.replace(" ", " ");
|
}
|
});
|
|
//-------------------------------------------------------//
|
m_SeriesMouseListener = new SeriesMouseListener(){
|
|
@Override
|
public void seriesClicked(SeriesMouseEvent arg0) {
|
// TODO Auto-generated method stub
|
//if(arg0.getMouseEvent().getClickCount() > 1)
|
// System.out.println("seriesClicked");
|
}
|
|
@Override
|
public void seriesEntered(SeriesMouseEvent arg0) {
|
// TODO Auto-generated method stub
|
Line L = (Line) arg0.getSource();
|
if(L.getTitle().contains("#"))
|
{
|
L.getLinePen().setWidth(2);
|
}
|
m_SelectedLine = L;
|
serial_title = m_SelectedLine.getTitle() + " ";
|
//int index = (int) L.xScreenToValue((int) arg0.getPoint().getX());
|
//System.out.println(al_LineSer.get(0).getLabels().get(index));
|
}
|
|
@Override
|
public void seriesExited(SeriesMouseEvent arg0) {
|
// TODO Auto-generated method stub
|
Line L = (Line) arg0.getSource();
|
if(L.getTitle().contains("#"))
|
{
|
L.getLinePen().setWidth(1);
|
}
|
m_SelectedLine = null;
|
serial_title = "";
|
}
|
};
|
//-------------------------------------------------------//
|
}
|
|
|
|
public void setChartLineType(byte line_type)
|
{
|
m_LineType = line_type;
|
}
|
|
public void restoreZoom()
|
{
|
this.getZoom().undo();
|
this.getAxes().getBottom().setMinMax(al_LineSer.get(0).getMinXValue()-1,
|
al_LineSer.get(0).getMaxXValue()*1.05);
|
}
|
|
public void setLineSerialVisiable(int batt_num, boolean state)
|
{
|
if(-1 == batt_num)
|
{
|
for(int n=0; n<al_LineSer.size(); n++)
|
{
|
if(false == al_LineSer.get(n).getTitle().contains("#AVG"))
|
al_LineSer.get(n).setVisible(state);
|
}
|
}
|
else
|
{
|
for(int n=0; n<al_LineSer.size(); n++)
|
{
|
if((al_LineSer.get(n).getTitle().equals("#" + batt_num))
|
|| (al_LineSer.get(n).getTitle().equals("Cap: " + batt_num)))
|
al_LineSer.get(n).setVisible(state);
|
}
|
}
|
}
|
|
public void clearSerialData()
|
{
|
this.getSeries().clear();
|
al_LineSer.clear();
|
}
|
|
public void updateChartData(BattTestData data, byte data_type)
|
{
|
clearSerialData();
|
m_LineType = data_type;
|
|
int mon_count = data.MonCount;
|
int record_count = data.al_TestData.size();
|
|
int[] monnum = data.getMonNum(0);
|
float[] monvol = data.getMonData(BattTestData.MonData_Vol, 0);
|
String value_format = "#0.###";
|
for(int n=0; n<mon_count; n++)
|
{
|
Line line = new Line();
|
if(0 == monnum[n])
|
line.setTitle("#AVG");
|
else line.setTitle("#" + monnum[n]);
|
|
if(LineType_MonVol == m_LineType)
|
{
|
m_LeftAxalValueFormat = "#0.00V";
|
value_format = "#0.000V";
|
}
|
else if(LineType_MonCap == m_LineType)
|
{
|
m_LeftAxalValueFormat = "#AH";
|
value_format = "#AH";
|
}
|
else if(LineType_MonTmp == m_LineType)
|
{
|
m_LeftAxalValueFormat = "#0.0¡ãC";
|
value_format = "#0.0¡ãC";
|
}
|
else if(LineType_MonRes == m_LineType)
|
{
|
m_LeftAxalValueFormat = "#0.00m¦¸";
|
value_format = "#0.000m¦¸";
|
}
|
else if(LineType_MonSer == m_LineType)
|
{
|
m_LeftAxalValueFormat = "#";
|
value_format = "#";
|
}
|
else if(LineType_MonSer_Percent == m_LineType)
|
{
|
m_LeftAxalValueFormat = "#%";
|
value_format = "#0.0%";;
|
}
|
|
line.setValueFormat(value_format);
|
line.setColor(Line_Color[n%Line_Color.length]);
|
line.getPointer().setStyle(PointerStyle.CIRCLE);
|
line.getPointer().setVertSize(3);
|
line.getPointer().setHorizSize(3);
|
line.getPointer().setVisible(true);
|
line.addSeriesMouseListener(m_SeriesMouseListener);
|
line.getMarks().setStyle(MarksStyle.VALUE);
|
line.getMarks().setVisible(m_ShowChartMarks);
|
line.getXValues().setDateTime(true);
|
al_LineSer.add(line);
|
}
|
|
long dt_max = new DateTime(1990, 1, 1).getTimeInMillis();
|
long dt_min = new DateTime(2990, 12, 12).getTimeInMillis();
|
for(int km=0; km<record_count; km++)
|
{
|
//if((LineType_MonVol == m_LineType) || (LineType_MonCap == m_LineType))
|
{
|
monnum = data.getMonNum(km);
|
monvol = data.getMonData(BattTestData.MonData_Vol, km);
|
}
|
|
float tmp_value = 0;
|
int tmp_mon_index = 0;
|
for(int n=0; n<mon_count; n++)
|
{
|
tmp_mon_index = n;
|
//if((LineType_MonVol == m_LineType) || (LineType_MonCap == m_LineType))
|
{
|
tmp_value = monvol[n];
|
tmp_mon_index = monnum[n];
|
}
|
|
int index = 0;
|
if(n > 0)
|
{
|
for(index=1; index<al_LineSer.size(); index++)
|
{
|
if(al_LineSer.get(index).getTitle().equals("#" + tmp_mon_index))
|
break;
|
}
|
if(index >= al_LineSer.size())
|
break;
|
}
|
|
long t = data.al_TestData.get(km).startTestTime.getTime();
|
if(dt_max < t)
|
dt_max = t;
|
if(dt_min > t)
|
dt_min=t;
|
|
al_LineSer.get(index).add(new DateTime(t), tmp_value);
|
}
|
}
|
|
maxValue = -90000;
|
minValue = 90000;
|
for(int n=0; n<mon_count; n++)
|
{
|
Line line = al_LineSer.get(n);
|
this.addSeries(line);
|
if(maxValue <= line.getMaxYValue())
|
maxValue = line.getMaxYValue();
|
if(minValue >= line.getMinYValue())
|
minValue = line.getMinYValue();
|
}
|
if(minValue > 0)
|
minValue *= 0.8;
|
else minValue *= 1.1;
|
|
if(maxValue > 0)
|
maxValue *= 1.1;
|
else maxValue *= 0.8;
|
|
this.getZoom().undo();
|
this.getAxes().getLeft().getLabels().setValueFormat(m_LeftAxalValueFormat);
|
this.getAxes().getLeft().setMinMax(minValue, maxValue);
|
long dt_time = dt_max-dt_min;
|
this.getAxes().getBottom().setMinMax(dt_min-dt_time*0.25, dt_max+dt_time*0.5);
|
}
|
|
private Line newLine(int groupid)
|
{
|
Line line = new Line();
|
line.setValueFormat("#AH ");
|
line.setColor(Line_Color[groupid%Line_Color.length]);
|
line.setTitle("Cap: " + groupid);
|
|
line.getPointer().setStyle(PointerStyle.CIRCLE);
|
line.getPointer().setVertSize(3);
|
line.getPointer().setHorizSize(3);
|
line.getPointer().setVisible(true);
|
line.getXValues().setDateTime(true);
|
line.addSeriesMouseListener(m_SeriesMouseListener);
|
line.getMarks().setStyle(MarksStyle.VALUE);
|
line.getMarks().setVisible(m_ShowChartMarks);
|
return line;
|
}
|
|
public void updateChartData_GroupCap(BattTestData data)
|
{
|
clearSerialData();
|
|
int record_count = data.al_TestData.size();
|
|
int[] monnum;
|
float[] monvol;
|
|
long dt_max = new DateTime(1990, 1, 1).getTimeInMillis();
|
long dt_min = new DateTime(2990, 12, 12).getTimeInMillis();
|
|
for(int km=0; km<record_count; km++)
|
{
|
monnum = data.getMonNum(km);
|
monvol = data.getMonData(BattTestData.MonData_Vol, km);
|
|
float tmp_value = monvol[0];
|
int group_id = monnum[0];
|
|
int index = 0;
|
Line line_t = null;
|
for(index=0; index<al_LineSer.size(); index++)
|
{
|
line_t = al_LineSer.get(index);
|
if(line_t.getTitle().equals("Cap: " + group_id))
|
break;
|
}
|
if(index >= al_LineSer.size())
|
{
|
line_t = newLine(group_id);
|
al_LineSer.add(line_t);
|
}
|
|
long t = data.al_TestData.get(km).startTestTime.getTime();
|
if(dt_max < t)
|
dt_max = t;
|
if(dt_min > t)
|
dt_min=t;
|
|
line_t.add(new DateTime(t), tmp_value);
|
}
|
|
maxValue = -90000;
|
minValue = 90000;
|
|
for(int n=0; n<al_LineSer.size(); n++)
|
{
|
Line line = al_LineSer.get(n);
|
this.addSeries(line);
|
if(maxValue <= line.getMaxYValue())
|
maxValue = line.getMaxYValue();
|
if(minValue >= line.getMinYValue())
|
minValue = line.getMinYValue();
|
}
|
if(minValue > 0)
|
minValue *= 0.8;
|
else minValue *= 1.1;
|
|
if(maxValue > 0)
|
maxValue *= 1.1;
|
else maxValue *= 0.8;
|
|
this.getZoom().undo();
|
this.getAxes().getLeft().getLabels().setValueFormat("#");
|
this.getAxes().getLeft().setMinMax(minValue, maxValue);
|
long dt_time = dt_max-dt_min;
|
this.getAxes().getBottom().setMinMax(dt_min-dt_time*0.25, dt_max+dt_time*0.5);
|
}
|
}
|
/************************************************************************************************/
|