⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 draw_minline.java

📁 一份java写的期货交易程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        {
            f += 0.01F;
            m_maxPrice = m_product.realData.closePrice * (1.0F + f);
            m_minPrice = m_product.realData.closePrice * (1.0F - f);
        } while(m_product.realData.highPrice > 0.0F && m_maxPrice < high || m_product.realData.lowPrice > 0.0F && m_minPrice > low);
    }

    private boolean inTrade(int minLineIndex, int tradeSecNo[])
    {
        if(m_applet.m_timeRange == null || m_applet.m_timeRange.length == 0)
            return false;
        int hhmmss = Common.GetTimeFromMinLineIndex(minLineIndex, m_applet.m_timeRange, m_applet.m_iMinLineInterval);
        int hhmm = hhmmss / 100;
        for(int i = 0; i < tradeSecNo.length; i++)
        {
            if(tradeSecNo[i] > m_applet.m_timeRange.length)
                return true;
            for(int j = 0; j < m_applet.m_timeRange.length; j++)
                if(m_applet.m_timeRange[j].orderID == tradeSecNo[i] && hhmm >= m_applet.m_timeRange[j].beginTime && hhmm <= m_applet.m_timeRange[j].endTime)
                    return true;

        }

        return false;
    }

    private void DrawTrace(Graphics g)
    {
        if(m_product == null || m_product.realData == null || m_product.vMinLine == null || m_product.realData.yesterBalancePrice < 0.01F)
            return;
        int oldX = m_rcPrice.x;
        int oldAverY;
        int oldPriceY = oldAverY = GetYFromPrice(m_product.realData.yesterBalancePrice);
        iNum = m_product.vMinLine.size();
        MinDataVO data;
        if(iNum > 0)
        {
            data = (MinDataVO)m_product.vMinLine.elementAt(iNum - 1);
        } else
        {
            data = new MinDataVO();
            data.averPrice = m_product.realData.yesterBalancePrice;
            data.curPrice = m_product.realData.yesterBalancePrice;
            data.reserveCount = 0;
            data.totalAmount = 0L;
            data.totalMoney = 0.0D;
        }
        int iCurIndex = Common.GetMinLineIndexFromTime(m_applet.m_iTime, m_applet.m_timeRange, m_applet.m_iMinLineInterval);
        for(int i = iNum; i < iCurIndex + 1; i++)
        {
            MinDataVO newData = new MinDataVO();
            newData.averPrice = data.averPrice;
            newData.curPrice = data.curPrice;
            newData.reserveCount = data.reserveCount;
            newData.totalAmount = data.totalAmount;
            newData.totalMoney = data.totalMoney;
            m_product.vMinLine.addElement(newData);
        }

        iNum = m_product.vMinLine.size();
        CodeTable s = (CodeTable)m_applet.m_htProduct.get(m_product.sCode);
        boolean bIsIndex = m_applet.isIndex(m_product.sCode);
        int oldReserveY = 0;
        for(int i = 0; i < iNum; i++)
        {
            data = (MinDataVO)m_product.vMinLine.elementAt(i);
            boolean bInTrade = bIsIndex || s == null || inTrade(i, s.tradeSecNo);
            if(data.curPrice == 0.0F)
                data.curPrice = data.averPrice = m_product.realData.yesterBalancePrice;
            int newX = GetXFromMinLineIndex(i);
            int newPriceY;
            if(data.curPrice < m_product.realData.lowPrice || data.curPrice > m_product.realData.highPrice)
                newPriceY = oldPriceY;
            else
                newPriceY = GetYFromPrice(data.curPrice);
            float fAver = 0.0F;
            fAver = data.averPrice;
            int newAverY;
            if(fAver < m_product.realData.lowPrice || fAver > m_product.realData.highPrice)
                newAverY = oldAverY;
            else
                newAverY = GetYFromPrice(fAver);
            float fCurVol;
            if(i == 0)
                fCurVol = data.totalAmount;
            else
                fCurVol = data.totalAmount - ((MinDataVO)m_product.vMinLine.elementAt(i - 1)).totalAmount;
            if(2 != m_iProductType && 3 != m_iProductType)
            {
                g.setColor(HQApplet.rhColor.clVolume);
                if(bInTrade)
                    g.drawLine(oldX, oldAverY, newX, newAverY);
            }
            if(fCurVol > 0.0F && bInTrade)
            {
                int volumeY = GetYFromVolume((long)fCurVol);
                g.setColor(HQApplet.rhColor.clVolume);
                g.drawLine(newX, (m_rcVolume.y + m_rcVolume.height) - 1, newX, volumeY);
            }
            int newReserveY = GetYFromReserve(data.reserveCount);
            if(bInTrade)
            {
                g.setColor(HQApplet.rhColor.clMinLine);
                g.drawLine(oldX, oldPriceY, newX, newPriceY);
                if(data.reserveCount > 0 && oldReserveY > 0)
                {
                    g.setColor(HQApplet.rhColor.clReserve);
                    g.drawLine(oldX, oldReserveY, newX, newReserveY);
                }
            }
            oldX = newX;
            oldPriceY = newPriceY;
            oldAverY = newAverY;
            oldReserveY = newReserveY;
        }

    }

    private int GetYFromPrice(float price)
    {
        if(m_maxPrice == m_minPrice)
        {
            return (m_rcPrice.y + m_rcPrice.height) - 1;
        } else
        {
            int tmp = (int)(((price - m_minPrice) * (float)m_rcPrice.height) / (m_maxPrice - m_minPrice));
            return (m_rcPrice.y + m_rcPrice.height) - tmp;
        }
    }

    private int GetYFromVolume(long volume)
    {
        if(0L >= m_maxVolume)
        {
            return (m_rcVolume.y + m_rcVolume.height) - 1;
        } else
        {
            int tmp = (int)(((double)volume * (double)(m_rcVolume.height - 1)) / (double)m_maxVolume);
            return (m_rcVolume.y + m_rcVolume.height) - 1 - tmp;
        }
    }

    private int GetYFromReserve(int reserveCount)
    {
        if(m_maxReserveCount <= 0 || reserveCount == 0)
        {
            return (m_rcVolume.y + m_rcVolume.height) - 1;
        } else
        {
            int tmp = (int)(((double)(reserveCount - m_minReserveCount) * (double)(m_rcVolume.height - 1)) / (double)(m_maxReserveCount - m_minReserveCount));
            return (m_rcVolume.y + m_rcVolume.height) - 1 - tmp;
        }
    }

    private int GetXFromTimeIndex(int index)
    {
        if(m_iTotalMinNum == 0)
            return 0;
        if(index >= m_iTotalMinNum)
            index = m_iTotalMinNum - 1;
        return m_rcPrice.x + 1 + (index * (m_rcPrice.width - 2)) / (m_iTotalMinNum - 1);
    }

    private int GetXFromMinLineIndex(int index)
    {
        if(m_iMinLineNum == 0)
            return 0;
        if(index >= m_iMinLineNum)
            index = m_iMinLineNum - 1;
        return m_rcPrice.x + 1 + (index * (m_rcPrice.width - 2)) / (m_iMinLineNum - 1);
    }

    private int GetTimeIndexFromX(int X)
    {
        if(m_iTotalMinNum == 0)
            return 0;
        else
            return ((X - m_rcPrice.x - 1) * (m_iTotalMinNum - 1)) / (m_rcPrice.width - 2);
    }

    private int GetMinLineIndexFromX(int X)
    {
        if(m_iMinLineNum == 0)
            return 0;
        else
            return ((X - m_rcPrice.x - 1) * (m_iMinLineNum - 1)) / (m_rcPrice.width - 2);
    }

    boolean KeyPressed(int iKeyCode)
    {
        boolean bResult = false;
        switch(iKeyCode)
        {
        default:
            break;

        case 37: // '%'
            if(m_iPos > 0)
            {
                DrawCursor(m_iPos - 1);
                DrawLabel();
                break;
            }
            if(m_iPos == -1 && iNum > 0)
            {
                DrawCursor(iNum - 1);
                DrawLabel();
            }
            break;

        case 39: // '\''
            if(m_iPos < m_iMinLineNum - 1 && m_iPos < iNum - 1)
            {
                DrawCursor(m_iPos + 1);
                DrawLabel();
            }
            break;

        case 27: // '\033'
            if(m_iPos != -1)
            {
                DrawCursor(-1);
                m_applet.Repaint(m_rcLabel);
                m_iPos = -1;
                bResult = true;
            }
            break;
        }
        return bResult;
    }

    boolean MouseLeftClicked(int x, int y)
    {
        if(m_rcPrice == null || m_rcVolume == null)
            return false;
        if(y < m_rcPrice.y || y > m_rcVolume.y + m_rcVolume.height)
            return false;
        int iNewPos = GetMinLineIndexFromX(x);
        if(iNewPos < 0 || iNewPos > m_iMinLineNum - 1)
            return false;
        if(iNewPos > iNum - 1)
        {
            iNewPos = iNum - 1;
            if(m_iPos != -1)
                return false;
        }
        DrawCursor(iNewPos);
        DrawLabel();
        return false;
    }

    boolean MouseDragged(int x, int y)
    {
        return MouseLeftClicked(x, y);
    }

    private void DrawCursor(int iNewPos)
    {
        Graphics g = m_applet.getGraphics();
        g.setColor(HQApplet.rhColor.clBackGround);
        g.setXORMode(HQApplet.rhColor.clCursor);
        if(m_iPos >= 0 && m_iPos <= m_iMinLineNum - 1)
        {
            int x = GetXFromMinLineIndex(m_iPos);
            g.drawLine(x, m_rcPrice.y + 1, x, (m_rcVolume.y + m_rcVolume.height) - 1);
        }
        if(iNewPos >= 0 && iNewPos <= m_iMinLineNum - 1)
        {
            m_iPos = iNewPos;
            int x = GetXFromMinLineIndex(m_iPos);
            g.drawLine(x, m_rcPrice.y + 1, x, (m_rcVolume.y + m_rcVolume.height) - 1);
        }
        g.setPaintMode();
    }

    private void DrawLabel()
    {
        if(m_iPos < 0 || m_iPos > m_iMinLineNum - 1)
            return;
        Graphics g = m_applet.getGraphics();
        g.clearRect(m_rcLabel.x, m_rcLabel.y, m_rcLabel.width, m_rcLabel.height);
        g.setColor(HQApplet.rhColor.clNumber);
        g.drawRect(m_rcLabel.x, m_rcLabel.y, m_rcLabel.width, m_rcLabel.height);
        g.setFont(new Font("宋体", 0, 14));
        FontMetrics fm = m_graphics.getFontMetrics();
        int x = m_rcLabel.x + 1;
        int y = m_rcLabel.y + fm.getAscent() + 1;
        g.setColor(HQApplet.rhColor.clItem);
        g.drawString(m_applet.getShowString("Time"), x, y);
        y += fm.getHeight();
        String str = String.valueOf(Common.GetTimeFromMinLineIndex(m_iPos, m_applet.m_timeRange, m_applet.m_iMinLineInterval));
        if(str.length() != 6)
            str = "0" + str;
        str = str.substring(0, 2) + ":" + str.substring(2, 4) + ":" + str.substring(4);
        if(m_applet.m_iMinLineInterval == 60)
            str = str.substring(0, 5);
        x = (m_rcLabel.x + m_rcLabel.width) - fm.stringWidth(str) - 1;
        g.setColor(HQApplet.rhColor.clEqual);
        g.drawString(str, x, y);
        x = m_rcLabel.x + 1;
        y += fm.getHeight();
        g.setColor(HQApplet.rhColor.clItem);
        g.drawString(m_applet.getShowString("Price"), x, y);
        y += fm.getHeight();
        if(m_product.vMinLine == null)
            return;
        MinDataVO data = (MinDataVO)m_product.vMinLine.elementAt(m_iPos);
        if(data != null)
        {
            str = Common.FloatToString(data.curPrice, m_iPrecision);
            if(data.curPrice > m_product.realData.yesterBalancePrice)
                g.setColor(HQApplet.rhColor.clIncrease);
            else
            if(data.curPrice < m_product.realData.yesterBalancePrice)
                g.setColor(HQApplet.rhColor.clDecrease);
            else
                g.setColor(HQApplet.rhColor.clEqual);
            x = (m_rcLabel.x + m_rcLabel.width) - fm.stringWidth(str) - 1;
            g.drawString(str, x, y);
        }
        x = m_rcLabel.x + 1;
        y += fm.getHeight();
        g.setColor(HQApplet.rhColor.clItem);
        g.drawString(m_applet.getShowString("ChangeValue"), x, y);
        y += fm.getHeight();
        if(data != null)
        {
            str = Common.FloatToString(data.curPrice - m_product.realData.yesterBalancePrice, m_iPrecision);
            if(data.curPrice > m_product.realData.yesterBalancePrice)
            {
                g.setColor(HQApplet.rhColor.clIncrease);
                str = "+" + str;
            } else
            if(data.curPrice < m_product.realData.yesterBalancePrice)
                g.setColor(HQApplet.rhColor.clDecrease);
            else
                g.setColor(HQApplet.rhColor.clEqual);
            x = (m_rcLabel.x + m_rcLabel.width) - fm.stringWidth(str) - 1;
            g.drawString(str, x, y);
        }
        x = m_rcLabel.x + 1;
        y += fm.getHeight();
        g.setColor(HQApplet.rhColor.clItem);
        g.drawString(m_applet.getShowString("Balance"), x, y);
        y += fm.getHeight();
        if(data != null)
        {
            str = Common.FloatToString(data.averPrice, m_iPrecision);
            if(data.averPrice > m_product.realData.yesterBalancePrice)
                g.setColor(HQApplet.rhColor.clIncrease);
            else
            if(data.averPrice < m_product.realData.yesterBalancePrice)
                g.setColor(HQApplet.rhColor.clDecrease);
            else
                g.setColor(HQApplet.rhColor.clEqual);
            x = (m_rcLabel.x + m_rcLabel.width) - fm.stringWidth(str) - 1;
            g.drawString(str, x, y);
        }
        x = m_rcLabel.x + 1;
        y += fm.getHeight();
        g.setColor(HQApplet.rhColor.clItem);
        g.drawString(m_applet.getShowString("Volume"), x, y);
        y += fm.getHeight();
        if(data != null)
        {
            float fCurVol;
            if(m_iPos == 0)
                fCurVol = data.totalAmount;
            else
                fCurVol = data.totalAmount - ((MinDataVO)m_product.vMinLine.elementAt(m_iPos - 1)).totalAmount;
            str = String.valueOf((int)fCurVol);
            g.setColor(HQApplet.rhColor.clVolume);
            x = (m_rcLabel.x + m_rcLabel.width) - fm.stringWidth(str) - 1;
            g.drawString(str, x, y);
        }
        x = m_rcLabel.x + 1;
        y += fm.getHeight();
        g.setColor(HQApplet.rhColor.clItem);
        g.drawString(m_applet.getShowString("Order"), x, y);
        y += fm.getHeight();
        if(data != null)
        {
            str = String.valueOf(data.reserveCount);
            g.setColor(HQApplet.rhColor.clReserve);
            x = (m_rcLabel.x + m_rcLabel.width) - fm.stringWidth(str) - 1;
            g.drawString(str, x, y);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -