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

📄 indicatorplot.java

📁 EclipseTrader is a stock exchange analysis system, featuring shares pricing watch, intraday and hi
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                for (int ll = indicator.getLines().size() - 1; ll >= 0; ll--)                {                    PlotLine plotLine = (PlotLine)indicator.getLines().get(ll);                    Scaler indicatorScaler = getScaler(indicator, plotLine);                                        switch(plotLine.getType())                    {                        case PlotLine.DOT:                        case PlotLine.DASH:                        case PlotLine.LINE:                        {                            int ofs = barData.size() - plotLine.getSize();                            int x = getMarginWidth() + getGridWidth() / 2 + ofs * getGridWidth();                            int[] pointArray = new int[plotLine.getSize() * 2];                            for (int i = 0, pa = 0; i < plotLine.getSize(); i++, x += getGridWidth())                            {                                pointArray[pa++] = x;                                pointArray[pa++] = indicatorScaler.convertToY(plotLine.getData(i));                            }                            if (PixelTools.isPointOnLine(point.x, point.y, pointArray))                                selection.add(indicator);                            break;                        }                        case PlotLine.HORIZONTAL:                            break;                        case PlotLine.HISTOGRAM: {                            int ofs = barData.size() - plotLine.getSize();							int x = getMarginWidth() + getGridWidth() / 2 + ofs * getGridWidth();							int[] pointArray = new int[plotLine.getSize() * 2];							for (int i = 0, pa = 0; i < plotLine.getSize(); i++, x += getGridWidth()) {								pointArray[pa++] = x;								pointArray[pa++] = indicatorScaler.convertToY(plotLine.getData(i));							}							if (PixelTools.isPointOnLine(point.x, point.y, pointArray))								selection.add(indicator);                            break;                        }                        case PlotLine.HISTOGRAM_BAR: {                            int zero = scaler.convertToY(0);							int ofs = barData.size() - plotLine.getSize();							int x = getMarginWidth() + getGridWidth() / 2 + ofs * getGridWidth();							for (int i = 0; i < plotLine.getSize(); i++, x += getGridWidth()) {								int y = scaler.convertToY(plotLine.getData(i));								if (point.x >= (x - 1) && point.x <= (x + 1) && point.y >= Math.min(y, zero) && point.y <= Math.max(y, zero)) {									selection.add(indicator);									break;								}							}                            break;                        }                        case PlotLine.BAR:                        case PlotLine.CANDLE:                        {                            int ofs = barData.size() - plotLine.getSize();                            int x = getMarginWidth() + getGridWidth() / 2 + ofs * getGridWidth();                            for (int i = 0; i < plotLine.getSize(); i++, x += getGridWidth())                            {                                int y1 = indicatorScaler.convertToY(plotLine.getBar(i).getHigh());                                int y2 = indicatorScaler.convertToY(plotLine.getBar(i).getLow());                                if (point.y >= y1 && point.y <= y2 && point.x >= (x - 2) && point.x <= (x + 2))                                    selection.add(indicator);                            }                            break;                        }                    }                }            }        }                return (Indicator[])selection.toArray(new Indicator[selection.size()]);    }        public ObjectPlugin getObjectSelection()    {        return objectSelection;    }        public void setObjectSelection(ObjectPlugin selection)    {        this.selection = null;        this.objectSelection = selection;    }    /**     * Returns a possibly empty array of all drawing objects at the given position.     *      * @param x - x position     * @param y - y position     * @return an array of objects     */    public ObjectPlugin[] getObjectAt(int x, int y)    {        List selection = new ArrayList();                for (int i = objects.size() - 1; i >= 0; i--)        {            ObjectPlugin object = (ObjectPlugin)objects.get(i);            if (object.isOverLine(x, y))                selection.add(object);        }                return (ObjectPlugin[])selection.toArray(new ObjectPlugin[selection.size()]);    }        public void redrawAll()    {        if (needRepaint == false)        {            needRepaint = true;            redraw();        }    }        protected Scaler getScaler(Indicator indicator, PlotLine plotLine)    {        Scaler indicatorScaler = scaler;        if (plotLine.getScaleFlag())        {            indicatorScaler = new Scaler();            indicatorScaler.setExtendRange(scaler.getExtendRange());            indicatorScaler.set(scaler.getHeight(), plotLine.getHigh(), plotLine.getLow(), scaler.getLogScaleHigh(), scaler.getLogRange(), scaler.getLogFlag());            if (isAutoScale())                computeScale(indicatorScaler, plotLine);        }        else if (indicator.getScaleFlag())        {            indicatorScaler = new Scaler();            indicatorScaler.setExtendRange(scaler.getExtendRange());            indicatorScaler.set(scaler.getHeight(), indicator.getHigh(), indicator.getLow(), scaler.getLogScaleHigh(), scaler.getLogRange(), scaler.getLogFlag());            if (isAutoScale())            {                double high = -99999999;                double low = 99999999;                for (Iterator iter = indicator.getLines().iterator(); iter.hasNext(); )                {                    PlotLine line = (PlotLine)iter.next();                    if (!line.getScaleFlag())                    {                        int first = ((- getPlotLocation().x) - getMarginWidth() - getGridWidth() / 2) / getGridWidth();                        if (first > 0)                            first--;                        int bars = (getBounds().width / getGridWidth()) + 1;                        switch(line.getType())                        {                            case PlotLine.DOT:                            case PlotLine.DASH:                            case PlotLine.LINE:                            case PlotLine.HISTOGRAM:                            case PlotLine.HISTOGRAM_BAR:                            {                                int ofs = barData.size() - line.getSize();                                int x = first - ofs;                                for (int i = 0; i < bars; i++, x++)                                {                                    if (x >= 0 && x < line.getSize())                                    {                                        double value = line.getData(x);                                         if (value > high)                                            high = value;                                        if (value < low)                                            low = value;                                    }                                }                                break;                            }                            case PlotLine.BAR:                            case PlotLine.CANDLE:                            {                                int ofs = barData.size() - line.getSize();                                int x = first - ofs;                                for (int i = 0; i < bars; i++, x++)                                {                                    if (x >= 0 && x < line.getSize())                                    {                                        Bar bar = line.getBar(x);                                         if (bar.getHigh() > high)                                            high = bar.getHigh();                                        if (bar.getLow() < low)                                            low = bar.getLow();                                    }                                }                                break;                            }                        }                    }                }                if (high != -99999999 && low != 99999999)                    indicatorScaler.set(high, low);            }        }                return indicatorScaler;    }        protected void computeScale(Scaler scaler, PlotLine plotLine)    {        int first = ((- getPlotLocation().x) - getMarginWidth() - getGridWidth() / 2) / getGridWidth();        if (first > 0)            first--;        int bars = (getBounds().width / getGridWidth()) + 1;        double high = -99999999;        double low = 99999999;        switch(plotLine.getType())        {            case PlotLine.DOT:            case PlotLine.DASH:            case PlotLine.LINE:            case PlotLine.HISTOGRAM:            case PlotLine.HISTOGRAM_BAR:            {                int ofs = barData.size() - plotLine.getSize();                int x = first - ofs;                for (int i = 0; i < bars; i++, x++)                {                    if (x >= 0 && x < plotLine.getSize())                    {                        double value = plotLine.getData(x);                         if (value > high)                            high = value;                        if (value < low)                            low = value;                    }                }                break;            }            case PlotLine.BAR:            case PlotLine.CANDLE:            {                int ofs = barData.size() - plotLine.getSize();                int x = first - ofs;                for (int i = 0; i < bars; i++, x++)                {                    if (x >= 0 && x < plotLine.getSize())                    {                        Bar bar = plotLine.getBar(x);                         if (bar.getHigh() > high)                            high = bar.getHigh();                        if (bar.getLow() < low)                            low = bar.getLow();                    }                }                break;            }        }        if (high != -99999999 && low != 99999999)            scaler.set(high, low);    }        public void draw(GC gc)    {        Rectangle bounds = image.getBounds();         Color background = getBackground();        Color foreground = getForeground();                if (background != null)            gc.setBackground(background);        if (foreground != null)            gc.setForeground(foreground);        gc.fillRectangle(bounds);        if (scaler != null && barData.size() != 0)        {            drawGrid(gc, bounds);                        for (Iterator iter = indicators.iterator(); iter.hasNext(); )            {                Indicator indicator = (Indicator)iter.next();                for (Iterator iter2 = indicator.iterator(); iter2.hasNext(); )                {                    PlotLine plotLine = (PlotLine)iter2.next();                    Scaler indicatorScaler = getScaler(indicator, plotLine);                                        switch(plotLine.getType())                    {                        case PlotLine.HISTOGRAM:                            drawHistogram(gc, plotLine, indicatorScaler, selection == indicator);                            break;                        case PlotLine.HISTOGRAM_BAR:                            drawHistogramBars(gc, plotLine, indicatorScaler, selection == indicator);                            break;                        case PlotLine.BAR:                            drawBars(gc, plotLine, indicatorScaler, selection == indicator);                            break;                        case PlotLine.CANDLE:                            drawCandles(gc, plotLine, indicatorScaler, selection == indicator);                            break;                    }                }            }                        for (Iterator iter = indicators.iterator(); iter.hasNext(); )            {                Indicator indicator = (Indicator)iter.next();                for (Iterator iter2 = indicator.iterator(); iter2.hasNext(); )                {                    PlotLine plotLine = (PlotLine)iter2.next();                    Scaler indicatorScaler = getScaler(indicator, plotLine);                    switch(plotLine.getType())                    {                        case PlotLine.DOT:                        case PlotLine.DASH:                        case PlotLine.LINE:                            drawLine(gc, plotLine, indicatorScaler, selection == indicator);                            break;                        case PlotLine.HORIZONTAL:                            drawHorizontalLine(gc, plotLine, indicatorScaler);                            break;                    }                }            }        }        if (background != null)            background.dispose();        if (foreground != null)            foreground.dispose();    }        /* (non-Javadoc)     * @see org.eclipse.swt.events.PaintListener#paintControl(org.eclipse.swt.events.PaintEvent)     */    public void paintControl(PaintEvent e)    {        if (image != null && !image.isDisposed())        {            if (image.getBounds().width < getBounds().width)                drawGrid(e.gc, getBounds());            if (needRepaint)            {                GC gc = new GC(image);                draw(gc);                gc.dispose();                needRepaint = false;            }            e.gc.drawImage(image, plotLocation.x, plotLocation.y);            if (marketValue != -1)            {                int y = scaler.convertToY(marketValue);                e.gc.drawLine(0, y, getSize().x, y);            }

⌨️ 快捷键说明

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