📄 chartsplugin.java
字号:
/* * Copyright (c) 2004-2007 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.io.BufferedWriter;import java.io.File;import java.io.FileOutputStream;import java.io.FileWriter;import java.io.InputStream;import java.io.OutputStream;import java.text.NumberFormat;import java.text.SimpleDateFormat;import java.util.Iterator;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import javax.xml.transform.OutputKeys;import javax.xml.transform.Transformer;import javax.xml.transform.TransformerFactory;import javax.xml.transform.dom.DOMSource;import javax.xml.transform.stream.StreamResult;import net.sourceforge.eclipsetrader.core.CorePlugin;import net.sourceforge.eclipsetrader.core.db.Chart;import net.sourceforge.eclipsetrader.core.db.ChartIndicator;import net.sourceforge.eclipsetrader.core.db.ChartObject;import net.sourceforge.eclipsetrader.core.db.ChartRow;import net.sourceforge.eclipsetrader.core.db.ChartTab;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.eclipse.core.runtime.FileLocator;import org.eclipse.core.runtime.IConfigurationElement;import org.eclipse.core.runtime.IExtensionPoint;import org.eclipse.core.runtime.IExtensionRegistry;import org.eclipse.core.runtime.Path;import org.eclipse.core.runtime.Platform;import org.eclipse.jface.resource.ImageDescriptor;import org.eclipse.ui.plugin.AbstractUIPlugin;import org.osgi.framework.BundleContext;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.Node;import org.w3c.dom.NodeList;/** * The main plugin class to be used in the desktop. */public class ChartsPlugin extends AbstractUIPlugin{ public static final String PLUGIN_ID = "net.sourceforge.eclipsetrader.charts"; public static final String INDICATORS_EXTENSION_POINT = PLUGIN_ID + ".indicators"; public static final String OBJECTS_EXTENSION_POINT = PLUGIN_ID + ".objects"; public static final String PREFS_HIDE_TABS = "HIDE_TABS"; public static final String PREFS_EXTEND_SCALE = "EXTEND_SCALE"; public static final String PREFS_EXTEND_PERIOD = "EXTEND_PERIOD"; private static ChartsPlugin plugin; private static NumberFormat numberFormat; private static NumberFormat percentageFormat; private static NumberFormat priceFormat; /** * The constructor. */ public ChartsPlugin() { plugin = this; } /** * This method is called upon plug-in activation */ public void start(BundleContext context) throws Exception { super.start(context); copyFileToStateLocation("defaultChart.xml"); } /** * This method is called when the plug-in is stopped */ public void stop(BundleContext context) throws Exception { super.stop(context); plugin = null; } /** * Returns the shared instance. */ public static ChartsPlugin getDefault() { return plugin; } public static NumberFormat getNumberFormat() { if (numberFormat == null) { numberFormat = NumberFormat.getInstance(); numberFormat.setGroupingUsed(true); numberFormat.setMinimumIntegerDigits(1); numberFormat.setMinimumFractionDigits(0); numberFormat.setMaximumFractionDigits(0); } return numberFormat; } public static NumberFormat getPercentageFormat() { if (percentageFormat == null) { percentageFormat = NumberFormat.getInstance(); percentageFormat.setGroupingUsed(false); percentageFormat.setMinimumIntegerDigits(1); percentageFormat.setMinimumFractionDigits(2); percentageFormat.setMaximumFractionDigits(2); } return percentageFormat; } public static NumberFormat getPriceFormat() { if (priceFormat == null) { priceFormat = NumberFormat.getInstance(); priceFormat.setGroupingUsed(true); priceFormat.setMinimumIntegerDigits(1); priceFormat.setMinimumFractionDigits(4); priceFormat.setMaximumFractionDigits(4); } return priceFormat; } /** * Returns an image descriptor for the image file at the given * plug-in relative path. * * @param path the path * @return the image descriptor */ public static ImageDescriptor getImageDescriptor(String path) { return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path); } public static IIndicatorPlugin createIndicatorPlugin(String id) { IConfigurationElement item = getIndicatorPlugin(id); if (item != null) { try { Object obj = item.createExecutableExtension("class"); if (obj instanceof IIndicatorPlugin) return (IIndicatorPlugin)obj; } catch(Exception e) { e.printStackTrace(); } } return null; } public static IConfigurationElement getIndicatorPlugin(String id) { IExtensionRegistry registry = Platform.getExtensionRegistry(); IExtensionPoint extensionPoint = registry.getExtensionPoint(ChartsPlugin.INDICATORS_EXTENSION_POINT); if (extensionPoint != null) { IConfigurationElement[] members = extensionPoint.getConfigurationElements(); for (int i = 0; i < members.length; i++) { IConfigurationElement item = members[i]; if (item.getAttribute("id").equals(id)) return item; } } return null; } public static ObjectPlugin createObjectPlugin(String id) { IConfigurationElement item = getObjectPlugin(id); if (item != null) { try { Object obj = item.createExecutableExtension("class"); if (obj instanceof ObjectPlugin) return (ObjectPlugin)obj; } catch(Exception e) { e.printStackTrace(); } } return null; } public static IConfigurationElement getObjectPlugin(String id) { IExtensionRegistry registry = Platform.getExtensionRegistry(); IExtensionPoint extensionPoint = registry.getExtensionPoint(ChartsPlugin.OBJECTS_EXTENSION_POINT); if (extensionPoint != null) { IConfigurationElement[] members = extensionPoint.getConfigurationElements(); for (int i = 0; i < members.length; i++) { IConfigurationElement item = members[i]; if (item.getAttribute("id").equals(id)) return item; } } return null; } public static Chart createDefaultChart() { Log logger = LogFactory.getLog(ChartsPlugin.class); SimpleDateFormat dateTimeFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); //$NON-NLS-1$ Chart chart = new Chart(); File file = ChartsPlugin.getDefault().getStateLocation().append("defaultChart.xml").toFile(); if (file.exists() == true) { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(file); NodeList firstNode = document.getFirstChild().getChildNodes(); for (int r = 0; r < firstNode.getLength(); r++) { Node item = firstNode.item(r); Node valueNode = item.getFirstChild(); String nodeName = item.getNodeName(); if (valueNode != null) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -