From: lempinen Date: Mon, 12 Dec 2011 12:27:10 +0000 (+0000) Subject: Cleaned the look of charts, chart panel elements and model browser chart elements X-Git-Tag: simantics-1.6~71 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=910b34c1664ed38aac6718a50b97389fdfa80367;p=simantics%2Fsysdyn.git Cleaned the look of charts, chart panel elements and model browser chart elements git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23495 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.jfreechart.ontology/graph.tg b/org.simantics.jfreechart.ontology/graph.tg index f85899a2..d250dc96 100644 Binary files a/org.simantics.jfreechart.ontology/graph.tg and b/org.simantics.jfreechart.ontology/graph.tg differ diff --git a/org.simantics.jfreechart.ontology/graph/JFreeChart.pgraph b/org.simantics.jfreechart.ontology/graph/JFreeChart.pgraph index 4611e693..2526730c 100644 --- a/org.simantics.jfreechart.ontology/graph/JFreeChart.pgraph +++ b/org.simantics.jfreechart.ontology/graph/JFreeChart.pgraph @@ -45,6 +45,7 @@ JFREE.Plot -- JFREE.backgroundColor --> G2D.Color -- JFREE.Plot.visibleGrid --> L0.Boolean -- JFREE.Plot.rangeAxisList --> L0.List -- JFREE.Plot.visibleLabels --> L0.Boolean @@ -463,6 +464,7 @@ @@ -565,6 +567,7 @@ @@ -581,6 +584,7 @@ @@ -597,6 +601,7 @@ diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java index e6051f38..5ff989ea 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java @@ -17,6 +17,7 @@ import org.simantics.browsing.ui.swt.ImagerContributor; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.Activator; import org.simantics.sysdyn.ui.browser.nodes.BookNode; import org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode; @@ -50,9 +51,13 @@ public class AbstractNodeImager extends ImagerContributor image = "icons/folder.png"; else if (node instanceof ModuleTypeNode || node instanceof ModuleNode || node instanceof ConfigurationNode) image = "icons/bricks.png"; - else if (node instanceof ExperimentNode) - image = "icons/time.png"; - else if (node instanceof InputNode) + else if (node instanceof ExperimentNode) { + SysdynResource sr = SysdynResource.getInstance(graph); + if(graph.isInstanceOf(node.data, sr.PlaybackExperiment)) + image = "icons/timeline_marker.png"; + else + image = "icons/time.png"; + } else if (node instanceof InputNode) image = "icons/brick_link.png"; else if (node instanceof ModelNode) image = "icons/chart_organisation.png"; 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 af8781d9..38370a9e 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 @@ -149,7 +149,7 @@ public class ChartPanel extends ViewPart { setupDropTarget(); body = new Composite(sc, SWT.NONE); - GridLayoutFactory.fillDefaults().spacing(0, 0).applyTo(body); + GridLayoutFactory.fillDefaults().margins(3, 0).spacing(0, 0).applyTo(body); GridDataFactory.fillDefaults().grab(true, true).applyTo(body); sc.setContent(body); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelHeader.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelHeader.java index f0334fc6..e37b82fb 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelHeader.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelHeader.java @@ -13,21 +13,29 @@ package org.simantics.sysdyn.ui.trend; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.MouseListener; -import org.eclipse.swt.graphics.Cursor; -import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.common.request.PossibleObjectWithType; import org.simantics.db.exception.DatabaseException; import org.simantics.db.procedure.Listener; import org.simantics.db.request.Read; import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.Activator; import org.simantics.ui.SimanticsUI; +import org.simantics.utils.datastructures.Pair; /** * Header of a chart element in {@link ChartPanel}. Only this header is @@ -42,7 +50,29 @@ public class ChartPanelHeader extends Composite { public static int HEADER_MINIMUM_WIDTH = 250; private ChartPanel panel; private Resource resource; - private Label name, minimize, remove; + private Label name; + private Canvas iconCanvas; + private Image icon; + private ToolItem minimize, remove; + + private static ImageDescriptor closeDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/close.gif")); + private static Image closeImage = closeDescriptor.createImage(); + + private static ImageDescriptor minimizeDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/minimize.gif")); + private static Image minimizeImage = minimizeDescriptor.createImage(); + + private static ImageDescriptor maximizeDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/maximize.gif")); + private static Image maximizeImage = maximizeDescriptor.createImage(); + + private static ImageDescriptor lineChartDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_line_light.png")); + private static Image lineChartImage = lineChartDescriptor.createImage(); + + private static ImageDescriptor barChartDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_bar_light.png")); + private static Image barChartImage = barChartDescriptor.createImage(); + + private static ImageDescriptor pieChartDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_pie_light.png")); + private static Image pieChartImage = pieChartDescriptor.createImage(); + /** * Chart panel header with minimize and close buttons. @@ -57,34 +87,65 @@ public class ChartPanelHeader extends Composite { this.resource = chartResource; this.panel = panel; - GridLayoutFactory.fillDefaults().numColumns(3).applyTo(this); + GridLayoutFactory.fillDefaults().margins(3, 0).numColumns(3).applyTo(this); GridDataFactory.fillDefaults().grab(true, false).applyTo(this); + // Chart icon + iconCanvas = new Canvas (this, SWT.NONE); + GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).hint(16, 16).applyTo(iconCanvas); + iconCanvas.addPaintListener (new PaintListener() { + + @Override + public void paintControl(PaintEvent e) { + if(icon != null) + e.gc.drawImage (icon, 0, 0); + } + }); + // Label for the chart name (also minimize/expand) name = new Label(this, SWT.NONE); try { // name updater - SimanticsUI.getSession().syncRequest(new Read() { + SimanticsUI.getSession().syncRequest(new Read>() { @Override - public String perform(ReadGraph graph) throws DatabaseException { - return graph.getPossibleRelatedValue(resource, Layer0.getInstance(graph).HasLabel); + public Pair perform(ReadGraph graph) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + String label = graph.getPossibleRelatedValue(resource, l0.HasLabel); + Image image = null; + Resource plot = graph.syncRequest(new PossibleObjectWithType(resource, l0.ConsistsOf, jfree.Plot)); + if(plot != null) { + if(graph.isInstanceOf(plot, jfree.CategoryPlot)) + image = barChartImage; + else if(graph.isInstanceOf(plot, jfree.PiePlot)) + image = pieChartImage; + else + image = lineChartImage; + } + return new Pair(label, image); } - }, new Listener() { + }, new Listener>() { @Override - public void execute(final String result) { + public void execute(final Pair result) { if(result == null) return; - + name.getDisplay().asyncExec(new Runnable() { - + @Override public void run() { - if(!name.isDisposed()) - name.setText(result); + if(!name.isDisposed() && result.first != null) + name.setText(result.first); + + if(!iconCanvas.isDisposed() && result.second != null) { + icon = result.second; + iconCanvas.redraw(); + ChartPanelHeader.this.layout(); + } } }); } @@ -104,36 +165,27 @@ public class ChartPanelHeader extends Composite { e.printStackTrace(); name.setText("No label"); } - - GridDataFactory.fillDefaults().grab(true, false).applyTo(name); - name.addMouseListener(new MinimizeListener(name)); - name.setCursor(new Cursor(name.getDisplay(), SWT.CURSOR_HAND)); - if(isMinimized()) - name.setToolTipText("Expand"); - else - name.setToolTipText("Minimize"); - - // Label for minimizing/expanding chart - minimize = new Label(this, SWT.NONE); - minimize.setText("^"); - GridDataFactory.fillDefaults().applyTo(minimize); - minimize.addMouseListener(new MinimizeListener(minimize)); - minimize.setCursor(new Cursor(minimize.getDisplay(), SWT.CURSOR_HAND)); - if(isMinimized()) + + ToolBar toolbar = new ToolBar(this, SWT.FLAT); + // item for minimizing/expanding chart + minimize = new ToolItem(toolbar, SWT.PUSH); + minimize.addSelectionListener(new MinimizeListener()); + if(isMinimized()) { minimize.setToolTipText("Expand"); - else + minimize.setImage(maximizeImage); + } else { minimize.setToolTipText("Minimize"); + minimize.setImage(minimizeImage); + } - // Label for closing/removing the chart - remove = new Label(this, SWT.NONE); - remove.setText("x"); - GridDataFactory.fillDefaults().applyTo(remove); - remove.addMouseListener(new RemoveChartListener(remove)); - remove.setCursor(new Cursor(remove.getDisplay(), SWT.CURSOR_HAND)); + // item for closing/removing the chart + remove = new ToolItem(toolbar, SWT.PUSH); + remove.setImage(closeImage); + remove.addSelectionListener(new RemoveChartListener()); remove.setToolTipText("Remove"); } - + /** * Return true if this element is minimized, false if expanded * @return true if this element is minimized, false if expanded @@ -143,39 +195,19 @@ public class ChartPanelHeader extends Composite { } /** - * Mouse listener to minimize chart button. Expands and minimizes + * Listener to minimize chart button. Expands and minimizes * the chart of this header. * * @author Teemu Lempinen * */ - private class MinimizeListener implements MouseListener { - - private Control control; - - public MinimizeListener(Control control) { - this.control = control; - } - + private class MinimizeListener implements SelectionListener { @Override - public void mouseDoubleClick(MouseEvent e) { - } - @Override - public void mouseDown(MouseEvent e) { - panel.setFocus(); - } - - @Override - public void mouseUp(MouseEvent e) { + public void widgetSelected(SelectionEvent e) { if(ChartPanelHeader.this.isDisposed()) return; - // Expand only if mouse was released inside the control - Rectangle bounds = control.getBounds(); - bounds.x = 0; - bounds.y = 0; - if(bounds.contains(e.x, e.y)) - panel.expandChart(resource); + panel.expandChart(resource); if(!name.isDisposed() && !minimize.isDisposed()) { if(isMinimized()) { @@ -185,46 +217,33 @@ public class ChartPanelHeader extends Composite { name.setToolTipText("Minimize"); minimize.setToolTipText("Minimize"); } - } + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); } } /** - * Mouse listener for removing this chart from the chart panel. + * Listener for removing this chart from the chart panel. * * @author Teemu Lempinen * */ - private class RemoveChartListener implements MouseListener { - - Control control; - - public RemoveChartListener(Control control) { - this.control = control; - } - - @Override - public void mouseDoubleClick(MouseEvent e) { - } - - @Override - public void mouseDown(MouseEvent e) { - panel.setFocus(); - } - + private class RemoveChartListener implements SelectionListener { @Override - public void mouseUp(MouseEvent e) { + public void widgetSelected(SelectionEvent e) { if(!ChartPanelHeader.this.isDisposed()) { - // Remove only if mouse was released inside the control - Rectangle bounds = control.getBounds(); - bounds.x = 0; - bounds.y = 0; - if(bounds.contains(e.x, e.y)) - panel.removeChart(resource); + panel.removeChart(resource); } + } - + @Override + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/BarRenderer.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/BarRenderer.java index d708ac5f..7d80fb88 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/BarRenderer.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/BarRenderer.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.trend.chart; +import org.jfree.chart.labels.StandardCategoryToolTipGenerator; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; @@ -30,8 +31,10 @@ public class BarRenderer extends AbstractRenderer { @Override public org.jfree.chart.renderer.AbstractRenderer getRenderer() { - if(renderer == null) + if(renderer == null) { renderer = new org.jfree.chart.renderer.category.BarRenderer(); + renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); + } return renderer; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryPlot.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryPlot.java index 60a00925..297eb678 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryPlot.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryPlot.java @@ -15,6 +15,7 @@ import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.Plot; import org.jfree.chart.renderer.category.CategoryItemRenderer; +import org.jfree.ui.RectangleInsets; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; @@ -81,6 +82,10 @@ public class CategoryPlot extends AbstractPlot { plot.setDomainGridlinesVisible(false); } + // Cleaner look: no outline borders + plot.setInsets(new RectangleInsets(2,2,2,2), false); + plot.setOutlineVisible(false); + return plot; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java index 830ff222..826c0320 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java @@ -11,12 +11,14 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.trend.chart; +import java.awt.Color; +import java.awt.Font; import java.lang.reflect.InvocationTargetException; import java.util.Collection; import javax.swing.SwingUtilities; -import org.jfree.chart.title.LegendTitle; +import org.jfree.ui.RectangleInsets; import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; @@ -82,16 +84,21 @@ public class JFreeChart implements IJFreeChart { @Override public void run() { jfreechart = new org.jfree.chart.JFreeChart(plot.getPlot()); + + jfreechart.setBackgroundPaint(Color.WHITE); + jfreechart.getLegend().setBorder(0, 0, 0, 0); + int size = jfreechart.getLegend().getItemFont().getSize(); + jfreechart.getLegend().setItemFont(new Font("helvetica", Font.PLAIN, size)); + org.jfree.chart.title.TextTitle t = (org.jfree.chart.title.TextTitle)title.getTitle(); - if(t.isVisible()) + if(t.isVisible()) { + t.setFont(new Font("georgia", Font.BOLD, 13)); + t.setPadding(new RectangleInsets(4, 0, 0, 0)); jfreechart.setTitle(t); + } if(legendVisible != null && !legendVisible) { - for(Object title : jfreechart.getSubtitles()) { - if(title instanceof LegendTitle) { - jfreechart.removeLegend(); - } - } + jfreechart.removeLegend(); } } }); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java index 62da8804..231b6446 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java @@ -12,15 +12,22 @@ package org.simantics.sysdyn.ui.trend.chart; import java.awt.Color; +import java.awt.Font; import java.util.HashMap; +import org.jfree.chart.labels.StandardPieSectionLabelGenerator; +import org.jfree.chart.labels.StandardPieToolTipGenerator; import org.jfree.chart.plot.DefaultDrawingSupplier; import org.jfree.chart.plot.Plot; import org.jfree.data.general.Dataset; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.DatasetChangeListener; +import org.jfree.ui.RectangleInsets; +import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.JFreeChartResource; /** * Class representing a PiePlot in JFreeChart ontology @@ -30,18 +37,27 @@ import org.simantics.db.Resource; */ public class PiePlot extends AbstractPlot { - org.jfree.chart.plot.PiePlot plot; - org.jfree.data.general.PieDataset pieDataset; - DatasetChangeListener listener; + private org.jfree.chart.plot.PiePlot plot; + private org.jfree.data.general.PieDataset pieDataset; + private DatasetChangeListener listener; + + private Boolean labelsVisible; public PiePlot(ReadGraph graph, Resource resource) { super(graph, resource); + + try { + labelsVisible = graph.getPossibleRelatedValue(resource, JFreeChartResource.getInstance(graph).Plot_visibleLabels, Bindings.BOOLEAN); + } catch (DatabaseException e) { + e.printStackTrace(); + } } @Override public Plot getPlot() { if(plot == null) { plot = new MyPiePlot(); + plot.setToolTipGenerator(new StandardPieToolTipGenerator()); } if(!datasets.isEmpty()) { @@ -49,15 +65,16 @@ public class PiePlot extends AbstractPlot { final IDataset ds = datasets.get(0); Dataset dataset = ((PieDataset)ds).getDataset(); - plot.clearSectionPaints(true); - plot.setDrawingSupplier(new DefaultDrawingSupplier()); - if(pieDataset != null && listener != null) { pieDataset.removeChangeListener(listener); } pieDataset = (org.jfree.data.general.PieDataset)dataset; plot.setDataset(pieDataset); + if(Boolean.FALSE.equals(labelsVisible)) + plot.setLabelGenerator(null); + else if(plot.getLabelGenerator() == null) + plot.setLabelGenerator(new StandardPieSectionLabelGenerator()); listener = new DatasetChangeListener() { @@ -83,9 +100,8 @@ public class PiePlot extends AbstractPlot { if(Boolean.TRUE.equals(exploded)) plot.setExplodePercent(name, 0.3); } - + plot.clearSectionPaints(false); plot.setDrawingSupplier(new DefaultDrawingSupplier()); - for(String name : colorMap.keySet()) plot.setSectionPaint(name, colorMap.get(name)); } @@ -93,6 +109,13 @@ public class PiePlot extends AbstractPlot { pieDataset.addChangeListener(listener); } + + // Cleaner look: no outline borders + plot.setInsets(new RectangleInsets(0,0,0,0), false); + plot.setOutlineVisible(false); + plot.setLabelBackgroundPaint(Color.WHITE); + plot.setLabelFont(new Font("helvetica", Font.PLAIN, 11)); + return plot; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/StackedBarRenderer.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/StackedBarRenderer.java index daf266b8..cd7f4cbf 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/StackedBarRenderer.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/StackedBarRenderer.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.trend.chart; +import org.jfree.chart.labels.StandardCategoryToolTipGenerator; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; @@ -29,8 +30,10 @@ public class StackedBarRenderer extends AbstractRenderer { @Override public org.jfree.chart.renderer.AbstractRenderer getRenderer() { - if(renderer == null) + if(renderer == null) { renderer = new org.jfree.chart.renderer.category.StackedBarRenderer(); + renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); + } return renderer; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYDataset.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYDataset.java index a9d6ce80..b2981b9f 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYDataset.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYDataset.java @@ -13,12 +13,15 @@ package org.simantics.sysdyn.ui.trend.chart; import java.awt.BasicStroke; import java.awt.Color; +import java.awt.Paint; import java.awt.Stroke; import java.util.ArrayList; import java.util.List; import javax.swing.SwingUtilities; +import org.jfree.chart.ChartColor; +import org.jfree.chart.labels.StandardXYToolTipGenerator; import org.jfree.chart.plot.DefaultDrawingSupplier; import org.jfree.chart.plot.ValueMarker; import org.jfree.chart.renderer.AbstractRenderer; @@ -155,20 +158,20 @@ public class XYDataset extends AbstractDataset { // Get a variable for the series Variable v = Variables.getVariable(graph, realizationURI + rvi); - + // Get values Object object = v.getPossiblePropertyValue(graph, SysdynVariableProperties.ACTIVE_DATASETS , Bindings.VARIANT); if(object == null || !(object instanceof ArrayList)) return series; - + ArrayList datasets = new ArrayList(); for(Object o : (ArrayList)object) { if(o instanceof SysdynDataSet) datasets.add((SysdynDataSet)o); } - - + + String[] filter = graph.getPossibleRelatedValue(r, jfree.variableFilter); if(filter != null) { ArrayList result2 = VariableRVIUtils.getDataset(datasets, filter); @@ -176,7 +179,7 @@ public class XYDataset extends AbstractDataset { datasets = result2; } } - + for(SysdynDataSet dataset : datasets) { double[] va = dataset.values; @@ -228,7 +231,7 @@ public class XYDataset extends AbstractDataset { } if(timeListener == null || timeListener.isDisposed()) { - timeListener = new TimeListener(new ValueMarker(0.0)); + timeListener = new TimeListener(); SimanticsUI.getSession().asyncRequest(new Read() { @Override public Double perform(ReadGraph graph) throws DatabaseException { @@ -257,6 +260,18 @@ public class XYDataset extends AbstractDataset { return dataset; } + /** + * Class for identifying a time marker in a plot + * @author Teemu Lempinen + * + */ + private class TimeMarker extends ValueMarker { + private static final long serialVersionUID = 2018755066561629172L; + + public TimeMarker(double value, Paint paint, Stroke stroke) { + super(value, paint, stroke); + } + } private class DataSetListener implements Listener> { @@ -278,7 +293,21 @@ public class XYDataset extends AbstractDataset { @Override public void run() { - ((AbstractXYItemRenderer)getRenderer()).getPlot().setDrawingSupplier(new DefaultDrawingSupplier()); + + /* + * Drawing supplier with a modified first yellow. The default first + * yellow is too light to be visible against a white background + */ + Paint[] paintSequence = ChartColor.createDefaultPaintArray(); + paintSequence[3] = new Color(0xFF, 0xDD, 0x00); + DefaultDrawingSupplier drawingsupplier = new DefaultDrawingSupplier( + paintSequence, + DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE, + DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, + DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, + DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, + DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE); + ((AbstractXYItemRenderer)getRenderer()).getPlot().setDrawingSupplier(drawingsupplier); // Remove all series for(int i = dataset.getSeriesCount() - 1; i >= 0; i-- ) { dataset.removeSeries(dataset.getSeriesKey(i)); @@ -303,17 +332,29 @@ public class XYDataset extends AbstractDataset { } + /** + * Listener for updating the time indicator for XY plots + * @author Teemu Lempinen + * + */ private class TimeListener implements Listener { private ValueMarker marker; private boolean disposed = false; + private Stroke dashStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, + BasicStroke.JOIN_MITER, 10.0f, new float[] {5.0f, 3.0f, 1.0f, 3.0f}, 0.0f); - public TimeListener(ValueMarker marker) { - this.marker = marker; + public TimeListener() { + this.marker = new TimeMarker(0.0, Color.red, dashStroke); } public void dispose() { this.disposed = true; + if(marker != null) { + org.jfree.chart.plot.XYPlot plot = ((AbstractXYItemRenderer)getRenderer()).getPlot(); + if(plot != null) + plot.removeDomainMarker(marker); + } } @Override @@ -330,18 +371,20 @@ public class XYDataset extends AbstractDataset { public void run() { org.jfree.chart.plot.XYPlot plot = ((AbstractXYItemRenderer)getRenderer()).getPlot(); - int i = 0; - for(i = 0; i < plot.getDatasetCount(); i++) { - if(plot.getDataset(i).equals(dataset)) - break; - } + if(plot == null) + return; plot.removeDomainMarker(marker); if(time != null) { - Stroke dashStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, - BasicStroke.JOIN_MITER, 10.0f, new float[] {5.0f, 3.0f, 1.0f, 3.0f}, 0.0f); - marker = new ValueMarker(time, Color.red, dashStroke); - plot.addDomainMarker(i, marker, Layer.FOREGROUND); + marker.setValue(time); + if(plot.getDomainMarkers(Layer.FOREGROUND) == null || !plot.getDomainMarkers(Layer.FOREGROUND).contains(marker)) { + int i = 0; + for(i = 0; i < plot.getDatasetCount(); i++) { + if(plot.getDataset(i) != null && plot.getDataset(i).equals(dataset)) + break; + } + plot.addDomainMarker(i, marker, Layer.FOREGROUND); + } } } @@ -390,8 +433,10 @@ public class XYDataset extends AbstractDataset { @Override public AbstractRenderer getRenderer() { - if(renderer == null) + if(renderer == null) { renderer = new XYLineAndShapeRenderer(true, false); + renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); + } return renderer; } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYPlot.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYPlot.java index a64f9cf1..af0cc336 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYPlot.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYPlot.java @@ -15,6 +15,7 @@ import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.Plot; import org.jfree.chart.renderer.xy.XYItemRenderer; import org.jfree.data.xy.XYDataset; +import org.jfree.ui.RectangleInsets; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; @@ -80,6 +81,10 @@ public class XYPlot extends AbstractPlot { plot.setRangeGridlinesVisible(visibleGrid); plot.setDomainGridlinesVisible(visibleGrid); + // Cleaner look: no outline borders + plot.setInsets(new RectangleInsets(2,2,2,2), false); + plot.setOutlineVisible(false); + return plot; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieGeneralPropertiesTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieGeneralPropertiesTab.java index fdff61b0..bbaa7b4b 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieGeneralPropertiesTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieGeneralPropertiesTab.java @@ -44,7 +44,7 @@ public class PieGeneralPropertiesTab extends LabelPropertyTabContributor { private ScrolledComposite sc; private Composite composite; - private Button htitle, hlegend; + private Button htitle, hlegend, hlabels; private TrackedText name, title; @Override @@ -101,6 +101,10 @@ public class PieGeneralPropertiesTab extends LabelPropertyTabContributor { hlegend.setText("Legend"); hlegend.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Chart_visibleLegend, true)); hlegend.addSelectionListener(new BooleanSelectionListener(context, null, JFreeChartResource.URIs.Chart_visibleLegend)); + hlabels = new Button(hideGroup, support, SWT.CHECK); + hlabels.setText("Section labels"); + hlabels.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleLabels, true)); + hlabels.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleLabels)); sc.setContent(composite); Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);