📄 barsummaryitem.java
字号:
/* * 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.charts;import java.text.NumberFormat;import net.sourceforge.eclipsetrader.charts.internal.Messages;import net.sourceforge.eclipsetrader.core.db.Bar;import org.eclipse.swt.SWT;import org.eclipse.swt.graphics.Color;import org.eclipse.swt.widgets.Label;public class BarSummaryItem extends SummaryItem{ private Label change; private Label open; private Label high; private Label low; private Label close; private Color positive = new Color(null, 0, 192, 0); private Color negative = new Color(null, 192, 0, 0); private NumberFormat pf = ChartsPlugin.getPriceFormat(); private NumberFormat pcf = ChartsPlugin.getPercentageFormat(); private double previousChange = 99999999; public BarSummaryItem(Summary parent, int style) { super(parent, style); Color background = parent.getBackground(); change = new Label(parent, SWT.NONE); change.setBackground(background); change.setText(Messages.BarSummaryItem_CH + pcf.format(0) + "%"); //$NON-NLS-2$ open = new Label(parent, SWT.NONE); open.setBackground(background); open.setText(Messages.BarSummaryItem_O + pf.format(0)); high = new Label(parent, SWT.NONE); high.setBackground(background); high.setText(Messages.BarSummaryItem_H + pf.format(0)); low = new Label(parent, SWT.NONE); low.setBackground(background); low.setText(Messages.BarSummaryItem_L + pf.format(0)); close = new Label(parent, SWT.NONE); close.setBackground(background); close.setText(Messages.BarSummaryItem_C + pf.format(0)); if (background != null) background.dispose(); } /* (non-Javadoc) * @see net.sourceforge.eclipsetrader.charts.SummaryItem#dispose() */ public void dispose() { change.dispose(); open.dispose(); high.dispose(); low.dispose(); close.dispose(); super.dispose(); } public void setData(Bar bar, Bar previous) { double ch = 0; if (previous != null) ch = (bar.getClose() - previous.getClose()) / previous.getClose() * 100.0; if (previousChange != ch) { change.setText(Messages.BarSummaryItem_CH + pcf.format(ch) + "%"); //$NON-NLS-2$ if (ch > 0) change.setForeground(positive); else if (ch < 0) change.setForeground(negative); else change.setForeground(getForeground()); previousChange = ch; } open.setText(Messages.BarSummaryItem_O + pf.format(bar.getOpen())); high.setText(Messages.BarSummaryItem_H + pf.format(bar.getHigh())); low.setText(Messages.BarSummaryItem_L + pf.format(bar.getLow())); close.setText(Messages.BarSummaryItem_C + pf.format(bar.getClose())); } public void setData(Bar bar) { if (bar != null) { if (previousChange != 0) { change.setText(Messages.BarSummaryItem_CH + pcf.format(0) + "%"); //$NON-NLS-2$ change.setForeground(getForeground()); previousChange = 0; } open.setText(Messages.BarSummaryItem_O + pf.format(bar.getOpen())); high.setText(Messages.BarSummaryItem_H + pf.format(bar.getHigh())); low.setText(Messages.BarSummaryItem_L + pf.format(bar.getLow())); close.setText(Messages.BarSummaryItem_C + pf.format(bar.getClose())); } else { change.setText(Messages.BarSummaryItem_CH); change.setForeground(getForeground()); open.setText(Messages.BarSummaryItem_19); high.setText(Messages.BarSummaryItem_20); low.setText(Messages.BarSummaryItem_21); close.setText(Messages.BarSummaryItem_22); } } /* (non-Javadoc) * @see net.sourceforge.eclipsetrader.charts.SummaryItem#setForeground(org.eclipse.swt.graphics.Color) */ public void setForeground(Color color) { open.setForeground(color); high.setForeground(color); low.setForeground(color); close.setForeground(color); super.setForeground(color); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -