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

📄 plot.java

📁 EclipseTrader is a stock exchange analysis system, featuring shares pricing watch, intraday and hi
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                            item.setData(line.getBar(line.getSize() - 1));                    }                    else                    {                        NumberSummaryItem item = (NumberSummaryItem)line.getData();                        item.setData(line.getDouble(line.getSize() - 1));                    }                }            }        }                summary.layout();    }    public void addObject(ObjectPlugin object)    {        object.setPlot(this);        indicatorPlot.addObject(object);        if (drawCount <= 0)            indicatorPlot.redrawAll();    }        public void removeObject(ObjectPlugin object)    {        indicatorPlot.removeObject(object);        if (drawCount <= 0)            indicatorPlot.redrawAll();    }    public IndicatorPlot getIndicatorPlot()    {        return indicatorPlot;    }    public ScalePlot getScalePlot()    {        return scalePlot;    }    public void setScaleWidth(int scaleWidth)    {        this.scaleWidth = scaleWidth;        ((GridData)scalePlot.getLayoutData()).widthHint = this.scaleWidth;    }        public Summary getSummary()    {        return summary;    }    public Scaler getScaler()    {        return scaler;    }        public DatePlot getDatePlot()    {        return datePlot;    }    public void setDatePlot(DatePlot datePlot)    {        this.datePlot = datePlot;        indicatorPlot.setBarData(datePlot.getBarData());    }    /* (non-Javadoc)     * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)     */    public void mouseDoubleClick(MouseEvent e)    {    }        public void addPlotSelectionListener(PlotSelectionListener listener)    {        selectionListeners.add(listener);    }        public void removePlotSelectionListener(PlotSelectionListener listener)    {        selectionListeners.remove(listener);    }        public void createNewObject(ObjectPlugin plugin, PlotMouseEvent e)    {        plugin.setPlot(this);        indicatorPlot.setObjectSelection(plugin);        if (currentCursor != crossCursor)        {            indicatorPlot.setCursor(crossCursor);            currentCursor = crossCursor;        }        plugin.mouseDown(e);        buttonDown = true;    }        private PlotMouseEvent createPlotMouseEvent(MouseEvent e)    {        PlotMouseEvent plotMouseEvent = new PlotMouseEvent();        plotMouseEvent.x = e.x - indicatorPlot.getPlotLocation().x;        plotMouseEvent.y = e.y;        plotMouseEvent.display = getDisplay();        plotMouseEvent.plot = this;        plotMouseEvent.mouse = new Point(e.x, e.y);        plotMouseEvent.button = e.button;        if (scaler != null)        {            plotMouseEvent.value = scaler.convertToValue(e.y);            plotMouseEvent.roundedValue = Scaler.roundToTick(plotMouseEvent.value);        }        if (datePlot != null)            plotMouseEvent.date = datePlot.mapToDate(plotMouseEvent.x);                return plotMouseEvent;    }        /* (non-Javadoc)     * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)     */    public void mouseDown(MouseEvent e)    {        PlotMouseEvent plotMouseEvent = createPlotMouseEvent(e);                Object[] selection = indicatorPlot.getElementsAt(new Point(plotMouseEvent.x, plotMouseEvent.y));        if (selection.length != 0)        {            int index = -1;            for (int i = 0; i < selection.length; i++)            {                if (selection[i] == indicatorPlot.getObjectSelection())                    index = i;                if (selection[i] == indicatorPlot.getSelection())                    index = i;            }            if (index == -1 || e.button == 1)                index++;            if (index >= selection.length)                index = 0;            if (selection[index] instanceof ObjectPlugin)            {                if (selection[index] != indicatorPlot.getObjectSelection())                {                    indicatorPlot.setObjectSelection((ObjectPlugin)selection[index]);                    indicatorPlot.redrawAll();                }                Event event = new Event();                event.x = e.x - indicatorPlot.getPlotLocation().x;                event.y = e.y;                event.type = SWT.Selection;                event.display = getDisplay();                event.widget = this;                PlotSelectionEvent selectionEvent = new PlotSelectionEvent(event);                selectionEvent.plot = this;                selectionEvent.object = (ObjectPlugin)selection[index];                for (Iterator iter = selectionListeners.iterator(); iter.hasNext(); )                    ((PlotSelectionListener)iter.next()).plotSelected(selectionEvent);                if (e.button == 1)                {                    buttonDown = true;                    ((ObjectPlugin)selection[index]).mouseDown(plotMouseEvent);                }                else if (currentCursor != null)                {                    indicatorPlot.setCursor(null);                    currentCursor = null;                }            }            else if (selection[index] instanceof Indicator && selection[index] != getIndicatorPlot().getSelection())            {                indicatorPlot.setSelection((Indicator)selection[index]);                indicatorPlot.redrawAll();                Event event = new Event();                event.x = e.x - indicatorPlot.getPlotLocation().x;                event.y = e.y;                event.type = SWT.Selection;                event.display = getDisplay();                event.widget = this;                PlotSelectionEvent selectionEvent = new PlotSelectionEvent(event);                selectionEvent.plot = this;                selectionEvent.indicator = (Indicator)selection[index];                for (Iterator iter = selectionListeners.iterator(); iter.hasNext(); )                    ((PlotSelectionListener)iter.next()).plotSelected(selectionEvent);            }            return;        }        if (e.button == 1)        {            if (getIndicatorPlot().getSelection() != null || indicatorPlot.getObjectSelection() != null)            {                indicatorPlot.setObjectSelection(null);                indicatorPlot.setSelection(null);                indicatorPlot.redrawAll();                Event event = new Event();                event.x = e.x - indicatorPlot.getPlotLocation().x;                event.y = e.y;                event.type = SWT.Selection;                event.display = getDisplay();                event.widget = this;                PlotSelectionEvent selectionEvent = new PlotSelectionEvent(event);                selectionEvent.plot = this;                for (Iterator iter = selectionListeners.iterator(); iter.hasNext(); )                    ((PlotSelectionListener)iter.next()).plotSelected(selectionEvent);                return;            }            buttonDown = true;        }        for (Iterator iter = plotMouseListeners.iterator(); iter.hasNext(); )            ((PlotMouseListener)iter.next()).mouseDown(plotMouseEvent);    }    /* (non-Javadoc)     * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)     */    public void mouseUp(MouseEvent e)    {        PlotMouseEvent plotMouseEvent = createPlotMouseEvent(e);        if (buttonDown)        {            buttonDown = false;            if (indicatorPlot.getObjectSelection() != null)                indicatorPlot.getObjectSelection().mouseUp(plotMouseEvent);            for (Iterator iter = plotMouseListeners.iterator(); iter.hasNext(); )                ((PlotMouseListener)iter.next()).mouseUp(plotMouseEvent);        }    }    /* (non-Javadoc)     * @see org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent)     */    public void mouseMove(MouseEvent e)    {        PlotMouseEvent plotMouseEvent = createPlotMouseEvent(e);        if (buttonDown)        {            if (indicatorPlot.getObjectSelection() != null)            {                indicatorPlot.getObjectSelection().mouseMove(plotMouseEvent);                return;            }            for (Iterator iter = plotMouseListeners.iterator(); iter.hasNext(); )                ((PlotMouseListener)iter.next()).mouseMove(plotMouseEvent);        }        else        {            for (Iterator iter = indicatorPlot.getObjects().iterator(); iter.hasNext(); )            {                ObjectPlugin plugin = (ObjectPlugin)iter.next();                if (plugin.isOverHandle(plotMouseEvent.x, plotMouseEvent.y))                {                    if (currentCursor != crossCursor)                    {                        indicatorPlot.setCursor(crossCursor);                        currentCursor = crossCursor;                    }                    return;                }                else if (plugin.isOverLine(plotMouseEvent.x, plotMouseEvent.y))                {                    if (currentCursor != handCursor)                    {                        indicatorPlot.setCursor(handCursor);                        currentCursor = handCursor;                    }                    return;                }            }            if (currentCursor != null)            {                indicatorPlot.setCursor(null);                currentCursor = null;            }        }    }    public void addPlotMouseListener(PlotMouseListener listener)    {        if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);        plotMouseListeners.add(listener);    }    public void removePlotMouseListener(PlotMouseListener listener)    {        if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);        plotMouseListeners.remove(listener);    }    public void updateScale()    {        BarData barData = datePlot.getBarData();        if (barData.size() != 0)        {            int first = ((- indicatorPlot.getPlotLocation().x) - indicatorPlot.getMarginWidth() - indicatorPlot.getGridWidth() / 2) / indicatorPlot.getGridWidth();            if (first > 0)                first--;            int bars = (indicatorPlot.getBounds().width / indicatorPlot.getGridWidth()) + 1;            double high = -99999999;            double low = 99999999;                        for (Iterator iter = indicatorPlot.getIndicators().iterator(); iter.hasNext(); )            {                Indicator indicator = (Indicator)iter.next();                if (indicator.getScaleFlag() && high != -99999999)                    continue;                                for (Iterator iter2 = indicator.iterator(); iter2.hasNext(); )                {                    PlotLine plotLine = (PlotLine)iter2.next();                    if (plotLine.getScaleFlag() && high != -99999999)                        continue;                    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;                        }                    }                }            }            scaler.set(high, low);            if (drawCount <= 0)            {                indicatorPlot.redrawAll();                scalePlot.redrawAll();            }        }    }    public void resetScale()    {        BarData barData = datePlot.getBarData();        if (barData.size() != 0)        {            double high = -99999999;            double low = 99999999;                        for (Iterator iter = indicatorPlot.getIndicators().iterator(); iter.hasNext(); )            {                Indicator indicator = (Indicator)iter.next();                if (indicator.getScaleFlag() && high != -99999999)                    continue;                                for (Iterator iter2 = indicator.iterator(); iter2.hasNext(); )                {                    PlotLine plotLine = (PlotLine)iter2.next();                    if (!plotLine.getScaleFlag() || high == -99999999)                    {                        if (plotLine.getHigh() > high)                            high = plotLine.getHigh();                        if (plotLine.getLow() < low)                            low = plotLine.getLow();                    }                }            }            scaler.set(high, low);            if (drawCount <= 0)            {                indicatorPlot.redrawAll();                scalePlot.redrawAll();            }        }    }}

⌨️ 快捷键说明

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