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.awt.event.MouseMotionListener; import java.util.ArrayList; import java.util.Calendar; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; import com.Com; import com.dev.ntm.BattTestData; import com.dev.ntm.ntm_page_datamanage_chart; import com.steema.teechart.TChart; import com.steema.teechart.drawing.Color; import com.steema.teechart.drawing.DashStyle; 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 Vol ***************************************/ public class TMultVolLineChart 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_MonTmp = 3; 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 ArrayList al_PxySer; private int PXY_index = -1; private String m_LeftAxalValueFormat = "#0.0"; private BattTestData mChartData = null; private int mLineVerticalPos = 0; private ntm_page_datamanage_chart m_UI; private byte m_LineType; private MarksTip tooltip1; private String serial_title = ""; private Line m_SelectedLine = null; private int m_UI_GridViewIndex = 0; private SeriesMouseListener m_SeriesMouseListener = null; public double maxValue = 0; public double minValue = 0; public TMultVolLineChart(ntm_page_datamanage_chart UI, byte line_type) { m_UI = UI; m_LineType = line_type; al_LineSer = new ArrayList(); this.getChart().getTitle().setText(""); this.getChart().getTitle().getFont().setColor(Color.GRAY); this.getChart().getTitle().setVisible(true); if((LineType_MonVol==line_type) || (LineType_MonTmp == line_type)) { this.getLegend().setVisible(false); } else { 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); this.getPanel().setMarginRight(1); this.getPanel().setMarginTop(1.5); 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("HH:mm:ss"); this.getAxes().getBottom().getGrid().setVisible(false); if(null != m_UI) { this.addMouseMotionListener(new MouseMotionListener(){ @Override public void mouseDragged(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseMoved(MouseEvent arg0) { // TODO Auto-generated method stub if(al_LineSer.size() < 1) return; int posx = Integer.parseInt(String.format("%1.0f", al_LineSer.get(0).xScreenToValue(arg0.getX()))); float posy = (float) al_LineSer.get(0).yScreenToValue(arg0.getY()); int pos_max = al_LineSer.get(0).getXValues().count; if(posx >= pos_max) { posx = pos_max-1; } if(posx >= 0) { setMLinePosition(posx, posy, PXY_index); } } }); this.addMouseListener(new MouseListener(){ @Override public void mouseClicked(MouseEvent arg0) { if(arg0.getClickCount() == 2) { setChartViewState(); } else if(arg0.getButton() == MouseEvent.BUTTON1) { if(null == al_PxySer) return; if((m_SelectedLine != null) && (null != al_PxySer) && (PXY_index < 0)) { for(int n=0; n= 0) && (PXY_index < al_PxySer.size())) { al_PxySer.get(PXY_index).setColor(Color.GRAY); PXY_index = -1; } } } else if(arg0.getButton() == MouseEvent.BUTTON3) { JPopupMenu popupMenu = new JPopupMenu(); Line m_SelLine = m_SelectedLine; JMenuItem item_mon_vol_line = new JMenuItem("µ¥ÌåµçѹÇúÏß"); JMenuItem item_mon_tmp_line = new JMenuItem("µ¥ÌåζÈÇúÏß"); JMenuItem item_posx1 = new JMenuItem("ÏÔʾ²¢Òƶ¯ XA »ù×¼Ïß"); JMenuItem item_posx2 = new JMenuItem("ÏÔʾ²¢Òƶ¯ XB »ù×¼Ïß"); JMenuItem item_posy1 = new JMenuItem("ÏÔʾ²¢Òƶ¯ YA »ù×¼Ïß"); JMenuItem item_posy2 = new JMenuItem("ÏÔʾ²¢Òƶ¯ YB »ù×¼Ïß"); JMenuItem item_pos_stop = new JMenuItem("Òþ²Ø XY »ù×¼Ïß"); JMenuItem item_posx_hide = new JMenuItem("Òþ²Ø X »ù×¼Ïß"); JMenuItem item_posy_hide = new JMenuItem("Òþ²Ø Y »ù×¼Ïß"); JMenuItem item_selline = new JMenuItem("½öÑ¡Ôñ¸ÃÇúÏß"); JMenuItem item_selall_line = new JMenuItem("ÏÔʾȫ²¿ÇúÏß"); JMenuItem item_cutline = new JMenuItem("½Ø¶ÏÊý¾Ý"); JMenuItem item_restore_cutline = new JMenuItem("»¹Ô­±»½Ø¶ÏµÄÊý¾Ý"); JMenuItem item_show_linetitle = new JMenuItem("ÏÔʾ/Òþ²ØÍ¼Àý"); JMenuItem item_restore_curve = new JMenuItem("»¹Ô­Ëõ·Å״̬"); JMenuItem item_max_normal = new JMenuItem("×î´ó/Õý³£»¯Í¼±í"); ActionListener act_Listener = new ActionListener(){ @Override public void actionPerformed(ActionEvent arg0) { if(arg0.getSource() == item_mon_vol_line) { m_UI.setMonLineChartType(LineType_MonVol); } else if(arg0.getSource() == item_mon_tmp_line) { m_UI.setMonLineChartType(LineType_MonTmp); } else if(arg0.getSource() == item_posx1) { PXY_index = 0; al_PxySer.get(PXY_index).setVisible(true); al_PxySer.get(PXY_index).setColor(Color.WHITE); } else if(arg0.getSource() == item_posx2) { PXY_index = 1; al_PxySer.get(PXY_index).setVisible(true); al_PxySer.get(PXY_index).setColor(Color.WHITE); } else if(arg0.getSource() == item_posy1) { PXY_index = 2; al_PxySer.get(PXY_index).setVisible(true); al_PxySer.get(PXY_index).setColor(Color.WHITE); } else if(arg0.getSource() == item_posy2) { PXY_index = 3; al_PxySer.get(PXY_index).setVisible(true); al_PxySer.get(PXY_index).setColor(Color.WHITE); } else if(arg0.getSource() == item_pos_stop) { PXY_index = -1; al_PxySer.get(0).setVisible(false); al_PxySer.get(1).setVisible(false); al_PxySer.get(2).setVisible(false); al_PxySer.get(3).setVisible(false); updateLinePositionText(); } else if(arg0.getSource() == item_posx_hide) { PXY_index = -1; al_PxySer.get(0).setVisible(false); al_PxySer.get(1).setVisible(false); updateLinePositionText(); } else if(arg0.getSource() == item_posy_hide) { PXY_index = -1; al_PxySer.get(2).setVisible(false); al_PxySer.get(3).setVisible(false); updateLinePositionText(); } else if(arg0.getSource() == item_selline) { boolean stat = false; for(int n=1; 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 setGridViewIndex(int index) { m_UI_GridViewIndex = index; } public int getGridViewIndex() { return m_UI_GridViewIndex; } private void setChartViewState() { m_UI.setChartViewState(getGridViewIndex(), !m_UI.getChartViewState()); } public void setLineSerialVisiable(int index, boolean state) { if(index >= al_LineSer.size()) return; else if(-1 == index) { for(int n=1; n 0) { title_pxy += ", "; } title_pxy += "PXB " + str_px2; } if((true == al_PxySer.get(0).getVisible()) && (true == al_PxySer.get(1).getVisible())) { if(title_pxy.length() > 0) { title_pxy += ", "; } title_pxy += str_dtpx; } if(true == al_PxySer.get(2).getVisible()) { if(title_pxy.length() > 0) { title_pxy += ", "; } title_pxy += str_py1; } if(true == al_PxySer.get(3).getVisible()) { if(title_pxy.length() > 0) { title_pxy += ", "; } title_pxy += str_py2; } if((true == al_PxySer.get(2).getVisible()) && (true == al_PxySer.get(3).getVisible())) { if(title_pxy.length() > 0) { title_pxy += ", "; } title_pxy += str_dtpy; } this.getChart().getTitle().setText(title_pxy); } public void setMLinePosition(int posx, float poxy, int pxy_index) { if((null == al_PxySer) || (null == al_LineSer) || (al_LineSer.size() < 1)) { return; } if((pxy_index<0) || (pxy_index>=al_PxySer.size())) { return; } Line pxy_line = al_PxySer.get(pxy_index); if(false == pxy_line.getVisible()) { pxy_line.setVisible(true); } pxy_line.clear(); mLineVerticalPos = posx; /* DateTime dt = new DateTime(mChartData.al_TestData.get(pos).testTimeLong*1000 - Com.DT_OFFSET); m_Line.add(dt, minValue); m_Line.add(dt, maxValue); */ /* if(0 == pos) { int timelong = mChartData.getTestTimeLong(pos); m_Line.add(pos, minValue, String.format("%02d:%02d:%02d", timelong/3600, (timelong%3600)/60, timelong%60)); m_Line.add(pos, maxValue, String.format("%02d:%02d:%02d", timelong/3600, (timelong%3600)/60, timelong%60)); } else */ { int pos_max = al_LineSer.get(0).getLabels().getCount(); if(pos_max < 1) return; if(pxy_index < 2) { pxy_line.add(posx, minValue); pxy_line.add(posx, maxValue); } else { pxy_line.add(0, poxy); pxy_line.add(pos_max, poxy); } if(al_LineSer.size() > 0) { if(mLineVerticalPos >= pos_max) { mLineVerticalPos = pos_max-1; } updateLinePositionText(); } } } public void clearAllSerialData() { for(int n=0; n= line.getMinYValue()) minValue = line.getMinYValue(); } if(minValue > 0) { minValue *= 0.95; if(LineType_BattCurr == m_LineType){ if(Math.abs(minValue) < 5) { minValue = -5; } } } else { minValue = (minValue * 1.05); if(LineType_BattCurr == m_LineType){ minValue -= 5; } } if(maxValue > 0) { maxValue = maxValue*1.05; if(LineType_BattCurr == m_LineType){ maxValue += 5; } } else { maxValue *= 0.95; if(LineType_BattCurr == m_LineType){ if(Math.abs(maxValue) < 5) { maxValue = 5; } } } al_PxySer = new ArrayList(); for(int n=0; n<4; n++) { Line pL = new Line(); pL.setVisible(false); pL.setTitle("#POS"); pL.setColor(Color.GRAY); pL.getLinePen().setStyle(DashStyle.DASH); pL.getPointer().setStyle(PointerStyle.CIRCLE); pL.getPointer().setVertSize(3); pL.getPointer().setHorizSize(3); pL.getPointer().setVisible(true); pL.getXValues().setDateTime(true); pL.addSeriesMouseListener(m_SeriesMouseListener); al_PxySer.add(pL); this.addSeries(pL); } al_PxySer.get(0).setTitle("PX1"); al_PxySer.get(1).setTitle("PX2"); al_PxySer.get(2).setTitle("PY1"); al_PxySer.get(3).setTitle("PY2"); this.getZoom().undo(); if(al_LineSer.size() < 1) return; /* long min_x = (long) ((0 - Com.DT_OFFSET) - Math.abs(timelong*1000*0.02)); long max_x = (long) ((timelong*1000 - Com.DT_OFFSET) + Math.abs(timelong*1000*0.1)); this.getAxes().getBottom().setMinMax(min_x, max_x); */ this.getAxes().getLeft().getLabels().setValueFormat(m_LeftAxalValueFormat); this.getAxes().getLeft().setMinMax(minValue, maxValue); this.getAxes().getBottom().setMinMax(0-al_LineSer.get(0).getMaxXValue()*0.02, al_LineSer.get(0).getMaxXValue()*1.1); } } /************************************************************************************************/