📄 chartview.java
字号:
Rectangle plotBounds = datePlot.getIndicatorPlot().getPlotBounds(); int hSelection = hBar.getSelection(); plotBounds.x = -hSelection; datePlot.getIndicatorPlot().setPlotBounds(plotBounds); setPlotBounds(plotBounds); } }); getSite().setSelectionProvider(new ChartSelectionProvider()); getSite().getSelectionProvider().setSelection(new NullSelection()); getSite().getPage().addSelectionListener(this); IActionBars actionBars = getViewSite().getActionBars(); actionBars.setGlobalActionHandler("settings", new Action() { //$NON-NLS-1$ public void run() { ChartSettingsDialog dlg = new ChartSettingsDialog(getChart(), getViewSite().getShell()); dlg.open(); } }); actionBars.setGlobalActionHandler("cut", cutAction = new CutAction(this)); //$NON-NLS-1$ actionBars.setGlobalActionHandler("copy", copyAction = new CopyAction(this)); //$NON-NLS-1$ actionBars.setGlobalActionHandler("paste", pasteAction = new PasteAction(this)); //$NON-NLS-1$ actionBars.setGlobalActionHandler("pasteSpecial", pasteSpecialAction = new PasteSpecialAction(this)); //$NON-NLS-1$ actionBars.setGlobalActionHandler("delete", deleteAction = new DeleteAction(this)); //$NON-NLS-1$ Integer id = new Integer(Integer.parseInt(getViewSite().getSecondaryId())); chart = (Chart)CorePlugin.getRepository().load(Chart.class, id); preferences = new PreferenceStore(getPreferenceStoreLocation(chart).toOSString()); preferences.setDefault(PREFS_FOLLOW_SELECTION, DEFAULT_FOLLOW_SELECTION); preferences.setDefault(PREFS_SHOW_ADJUSTED_VALUES, DEFAULT_SHOW_ADJUSTED_VALUES); preferences.setDefault(PREFS_SHOW_MARKETVALUE, DEFAULT_SHOW_MARKET_VALUE); try { preferences.load(); } catch(Exception e) { } security = chart.getSecurity(); setPartName(chart.getTitle()); setTitleToolTip(security.getDescription()); autoScale = chart.isAutoScale(); followSelection = preferences.getBoolean(PREFS_FOLLOW_SELECTION); showAdjustedValues = preferences.getBoolean(PREFS_SHOW_ADJUSTED_VALUES); showMarketValue = preferences.getBoolean(PREFS_SHOW_MARKETVALUE); updateActionBars(); setContentDescription(followSelection ? security.getDescription() : ""); IPreferenceStore pluginPreferences = ChartsPlugin.getDefault().getPreferenceStore(); datePlot.setExtendPeriod(pluginPreferences.getInt(ChartsPlugin.PREFS_EXTEND_PERIOD)); pluginPreferences.addPropertyChangeListener(pluginPropertiesChangeListener); try { sashForm.getDisplay().asyncExec(new Runnable() { public void run() { 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); }/* Calendar day = Calendar.getInstance(); for (Iterator iter = datePlot.getBarData().iterator(); iter.hasNext(); ) { Bar bar = (Bar)iter.next(); day.setTime(bar.getDate()); System.out.println("day.set(" + day.get(Calendar.YEAR) + ", " + day.get(Calendar.MONTH) + ", " + day.get(Calendar.DAY_OF_MONTH) + ", 0, 0, 0);"); System.out.println("barData.append(new Bar(day.getTime(), " + bar.getOpen() + ", " + bar.getHigh() + ", " + bar.getLow() + ", " + bar.getClose() + ", " + bar.getVolume() + "));"); }*/ try { for (int r = 0; r < chart.getRows().size(); r++) itemAdded(chart.getRows().get(r)); chart.getRows().addCollectionObserver(ChartView.this); chart.addObserver(chartUpdateObserver); } catch(Exception e) { e.printStackTrace(); } updateObservers(); String[] values = preferences.getString(PREFS_WEIGHTS).split(";"); int weights[] = new int[values.length]; if (weights.length == tabGroups.size()) { for (int i = 0; i < weights.length; i++) weights[i] = Integer.parseInt(values[i]); sashForm.setWeights(weights); } else if (tabGroups.size() != 0) { 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); } Control[] controls = sashForm.getChildren(); for (int i = 0; i < controls.length; i++) { if (controls[i] instanceof ChartTabFolder) controls[i].addControlListener(sashResizeListener); } if (showMarketValue) { security.getQuoteMonitor().addObserver(quoteObserver); quoteObserver.update(security, security.getQuote()); FeedMonitor.monitor(security); } boolean askInitialUpdate = false; if (datePlot.getInterval() < BarData.INTERVAL_DAILY) askInitialUpdate = (security.getIntradayHistory().size() == 0); else askInitialUpdate = (security.getHistory().size() == 0); if (askInitialUpdate) { if (MessageDialog.openQuestion(getViewSite().getShell(), chart.getTitle(), Messages.ChartView_NoDataMessage)) { String id = ""; //$NON-NLS-1$ if (chart.getSecurity().getHistoryFeed() != null) id = chart.getSecurity().getHistoryFeed().getId(); final IHistoryFeed feed = CorePlugin.createHistoryFeedPlugin(id); if (feed != null) { Job job = new Job(Messages.ChartView_UpdateChartMessage) { protected IStatus run(IProgressMonitor monitor) { monitor.beginTask(Messages.ChartView_UpdatingMessage + chart.getSecurity().getDescription(), 1); int interval = IHistoryFeed.INTERVAL_DAILY; if (getInterval() < BarData.INTERVAL_DAILY) interval = IHistoryFeed.INTERVAL_MINUTE; feed.updateHistory(chart.getSecurity(), interval); monitor.worked(1); monitor.done(); return Status.OK_STATUS; } }; job.setUser(true); job.schedule(); } } } } }); } catch(Exception e) { e.printStackTrace(); } try { sashForm.getDisplay().asyncExec(new Runnable() { public void run() { } }); } catch(Exception e) { e.printStackTrace(); } } /* (non-Javadoc) * @see org.eclipse.ui.part.WorkbenchPart#setFocus() */ public void setFocus() { sashForm.setFocus(); } /* (non-Javadoc) * @see org.eclipse.ui.part.WorkbenchPart#dispose() */ public void dispose() { theme.removePropertyChangeListener(themeChangeListener); ChartsPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(pluginPropertiesChangeListener); if (showMarketValue) { security.getQuoteMonitor().deleteObserver(quoteObserver); FeedMonitor.cancelMonitor(security); } getSite().getPage().removeSelectionListener(this); if (chart != null) { chart.deleteObserver(chartUpdateObserver); chart.getRows().removeCollectionObserver(ChartView.this); } for (Iterator iter = observedHistories.iterator(); iter.hasNext(); ) { History security = (History)iter.next(); security.deleteObserver(chartUpdateObserver); } observedHistories.clear(); try { if (preferences != null) preferences.save(); } catch(Exception e) { LogFactory.getLog(getClass()).warn(e); } super.dispose(); } public void updateActionBars() { viewAll.setChecked(chart.getPeriod() == PERIOD_ALL); viewLast2Years.setChecked(chart.getPeriod() == PERIOD_LAST2YEARS); viewLastYear.setChecked(chart.getPeriod() == PERIOD_LASTYEAR); viewLast6Months.setChecked(chart.getPeriod() == PERIOD_LAST6MONTHS); viewCustom.setChecked(chart.getPeriod() == PERIOD_CUSTOM); minute1Action.setChecked(chart.getCompression() == BarData.INTERVAL_MINUTE1); minute2Action.setChecked(chart.getCompression() == BarData.INTERVAL_MINUTE2); minute5Action.setChecked(chart.getCompression() == BarData.INTERVAL_MINUTE5); minute10Action.setChecked(chart.getCompression() == BarData.INTERVAL_MINUTE10); minute15Action.setChecked(chart.getCompression() == BarData.INTERVAL_MINUTE15); minute30Action.setChecked(chart.getCompression() == BarData.INTERVAL_MINUTE30); minute60Action.setChecked(chart.getCompression() == BarData.INTERVAL_MINUTE60); dailyAction.setChecked(chart.getCompression() == BarData.INTERVAL_DAILY); weeklyAction.setChecked(chart.getCompression() == BarData.INTERVAL_WEEKLY); monthlyAction.setChecked(chart.getCompression() == BarData.INTERVAL_MONTHLY); autoScaleAction.setChecked(autoScale); toggleFollowSelectionAction.setChecked(followSelection); toggleAdjustedValuesAction.setChecked(showAdjustedValues); toggleMarketValueAction.setChecked(showMarketValue); } public Chart getChart() { return chart; } public int getInterval() { return datePlot.getInterval(); } public void setInterval(int interval) { chart.setCompression(interval); CorePlugin.getRepository().save(chart); } public void setAutoScale(boolean autoScale) { this.autoScale = autoScale; 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().setAutoScale(autoScale); } chart.setAutoScale(autoScale); CorePlugin.getRepository().save(chart); } public int getPeriod() { return chart.getPeriod(); } public void setPeriod(int period)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -