--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import java.util.Map;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.jface.dialogs.IDialogSettings;\r
+import org.eclipse.jface.resource.ImageDescriptor;\r
+import org.eclipse.ui.IWorkbenchPart;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.eclipse.ui.commands.ICommandService;\r
+import org.eclipse.ui.commands.IElementUpdater;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.eclipse.ui.menus.UIElement;\r
+import org.simantics.sysdyn.ui.Activator;\r
+import org.simantics.sysdyn.ui.trend.ChartPanel;\r
+\r
+/**\r
+ * This handler changes the orientation of a {@link ChartPanel}\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class ChartPanelOrientationHandler extends AbstractHandler implements IElementUpdater {\r
+\r
+ private static String COMMAND = "org.simantics.sysdyn.ui.chartPanelOrientation";\r
+ \r
+ /**\r
+ * Read chart panel settings from IDialogSettings and change the orientation accordingly.\r
+ * Finally order the element to update its appearance.\r
+ */\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+ IWorkbenchPart part = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getActivePart();\r
+ if(part instanceof ChartPanel) {\r
+ IDialogSettings settings = Activator.getDefault().getDialogSettings().getSection(ChartPanel.CHART_PANEL_SETTINGS);\r
+ if (settings == null) {\r
+ settings = Activator.getDefault().getDialogSettings().addNewSection(ChartPanel.CHART_PANEL_SETTINGS);\r
+ }\r
+ \r
+ String orientation = settings.get(ChartPanel.CHART_PANEL_ORIENTATION);\r
+ if(orientation == null)\r
+ settings.put(ChartPanel.CHART_PANEL_ORIENTATION, ChartPanel.CHART_PANEL_VERTICAL);\r
+ \r
+ if(ChartPanel.CHART_PANEL_VERTICAL.equals(orientation))\r
+ orientation = ChartPanel.CHART_PANEL_HORIZONTAL;\r
+ else\r
+ orientation = ChartPanel.CHART_PANEL_VERTICAL;\r
+ \r
+ settings.put(ChartPanel.CHART_PANEL_ORIENTATION, orientation);\r
+ ((ChartPanel)part).setOrientation(orientation);\r
+ \r
+ ICommandService commandService =\r
+ (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);\r
+ commandService.refreshElements(COMMAND, null);\r
+ }\r
+\r
+ return null;\r
+ }\r
+\r
+ /**\r
+ * Update the icon of the element. The new icon and text are always opposite to the current situation.\r
+ */\r
+ @SuppressWarnings("rawtypes")\r
+ @Override\r
+ public void updateElement(UIElement element, Map parameters) {\r
+ if(parameters == null)\r
+ return;\r
+ \r
+ IDialogSettings settings = Activator.getDefault().getDialogSettings().getSection(ChartPanel.CHART_PANEL_SETTINGS);\r
+ if (settings == null) {\r
+ settings = Activator.getDefault().getDialogSettings().addNewSection(ChartPanel.CHART_PANEL_SETTINGS);\r
+ }\r
+ \r
+ String orientation = settings.get(ChartPanel.CHART_PANEL_ORIENTATION);\r
+ if(orientation == null)\r
+ return;\r
+ \r
+ // Show the opposite icon and text to indicate change when the button is pressed\r
+ if(ChartPanel.CHART_PANEL_HORIZONTAL.equals(orientation)) {\r
+ element.setIcon(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/page_white_text.png")));\r
+ element.setTooltip("Vertical Orientation");\r
+ } else if (ChartPanel.CHART_PANEL_VERTICAL.equals(orientation)) {\r
+ element.setIcon(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/page_white_text_width.png")));\r
+ element.setTooltip("Horizontal Orientation");\r
+ }\r
+ }\r
+\r
+}\r
*******************************************************************************/\r
package org.simantics.sysdyn.ui.trend;\r
\r
-import java.awt.Frame;\r
-import java.text.SimpleDateFormat;\r
+import java.util.ArrayList;\r
\r
+import org.eclipse.jface.dialogs.IDialogSettings;\r
import org.eclipse.jface.layout.GridDataFactory;\r
import org.eclipse.jface.layout.GridLayoutFactory;\r
import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.awt.SWT_AWT;\r
import org.eclipse.swt.custom.ScrolledComposite;\r
-import org.eclipse.swt.events.ControlAdapter;\r
-import org.eclipse.swt.events.ControlEvent;\r
-import org.eclipse.swt.events.MouseEvent;\r
-import org.eclipse.swt.events.MouseListener;\r
-import org.eclipse.swt.events.PaintEvent;\r
-import org.eclipse.swt.events.PaintListener;\r
-import org.eclipse.swt.graphics.Cursor;\r
-import org.eclipse.swt.graphics.Point;\r
-import org.eclipse.swt.graphics.Rectangle;\r
-import org.eclipse.swt.graphics.Transform;\r
-import org.eclipse.swt.layout.FillLayout;\r
-import org.eclipse.swt.widgets.Canvas;\r
import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.swt.widgets.Event;\r
-import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.swt.widgets.Listener;\r
-import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.swt.widgets.Control;\r
+import org.eclipse.ui.IMemento;\r
+import org.eclipse.ui.IViewSite;\r
+import org.eclipse.ui.PartInitException;\r
import org.eclipse.ui.part.ViewPart;\r
-import org.jfree.chart.ChartFactory;\r
-import org.jfree.chart.ChartFrame;\r
-import org.jfree.chart.JFreeChart;\r
-import org.jfree.chart.axis.DateAxis;\r
-import org.jfree.chart.plot.XYPlot;\r
-import org.jfree.data.time.Day;\r
-import org.jfree.data.time.TimeSeries;\r
-import org.jfree.data.time.TimeSeriesCollection;\r
-import org.simantics.g2d.chassis.SWTChassis;\r
-import org.simantics.utils.threads.SWTThread;\r
-import org.simantics.utils.threads.ThreadUtils;\r
-import org.simantics.utils.ui.SWTAWTComponent;\r
-\r
+import org.simantics.sysdyn.ui.Activator;\r
+\r
+/**\r
+ * Chart panel displays multiple charts in a single view. The view can be oriented \r
+ * vertically or horizontally, the default is vertical. Charts can be added, removed \r
+ * minimized or expanded. The order of the charts can be changed by dragging the charts.\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
public class ChartPanel extends ViewPart {\r
\r
- ScrolledComposite sc;\r
- Composite composite;\r
+ private Composite body;\r
+ private ScrolledComposite sc;\r
+ \r
+ private IDialogSettings settings;\r
+ private ArrayList<String> expandedCharts;\r
+ private ArrayList<String> minimizedCharts;\r
+ \r
+// private ArrayList<ChartPanelElement> elements;\r
+// private ArrayList<Label> separators;\r
\r
- @Override\r
- public void createPartControl(Composite parent) {\r
- Composite c = new Composite(parent, SWT.NONE);\r
- GridLayoutFactory.fillDefaults().applyTo(c);\r
+ public static final String CHART_PANEL_SETTINGS = "CHART_PANEL_SETTINGS";\r
+ public static final String EXPANDED_CHARTS = "ChartPanel.EXPANDED_CHARTS";\r
+ public static final String MINIMIZED_CHARTS = "ChartPanel.MINIMIZED_CHARTS";\r
+ public static final String CHART_PANEL_ORIENTATION = "CHART_PANEL_ORIENTATION";\r
+ \r
+ public static final String CHART_PANEL_VERTICAL = "CHART_PANEL_ORIENTATION_VERTICAL";\r
+ public static final String CHART_PANEL_HORIZONTAL = "CHART_PANEL_ORIENTATION_HORIZONTAL";\r
+ \r
+ private boolean vertical = true;\r
\r
- sc = new ScrolledComposite(c, SWT.H_SCROLL | SWT.V_SCROLL);\r
- GridDataFactory.fillDefaults().grab(true, true).applyTo(sc);\r
- GridLayoutFactory.fillDefaults().applyTo(sc);\r
+ /**\r
+ * Initialize the view. Load charts that have previously been open (if there are any).\r
+ */\r
+ @Override\r
+ public void init(IViewSite site, IMemento memento) throws PartInitException {\r
+ super.init(site, memento);\r
+ \r
+// elements = new ArrayList<ChartPanelElement>();\r
+// separators = new ArrayList<Label>();\r
+ \r
+ settings = Activator.getDefault().getDialogSettings().getSection(CHART_PANEL_SETTINGS);\r
+ if (settings == null) {\r
+ settings = Activator.getDefault().getDialogSettings().addNewSection(CHART_PANEL_SETTINGS);\r
+ \r
+ String[] expandedUris = new String[] {"Module1.Variable1[index3]", "Module1.Variable2[index3]"};\r
+ settings.put(EXPANDED_CHARTS, expandedUris);\r
+ \r
+ String[] minimizedUris = new String[] {"Module1.Variable3[index3]", "Module1.Variable4[index3]", "Module1.Variable5[index3]", "Module1.Variable6[index3]"};\r
+ settings.put(MINIMIZED_CHARTS, minimizedUris);\r
+ }\r
+ \r
+ expandedCharts = new ArrayList<String>();\r
+ String[] expandedURIs = settings.getArray(EXPANDED_CHARTS);\r
+ for(String e : expandedURIs)\r
+ expandedCharts.add(e);\r
\r
- composite = new Composite(sc, SWT.NONE);\r
- GridLayoutFactory.fillDefaults().numColumns(6).applyTo(composite);\r
- GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);\r
+ minimizedCharts = new ArrayList<String>();\r
+ String[] minimizedURIs = settings.getArray(MINIMIZED_CHARTS);\r
+ for(String m : minimizedURIs)\r
+ minimizedCharts.add(m);\r
\r
\r
- sc.setContent(composite);\r
+ String orientation = settings.get(CHART_PANEL_ORIENTATION);\r
+ if(CHART_PANEL_VERTICAL.equals(orientation))\r
+ this.vertical = true;\r
+ else\r
+ this.vertical = false;\r
+ }\r
+\r
+ /**\r
+ * Create a scrolled composite that will contain all the charts, then call the actual \r
+ * content creator.\r
+ */\r
+ @Override\r
+ public void createPartControl(Composite parent) {\r
+ sc = new ScrolledComposite(parent, SWT.NONE | SWT.H_SCROLL | SWT.V_SCROLL);\r
+ GridLayoutFactory.fillDefaults().spacing(0, 0).applyTo(sc);\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(sc);\r
sc.setExpandHorizontal(true);\r
sc.setExpandVertical(true);\r
- sc.getVerticalBar().setIncrement(30);\r
- sc.getVerticalBar().setPageIncrement(200);\r
- sc.addControlListener( new ControlAdapter() {\r
- @Override\r
- public void controlResized(ControlEvent e) {\r
- //System.out.println("ScrolledComposite resized: " + sc.getSize());\r
- refreshScrolledComposite();\r
- }\r
- });\r
\r
- final Canvas canvas = new Canvas(composite, SWT.BORDER);\r
- // Create a paint handler for the canvas\r
- canvas.addPaintListener(new PaintListener() {\r
- public void paintControl(PaintEvent e) {\r
- int canvasHeight = canvas.getSize().y;\r
- String text = "Module1.Variable2[index3]";\r
- Transform t = new Transform(e.display);\r
- t.rotate(-90);\r
- t.translate(- (canvasHeight - 10), 0);\r
- e.gc.setTransform(t);\r
- e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_BLACK));\r
- e.gc.drawText(text, 0, 0);\r
- }\r
- });\r
- GridDataFactory.fillDefaults().hint(20, SWT.DEFAULT).grab(false, true).applyTo(canvas);\r
- canvas.setCursor(new Cursor(canvas.getDisplay(), SWT.CURSOR_HAND));\r
- canvas.addMouseListener(new NewTrendListener());\r
- ToolTipListener ttl = new ToolTipListener(canvas);\r
- canvas.addListener(SWT.Dispose, ttl);\r
- canvas.addListener(SWT.KeyDown, ttl);\r
- canvas.addListener(SWT.MouseMove, ttl);\r
- canvas.addListener(SWT.MouseHover, ttl);\r
+ body = new Composite(sc, SWT.NONE);\r
+ GridLayoutFactory.fillDefaults().spacing(0, 0).applyTo(body);\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(body);\r
\r
- Composite swtComposite = new Composite(composite,\r
- SWT.NO_BACKGROUND | SWT.EMBEDDED);\r
- GridDataFactory.fillDefaults().hint(200, 200).applyTo(swtComposite);\r
- Frame frame = SWT_AWT.new_Frame(swtComposite);\r
- setChart(frame);\r
+ sc.setContent(body);\r
+\r
+ createContents(body);\r
}\r
+ \r
+ /**\r
+ * Display charts in this chart panel in the following order regardless of the orientation:\r
+ * 1. Remove old content\r
+ * 2. Display expanded charts\r
+ * 3. Display minimized charts \r
+ * \r
+ * @param parent Body located inside a scrolled composite and containing the charts. (always private Composite body?)\r
+ */\r
+ private void createContents(Composite parent) {\r
+ for(Control c : parent.getChildren()) \r
+ c.dispose();\r
+ \r
+ Composite composite = new Composite(parent, SWT.NONE);\r
+\r
+ if(vertical) {\r
+ GridLayoutFactory.fillDefaults().spacing(0, 0).applyTo(composite);\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);\r
+ } else {\r
+ int en = expandedCharts.size();\r
+ int mn = minimizedCharts.isEmpty() ? 0 : 1;\r
+ GridLayoutFactory.fillDefaults().spacing(0, 0).numColumns(en + mn).applyTo(composite);\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);\r
+ }\r
+\r
+ for(String e : expandedCharts)\r
+ new ChartPanelElement(composite, this, e, SWT.NONE);\r
\r
+ if(!minimizedCharts.isEmpty()) {\r
+ Composite minimized = new Composite(composite, SWT.NONE);\r
+ GridDataFactory.fillDefaults().hint(ChartPanelHeader.HEADER_MINIMUM_WIDTH, SWT.DEFAULT).applyTo(minimized);\r
+ GridLayoutFactory.fillDefaults().spacing(0, 0).applyTo(minimized);\r
+\r
+ for(String m : minimizedCharts)\r
+ new ChartPanelHeader(minimized, this, m, SWT.BORDER);\r
+ }\r
+\r
+ parent.layout();\r
+ \r
+ sc.setMinSize(body.computeSize(SWT.DEFAULT, SWT.DEFAULT));\r
+ saveState();\r
+ }\r
\r
@Override\r
public void setFocus() {\r
+ if(!body.isDisposed())\r
+ body.setFocus();\r
}\r
\r
@Override\r
- public void dispose() {\r
-\r
+ public void saveState(IMemento memento) {\r
+ super.saveState(memento);\r
+ saveState();\r
}\r
\r
- \r
- void refreshScrolledComposite() {\r
- // Execute asynchronously to give the UI events triggering this method\r
- // call time to run through before actually doing any resizing.\r
- // Otherwise the result will lag behind reality when scrollbar\r
- // visibility is toggled by the toolkit.\r
- ThreadUtils.asyncExec(SWTThread.getThreadAccess(composite.getDisplay()), new Runnable() {\r
- @Override\r
- public void run() {\r
- if (sc.isDisposed())\r
- return;\r
- syncRefreshScrolledComposite();\r
+ /**\r
+ * Save the current state of the view to IDialogSettings \r
+ */\r
+ private void saveState() {\r
+ if (settings != null) {\r
+ String[] expandedURIs = settings.getArray(EXPANDED_CHARTS);\r
+ if (expandedURIs == null) {\r
+ expandedURIs = new String[0];\r
}\r
- });\r
- }\r
-\r
- void syncRefreshScrolledComposite() {\r
- // Execute asynchronously to give the UI events triggering this method\r
- // call time to run through before actually doing any resizing.\r
- // Otherwise the result will lag behind reality when scrollbar\r
- // visibility is toggled by the toolkit.\r
- Rectangle r = sc.getClientArea();\r
- Point contentSize = composite.computeSize(r.width, SWT.DEFAULT);\r
- //System.out.println("[" + Thread.currentThread() + "] computed content size: " + contentSize + ", " + r);\r
- composite.setSize(contentSize);\r
- }\r
- \r
- private class NewTrendListener implements MouseListener {\r
-\r
- @Override\r
- public void mouseUp(MouseEvent e) {\r
- final Canvas canvas = new Canvas(composite, SWT.BORDER);\r
- // Create a paint handler for the canvas\r
- canvas.addPaintListener(new PaintListener() {\r
- public void paintControl(PaintEvent e) {\r
- int canvasHeight = canvas.getSize().y;\r
- String text = "Module1.Variable2[index3]";\r
- Transform t = new Transform(e.display);\r
- t.rotate(-90);\r
- t.translate(- (canvasHeight - 10), 0);\r
- e.gc.setTransform(t);\r
- e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_BLACK));\r
- e.gc.drawText(text, 0, 0);\r
- }\r
- });\r
- GridDataFactory.fillDefaults().hint(20, SWT.DEFAULT).grab(false, true).applyTo(canvas);\r
- composite.layout();\r
- canvas.addMouseListener(this);\r
- canvas.setCursor(new Cursor(canvas.getDisplay(), SWT.CURSOR_HAND));\r
- ToolTipListener ttl = new ToolTipListener(canvas);\r
- canvas.addListener(SWT.Dispose, ttl);\r
- canvas.addListener(SWT.KeyDown, ttl);\r
- canvas.addListener(SWT.MouseMove, ttl);\r
- canvas.addListener(SWT.MouseHover, ttl);\r
+ expandedURIs = expandedCharts.toArray(new String[expandedCharts.size()]);\r
+ settings.put(EXPANDED_CHARTS, expandedURIs);\r
\r
- Composite swtComposite = new Composite(composite,\r
- SWT.NO_BACKGROUND | SWT.EMBEDDED);\r
- Frame frame = SWT_AWT.new_Frame(swtComposite);\r
- GridDataFactory.fillDefaults().hint(200, 200).applyTo(swtComposite);\r
- setChart(frame);\r
- syncRefreshScrolledComposite();\r
- }\r
-\r
- @Override\r
- public void mouseDown(MouseEvent e) {\r
- // TODO Auto-generated method stub\r
-\r
- }\r
-\r
- @Override\r
- public void mouseDoubleClick(MouseEvent e) {\r
- // TODO Auto-generated method stub\r
-\r
- }\r
+ String[] minimizedURIs = settings.getArray(MINIMIZED_CHARTS);\r
+ if (minimizedURIs == null) {\r
+ minimizedURIs = new String[0];\r
+ }\r
+ minimizedURIs = minimizedCharts.toArray(new String[minimizedCharts.size()]);\r
+ settings.put(MINIMIZED_CHARTS, minimizedURIs);\r
+ \r
+ if(vertical)\r
+ settings.put(CHART_PANEL_ORIENTATION, CHART_PANEL_VERTICAL);\r
+ else\r
+ settings.put(CHART_PANEL_ORIENTATION, CHART_PANEL_HORIZONTAL);\r
+ }\r
+ \r
}\r
\r
- \r
- private void setChart(Frame frame) {\r
- TimeSeries population = new TimeSeries("Indian Population");\r
- population.add(new Day(1, 3, 1961), 439234771);\r
- population.add(new Day(1, 3, 1971), 548159652);\r
- population.add(new Day(1, 3, 1981), 683329097);\r
- population.add(new Day(1, 3, 1991), 843387888);\r
- population.add(new Day(1, 3, 2001), 1028610328);\r
- population.add(new Day(1, 3, 2011), 1210193422);\r
- TimeSeriesCollection dataset = new TimeSeriesCollection(population);\r
+ /**\r
+ * Expand or minimize chart depending on the current status of that chart.\r
+ * \r
+ * @param chart The name of the chart to be expanded or minimized\r
+ */\r
+ public void expandChart(String chart) {\r
+ boolean expand = false;\r
+ if(minimizedCharts.contains(chart)) {\r
+ minimizedCharts.remove(chart);\r
+ expand = true;\r
+ }\r
\r
- // Create the chart\r
- JFreeChart chart = ChartFactory.createTimeSeriesChart(\r
- "Population of India", "Date", "Population", dataset,\r
- true, true, false);\r
+ if(expandedCharts.contains(chart))\r
+ expandedCharts.remove(chart);\r
\r
- //Get the plot and set date format\r
- XYPlot plot = chart.getXYPlot();\r
- DateAxis axis = (DateAxis) plot.getDomainAxis();\r
- axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));\r
-\r
- // Render the frame\r
- org.jfree.chart.ChartPanel panel = new org.jfree.chart.ChartPanel(chart);\r
- panel.setSize(200, 200);\r
- frame.add(panel);\r
+ if(expand)\r
+ expandedCharts.add(expandedCharts.isEmpty() ? 0 : expandedCharts.size(), chart);\r
+ else\r
+ minimizedCharts.add(0, chart);\r
+ \r
+ createContents(body);\r
}\r
-\r
\r
- \r
- private class ToolTipListener implements Listener {\r
- Shell tip = null;\r
- Label label = null;\r
- Composite composite;\r
+ /**\r
+ * Set the orientation for this chart panel.\r
+ * \r
+ * @param orientation Orientation (ChartPanel.CHART_PANEL_VERTICAL or ChartPanel.CHART_PANEL_HORIZONTAL)\r
+ */\r
+ public void setOrientation(String orientation) {\r
+ if(CHART_PANEL_VERTICAL.equals(orientation))\r
+ this.vertical = true;\r
+ else\r
+ this.vertical = false;\r
\r
- public ToolTipListener(Composite composite) {\r
- this.composite = composite;\r
- }\r
-\r
- public void handleEvent(Event event) {\r
- switch (event.type) {\r
- case SWT.Dispose:\r
- case SWT.KeyDown:\r
- case SWT.MouseMove: {\r
- if (tip == null)\r
- break;\r
- tip.dispose();\r
- tip = null;\r
- label = null;\r
- break;\r
- }\r
- case SWT.MouseHover: {\r
- if(composite.isDisposed())\r
- return;\r
- if (tip != null && !tip.isDisposed())\r
- tip.dispose();\r
- Display display = composite.getDisplay();\r
- tip = new Shell(display, SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);\r
- tip.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));\r
- FillLayout layout = new FillLayout();\r
- layout.marginWidth = 2;\r
- tip.setLayout(layout);\r
- label = new Label(tip, SWT.NONE);\r
- label.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));\r
- label.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));\r
- label.setText("Module1.Variable2[index3]");\r
-// label.addListener(SWT.MouseExit, labelListener);\r
-// label.addListener(SWT.MouseDown, labelListener);\r
- Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r
- Point pt = composite.toDisplay(event.x, event.y);\r
- tip.setBounds(pt.x, pt.y, size.x, size.y);\r
- tip.setVisible(true);\r
- }\r
- }\r
- }\r
- };\r
+ createContents(body);\r
+ }\r
}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.trend;\r
+\r
+import java.awt.Frame;\r
+import java.text.SimpleDateFormat;\r
+\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.awt.SWT_AWT;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.jfree.chart.ChartFactory;\r
+import org.jfree.chart.JFreeChart;\r
+import org.jfree.chart.axis.DateAxis;\r
+import org.jfree.chart.plot.XYPlot;\r
+import org.jfree.data.time.Day;\r
+import org.jfree.data.time.TimeSeries;\r
+import org.jfree.data.time.TimeSeriesCollection;\r
+\r
+/**\r
+ * This class represents an expanded chart element in {@link ChartPanel}. It contains \r
+ * a header {@link ChartPanelHeader} and the actual chart.\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class ChartPanelElement extends Composite {\r
+\r
+ public static int CHART_MINIMUM_WIDTH = 300;\r
+ public static int CHART_MINIMUM_HEIGHT = 200;\r
+ \r
+ /**\r
+ * Creates a chart panel element into parent composite.\r
+ * \r
+ * @param parent The parent composite where the chart element is created\r
+ * @param panel The {@link ChartPanel} containing the chart element\r
+ * @param name The name of the chart\r
+ * @param style The Style of the created chart element\r
+ */\r
+ public ChartPanelElement(Composite parent, ChartPanel panel, String name, int style) {\r
+ super(parent, style);\r
+ \r
+ GridDataFactory.fillDefaults().grab(true, true).hint(CHART_MINIMUM_WIDTH,CHART_MINIMUM_HEIGHT).applyTo(this);\r
+ GridLayoutFactory.fillDefaults().spacing(0,0).applyTo(this);\r
+ \r
+ // Header\r
+ new ChartPanelHeader(this, panel, name, SWT.BORDER);\r
+ \r
+ // Chart\r
+ Composite swtComposite = new Composite(this,\r
+ SWT.NO_BACKGROUND | SWT.EMBEDDED);\r
+ Frame frame = SWT_AWT.new_Frame(swtComposite);\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(swtComposite);\r
+ setChart(frame);\r
+ \r
+ }\r
+ \r
+ /** \r
+ * A dummy chart containing information about the population in India\r
+ * \r
+ * @param frame\r
+ */\r
+ private void setChart(Frame frame) {\r
+ TimeSeries population = new TimeSeries("Indian Population");\r
+ population.add(new Day(1, 3, 1961), 439234771);\r
+ population.add(new Day(1, 3, 1971), 548159652);\r
+ population.add(new Day(1, 3, 1981), 683329097);\r
+ population.add(new Day(1, 3, 1991), 843387888);\r
+ population.add(new Day(1, 3, 2001), 1028610328);\r
+ population.add(new Day(1, 3, 2011), 1210193422);\r
+ TimeSeriesCollection dataset = new TimeSeriesCollection(population);\r
+ \r
+ // Create the chart\r
+ JFreeChart chart = ChartFactory.createTimeSeriesChart(\r
+ "Population of India", "Date", "Population", dataset,\r
+ true, true, false);\r
+ \r
+ //Get the plot and set date format\r
+ XYPlot plot = chart.getXYPlot();\r
+ DateAxis axis = (DateAxis) plot.getDomainAxis();\r
+ axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));\r
+\r
+ // Render the frame\r
+ org.jfree.chart.ChartPanel panel = new org.jfree.chart.ChartPanel(chart);\r
+ panel.setSize(CHART_MINIMUM_WIDTH, CHART_MINIMUM_HEIGHT);\r
+ frame.add(panel);\r
+ }\r
+\r
+}\r