From 8b6ace550ca115d15b1d93ffc4e1b7e0e163aaa9 Mon Sep 17 00:00:00 2001 From: lempinen Date: Tue, 8 Nov 2011 10:50:20 +0000 Subject: [PATCH] Orientation handling for the chart panel prototype git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23228 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../icons/page_white_text.png | Bin 0 -> 342 bytes .../icons/page_white_text_width.png | Bin 0 -> 315 bytes org.simantics.sysdyn.ui/plugin.xml | 20 +- .../ChartPanelOrientationHandler.java | 101 +++++ .../simantics/sysdyn/ui/trend/ChartPanel.java | 411 ++++++++---------- .../sysdyn/ui/trend/ChartPanelElement.java | 99 +++++ .../sysdyn/ui/trend/ChartPanelHeader.java | 94 ++++ 7 files changed, 497 insertions(+), 228 deletions(-) create mode 100644 org.simantics.sysdyn.ui/icons/page_white_text.png create mode 100644 org.simantics.sysdyn.ui/icons/page_white_text_width.png create mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ChartPanelOrientationHandler.java create mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelElement.java create mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelHeader.java diff --git a/org.simantics.sysdyn.ui/icons/page_white_text.png b/org.simantics.sysdyn.ui/icons/page_white_text.png new file mode 100644 index 0000000000000000000000000000000000000000..813f712f726c935f9adf8d2f2dd0d7683791ef11 GIT binary patch literal 342 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6SkfJR9T^zbpD<_bdI{u9mbgZg z1m~xflqVLYGB~E>C#5QQ<|d}62BjvZR2H60wE-%6;pyTSA|c6o&@eC9QG)Hj&ExYL zO&oVL^)+cM^qd@ApywS>pwx0H@RDN}hq;7mU-SKczYQ-hnrr=;iDAQMZQ+*g=YOM= z!QlMQEn7FbaD->uKAYgo_j9)W&$$zS*W9}m(ey0q$&7l-XEWO0Y(9M=SnhLbwy;d>@~SY$Ku*0xPvIOQeV1x7u_z-2-X>_74(yfh7C znXL|3GZ+d2`3re2hs?MKC#5QQ<|d}62BjvZR2H60wE-$R>*?YcqH(@;f-l!01CbW>s1Izr z3LkoHh<3E?TVANoG4CX|$empRCCS=R(U(hVJfm~E?IkDKRK&NP2|n`v>d(vV;W1uY zrFGVdwn;4b{qUtE`?GB`)E1ga&i2|7ncUL1b!KMq^QnT#_gn?_Z8(c`1Q~Vy3oL!N z$M8vHL&U1J3SJF!56azQU3B6>r|Z @@ -735,6 +736,16 @@ style="push"> + + + + @@ -904,6 +915,11 @@ id="org.simantics.sysdyn.ui.playbackReload" name="Reload Playback"> + + diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ChartPanelOrientationHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ChartPanelOrientationHandler.java new file mode 100644 index 00000000..c000bf81 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ChartPanelOrientationHandler.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * 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: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers; + +import java.util.Map; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.commands.ICommandService; +import org.eclipse.ui.commands.IElementUpdater; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.menus.UIElement; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.sysdyn.ui.trend.ChartPanel; + +/** + * This handler changes the orientation of a {@link ChartPanel} + * + * @author Teemu Lempinen + * + */ +public class ChartPanelOrientationHandler extends AbstractHandler implements IElementUpdater { + + private static String COMMAND = "org.simantics.sysdyn.ui.chartPanelOrientation"; + + /** + * Read chart panel settings from IDialogSettings and change the orientation accordingly. + * Finally order the element to update its appearance. + */ + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + IWorkbenchPart part = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getActivePart(); + if(part instanceof ChartPanel) { + IDialogSettings settings = Activator.getDefault().getDialogSettings().getSection(ChartPanel.CHART_PANEL_SETTINGS); + if (settings == null) { + settings = Activator.getDefault().getDialogSettings().addNewSection(ChartPanel.CHART_PANEL_SETTINGS); + } + + String orientation = settings.get(ChartPanel.CHART_PANEL_ORIENTATION); + if(orientation == null) + settings.put(ChartPanel.CHART_PANEL_ORIENTATION, ChartPanel.CHART_PANEL_VERTICAL); + + if(ChartPanel.CHART_PANEL_VERTICAL.equals(orientation)) + orientation = ChartPanel.CHART_PANEL_HORIZONTAL; + else + orientation = ChartPanel.CHART_PANEL_VERTICAL; + + settings.put(ChartPanel.CHART_PANEL_ORIENTATION, orientation); + ((ChartPanel)part).setOrientation(orientation); + + ICommandService commandService = + (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); + commandService.refreshElements(COMMAND, null); + } + + return null; + } + + /** + * Update the icon of the element. The new icon and text are always opposite to the current situation. + */ + @SuppressWarnings("rawtypes") + @Override + public void updateElement(UIElement element, Map parameters) { + if(parameters == null) + return; + + IDialogSettings settings = Activator.getDefault().getDialogSettings().getSection(ChartPanel.CHART_PANEL_SETTINGS); + if (settings == null) { + settings = Activator.getDefault().getDialogSettings().addNewSection(ChartPanel.CHART_PANEL_SETTINGS); + } + + String orientation = settings.get(ChartPanel.CHART_PANEL_ORIENTATION); + if(orientation == null) + return; + + // Show the opposite icon and text to indicate change when the button is pressed + if(ChartPanel.CHART_PANEL_HORIZONTAL.equals(orientation)) { + element.setIcon(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/page_white_text.png"))); + element.setTooltip("Vertical Orientation"); + } else if (ChartPanel.CHART_PANEL_VERTICAL.equals(orientation)) { + element.setIcon(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/page_white_text_width.png"))); + element.setTooltip("Horizontal Orientation"); + } + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanel.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanel.java index 65e97ddf..5782adf4 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanel.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanel.java @@ -11,267 +11,226 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.trend; -import java.awt.Frame; -import java.text.SimpleDateFormat; +import java.util.ArrayList; +import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.swt.SWT; -import org.eclipse.swt.awt.SWT_AWT; import org.eclipse.swt.custom.ScrolledComposite; -import org.eclipse.swt.events.ControlAdapter; -import org.eclipse.swt.events.ControlEvent; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.MouseListener; -import org.eclipse.swt.events.PaintEvent; -import org.eclipse.swt.events.PaintListener; -import org.eclipse.swt.graphics.Cursor; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.graphics.Transform; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.IViewSite; +import org.eclipse.ui.PartInitException; import org.eclipse.ui.part.ViewPart; -import org.jfree.chart.ChartFactory; -import org.jfree.chart.ChartFrame; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.axis.DateAxis; -import org.jfree.chart.plot.XYPlot; -import org.jfree.data.time.Day; -import org.jfree.data.time.TimeSeries; -import org.jfree.data.time.TimeSeriesCollection; -import org.simantics.g2d.chassis.SWTChassis; -import org.simantics.utils.threads.SWTThread; -import org.simantics.utils.threads.ThreadUtils; -import org.simantics.utils.ui.SWTAWTComponent; - +import org.simantics.sysdyn.ui.Activator; + +/** + * Chart panel displays multiple charts in a single view. The view can be oriented + * vertically or horizontally, the default is vertical. Charts can be added, removed + * minimized or expanded. The order of the charts can be changed by dragging the charts. + * + * @author Teemu Lempinen + * + */ public class ChartPanel extends ViewPart { - ScrolledComposite sc; - Composite composite; + private Composite body; + private ScrolledComposite sc; + + private IDialogSettings settings; + private ArrayList expandedCharts; + private ArrayList minimizedCharts; + +// private ArrayList elements; +// private ArrayList