📄 draw_kline.java
字号:
// NMI's Java Code Viewer 6.0a
// www.trinnion.com/javacodeviewer
// Registered to Evaluation Copy
// Generated PGFZKD AyTB 14 2007 15:44:19
//source File Name: Draw_KLine.java
package gnnt.MEBS.HQApplet;
import gnnt.MEBS.HQApplet.Indicator.ASI;
import gnnt.MEBS.HQApplet.Indicator.BIAS;
import gnnt.MEBS.HQApplet.Indicator.BOLL;
import gnnt.MEBS.HQApplet.Indicator.BRAR;
import gnnt.MEBS.HQApplet.Indicator.CCI;
import gnnt.MEBS.HQApplet.Indicator.CR;
import gnnt.MEBS.HQApplet.Indicator.DMA;
import gnnt.MEBS.HQApplet.Indicator.DMI;
import gnnt.MEBS.HQApplet.Indicator.EMV;
import gnnt.MEBS.HQApplet.Indicator.EXPMA;
import gnnt.MEBS.HQApplet.Indicator.IndicatorBase;
import gnnt.MEBS.HQApplet.Indicator.IndicatorPos;
import gnnt.MEBS.HQApplet.Indicator.KDJ;
import gnnt.MEBS.HQApplet.Indicator.MA;
import gnnt.MEBS.HQApplet.Indicator.MACD;
import gnnt.MEBS.HQApplet.Indicator.MIKE;
import gnnt.MEBS.HQApplet.Indicator.OBV;
import gnnt.MEBS.HQApplet.Indicator.PSY;
import gnnt.MEBS.HQApplet.Indicator.ROC;
import gnnt.MEBS.HQApplet.Indicator.RSI;
import gnnt.MEBS.HQApplet.Indicator.Reserve;
import gnnt.MEBS.HQApplet.Indicator.SAR;
import gnnt.MEBS.HQApplet.Indicator.TRIX;
import gnnt.MEBS.HQApplet.Indicator.VOL;
import gnnt.MEBS.HQApplet.Indicator.VR;
import gnnt.MEBS.HQApplet.Indicator.WVAD;
import gnnt.MEBS.HQApplet.Indicator.W_R;
import gnnt.MEBS.hq.*;
import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.util.*;
// Referenced classes of package gnnt.MEBS.HQApplet:
// MenuListener, HQApplet, Page_KLine, ProductData,
// RHColor, KLineData, CodeTable, Common
public class Draw_KLine {
private static int cache_m_VirtualRatio = 15;
Page_KLine parent;
static final int CYCLE_DAY = 1;
static final int CYCLE_WEEK = 2;
static final int CYCLE_MONTH = 3;
static final int CYCLE_MIN5 = 4;
static final int CYCLE_MIN15 = 5;
static final int CYCLE_MIN30 = 6;
static final int CYCLE_MIN60 = 7;
private ProductData m_product;
KLineData m_kData[];
Rectangle m_rcPane[];
IndicatorBase m_indicator[];
IndicatorPos m_pos;
private int m_iPos;
private Rectangle m_rcLabel;
int m_iPrecision;
public Draw_KLine(Page_KLine _parent) {
m_rcPane = new Rectangle[3];
m_indicator = new IndicatorBase[3];
m_pos = new IndicatorPos();
m_iPos = -1;
m_pos.m_VirtualRatio = cache_m_VirtualRatio;
parent = _parent;
int iPrecision = ((MenuListener) (parent)).m_applet.GetPrecision(((MenuListener) (parent)).m_applet.strCurrentCode);
if(((MenuListener) (parent)).m_applet.isIndex(((MenuListener) (parent)).m_applet.strCurrentCode) && ((MenuListener) (parent)).m_applet.m_bShowIndexKLine == 0)
m_indicator[0] = new MA(m_pos, 2, iPrecision);
else
m_indicator[0] = new MA(m_pos, Page_KLine.m_iCurKLineType, iPrecision);
m_indicator[1] = new VOL(m_pos, 0);
CreateIndicator();
}
void Paint(Graphics g, Rectangle rc, ProductData product) {
m_product = product;
if(product != null)
m_iPrecision = ((MenuListener) (parent)).m_applet.GetPrecision(m_product.sCode);
MakeCycleData();
GetScreen(g, rc);
DrawCycle(g);
if(m_rcPane[0].width < 0)
return;
DrawTimeCoordinate(g);
for(int i = 0; i < 3; i++)
m_indicator[i].Paint(g, m_rcPane[i], m_kData);
((MenuListener) (parent)).m_applet.EndPaint();
DrawCursor(-1);
DrawLabel();
}
private void GetScreen(Graphics g, Rectangle rc) {
g.setFont(new Font("\u5B8B\u4F53", 0, 14));
FontMetrics fm = g.getFontMetrics();
int iHeight = fm.getHeight();
int x = rc.x + 4 * iHeight;
int width = rc.width - 4 * iHeight - 2;
m_rcPane[0] = new Rectangle(x, rc.y, width, (rc.height - iHeight) / 2);
m_rcPane[1] = new Rectangle(x, rc.y + m_rcPane[0].height, width, (rc.height - iHeight) / 4);
m_rcPane[2] = new Rectangle(x, m_rcPane[1].y + m_rcPane[1].height, width, (rc.height - iHeight) / 4);
g.setColor(HQApplet.rhColor.clGrid);
g.drawRect(m_rcPane[0].x, m_rcPane[0].y, width, rc.height - iHeight);
g.drawLine(m_rcPane[1].x, m_rcPane[1].y, m_rcPane[1].x + width, m_rcPane[1].y);
g.drawLine(m_rcPane[2].x, m_rcPane[2].y, m_rcPane[1].x + width, m_rcPane[2].y);
int iIndex = -1;
if(m_iPos != -1)
iIndex = m_pos.m_Begin + m_iPos;
if(m_kData != null)
m_pos.GetScreen(m_rcPane[0].width, m_kData.length);
else
m_pos.GetScreen(m_rcPane[0].width, 0);
if(m_iPos != -1)
if(iIndex >= m_pos.m_Begin && iIndex <= m_pos.m_End)
m_iPos = iIndex - m_pos.m_Begin;
else
m_iPos = -1;
if(((MenuListener) (parent)).m_applet.m_iKLineCycle >= 4 && ((MenuListener) (parent)).m_applet.m_iKLineCycle <= 7)
m_rcLabel = new Rectangle(rc.x + 1, rc.y + iHeight, x - 1, iHeight * 19);
else
m_rcLabel = new Rectangle(rc.x + 1, rc.y + iHeight, x - 1, iHeight * 18);
}
private void DrawTimeCoordinate(Graphics g) {
if(m_kData == null || m_kData.length == 0)
return;
g.setFont(new Font("\u5B8B\u4F53", 0, 14));
FontMetrics fm = g.getFontMetrics();
int iHeight = fm.getHeight();
Rectangle rc = new Rectangle(m_rcPane[2].x, m_rcPane[2].y + m_rcPane[2].height, m_rcPane[2].width, iHeight);
int iStringWidth;
switch(((MenuListener) (parent)).m_applet.m_iKLineCycle) {
case 3: // '\003'
iStringWidth = fm.stringWidth("2004-10");
break;
case 1: // '\001'
case 2: // '\002'
iStringWidth = fm.stringWidth("2004-10-10");
break;
default:
iStringWidth = fm.stringWidth("10-30 09:40");
break;
}
int step = (int)(((double)iStringWidth * 1.5D) / (double)m_pos.m_Ratio) + 1;
int scrcount = (m_pos.m_End - m_pos.m_Begin) + 1;
int count = (m_pos.m_End - m_pos.m_Begin) / step;
int y = rc.y + fm.getAscent();
int x = (int)((float)rc.x + m_pos.m_Ratio / 2.0F);
g.setColor(HQApplet.rhColor.clGrid);
g.drawLine(x, rc.y, x, rc.y + 5);
String str = TimeToString(((MenuListener) (parent)).m_applet.m_iKLineCycle, m_kData[m_pos.m_Begin].date);
g.setColor(HQApplet.rhColor.clNumber);
g.drawString(str, x, y);
for(int i = 1; i < count; i++) {
x = (int)((float)rc.x + (float)(i * step) * m_pos.m_Ratio + m_pos.m_Ratio / 2.0F);
g.setColor(HQApplet.rhColor.clGrid);
g.drawLine(x, rc.y, x, rc.y + 5);
str = TimeToString(((MenuListener) (parent)).m_applet.m_iKLineCycle, m_kData[i * step + m_pos.m_Begin].date);
x -= iStringWidth / 2;
g.setColor(HQApplet.rhColor.clNumber);
g.drawString(str, x, y);
}
if(count > 0) {
x = rc.x + (int)((float)scrcount * m_pos.m_Ratio - m_pos.m_Ratio / 2.0F);
g.setColor(HQApplet.rhColor.clGrid);
g.drawLine(x, rc.y, x, rc.y + 5);
str = TimeToString(((MenuListener) (parent)).m_applet.m_iKLineCycle, m_kData[m_pos.m_End].date);
if(count > 1 || x + iStringWidth > rc.x + rc.width)
x -= iStringWidth;
g.setColor(HQApplet.rhColor.clNumber);
g.drawString(str, x, y);
}
}
private String TimeToString(int iCycle, long date) {
String str;
switch(iCycle) {
case 1: // '\001'
case 2: // '\002'
str = String.valueOf(date);
if(str.length() >= 8)
str = str.substring(0, 4) + "-" + str.substring(4, 6) + "-" + str.substring(6, 8);
break;
case 3: // '\003'
str = String.valueOf(date / 100L);
if(str.length() >= 6)
str = str.substring(0, 4) + "-" + str.substring(4, 6);
break;
default:
str = String.valueOf(date);
if(str.length() >= 12) {
str = str.substring(4);
str = str.substring(0, 2) + "-" + str.substring(2, 4) + " " + str.substring(4, 6) + ":" + str.substring(6, 8);
}
break;
}
return str;
}
private void MakeCycleData() {
if(m_product == null)
return;
if(1 == ((MenuListener) (parent)).m_applet.m_iKLineCycle || 2 == ((MenuListener) (parent)).m_applet.m_iKLineCycle || 3 == ((MenuListener) (parent)).m_applet.m_iKLineCycle)
MakeTodayDayLine();
else
MakeToday5MinLine();
if(m_kData == null)
return;
switch(((MenuListener) (parent)).m_applet.m_iKLineCycle) {
case 2: // '\002'
MakeWeek();
break;
case 3: // '\003'
MakeMonth();
break;
case 5: // '\005'
MakeMinCycle(15);
break;
case 6: // '\006'
MakeMinCycle(30);
break;
case 7: // '\007'
MakeMinCycle(60);
break;
}
}
private void MakeTodayDayLine() {
if(m_product.realData == null || m_product.realData.curPrice < 0.001F) {
m_kData = m_product.dayKLine;
return;
}
int iNum;
if(m_product.dayKLine == null)
iNum = 0;
else
iNum = m_product.dayKLine.length;
if(iNum > 0 && m_product.dayKLine[iNum - 1].date > (long)((MenuListener) (parent)).m_applet.m_iDate) {
m_kData = m_product.dayKLine;
return;
}
if(iNum > 0 && m_product.dayKLine[iNum - 1].date == (long)((MenuListener) (parent)).m_applet.m_iDate) {
if(m_product.realData.totalAmount <= 0L) {
m_kData = m_product.dayKLine;
return;
}
iNum--;
}
m_kData = new KLineData[iNum + 1];
for(int i = 0; i < iNum; i++)
m_kData[i] = m_product.dayKLine[i];
m_kData[iNum] = new KLineData();
m_kData[iNum].date = ((MenuListener) (parent)).m_applet.m_iDate;
m_kData[iNum].openPrice = m_product.realData.openPrice;
m_kData[iNum].highPrice = m_product.realData.highPrice;
m_kData[iNum].lowPrice = m_product.realData.lowPrice;
m_kData[iNum].closePrice = m_product.realData.curPrice;
m_kData[iNum].balancePrice = m_product.realData.balancePrice;
m_kData[iNum].totalAmount = m_product.realData.totalAmount;
m_kData[iNum].totalMoney = m_product.realData.totalMoney;
m_kData[iNum].reserveCount = m_product.realData.reserveCount;
}
private void MakeToday5MinLine() {
if(m_product.realData == null)
return;
KLineData today5Min[] = get5MinKLine(m_product.sCode, m_product.vBill, m_product.realData.yesterBalancePrice);
if(m_product.min5KLine == null) {
m_kData = today5Min;
return;
}
if(today5Min.length == 0) {
m_kData = m_product.min5KLine;
return;
}
int iMax;
for(iMax = m_product.min5KLine.length - 1; iMax >= 0; iMax--)
if(m_product.min5KLine[iMax].date / 10000L < (long)((MenuListener) (parent)).m_applet.m_iDate)
break;
iMax++;
m_kData = new KLineData[iMax + today5Min.length];
for(int i = 0; i < iMax; i++)
m_kData[i] = m_product.min5KLine[i];
for(int i = 0; i < today5Min.length; i++)
m_kData[i + iMax] = today5Min[i];
}
KLineData[] get5MinKLine(String code, Vector vBillData, float fPreClosePrice) {
if(vBillData == null)
return new KLineData[0];
CodeTable codeTable = (CodeTable)((MenuListener) (parent)).m_applet.m_htProduct.get(code);
Vector vector = new Vector();
KLineData data = null;
int curTime = -1;
float preMoney = 0.0F;
long preAmount = 0L;
for(int i = 0; i < vBillData.size(); i++) {
BillDataVO bill = (BillDataVO)vBillData.elementAt(i);
if(bill.curPrice > 0.0F) {
int time = Common.GetCurrent5MinTime(bill.time);
if(time != curTime) {
if(data != null) {
if(data.totalAmount > 0L)
data.balancePrice = (float)(data.totalMoney / (double)data.totalAmount);
vector.addElement(data);
}
data = new KLineData();
data.date = (long)((MenuListener) (parent)).m_applet.m_iDate * 10000L + (long)(time / 100);
data.openPrice = bill.curPrice;
data.highPrice = bill.curPrice;
data.lowPrice = bill.curPrice;
data.closePrice = bill.curPrice;
data.balancePrice = bill.balancePrice;
data.reserveCount = bill.reserveCount;
data.totalAmount += bill.totalAmount - preAmount;
data.totalMoney += bill.totalMoney - (double)preMoney;
curTime = time;
} else {
if(bill.curPrice > data.highPrice)
data.highPrice = bill.curPrice;
if(bill.curPrice < data.lowPrice)
data.lowPrice = bill.curPrice;
data.closePrice = bill.curPrice;
data.balancePrice = bill.balancePrice;
data.reserveCount = bill.reserveCount;
data.totalAmount += bill.totalAmount - preAmount;
data.totalMoney += bill.totalMoney - (double)preMoney;
}
preAmount = bill.totalAmount;
preMoney = (float)bill.totalMoney;
}
}
if(data != null) {
if(data.totalAmount > 0L)
if(codeTable != null)
data.balancePrice = (float)(data.totalMoney / (double)data.totalAmount / (double)codeTable.fUnit);
else
data.balancePrice = (float)(data.totalMoney / (double)data.totalAmount);
vector.addElement(data);
}
KLineData dataList[] = new KLineData[0];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -