📄 watchlistboxviewer.java
字号:
Control[] items = content.getChildren(); for (int i = 0; i < items.length; i++) items[i].dispose(); for (Iterator iter = getView().getWatchlist().getItems().iterator(); iter.hasNext(); ) { WatchlistItem watchlistItem = (WatchlistItem)iter.next(); BoxViewItem viewItem = new BoxViewItem(content, SWT.NONE, watchlistItem); viewItem.setBackground(background); viewItem.setForeground(foreground); viewItem.setPositiveForeground(positiveForeground); viewItem.setNegativeForeground(negativeForeground); } content.setRedraw(true); content.layout(); } /* (non-Javadoc) * @see net.sourceforge.eclipsetrader.trading.views.AbstractWatchlistView#update(java.util.Observable, java.lang.Object) */ public void update(Observable o, Object arg) { content.getDisplay().asyncExec(new Runnable() { public void run() { if (!content.isDisposed()) updateView(); } }); } /* (non-Javadoc) * @see net.sourceforge.eclipsetrader.trading.views.AbstractWatchlistView#itemAdded(java.lang.Object) */ public void itemAdded(Object o) { if (o instanceof WatchlistItem) { WatchlistItem watchlistItem = (WatchlistItem)o; BoxViewItem viewItem = new BoxViewItem(content, SWT.NONE, watchlistItem); viewItem.setBackground(background); viewItem.setForeground(foreground); viewItem.setPositiveForeground(positiveForeground); viewItem.setNegativeForeground(negativeForeground); content.layout(); } } /* (non-Javadoc) * @see net.sourceforge.eclipsetrader.trading.views.AbstractWatchlistView#itemRemoved(java.lang.Object) */ public void itemRemoved(Object o) { Control[] items = content.getChildren(); for (int i = 0; i < items.length; i++) { BoxViewItem tableItem = (BoxViewItem)items[i]; if (tableItem.getWatchlistItem().equals(o)) { tableItem.dispose(); content.layout(); break; } } } /* (non-Javadoc) * @see net.sourceforge.eclipsetrader.trading.internal.AbstractLayout#getItemIndex(org.eclipse.swt.graphics.Point) */ public int getItemIndex(Point point) { return -1; } protected void setTheme(ITheme theme) { positiveForeground = theme.getColorRegistry().get(POSITIVE_FOREGROUND); negativeForeground = theme.getColorRegistry().get(NEGATIVE_FOREGROUND); foreground = theme.getColorRegistry().get(FOREGROUND); background = theme.getColorRegistry().get(BACKGROUND); theme.addPropertyChangeListener(themeChangeListener); } /* (non-Javadoc) * @see net.sourceforge.eclipsetrader.trading.internal.AbstractLayout#getSelection() */ public WatchlistItem[] getSelection() { if (selectedItem != null) return new WatchlistItem[] { selectedItem }; else return new WatchlistItem[0]; } private class BoxViewItem extends Box implements DisposeListener, Observer { private WatchlistItem watchlistItem; private Double lastValue; private MenuManager menuMgr; public BoxViewItem(Composite parent, int style, WatchlistItem watchlistItem) { super(parent, style); addDisposeListener(this); setWatchlistItem(watchlistItem); addSelectionListener(selectionListener); menuMgr = new MenuManager("#popupMenu", "popupMenu"); //$NON-NLS-1$ //$NON-NLS-2$ menuMgr.setRemoveAllWhenShown(true); menuMgr.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager menuManager) { menuManager.add(new Separator("top")); //$NON-NLS-1$ menuManager.add(new Separator("search")); //$NON-NLS-1$ getView().fillMenuBars(menuManager); menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); menuManager.add(new Separator("bottom")); //$NON-NLS-1$ } }); getView().getSite().registerContextMenu(menuMgr, getView().getSite().getSelectionProvider()); setMenu(menuMgr.createContextMenu(this)); } WatchlistItem getWatchlistItem() { return watchlistItem; } void setWatchlistItem(WatchlistItem watchlistItem) { if (this.watchlistItem != null) this.watchlistItem.deleteObserver(this); this.watchlistItem = watchlistItem; updateDisplay(); this.watchlistItem.addObserver(this); } private void updateDisplay() { Security security = watchlistItem.getSecurity(); setName(security.getDescription()); Quote quote = security.getQuote(); if (quote != null) { double last = CurrencyConverter.getInstance().convert(quote.getLast(), security.getCurrency(), watchlistItem.getParent().getCurrency()); double close = CurrencyConverter.getInstance().convert(security.getClose(), security.getCurrency(), watchlistItem.getParent().getCurrency()); setValue(numberFormatter.format(last)); if (security.getClose() != null) { double change = last - close; double percentage = change / close * 100; String prefix = ""; if (change > 0) prefix = "+"; setChange(prefix + numberFormatter.format(change) + " (" + prefix + percentageFormatter.format(percentage) + "%)"); } if (quote.getDate() != null) setTime(formatter.format(quote.getDate())); if (lastValue != null) { if (quote.getLast() > lastValue.doubleValue()) setImage(up); else if (quote.getLast() < lastValue.doubleValue()) setImage(down); else setImage(equal); } lastValue = new Double(quote.getLast()); } getParent().layout(true, true); } /* (non-Javadoc) * @see java.util.Observer#update(java.util.Observable, java.lang.Object) */ public void update(Observable o, Object arg) { getDisplay().asyncExec(new Runnable() { public void run() { if (!isDisposed()) updateDisplay(); } }); } /* (non-Javadoc) * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent) */ public void widgetDisposed(DisposeEvent e) { if (watchlistItem != null) watchlistItem.deleteObserver(this); if (menuMgr != null) menuMgr.dispose(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -