draw_minline.java

来自「java 写的股票技术分析;软件」· Java 代码 · 共 703 行 · 第 1/2 页

JAVA
703
字号
// 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_MinLine.java

package gnnt.MEBS.HQApplet;

import gnnt.MEBS.hq.*;
import java.awt.*;
import java.util.Hashtable;
import java.util.Vector;

// Referenced classes of package gnnt.MEBS.HQApplet:
//            HQApplet, ProductData, RHColor, Common, 
//            CodeTable

public class Draw_MinLine {

    HQApplet m_applet;
    Graphics m_graphics;
    boolean bLarge;
    private int m_iTotalMinNum;
    private int m_iMinLineNum;
    private int m_iPos;
    private int iNum;
    int m_iPrecision;
    float m_maxPrice;
    float m_minPrice;
    long m_maxVolume;
    int m_maxReserveCount;
    int m_minReserveCount;
    private ProductData m_product;
    private int iHeight;
    private int iWidth;
    Rectangle m_rcPrice;
    Rectangle m_rcVolume;
    Rectangle m_rcLabel;
    private int m_iProductType;

    public Draw_MinLine(HQApplet applet, boolean _bLarge) {
        m_iTotalMinNum = 0;
        m_iMinLineNum = 0;
        m_iPos = -1;
        iNum = 0;
        m_maxVolume = 0L;
        m_maxReserveCount = 0;
        m_minReserveCount = 0;
        m_applet = applet;
        bLarge = _bLarge;
        if(m_applet.m_timeRange != null) {
            m_iTotalMinNum = TradeTimeVO.GetTotalMinute(m_applet.m_timeRange);
            m_iMinLineNum = m_iTotalMinNum * (60 / applet.m_iMinLineInterval);
        }
    }

    void Paint(Graphics g, Rectangle rc, ProductData product) {
        m_graphics = g;
        m_product = product;
        if(product != null) {
            m_iProductType = m_applet.getProductType(product.sCode);
            GetMaxMinPrice();
            if(product.vMinLine != null) {
                m_maxReserveCount = 0;
                m_minReserveCount = 0;
                for(int i = 0; i < product.vMinLine.size(); i++) {
                    MinDataVO minLine = (MinDataVO)product.vMinLine.elementAt(i);
                    float fCurVol;
                    if(i == 0)
                        fCurVol = minLine.totalAmount;
                    else
                        fCurVol = minLine.totalAmount - ((MinDataVO)m_product.vMinLine.elementAt(i - 1)).totalAmount;
                    if((float)m_maxVolume < fCurVol)
                        m_maxVolume = (long)fCurVol;
                    if(m_maxReserveCount < minLine.reserveCount)
                        m_maxReserveCount = minLine.reserveCount;
                    if(m_minReserveCount == 0 || m_minReserveCount > minLine.reserveCount)
                        m_minReserveCount = minLine.reserveCount;
                }

            }
        }
        DrawGrid(g, rc);
        DrawTrace(g);
        if(bLarge)
            m_applet.EndPaint();
        if(m_iPos >= 0) {
            DrawCursor(-1);
            DrawLabel();
        }
    }

    private void DrawGrid(Graphics g, Rectangle rc) {
        if(bLarge)
            g.setFont(new Font("\u5B8B\u4F53", 0, 14));
        else
            g.setFont(new Font("\u5B8B\u4F53", 0, 12));
        FontMetrics fm = g.getFontMetrics();
        iHeight = fm.getHeight();
        iWidth = fm.charWidth('A');
        int w1;
        int w2;
        int h1;
        int h2;
        if(bLarge) {
            w1 = iWidth * 9 - 1;
            w2 = rc.width - w1 - iWidth * 6;
            h1 = (rc.height * 7) / 10 - iHeight / 2;
            h2 = (rc.height * 3) / 10 - (iHeight * 5) / 2;
        } else {
            w1 = iWidth * 7 - 1;
            w2 = rc.width - w1 - iWidth * 1;
            h1 = (rc.height * 6) / 10 - iHeight / 2;
            h2 = (rc.height * 3) / 10 - iHeight / 2;
        }
        m_rcPrice = new Rectangle(rc.x + w1, rc.y + iHeight, w2, h1);
        m_rcVolume = new Rectangle(rc.x + w1, m_rcPrice.y + m_rcPrice.height + iHeight, w2, h2);
        m_rcLabel = new Rectangle(rc.x + 1, rc.y + iHeight * 2, w1, fm.getHeight() * 12);
        if(m_rcLabel.y + m_rcLabel.height > rc.y + rc.height)
            m_rcLabel.height = (rc.y + rc.height) - m_rcLabel.y;
        int iPriceGridNum = ((m_rcPrice.height / iHeight) * 2) / 3;
        if(iPriceGridNum % 2 == 1)
            iPriceGridNum++;
        if(iPriceGridNum <= 0)
            return;
        g.setColor(HQApplet.rhColor.clGrid);
        if(!bLarge)
            g.drawLine(rc.x, rc.y, rc.x, rc.y + rc.height);
        for(int i = 0; i <= iPriceGridNum; i++)
            g.drawLine(m_rcPrice.x, m_rcPrice.y + (m_rcPrice.height * i) / iPriceGridNum, m_rcPrice.x + m_rcPrice.width, m_rcPrice.y + (m_rcPrice.height * i) / iPriceGridNum);

        int iVolGridNum = ((m_rcVolume.height / iHeight) * 2) / 3;
        if(iVolGridNum <= 0)
            iVolGridNum = 1;
        for(int i = 0; i <= iVolGridNum; i++)
            g.drawLine(m_rcVolume.x, m_rcVolume.y + (m_rcVolume.height * i) / iVolGridNum, m_rcVolume.x + m_rcVolume.width, m_rcVolume.y + (m_rcVolume.height * i) / iVolGridNum);

        if(m_iTotalMinNum == 0 && m_applet.m_timeRange != null)
            m_iTotalMinNum = TradeTimeVO.GetTotalMinute(m_applet.m_timeRange);
        int iIndex = 0;
        int iOldX = 0;
        int iEndX = GetXFromTimeIndex(m_iTotalMinNum);
        if(m_applet.m_timeRange == null)
            return;
        int iRangeIndex[] = new int[m_applet.m_timeRange.length + 1];
        iRangeIndex[0] = 0;
        for(int i = 0; i < m_applet.m_timeRange.length; i++)
            iRangeIndex[i + 1] = Common.GetTimeIndexFromTime(m_applet.m_timeRange[i].endTime, m_applet.m_timeRange) + 1;

        String strLastTime = "09:00";
        while(iIndex <= m_iTotalMinNum)  {
            if(iIndex > 0 && m_iTotalMinNum - iIndex < 10)
                iIndex = m_iTotalMinNum;
            int x = GetXFromTimeIndex(iIndex <= 0 ? iIndex : iIndex - 1);
            boolean bDrawed = false;
            g.setColor(HQApplet.rhColor.clGrid);
            String strNextStartTime = "";
            boolean isRangeTime = false;
            for(int i = 0; i < iRangeIndex.length; i++)
                if(iIndex == iRangeIndex[i]) {
                    isRangeTime = true;
                    if(i > 0 && i < m_applet.m_timeRange.length) {
                    	  //for(strNextStartTime =m_applet.m_timeRange[i].beginTime; strNextStartTime.length() < 4; strNextStartTime = "0" + strNextStartTime);
                        for(strNextStartTime =String.valueOf( m_applet.m_timeRange[i].beginTime); strNextStartTime.length() < 4; strNextStartTime = "0" + strNextStartTime);
                        strNextStartTime = strNextStartTime.substring(0, 2) + ":" + strNextStartTime.substring(2, 4);
                    }
                }

            if(isRangeTime) {
                if(iIndex == 0)
                    x--;
                else
                if(iIndex == m_iTotalMinNum)
                    x++;
                g.drawLine(x, m_rcPrice.y, x, m_rcPrice.y + m_rcPrice.height);
                g.drawLine(x, m_rcVolume.y, x, m_rcVolume.y + m_rcVolume.height);
                bDrawed = true;
            } else
            if(x - iOldX > (int)((double)fm.stringWidth("09:30") * 1.2D) && iEndX - x > fm.stringWidth("09:30")) {
                Common.DrawDotLine(g, x, m_rcPrice.y, x, m_rcPrice.y + m_rcPrice.height);
                Common.DrawDotLine(g, x, m_rcVolume.y, x, m_rcVolume.y + m_rcVolume.height);
                if(x - iOldX >= (int)((float)fm.stringWidth(strLastTime) * 0.8F))
                    bDrawed = true;
            }
            if(bDrawed && bLarge) {
                g.setColor(HQApplet.rhColor.clNumber);
                int iTime;
                if(iIndex == 0)
                    iTime = m_applet.m_timeRange[0].beginTime;
                else
                if(iIndex == m_iTotalMinNum)
                    iTime = m_applet.m_timeRange[m_applet.m_timeRange.length - 1].endTime;
                else
                    iTime = Common.GetTimeFromTimeIndex(iIndex - 1, m_applet.m_timeRange);
                String str;
                for(str = String.valueOf(iTime); str.length() < 4; str = "0" + str);
                str = str.substring(0, 2) + ":" + str.substring(2, 4);
                if(strNextStartTime.length() > 0 && !str.equals(strNextStartTime))
                    str = str + "/" + strNextStartTime;
                int y = m_rcVolume.y + m_rcVolume.height + fm.getAscent();
                if(x - iOldX < (int)((float)fm.stringWidth(str) * 0.8F))
                    g.clearRect(iOldX - fm.stringWidth(strLastTime) / 2, m_rcVolume.y + m_rcVolume.height + 1, fm.stringWidth(strLastTime), fm.getHeight());
                g.drawString(str, x - fm.stringWidth(str) / 2, y);
                iOldX = x;
                strLastTime = str;
            } else {
                strLastTime = "";
            }
            if(iIndex >= m_iTotalMinNum)
                break;
            if((iIndex += 30) > m_iTotalMinNum)
                iIndex = m_iTotalMinNum;
        }
        if(m_product == null || m_product.realData == null)
            return;
        m_iPrecision = m_applet.GetPrecision(m_product.sCode);
        float fDiff = m_maxPrice - m_minPrice;
        float fUnit = 1.0F;
        for(int i = 0; i < m_iPrecision; i++) {
            fDiff *= 10F;
            fUnit /= 10F;
        }

        int iDiff = (int)((fDiff + 1.0F) - fUnit);
        if(iDiff % iPriceGridNum > 0)
            iDiff = (iDiff / iPriceGridNum + 1) * iPriceGridNum;
        fDiff = iDiff;
        for(int i = 0; i < m_iPrecision; i++)
            fDiff /= 10F;

        m_maxPrice = m_product.realData.yesterBalancePrice + fDiff / 2.0F;
        m_minPrice = m_product.realData.yesterBalancePrice - fDiff / 2.0F;
        float preclose = m_product.realData.yesterBalancePrice;
        for(int i = 0; i <= iPriceGridNum; i++) {
            float price = m_maxPrice - ((m_maxPrice - m_minPrice) * (float)i) / (float)iPriceGridNum;
            if(price > preclose)
                g.setColor(HQApplet.rhColor.clIncrease);
            else
            if(preclose > price) {
                g.setColor(HQApplet.rhColor.clDecrease);
            } else {
                if(m_maxPrice > m_minPrice) {
                    g.setColor(HQApplet.rhColor.clGrid);
                    g.drawLine(m_rcPrice.x, m_rcPrice.y + (m_rcPrice.height * i) / iPriceGridNum + 1, m_rcPrice.x + m_rcPrice.width, m_rcPrice.y + (m_rcPrice.height * i) / iPriceGridNum + 1);
                }
                g.setColor(HQApplet.rhColor.clEqual);
            }
            String str = Common.FloatToString(price, m_iPrecision);
            int x = m_rcPrice.x - fm.stringWidth(str) - 1;
            int y = ((m_rcPrice.y + (m_rcPrice.height * i) / iPriceGridNum) - fm.getAscent()) + fm.getHeight();
            g.drawString(str, x, y);
            if(bLarge) {
                float percent;
                if(0.0F != preclose)
                    percent = ((price - preclose) * 100F) / preclose;
                else
                    percent = 0.0F;
                if(percent < 0.0F)
                    percent = -percent;
                str = Common.FloatToString(percent, 2);
                if(percent >= 100F)
                    str = str.substring(0, str.length() - 1);
                str = str + "%";
                x = m_rcPrice.x + m_rcPrice.width + 2;
                g.drawString(str, x, y);
            }
        }

        if(m_maxReserveCount == m_minReserveCount) {
            if(m_minReserveCount > 0) {
                m_maxReserveCount += iVolGridNum - 1;
                m_minReserveCount--;
            }
        } else {
            int change = (int)((double)(m_maxReserveCount - m_minReserveCount) * 0.10000000000000001D);
            if(change <= 0)
                change = 1;
            m_maxReserveCount += change;
            m_minReserveCount -= change;
        }
        g.setColor(HQApplet.rhColor.clVolume);
        for(int i = 0; i < iVolGridNum; i++) {
            long volume = m_maxVolume - (m_maxVolume * (long)i) / (long)iVolGridNum;
            String str = String.valueOf(volume);
            int x = m_rcVolume.x - fm.stringWidth(str);
            int y = ((m_rcVolume.y + (m_rcVolume.height * i) / iVolGridNum) - fm.getAscent()) + fm.getHeight();
            g.drawString(str, x, y);
        }

        if(bLarge) {
            g.setColor(HQApplet.rhColor.clReserve);
            for(int i = 0; i <= iVolGridNum; i++) {
                long reserveCount = m_maxReserveCount - ((m_maxReserveCount - m_minReserveCount) * i) / iVolGridNum;
                String str = String.valueOf(reserveCount);
                int x = m_rcVolume.x + m_rcVolume.width + 1;
                int y = ((m_rcVolume.y + (m_rcVolume.height * i) / iVolGridNum) - fm.getAscent()) + fm.getHeight();
                g.drawString(str, x, y);
            }

        }
    }

    void GetMaxMinPrice() {
        if(m_product.realData == null)
            return;
        if(m_product.realData != null && m_product.realData.highPrice < m_product.realData.yesterBalancePrice)
            m_maxPrice = m_product.realData.yesterBalancePrice;
        else
            m_maxPrice = m_product.realData.highPrice;
        if(m_maxPrice < 0.001F)
            return;
        if(m_product.realData.lowPrice > m_product.realData.yesterBalancePrice)
            m_minPrice = m_product.realData.yesterBalancePrice;
        else
            m_minPrice = m_product.realData.lowPrice;
        float scale;
        if(m_applet.GetPrecision(m_product.sCode) == 3)
            scale = 0.0055F;
        else
            scale = m_product.realData.yesterBalancePrice / 1000F;
        if(m_product.realData.highPrice == 0.0F && m_product.realData.lowPrice == 0.0F) {
            m_minPrice = 0.0F;
            m_maxPrice = 2.0F * m_product.realData.yesterBalancePrice;
        } else {
            float higher = 0.0F;
            float lowwer = 0.0F;
            float price = m_product.realData.yesterBalancePrice;
            if(m_product.realData.highPrice - price >= scale) {
                m_maxPrice = m_product.realData.highPrice;
                higher = m_product.realData.highPrice - price;
            } else {
                m_maxPrice = price + scale;
            }
            if(price - m_product.realData.lowPrice >= scale) {
                m_minPrice = m_product.realData.lowPrice;
                lowwer = price - m_product.realData.lowPrice;
            } else {
                m_minPrice = price - scale;
            }
            if(higher > lowwer)
                m_minPrice = price - higher;
            if(higher < lowwer)
                m_maxPrice = price + lowwer;
        }
    }

    void GetMaxMinPriceIndex() {
        m_maxPrice = 0.0F;
        m_minPrice = 0.0F;
        if(m_product == null || m_product.realData == null || m_product.realData.closePrice < 0.001F)

⌨️ 快捷键说明

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