📄 indicatorplot.java
字号:
if (scaler != null && barData.size() != 0) { for (Iterator iter = objects.iterator(); iter.hasNext(); ) { ObjectPlugin object = (ObjectPlugin)iter.next(); object.drawObject(e.gc, objectSelection == object); } } } } /* (non-Javadoc) * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent) */ public void widgetDisposed(DisposeEvent e) { for (Iterator iter = indicators.iterator(); iter.hasNext(); ) ((Indicator)iter.next()).dispose(); for (Iterator iter = objects.iterator(); iter.hasNext(); ) ((ObjectPlugin)iter.next()).dispose(); if (image != null && !image.isDisposed()) image.dispose(); if (gridColor != null) gridColor.dispose(); } private void drawGrid(GC gc, Rectangle bounds) { if (scaler == null) return; List scaleArray = scaler.getScaleArray(); if (gridColor != null) gc.setForeground(gridColor); int dashes[] = { 3, 3 }; gc.setLineDash(dashes); int loop; for (loop = 0; loop < scaleArray.size(); loop++) { int y = scaler.convertToY(((Double) scaleArray.get(loop)).doubleValue()); String s = nf.format((Double) scaleArray.get(loop)); int h = gc.stringExtent(s).y / 2; if ((y + h) <= bounds.height) gc.drawLine(0, y, bounds.width, y); } gc.setLineStyle(SWT.LINE_SOLID); } private void drawLine(GC gc, PlotLine plotLine, Scaler scaler, boolean selected) { 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++] = scaler.convertToY(plotLine.getData(i)); } gc.setLineStyle(SWT.LINE_SOLID); if (plotLine.getType() == PlotLine.DOT) { int[] dashes = { 1, 2 }; gc.setLineDash(dashes); } else if (plotLine.getType() == PlotLine.DASH) { int[] dashes = { 3, 3 }; gc.setLineDash(dashes); } gc.setForeground(plotLine.getColor()); gc.drawPolyline(pointArray); // Draw the selection marks if (selected && pointArray.length > 0) { gc.setBackground(plotLine.getColor()); int length = pointArray.length / 2; if (length <= 20) { gc.fillRectangle(pointArray[0] - 2, pointArray[1] - 2, 5, 5); gc.fillRectangle(pointArray[(length / 2) * 2] - 2, pointArray[(length / 2) * 2 + 1] - 2, 5, 5); } else { for (int i = 0; i < length - 5; i += 10) gc.fillRectangle(pointArray[i * 2] - 2, pointArray[i * 2 + 1] - 2, 5, 5); } gc.fillRectangle(pointArray[pointArray.length - 2] - 2, pointArray[pointArray.length - 2] - 1, 5, 5); } } private void drawHorizontalLine(GC gc, PlotLine plotLine, Scaler scaler) { gc.setLineStyle(SWT.LINE_SOLID); gc.setForeground(plotLine.getColor()); int x1 = getMarginWidth() + getGridWidth() / 2; int x2 = x1 + getGridWidth() * barData.size(); for (int i = 0; i < plotLine.getSize(); i++) { int y = scaler.convertToY(plotLine.getDouble(i).doubleValue()); if (plotLine.getColor(i) != null) gc.setForeground(plotLine.getColor(i)); gc.drawLine(x1, y, x2, y); } } private void drawCandles(GC gc, PlotLine plotLine, Scaler scaler, boolean selected) { gc.setLineStyle(SWT.LINE_SOLID); gc.setForeground(plotLine.getColor()); int ofs = barData.size() - plotLine.getSize(); int x = getMarginWidth() + getGridWidth() / 2 + ofs * getGridWidth(); for (int i = 0; i < plotLine.getSize(); i++, x += getGridWidth()) { Bar bar = plotLine.getBar(i); int h = scaler.convertToY(bar.getHigh()); int l = scaler.convertToY(bar.getLow()); int c = scaler.convertToY(bar.getClose()); int o = scaler.convertToY(bar.getOpen()); if (plotLine.getColor(i) != null) gc.setBackground(plotLine.getColor(i)); gc.drawLine(x, h, x, c); gc.drawLine(x, o, x, l); if (o == c) gc.drawLine(x - 2, c, x + 2, c); else { gc.fillRectangle(x - 2, c, 5, o - c); gc.drawRectangle(x - 2, c, 5, o - c); } } // Draw the selection marks if (selected) { 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++] = scaler.convertToY(plotLine.getBar(i).getLow() + (plotLine.getBar(i).getHigh() - plotLine.getBar(i).getLow()) / 2); } if (pointArray.length > 0) { gc.setBackground(selectionMarks); int length = pointArray.length / 2; if (length <= 20) { gc.fillRectangle(pointArray[0] - 1, pointArray[1] - 1, 5, 5); gc.fillRectangle(pointArray[(length / 2) * 2] - 1, pointArray[(length / 2) * 2 + 1] - 1, 5, 5); } else { for (int i = 0; i < length - 5; i += 10) gc.fillRectangle(pointArray[i * 2] - 1, pointArray[i * 2 + 1] - 1, 5, 5); } gc.fillRectangle(pointArray[pointArray.length - 2] - 1, pointArray[pointArray.length - 1] - 1, 5, 5); } } } private void drawBars(GC gc, PlotLine plotLine, Scaler scaler, boolean selected) { gc.setLineStyle(SWT.LINE_SOLID); gc.setForeground(plotLine.getColor()); int ofs = barData.size() - plotLine.getSize(); int x = getMarginWidth() + getGridWidth() / 2 + ofs * getGridWidth(); for (int i = 0; i < plotLine.getSize(); i++, x += getGridWidth()) { if (plotLine.getColor(i) != null) gc.setForeground(plotLine.getColor(i)); int y = scaler.convertToY(plotLine.getBar(i).getOpen()); gc.drawLine(x - 2, y, x, y); y = scaler.convertToY(plotLine.getBar(i).getClose()); gc.drawLine(x, y, x + 2, y); int y1 = scaler.convertToY(plotLine.getBar(i).getHigh()); int y2 = scaler.convertToY(plotLine.getBar(i).getLow()); gc.drawLine(x, y1, x, y2); } // Draw the selection marks if (selected) { 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++] = scaler.convertToY(plotLine.getBar(i).getLow() + (plotLine.getBar(i).getHigh() - plotLine.getBar(i).getLow()) / 2); } if (pointArray.length > 0) { gc.setBackground(selectionMarks); int length = pointArray.length / 2; if (length <= 20) { gc.fillRectangle(pointArray[0] - 1, pointArray[1] - 1, 5, 5); gc.fillRectangle(pointArray[(length / 2) * 2] - 1, pointArray[(length / 2) * 2 + 1] - 1, 5, 5); } else { for (int i = 0; i < length - 5; i += 10) gc.fillRectangle(pointArray[i * 2] - 1, pointArray[i * 2 + 1] - 1, 5, 5); } gc.fillRectangle(pointArray[pointArray.length - 2] - 1, pointArray[pointArray.length - 1] - 1, 5, 5); } } } private void drawHistogram(GC gc, PlotLine plotLine, Scaler scaler, boolean selected) { gc.setLineStyle(SWT.LINE_SOLID); gc.setBackground(plotLine.getColor()); int zero = scaler.convertToY(0); int ofs = barData.size() - plotLine.getSize(); int x = -1; int x2 = getMarginWidth() + getGridWidth() / 2 + ofs * getGridWidth(); int y = -1; int y2 = -1; int[] pointArray = new int[8]; for (int i = 0; i < plotLine.getSize(); i++, x2 += getGridWidth()) { y2 = scaler.convertToY(plotLine.getData(i)); pointArray[0] = x; pointArray[1] = zero; pointArray[2] = x; pointArray[3] = y; pointArray[4] = x2; pointArray[5] = y2; pointArray[6] = x2; pointArray[7] = zero; if (y != -1) gc.fillPolygon(pointArray); x = x2; y = y2; } // Draw the selection marks if (selected && plotLine.getSize() > 0) { ofs = barData.size() - plotLine.getSize(); x = getMarginWidth() + getGridWidth() / 2 + ofs * getGridWidth(); pointArray = new int[plotLine.getSize() * 2]; for (int i = 0, pa = 0; i < plotLine.getSize(); i++, x += getGridWidth()) { pointArray[pa++] = x; pointArray[pa++] = scaler.convertToY(plotLine.getData(i)); } gc.setBackground(plotLine.getColor()); int length = pointArray.length / 2; if (length <= 20) { gc.fillRectangle(pointArray[0] - 2, pointArray[1] - 2, 5, 5); gc.fillRectangle(pointArray[(length / 2) * 2] - 2, pointArray[(length / 2) * 2 + 1] - 2, 5, 5); } else { for (int i = 0; i < length - 5; i += 10) gc.fillRectangle(pointArray[i * 2] - 2, pointArray[i * 2 + 1] - 2, 5, 5); } gc.fillRectangle(pointArray[pointArray.length - 2] - 2, pointArray[pointArray.length - 2] - 1, 5, 5); } } private void drawHistogramBars(GC gc, PlotLine plotLine, Scaler scaler, boolean selected) { gc.setLineStyle(SWT.LINE_SOLID); 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)); Color color = plotLine.getColor(i); if (color == null) color = plotLine.getColor(); gc.setBackground(color); gc.fillRectangle(x - 1, y, 3, zero - y); } // Draw the selection marks if (selected && plotLine.getSize() > 0) { ofs = barData.size() - plotLine.getSize(); 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++] = scaler.convertToY(plotLine.getData(i)); } gc.setBackground(plotLine.getColor()); int length = pointArray.length / 2; if (length <= 20) { gc.fillRectangle(pointArray[0] - 2, pointArray[1] - 2, 5, 5); gc.fillRectangle(pointArray[(length / 2) * 2] - 2, pointArray[(length / 2) * 2 + 1] - 2, 5, 5); } else { for (int i = 0; i < length - 5; i += 10) gc.fillRectangle(pointArray[i * 2] - 2, pointArray[i * 2 + 1] - 2, 5, 5); } gc.fillRectangle(pointArray[pointArray.length - 2] - 2, pointArray[pointArray.length - 2] - 1, 5, 5); } } public void setMarketValue(double value) { marketValue = value; redraw(); } public void hideMarketValue() { marketValue = -1; redraw(); } public boolean isAutoScale() { return autoScale; } public void setAutoScale(boolean autoScale) { this.autoScale = autoScale; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -