📄 chartview.java
字号:
{ chart.setPeriod(period); CorePlugin.getRepository().save(chart); } public void setPeriod(Date beginDate, Date endDate) { chart.setPeriod(PERIOD_CUSTOM); chart.setBeginDate(beginDate); chart.setEndDate(endDate); CorePlugin.getRepository().save(chart); } public void setNewChartObject(ChartObject object) { this.newChartObject = object; for(Iterator iter = tabGroups.iterator(); iter.hasNext(); ) { CTabFolder folder = (CTabFolder)iter.next(); Plot plot = (Plot)folder.getSelection().getControl(); if (plot.getIndicatorPlot().getSelection() != null || plot.getIndicatorPlot().getObjectSelection() != null) { plot.getIndicatorPlot().deselectAll(); plot.getIndicatorPlot().redrawAll(); plot.getIndicatorPlot().update(); } } sashForm.setCursor(new Cursor(null, SWT.CURSOR_CROSS)); } private void updateScrollbar() { Rectangle plotBounds = datePlot.getIndicatorPlot().getPlotBounds(); if (plotBounds.width != 0) { Rectangle controlRect = datePlot.getIndicatorPlot().getBounds(); if (plotBounds.width < controlRect.width) plotBounds.x = controlRect.width - plotBounds.width; else { if (!hBar.getVisible()) { hBar.setMaximum (plotBounds.width); hBar.setThumb(Math.min(plotBounds.width, controlRect.width)); int hPage = plotBounds.width - controlRect.width; hBar.setSelection(hPage); plotBounds.x = -hPage; } else { int hPage = hBar.getSelection() + (plotBounds.width - hBar.getMaximum()); if ((hPage + controlRect.width) > plotBounds.width) hPage = plotBounds.width - controlRect.width; hBar.setMaximum (plotBounds.width); hBar.setThumb(Math.min(plotBounds.width, controlRect.width));// plotBounds.x = -hBar.getSelection(); hBar.setSelection(hPage); plotBounds.x = -hPage; } } hBar.setVisible(plotBounds.width > controlRect.width); datePlot.getIndicatorPlot().setPlotBounds(plotBounds); setPlotBounds(plotBounds); } else if (hBar.getVisible()) hBar.setVisible(false); } private void setPlotBounds(Rectangle bounds) { for(Iterator iter = tabGroups.iterator(); iter.hasNext(); ) { CTabFolder folder = (CTabFolder)iter.next(); CTabItem[] items = folder.getItems(); for (int i = 0; i < items.length; i++) { ((Plot)items[i].getControl()).getIndicatorPlot().setPlotBounds(bounds); if (autoScale) ((Plot)items[i].getControl()).updateScale(); } } } public void setSecurity(Security newSecurity) { if (!newSecurity.equals(security)) { if (showMarketValue) { security.getQuoteMonitor().deleteObserver(quoteObserver); FeedMonitor.cancelMonitor(security); } security = newSecurity; setTitleToolTip(newSecurity.getDescription()); setContentDescription(followSelection ? security.getDescription() : ""); chart.setSecurity(newSecurity); for(Iterator iter1 = chart.getRows().iterator(); iter1.hasNext(); ) { ChartRow row = (ChartRow)iter1.next(); for (Iterator iter2 = row.getTabs().iterator(); iter2.hasNext(); ) { ChartTab tab = (ChartTab)iter2.next(); ChartObject[] obj = (ChartObject[])tab.getObjects().toArray(new ChartObject[tab.getObjects().size()]); for (int i = 0; i < obj.length; i++) tab.getObjects().remove(obj[i]); } } if (showMarketValue) { security.getQuoteMonitor().addObserver(quoteObserver); quoteObserver.update(security, security.getQuote()); FeedMonitor.monitor(security); } CorePlugin.getRepository().save(chart); } } public void redrawView() { for(Iterator iter = tabGroups.iterator(); iter.hasNext(); ) { CTabFolder folder = (CTabFolder)iter.next(); CTabItem[] items = folder.getItems(); for (int i = 0; i < items.length; i++) { if (autoScale) ((Plot)items[i].getControl()).updateScale(); else ((Plot)items[i].getControl()).resetScale(); } } } public void resetViewLayout() { Control[] controls = sashForm.getChildren(); for (int i = 0; i < controls.length; i++) { if (controls[i] instanceof ChartTabFolder) controls[i].removeControlListener(sashResizeListener); } try { sashForm.getDisplay().asyncExec(new Runnable() { public void run() { int[] weights = new int[tabGroups.size()]; int w = 100 / (weights.length + 2); weights[0] = 100 - w * (weights.length - 1); for (int i = 1; i < weights.length; i++) weights[i] = w; sashForm.setWeights(weights); sashForm.layout(); Control[] controls = sashForm.getChildren(); for (int i = 0; i < controls.length; i++) { if (controls[i] instanceof ChartTabFolder) controls[i].addControlListener(sashResizeListener); } String values = ""; for (int i = 0; i < weights.length; i++) values += (i == 0 ? "" : ";") + String.valueOf(weights[i]); preferences.setValue(PREFS_WEIGHTS, values); } }); } catch(Exception e) { e.printStackTrace(); } } protected void updateObservers() { for (Iterator iter = observedHistories.iterator(); iter.hasNext(); ) { History security = (History)iter.next(); security.deleteObserver(chartUpdateObserver); } observedHistories.clear(); chart.accept(new ChartVisitorAdapter() { public void visit(Chart chart) { if (datePlot.getInterval() < BarData.INTERVAL_DAILY) { History history = chart.getSecurity().getIntradayHistory(); history.addObserver(chartUpdateObserver); observedHistories.add(history); } else { History history = chart.getSecurity().getHistory(); history.addObserver(chartUpdateObserver); observedHistories.add(history); } } public void visit(ChartIndicator indicator) { String securityId = (String)indicator.getParameters().get("securityId"); if (securityId != null) { Security security = (Security)CorePlugin.getRepository().load(Security.class, new Integer(securityId)); if (security != null) { if (datePlot.getInterval() < BarData.INTERVAL_DAILY) { History history = security.getIntradayHistory(); history.addObserver(chartUpdateObserver); observedHistories.add(history); } else { History history = security.getHistory(); history.addObserver(chartUpdateObserver); observedHistories.add(history); } } } } }); } public void updateView() { datePlot.setInterval(chart.getCompression()); if (datePlot.getInterval() < BarData.INTERVAL_DAILY) datePlot.setBarData(new BarData(security.getIntradayHistory().getList()).getCompressed(datePlot.getInterval())); else { int period = chart.getPeriod(); int size = security.getHistory().size(); BarData barData = new BarData(showAdjustedValues ? security.getAdjustedHistory().getList() : security.getHistory().getList()); if (period != PERIOD_ALL && size != 0) { Date end = barData.getEnd(); Calendar calendar = Calendar.getInstance(); calendar.setTime(end); switch(period) { case PERIOD_LAST6MONTHS: calendar.add(Calendar.MONTH, -6); break; case PERIOD_LASTYEAR: calendar.add(Calendar.MONTH, -12); break; case PERIOD_LAST2YEARS: calendar.add(Calendar.MONTH, -24); break; case PERIOD_CUSTOM: calendar.setTime(chart.getBeginDate()); end = chart.getEndDate(); break; } barData = barData.getPeriod(calendar.getTime(), end); } if (datePlot.getInterval() != BarData.INTERVAL_DAILY) barData = barData.getCompressed(datePlot.getInterval()); datePlot.setBarData(barData); } for(Iterator iter = tabGroups.iterator(); iter.hasNext(); ) { CTabFolder folder = (CTabFolder)iter.next(); CTabItem[] items = folder.getItems(); for (int i = 0; i < items.length; i++) ((ChartTabItem)items[i]).update(); } quoteObserver.update(security, security.getQuote()); } /* (non-Javadoc) * @see java.util.Observer#update(java.util.Observable, java.lang.Object) */ public void update(Observable o, Object arg) { sashForm.getDisplay().asyncExec(new Runnable() { public void run() { if (!sashForm.isDisposed()) { setPartName(chart.getTitle()); updateActionBars(); updateView(); } } }); } /* (non-Javadoc) * @see net.sourceforge.eclipsetrader.core.ICollectionObserver#itemAdded(java.lang.Object) */ public void itemAdded(Object o) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -