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

📄 level2view.java

📁 EclipseTrader is a stock exchange analysis system, featuring shares pricing watch, intraday and hi
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        super.saveState(memento);    }    /* (non-Javadoc)     * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)     */    public void createPartControl(Composite parent)    {        DropTarget target = new DropTarget(parent, DND.DROP_COPY|DND.DROP_MOVE);        target.setTransfer(new Transfer[] { SecurityTransfer.getInstance() });        target.addDropListener(dropTargetListener);                Composite content = new Composite(parent, SWT.NONE);        GridLayout gridLayout = new GridLayout();        gridLayout.marginWidth = gridLayout.marginHeight = 0;        gridLayout.horizontalSpacing = 0;        gridLayout.verticalSpacing = 0;        content.setLayout(gridLayout);        IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager();        theme = themeManager.getCurrentTheme();        bandBackground[0] = theme.getColorRegistry().get(LEVEL_1_BACKGROUND);        bandForeground[0] = theme.getColorRegistry().get(LEVEL_1_FOREGROUND);        bandBackground[1] = theme.getColorRegistry().get(LEVEL_2_BACKGROUND);        bandForeground[1] = theme.getColorRegistry().get(LEVEL_2_FOREGROUND);        bandBackground[2] = theme.getColorRegistry().get(LEVEL_3_BACKGROUND);        bandForeground[2] = theme.getColorRegistry().get(LEVEL_3_FOREGROUND);        bandBackground[3] = theme.getColorRegistry().get(LEVEL_4_BACKGROUND);        bandForeground[3] = theme.getColorRegistry().get(LEVEL_4_FOREGROUND);        bandBackground[4] = theme.getColorRegistry().get(LEVEL_5_BACKGROUND);        bandForeground[4] = theme.getColorRegistry().get(LEVEL_5_FOREGROUND);        theme.addPropertyChangeListener(themeChangeListener);        info = new Composite(content, SWT.NONE);        gridLayout = new GridLayout(4, false);        gridLayout.marginWidth = 3;        gridLayout.marginHeight = 3;        gridLayout.verticalSpacing = 2;        gridLayout.horizontalSpacing = 10;        info.setLayout(gridLayout);        info.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));        info.addPaintListener(new PaintListener() {            public void paintControl(PaintEvent e)            {                // Disegna il bordo inferiore                Rectangle r = info.getClientArea();                e.gc.setForeground(info.getDisplay().getSystemColor(SWT.COLOR_GRAY));                e.gc.drawLine(0, r.height - 1, r.width, r.height - 1);            }        });        Label label = new Label(info, SWT.NONE);        label.setText("Time"); //$NON-NLS-1$        time = new Label(info, SWT.RIGHT);        time.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));        label = new Label(info, SWT.NONE);        label.setText("Volume"); //$NON-NLS-1$        volume = new Label(info, SWT.RIGHT);        volume.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));        label = new Label(info, SWT.NONE);        label.setText("Last Price"); //$NON-NLS-1$        last = new Label(info, SWT.NONE);        last.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false));        label = new Label(info, SWT.NONE);        label.setText("High"); //$NON-NLS-1$        high = new Label(info, SWT.NONE);        high.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false));        label = new Label(info, SWT.NONE);        label.setText("Change"); //$NON-NLS-1$        change = new Label(info, SWT.NONE);        change.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false));        label = new Label(info, SWT.NONE);        label.setText("Low"); //$NON-NLS-1$        low = new Label(info, SWT.NONE);        low.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false));        trendbar = new Trendbar(content, SWT.NONE);        GridData gridData = new GridData();        gridData.grabExcessHorizontalSpace = true;        gridData.horizontalAlignment = SWT.FILL;        gridData.heightHint = 16;        trendbar.setLayoutData(gridData);        trendbar.setBandColors(bandBackground);        trendbar.setIndicatorColor(theme.getColorRegistry().get(TRENDBAR_INDICATOR));        table = new Table(content, SWT.SINGLE|SWT.FULL_SELECTION|SWT.HIDE_SELECTION);        table.setLayoutData(new GridData(GridData.FILL_BOTH));        table.setHeaderVisible(true);        table.setLinesVisible(false);        background = table.getBackground();        emptyBackground = parent.getBackground();        table.setBackground(emptyBackground);        TableColumn column = new TableColumn(table, SWT.NONE);        column.setWidth(0);        column.setResizable(false);        column = new TableColumn(table, SWT.CENTER);        column.setText("#");        column = new TableColumn(table, SWT.CENTER);        column.setText("Q.ty");        column = new TableColumn(table, SWT.CENTER);        column.setText("Bid");        column = new TableColumn(table, SWT.CENTER);        column.setText("Ask");        column = new TableColumn(table, SWT.CENTER);        column.setText("Q.ty");        column = new TableColumn(table, SWT.CENTER);        column.setText("#");        table.addControlListener(new ControlAdapter() {            public void controlResized(ControlEvent e)            {                table.setRedraw(false);                updateColumnWidth();                table.setRedraw(true);            }        });        table.addFocusListener(new FocusAdapter() {            public void focusGained(FocusEvent e)            {                ((Table)e.widget).deselectAll();                info.getParent().setFocus();            }        });                IMenuManager menuManager = getViewSite().getActionBars().getMenuManager();        menuManager.add(toggleLevelColorsAction);        menuManager.add(togglePriceGroupingAction);        menuManager.add(toggleFollowSelectionAction);        getViewSite().getActionBars().updateActionBars();        if (security != null)        {            setPartName(security.getDescription());            loadPreferences();            content.getDisplay().asyncExec(new Runnable() {                public void run()                {                    updateInfo();                    updateTable();                    security.addObserver(Level2View.this);                    security.getQuoteMonitor().addObserver(Level2View.this);                    security.getLevel2Monitor().addObserver(Level2View.this);                    Level2FeedMonitor.monitor(security);                }            });        }        getSite().getPage().addSelectionListener(this);    }    /* (non-Javadoc)     * @see org.eclipse.ui.part.WorkbenchPart#setFocus()     */    public void setFocus()    {        info.getParent().setFocus();    }    /* (non-Javadoc)     * @see org.eclipse.ui.part.WorkbenchPart#dispose()     */    public void dispose()    {        if (security != null)        {            security.deleteObserver(this);            security.getQuoteMonitor().deleteObserver(this);            security.getLevel2Monitor().deleteObserver(this);            Level2FeedMonitor.cancelMonitor(security);            savePreferences();        }                if (theme != null)            theme.removePropertyChangeListener(themeChangeListener);                background.dispose();        negativeForeground.dispose();        positiveForeground.dispose();        emptyBackground.dispose();        getSite().getPage().removeSelectionListener(this);                super.dispose();    }    protected void loadPreferences()    {        preferences = new PreferenceStore(getPreferenceStoreLocation(security).toOSString());        preferences.setDefault(PREFS_SECONDARY_ID, "");        preferences.setDefault(PREFS_GROUP_PRICES, DEFAULT_GROUP_PRICES);        preferences.setDefault(PREFS_COLOR_LEVELS, DEFAULT_COLOR_LEVELS);        preferences.setDefault(PREFS_FOLLOW_SELECTION, DEFAULT_FOLLOW_SELECTION);        try {            preferences.load();        } catch(Exception e) {            // Reads the preferences from the old-style preference store            String[] prefs = TradingPlugin.getDefault().getPluginPreferences().getString(PREFERENCES_ID + String.valueOf(security.getId())).split(",");            if (prefs.length > 0)                preferences.setValue(PREFS_GROUP_PRICES, prefs[0].equals("true"));            if (prefs.length > 1)                preferences.setValue(PREFS_COLOR_LEVELS, prefs[1].equals("true"));            if (prefs.length > 2)            	preferences.setValue(PREFS_FOLLOW_SELECTION, prefs[2].equals("true"));            TradingPlugin.getDefault().getPluginPreferences().setValue(PREFERENCES_ID + String.valueOf(security.getId()), "");        }                        groupPrices = preferences.getBoolean(PREFS_GROUP_PRICES);        colorLevels = preferences.getBoolean(PREFS_COLOR_LEVELS);        followSelection = preferences.getBoolean(PREFS_FOLLOW_SELECTION);        // Save the secondary id value immediately, so subsequent level2 requests for the same        // security will open this view        preferences.setValue(PREFS_SECONDARY_ID, getViewSite().getSecondaryId());        try {            preferences.save();        } catch(Exception e) {            LogFactory.getLog(getClass()).warn(e);        }        toggleLevelColorsAction.setChecked(colorLevels);        togglePriceGroupingAction.setChecked(groupPrices);        toggleFollowSelectionAction.setChecked(followSelection);    }    protected void savePreferences()    {        preferences.setFilename(getPreferenceStoreLocation(security).toOSString());        preferences.setValue(PREFS_GROUP_PRICES, groupPrices);        preferences.setValue(PREFS_COLOR_LEVELS, colorLevels);        preferences.setValue(PREFS_FOLLOW_SELECTION, followSelection);        try {            preferences.save();        } catch(Exception e) {            LogFactory.getLog(getClass()).warn(e);        }    }        public void setSecurity(Security newSecurity)    {        if (security == null)        {            security = newSecurity;            loadPreferences();        }        else        {            security.deleteObserver(this);            security.getQuoteMonitor().deleteObserver(this);            security.getLevel2Monitor().deleteObserver(this);            Level2FeedMonitor.cancelMonitor(security);            preferences.setValue(PREFS_SECONDARY_ID, "");            savePreferences();                        security = newSecurity;                        preferences.setValue(PREFS_SECONDARY_ID, getViewSite().getSecondaryId());            savePreferences();        }                updateInfo();        updateTable();        security.addObserver(this);        security.getQuoteMonitor().addObserver(this);        security.getLevel2Monitor().addObserver(this);        Level2FeedMonitor.monitor(security);    }        void updateInfo()    {        if (!getPartName().equals(security.getDescription()))            setPartName(security.getDescription());        if (security.getQuote() != null)        {            if (security.getQuote().getDate() != null)                time.setText(dateFormatter.format(security.getQuote().getDate()));            volume.setText(numberFormatter.format(security.getQuote().getVolume()));            last.setText(priceFormatter2.format(security.getQuote().getLast()));            if (security.getClose() != null)            {                double chg = (security.getQuote().getLast() - security.getClose().doubleValue()) / security.getClose().doubleValue() * 100;                if (chg > 0)                {                    change.setText("+" + percentFormatter.format(chg) + "%"); //$NON-NLS-1$ //$NON-NLS-2$                    change.setForeground(positiveForeground);                }                else                {                    change.setText(percentFormatter.format(chg) + "%"); //$NON-NLS-1$ //$NON-NLS-2$                    if (chg < 0)                        change.setForeground(negativeForeground);                    else                        change.setForeground(null);                }            }        }        if (security.getHigh() != null)            high.setText(priceFormatter2.format(security.getHigh()));

⌨️ 快捷键说明

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