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

📄 watchlistitempropertiesdialog.java

📁 EclipseTrader is a stock exchange analysis system, featuring shares pricing watch, intraday and hi
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 2004-2006 Marco Maccaferri and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: *     Marco Maccaferri - initial API and implementation */package net.sourceforge.eclipsetrader.trading.wizards;import java.text.NumberFormat;import java.text.SimpleDateFormat;import java.util.Date;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import net.sourceforge.eclipsetrader.core.CorePlugin;import net.sourceforge.eclipsetrader.core.db.Alert;import net.sourceforge.eclipsetrader.core.db.WatchlistItem;import net.sourceforge.eclipsetrader.trading.AlertPlugin;import net.sourceforge.eclipsetrader.trading.AlertPluginPreferencePage;import net.sourceforge.eclipsetrader.trading.TradingPlugin;import org.eclipse.core.runtime.IConfigurationElement;import org.eclipse.jface.preference.PreferenceDialog;import org.eclipse.jface.preference.PreferenceManager;import org.eclipse.jface.preference.PreferenceNode;import org.eclipse.jface.preference.PreferencePage;import org.eclipse.swt.SWT;import org.eclipse.swt.custom.CTabFolder;import org.eclipse.swt.custom.CTabItem;import org.eclipse.swt.custom.StackLayout;import org.eclipse.swt.events.FocusAdapter;import org.eclipse.swt.events.FocusEvent;import org.eclipse.swt.events.MouseAdapter;import org.eclipse.swt.events.MouseEvent;import org.eclipse.swt.events.SelectionAdapter;import org.eclipse.swt.events.SelectionEvent;import org.eclipse.swt.graphics.Point;import org.eclipse.swt.layout.GridData;import org.eclipse.swt.layout.GridLayout;import org.eclipse.swt.widgets.Button;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Control;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.widgets.Table;import org.eclipse.swt.widgets.TableColumn;import org.eclipse.swt.widgets.TableItem;import org.eclipse.swt.widgets.Text;import org.eclipse.ui.ISharedImages;import org.eclipse.ui.PlatformUI;public class WatchlistItemPropertiesDialog extends PreferenceDialog{    WatchlistItem watchlistItem;    private NumberFormat priceFormatter = NumberFormat.getInstance();    public WatchlistItemPropertiesDialog(WatchlistItem watchlistItem, Shell parentShell)    {        super(parentShell, new PreferenceManager());        this.watchlistItem = watchlistItem;        priceFormatter.setGroupingUsed(true);        priceFormatter.setMinimumIntegerDigits(1);        priceFormatter.setMinimumFractionDigits(4);        priceFormatter.setMaximumFractionDigits(4);        getPreferenceManager().addToRoot(new PreferenceNode("general", new GeneralPage()));        getPreferenceManager().addToRoot(new PreferenceNode("alerts", new AlertsPage()));    }    /* (non-Javadoc)     * @see org.eclipse.jface.preference.PreferenceDialog#configureShell(org.eclipse.swt.widgets.Shell)     */    protected void configureShell(Shell newShell)    {        super.configureShell(newShell);        newShell.setText(watchlistItem.getSecurity().getDescription() + " Properties");    }        /* (non-Javadoc)     * @see org.eclipse.jface.preference.PreferenceDialog#handleSave()     */    protected void handleSave()    {        watchlistItem.notifyObservers();        super.handleSave();    }    private class GeneralPage extends PreferencePage    {        private Text position;        private Text price;        public GeneralPage()        {            super("");            setTitle("General");            setValid(false);            noDefaultAndApplyButton();        }        /* (non-Javadoc)         * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)         */        protected Control createContents(Composite parent)        {            Composite content = new Composite(parent, SWT.NONE);            GridLayout gridLayout = new GridLayout(2, false);            gridLayout.marginWidth = gridLayout.marginHeight = 0;            content.setLayout(gridLayout);            content.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));                        Label label = new Label(content, SWT.NONE);            label.setText("Position");            label.setLayoutData(new GridData(125, SWT.DEFAULT));            position = new Text(content, SWT.BORDER);            position.setLayoutData(new GridData(80, SWT.DEFAULT));            if (watchlistItem.getPosition() != null)                position.setText(String.valueOf(watchlistItem.getPosition()));                        label = new Label(content, SWT.NONE);            label.setText("Price");            label.setLayoutData(new GridData(125, SWT.DEFAULT));            price = new Text(content, SWT.BORDER);            price.setLayoutData(new GridData(80, SWT.DEFAULT));            price.addFocusListener(new FocusAdapter() {                public void focusLost(FocusEvent e)                {                    if (price.getText().length() != 0)                        try {                            double value = priceFormatter.parse(price.getText()).doubleValue();                            price.setText(priceFormatter.format(value));                        } catch(Exception e1) {                            CorePlugin.logException(e1);                        }                }            });            if (watchlistItem.getPaidPrice() != null)                price.setText(priceFormatter.format(watchlistItem.getPaidPrice()));                        setValid(true);                        return content;        }        /* (non-Javadoc)         * @see org.eclipse.jface.preference.PreferencePage#performOk()         */        public boolean performOk()        {            if (isValid())            {                if (position.getText().length() != 0)                    watchlistItem.setPosition(Integer.parseInt(position.getText()));                else                    watchlistItem.setPaidPrice(null);                    if (price.getText().length() != 0)                {                    try {                        watchlistItem.setPaidPrice(priceFormatter.parse(price.getText()).doubleValue());                    } catch(Exception e1) {                        CorePlugin.logException(e1);                    }                }                else                    watchlistItem.setPaidPrice(null);            }                        return super.performOk();        }    }        private class AlertsPage extends PreferencePage    {        private Table table;        private Button add;        private Button delete;        private Button reset;        private Composite group;        private Button popup;        private Button hilight;        public AlertsPage()        {            super("");            setTitle("Alerts");            setValid(false);            noDefaultAndApplyButton();        }        /* (non-Javadoc)         * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)         */        protected Control createContents(Composite parent)        {            Composite content = new Composite(parent, SWT.NONE);            GridLayout gridLayout = new GridLayout(2, false);            gridLayout.marginWidth = gridLayout.marginHeight = 0;            content.setLayout(gridLayout);            content.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));                        table = new Table(content, SWT.SINGLE|SWT.FULL_SELECTION);            GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);            gridData.widthHint = 250;            gridData.heightHint = table.getItemHeight() * 5;            table.setLayoutData(gridData);            table.setHeaderVisible(true);            table.setLinesVisible(false);            table.addSelectionListener(new SelectionAdapter() {                public void widgetSelected(SelectionEvent e)                {                    if (table.getSelectionIndex() != -1)                    {                        CTabFolder folder = (CTabFolder) group.getChildren()[table.getSelectionIndex()];                        ((StackLayout)group.getLayout()).topControl = folder;                        reset.setEnabled(((CTabFolder)table.getItem(table.getSelectionIndex()).getData("folder")).getData("last") != null);                        popup.setEnabled(true);                        popup.setSelection(((Boolean) folder.getData("popup")).booleanValue());                        hilight.setEnabled(true);                        hilight.setSelection(((Boolean) folder.getData("hilight")).booleanValue());                    }

⌨️ 快捷键说明

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