From: lempinen Date: Tue, 8 Nov 2011 10:50:20 +0000 (+0000) Subject: Orientation handling for the chart panel prototype X-Git-Tag: simantics-1.6~109 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=8b6ace550ca115d15b1d93ffc4e1b7e0e163aaa9;p=simantics%2Fsysdyn.git Orientation handling for the chart panel prototype git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23228 ac1ea38d-2e2b-0410-8846-a27921b304fc --- 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 00000000..813f712f Binary files /dev/null and b/org.simantics.sysdyn.ui/icons/page_white_text.png differ diff --git a/org.simantics.sysdyn.ui/icons/page_white_text_width.png b/org.simantics.sysdyn.ui/icons/page_white_text_width.png new file mode 100644 index 00000000..d9cf1325 Binary files /dev/null and b/org.simantics.sysdyn.ui/icons/page_white_text_width.png differ diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index c6f9ccb5..2fa55a78 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -107,6 +107,7 @@ @@ -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