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 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(); 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 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 0) { for(index=1; 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= 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= 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= 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); } } /************************************************************************************************/