page_marketstatus.java
来自「java 写的股票技术分析;软件」· Java 代码 · 共 494 行 · 第 1/2 页
JAVA
494 行
fm = g.getFontMetrics(font);
int fontHeight = fm.getHeight() + 2;
int iCount = (super.m_rc.height / 3 - (fontHeight + 2)) / fontHeight;
return iCount;
}
void paintStockData(Graphics g) {
if(packetInfo != null && statusData != null) {
for(int i = 0; i < iCount * 3; i++) {
for(int j = 0; j < 3; j++) {
int index = getIndexOfStatusDataArray(i, j);
if(index >= 0 && index < statusData.length) {
MarketStatusVO value = statusData[index];
int x = pos[i][j].x;
int y = pos[i][j].y;
if(j == 0 || j == 1 && i >= 0 && i < 2 * iCount)
paintRankData(g, value, 0, x, y);
else
if(i >= 2 * iCount && i < 3 * iCount && j == 1)
paintRankData(g, value, 5, x, y);
else
if(i >= 2 * iCount && i < 3 * iCount && j == 2)
paintRankData(g, value, 8, x, y);
else
paintRankData(g, value, 6, x, y);
}
}
}
}
}
void paintRankData(Graphics g, MarketStatusVO value, int rankType, int x, int y) {
Font font = new Font("\u5B8B\u4F53", 0, 16);
FontMetrics fm = g.getFontMetrics(font);
g.setFont(font);
String strCode = value.code;
CodeTable stockTable = (CodeTable)super.m_applet.m_htProduct.get(strCode);
String strName = "";
if(stockTable != null)
strName = stockTable.sName;
int iPrecision = super.m_applet.GetPrecision(strCode);
boolean showPercent = true;
if(rankType == 8 || rankType == 5)
showPercent = false;
String strCur = formatRankData(g, value.cur, iPrecision, false);
String strValue = formatRankData(g, value.value, 2, showPercent);
g.setColor(HQApplet.rhColor.clProductName);
g.drawString(strCode, x + 3, y + fm.getAscent());
switch(value.status) {
case 0: // '\0'
g.setColor(HQApplet.rhColor.clIncrease);
break;
case 1: // '\001'
g.setColor(HQApplet.rhColor.clDecrease);
break;
case 2: // '\002'
g.setColor(HQApplet.rhColor.clEqual);
break;
}
int spare = super.m_rc.width / 3 - 128;
if(spare > 64) {
int gap = (spare - 64) / 2;
g.drawString(strCur, (x + super.m_rc.width / 3) - 64 - gap - fm.stringWidth(strCur), y + fm.getAscent());
} else {
g.drawString(strCur, (x + 128) - fm.stringWidth(strCur), y + fm.getAscent());
}
switch(rankType) {
case 5: // '\005'
g.setColor(HQApplet.rhColor.clVolume);
break;
case 6: // '\006'
g.setColor(HQApplet.rhColor.clNumber);
break;
case 8: // '\b'
g.setColor(HQApplet.rhColor.clNumber);
break;
case 7: // '\007'
default:
if(value.value > 0.0F) {
g.setColor(HQApplet.rhColor.clIncrease);
break;
}
if(value.value == 0.0F)
g.setColor(HQApplet.rhColor.clEqual);
else
g.setColor(HQApplet.rhColor.clDecrease);
break;
}
g.drawString(strValue, (x + super.m_rc.width / 3) - fm.stringWidth(strValue) - 3, y + fm.getAscent());
}
String formatRankData(Graphics g, float num, int iPrecision, boolean isPercent) {
StringBuffer buf = new StringBuffer();
if(!isPercent) {
buf.append(Common.FloatToString(num, iPrecision));
} else {
if(num >= 0.0F)
buf.append("+");
buf.append(Common.FloatToString(num, iPrecision));
buf.append("%");
}
return buf.toString();
}
boolean MouseLeftClicked(int x, int y) {
if(packetInfo == null || statusData == null) {
return false;
} else {
selectStock(x, y);
return false;
}
}
private void selectStock(int x, int y) {
int fontHeight = fm.getHeight();
for(int i = 0; i < iCount * 3; i++) {
for(int j = 0; j < 3; j++) {
int left = pos[i][j].x;
int top = pos[i][j].y;
if(x > left && x < left + super.m_rc.width / 3 && y > top && y < top + fontHeight && (iHighlightRowIndex != i || iHighlightColIndex != j) && getIndexOfStatusDataArray(i, j) >= 0)
paintHighlight(i, j);
}
}
}
boolean MouseLeftDblClicked(int x, int y) {
if(packetInfo == null || statusData == null)
return false;
for(int i = 0; i < iCount * 3; i++) {
for(int j = 0; j < 3; j++) {
int left = pos[i][j].x;
int top = pos[i][j].y;
int fontHeight = fm.getHeight();
if(x > left && x < left + super.m_rc.width / 3 && y > top && y < top + fontHeight) {
int rows = statusData.length / 9;
int index = getIndexOfStatusDataArray(i, j);
if(index >= 0)
super.m_applet.QueryStock(statusData[index].code);
return true;
}
}
}
return false;
}
int getIndexOfStatusDataArray(int i, int j) {
if(i % iCount >= packetInfo.iCount)
return -1;
int rows = statusData.length / 9;
if(i >= 0 && i < iCount)
return j * 3 * rows + i;
if(i >= iCount && i < 2 * iCount)
return ((j * 3 + 1) * rows + i) - iCount;
if(i >= 2 * iCount && i < 3 * iCount)
return ((j * 3 + 2) * rows + i) - 2 * iCount;
else
return -1;
}
void makeMenus() {
menuQuote = new MenuItem(super.m_applet.getShowString("MultiQuote") + " F2");
menuQuote.setActionCommand("cmd_XX");
menuQuote.addActionListener(this);
menuMinLine = new MenuItem(super.m_applet.getShowString("MinLine") + " F5");
menuMinLine.setActionCommand("minline");
menuMinLine.addActionListener(this);
menuKLine = new MenuItem(super.m_applet.getShowString("Analysis"));
menuKLine.setActionCommand("kline");
menuKLine.addActionListener(this);
}
void processMenuEvent(PopupMenu popupMenu, int x, int y) {
selectStock(x, y);
popupMenu.removeAll();
popupMenu.add(menuMinLine);
popupMenu.add(menuKLine);
popupMenu.add(menuQuote);
processCommonMenuEvent(popupMenu, this);
popupMenu.show(super.m_applet, x, y);
}
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if(cmd.indexOf("cmd_") >= 0)
executeCommand();
else
if(cmd.indexOf("STOCK_") >= 0) {
byte stockType = getStockType(cmd);
changeStockType(stockType);
} else
if(cmd.equals("minline")) {
int index = getIndexOfStatusDataArray(iHighlightRowIndex, iHighlightColIndex);
if(index >= 0) {
String code = statusData[index].code;
super.m_applet.showPageMinLine(code);
}
} else
if(cmd.equals("kline")) {
int index = getIndexOfStatusDataArray(iHighlightRowIndex, iHighlightColIndex);
if(index >= 0) {
String code = statusData[index].code;
super.m_applet.showPageKLine(code);
}
} else {
super.actionPerformed(e);
}
}
private void changeStockType(byte stockType) {
if(stockType == currentStockType || stockType == -1) {
return;
} else {
setMenuEnable(currentStockType, true);
setMenuEnable(stockType, false);
currentStockType = stockType;
AskForDataOnTimer();
return;
}
}
void setMenuEnable(byte byte0, boolean flag) {
}
private byte getStockType(String name) {
return ((byte)(!name.equals("PRODUCT_COMMON") ? -1 : 1));
}
private void executeCommand() {
switch(currentStockType) {
case 1: // '\001'
super.m_applet.UserCommand("60");
break;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?