>-- JFREE.backgroundColor --> G2D.Color <R L0.HasProperty : L0.FunctionalRelation
>-- JFREE.Plot.visibleGrid --> L0.Boolean <R L0.HasProperty : L0.FunctionalRelation
>-- JFREE.Plot.rangeAxisList --> L0.List <R L0.HasProperty : L0.FunctionalRelation
+ >-- JFREE.Plot.visibleLabels --> L0.Boolean <R L0.HasProperty : L0.FunctionalRelation
JFREE.CategoryPlot <T JFREE.Plot
JFREE.XYPlot <T JFREE.Plot
public final Resource Plot_rangeAxis_Inverse;\r
public final Resource Plot_visibleGrid;\r
public final Resource Plot_visibleGrid_Inverse;\r
+ public final Resource Plot_visibleLabels;\r
+ public final Resource Plot_visibleLabels_Inverse;\r
public final Resource Position;\r
public final Resource Renderer;\r
public final Resource Right;\r
public static final String Plot_rangeAxis_Inverse = "http://www.simantics.org/JFreeChart-1.0/Plot/rangeAxis/Inverse";\r
public static final String Plot_visibleGrid = "http://www.simantics.org/JFreeChart-1.0/Plot/visibleGrid";\r
public static final String Plot_visibleGrid_Inverse = "http://www.simantics.org/JFreeChart-1.0/Plot/visibleGrid/Inverse";\r
+ public static final String Plot_visibleLabels = "http://www.simantics.org/JFreeChart-1.0/Plot/visibleLabels";\r
+ public static final String Plot_visibleLabels_Inverse = "http://www.simantics.org/JFreeChart-1.0/Plot/visibleLabels/Inverse";\r
public static final String Position = "http://www.simantics.org/JFreeChart-1.0/Position";\r
public static final String Renderer = "http://www.simantics.org/JFreeChart-1.0/Renderer";\r
public static final String Right = "http://www.simantics.org/JFreeChart-1.0/Right";\r
Plot_rangeAxis_Inverse = getResourceOrNull(graph, URIs.Plot_rangeAxis_Inverse);\r
Plot_visibleGrid = getResourceOrNull(graph, URIs.Plot_visibleGrid);\r
Plot_visibleGrid_Inverse = getResourceOrNull(graph, URIs.Plot_visibleGrid_Inverse);\r
+ Plot_visibleLabels = getResourceOrNull(graph, URIs.Plot_visibleLabels);\r
+ Plot_visibleLabels_Inverse = getResourceOrNull(graph, URIs.Plot_visibleLabels_Inverse);\r
Position = getResourceOrNull(graph, URIs.Position);\r
Renderer = getResourceOrNull(graph, URIs.Renderer);\r
Right = getResourceOrNull(graph, URIs.Right);\r
</command>\r
<command\r
commandId="org.simantics.sysdyn.ui.newExperiment"\r
+ icon="platform:/plugin/com.famfamfam.silk/icons/time.png"\r
id="org.simantics.sysdyn.ui.browser.newExperiment"\r
label="Experiment"\r
style="push">\r
</command>\r
<command\r
commandId="org.simantics.sysdyn.ui.newPlaybackExperiment"\r
+ icon="platform:/plugin/com.famfamfam.silk/icons/timeline_marker.png"\r
id="org.simantics.sysdyn.ui.browser.newPlaybackExperiment"\r
label="Playback Experiment"\r
style="push">\r
</command>\r
<command\r
commandId="org.simantics.sysdyn.ui.newXYLineChart"\r
+ icon="platform:/plugin/com.famfamfam.silk/icons/chart_line.png"\r
id="org.simantics.sysdyn.ui.browser.newXYLineChart"\r
label="Line Chart"\r
style="push">\r
</command>\r
<command\r
commandId="org.simantics.sysdyn.ui.newBarChart"\r
+ icon="platform:/plugin/com.famfamfam.silk/icons/chart_bar.png"\r
id="org.simantics.sysdyn.ui.browser.newBarChart"\r
label="Bar Chart"\r
style="push">\r
</command>\r
<command\r
commandId="org.simantics.sysdyn.ui.newPieChart"\r
+ icon="platform:/plugin/com.famfamfam.silk/icons/chart_pie.png"\r
id="org.simantics.sysdyn.ui.browser.newPieChart"\r
label="Pie Chart"\r
style="push">\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.Activator;\r
import org.simantics.sysdyn.ui.browser.nodes.BookNode;\r
import org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode;\r
image = "icons/folder.png";\r
else if (node instanceof ModuleTypeNode || node instanceof ModuleNode || node instanceof ConfigurationNode)\r
image = "icons/bricks.png";\r
- else if (node instanceof ExperimentNode)\r
- image = "icons/time.png";\r
- else if (node instanceof InputNode)\r
+ else if (node instanceof ExperimentNode) {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ if(graph.isInstanceOf(node.data, sr.PlaybackExperiment))\r
+ image = "icons/timeline_marker.png";\r
+ else\r
+ image = "icons/time.png";\r
+ } else if (node instanceof InputNode)\r
image = "icons/brick_link.png";\r
else if (node instanceof ModelNode)\r
image = "icons/chart_organisation.png";\r
setupDropTarget();\r
\r
body = new Composite(sc, SWT.NONE);\r
- GridLayoutFactory.fillDefaults().spacing(0, 0).applyTo(body);\r
+ GridLayoutFactory.fillDefaults().margins(3, 0).spacing(0, 0).applyTo(body);\r
GridDataFactory.fillDefaults().grab(true, true).applyTo(body);\r
\r
sc.setContent(body);\r
\r
import org.eclipse.jface.layout.GridDataFactory;\r
import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.jface.resource.ImageDescriptor;\r
import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.events.MouseEvent;\r
-import org.eclipse.swt.events.MouseListener;\r
-import org.eclipse.swt.graphics.Cursor;\r
-import org.eclipse.swt.graphics.Rectangle;\r
+import org.eclipse.swt.events.PaintEvent;\r
+import org.eclipse.swt.events.PaintListener;\r
+import org.eclipse.swt.events.SelectionEvent;\r
+import org.eclipse.swt.events.SelectionListener;\r
+import org.eclipse.swt.graphics.Image;\r
+import org.eclipse.swt.widgets.Canvas;\r
import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Control;\r
import org.eclipse.swt.widgets.Label;\r
+import org.eclipse.swt.widgets.ToolBar;\r
+import org.eclipse.swt.widgets.ToolItem;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.PossibleObjectWithType;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.procedure.Listener;\r
import org.simantics.db.request.Read;\r
import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.JFreeChartResource;\r
+import org.simantics.sysdyn.ui.Activator;\r
import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.datastructures.Pair;\r
\r
/**\r
* Header of a chart element in {@link ChartPanel}. Only this header is\r
public static int HEADER_MINIMUM_WIDTH = 250;\r
private ChartPanel panel;\r
private Resource resource;\r
- private Label name, minimize, remove;\r
+ private Label name;\r
+ private Canvas iconCanvas;\r
+ private Image icon;\r
+ private ToolItem minimize, remove;\r
+\r
+ private static ImageDescriptor closeDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/close.gif"));\r
+ private static Image closeImage = closeDescriptor.createImage();\r
+\r
+ private static ImageDescriptor minimizeDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/minimize.gif"));\r
+ private static Image minimizeImage = minimizeDescriptor.createImage();\r
+\r
+ private static ImageDescriptor maximizeDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/maximize.gif"));\r
+ private static Image maximizeImage = maximizeDescriptor.createImage();\r
+\r
+ private static ImageDescriptor lineChartDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_line_light.png"));\r
+ private static Image lineChartImage = lineChartDescriptor.createImage();\r
+\r
+ private static ImageDescriptor barChartDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_bar_light.png"));\r
+ private static Image barChartImage = barChartDescriptor.createImage();\r
+\r
+ private static ImageDescriptor pieChartDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_pie_light.png"));\r
+ private static Image pieChartImage = pieChartDescriptor.createImage();\r
+\r
\r
/**\r
* Chart panel header with minimize and close buttons.\r
this.resource = chartResource;\r
this.panel = panel;\r
\r
- GridLayoutFactory.fillDefaults().numColumns(3).applyTo(this);\r
+ GridLayoutFactory.fillDefaults().margins(3, 0).numColumns(3).applyTo(this);\r
GridDataFactory.fillDefaults().grab(true, false).applyTo(this);\r
\r
+ // Chart icon\r
+ iconCanvas = new Canvas (this, SWT.NONE);\r
+ GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).hint(16, 16).applyTo(iconCanvas);\r
+ iconCanvas.addPaintListener (new PaintListener() {\r
+\r
+ @Override\r
+ public void paintControl(PaintEvent e) {\r
+ if(icon != null)\r
+ e.gc.drawImage (icon, 0, 0); \r
+ }\r
+ });\r
+\r
// Label for the chart name (also minimize/expand)\r
name = new Label(this, SWT.NONE);\r
\r
try {\r
// name updater\r
- SimanticsUI.getSession().syncRequest(new Read<String>() {\r
+ SimanticsUI.getSession().syncRequest(new Read<Pair<String, Image>>() {\r
\r
@Override\r
- public String perform(ReadGraph graph) throws DatabaseException {\r
- return graph.getPossibleRelatedValue(resource, Layer0.getInstance(graph).HasLabel);\r
+ public Pair<String, Image> perform(ReadGraph graph) throws DatabaseException {\r
+ JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ String label = graph.getPossibleRelatedValue(resource, l0.HasLabel);\r
+ Image image = null;\r
+ Resource plot = graph.syncRequest(new PossibleObjectWithType(resource, l0.ConsistsOf, jfree.Plot));\r
+ if(plot != null) {\r
+ if(graph.isInstanceOf(plot, jfree.CategoryPlot))\r
+ image = barChartImage;\r
+ else if(graph.isInstanceOf(plot, jfree.PiePlot))\r
+ image = pieChartImage;\r
+ else\r
+ image = lineChartImage;\r
+ }\r
+ return new Pair<String, Image>(label, image);\r
}\r
\r
- }, new Listener<String>() {\r
+ }, new Listener<Pair<String, Image>>() {\r
\r
@Override\r
- public void execute(final String result) {\r
+ public void execute(final Pair<String, Image> result) {\r
if(result == null)\r
return;\r
- \r
+\r
name.getDisplay().asyncExec(new Runnable() {\r
- \r
+\r
@Override\r
public void run() {\r
- if(!name.isDisposed())\r
- name.setText(result);\r
+ if(!name.isDisposed() && result.first != null)\r
+ name.setText(result.first);\r
+\r
+ if(!iconCanvas.isDisposed() && result.second != null) {\r
+ icon = result.second;\r
+ iconCanvas.redraw();\r
+ ChartPanelHeader.this.layout();\r
+ }\r
}\r
});\r
}\r
e.printStackTrace();\r
name.setText("No label");\r
}\r
-\r
-\r
GridDataFactory.fillDefaults().grab(true, false).applyTo(name);\r
- name.addMouseListener(new MinimizeListener(name));\r
- name.setCursor(new Cursor(name.getDisplay(), SWT.CURSOR_HAND));\r
- if(isMinimized())\r
- name.setToolTipText("Expand");\r
- else\r
- name.setToolTipText("Minimize");\r
-\r
- // Label for minimizing/expanding chart\r
- minimize = new Label(this, SWT.NONE);\r
- minimize.setText("^");\r
- GridDataFactory.fillDefaults().applyTo(minimize);\r
- minimize.addMouseListener(new MinimizeListener(minimize));\r
- minimize.setCursor(new Cursor(minimize.getDisplay(), SWT.CURSOR_HAND));\r
- if(isMinimized())\r
+\r
+ ToolBar toolbar = new ToolBar(this, SWT.FLAT);\r
+ // item for minimizing/expanding chart\r
+ minimize = new ToolItem(toolbar, SWT.PUSH);\r
+ minimize.addSelectionListener(new MinimizeListener());\r
+ if(isMinimized()) {\r
minimize.setToolTipText("Expand");\r
- else\r
+ minimize.setImage(maximizeImage);\r
+ } else {\r
minimize.setToolTipText("Minimize");\r
+ minimize.setImage(minimizeImage);\r
+ }\r
\r
- // Label for closing/removing the chart\r
- remove = new Label(this, SWT.NONE);\r
- remove.setText("x");\r
- GridDataFactory.fillDefaults().applyTo(remove);\r
- remove.addMouseListener(new RemoveChartListener(remove));\r
- remove.setCursor(new Cursor(remove.getDisplay(), SWT.CURSOR_HAND));\r
+ // item for closing/removing the chart\r
+ remove = new ToolItem(toolbar, SWT.PUSH);\r
+ remove.setImage(closeImage);\r
+ remove.addSelectionListener(new RemoveChartListener());\r
remove.setToolTipText("Remove");\r
}\r
- \r
+\r
/**\r
* Return true if this element is minimized, false if expanded\r
* @return true if this element is minimized, false if expanded\r
}\r
\r
/**\r
- * Mouse listener to minimize chart button. Expands and minimizes \r
+ * Listener to minimize chart button. Expands and minimizes \r
* the chart of this header.\r
* \r
* @author Teemu Lempinen\r
*\r
*/\r
- private class MinimizeListener implements MouseListener {\r
-\r
- private Control control;\r
-\r
- public MinimizeListener(Control control) {\r
- this.control = control;\r
- }\r
-\r
+ private class MinimizeListener implements SelectionListener {\r
@Override\r
- public void mouseDoubleClick(MouseEvent e) {\r
- }\r
- @Override\r
- public void mouseDown(MouseEvent e) {\r
- panel.setFocus();\r
- }\r
-\r
- @Override\r
- public void mouseUp(MouseEvent e) {\r
+ public void widgetSelected(SelectionEvent e) {\r
if(ChartPanelHeader.this.isDisposed())\r
return;\r
\r
- // Expand only if mouse was released inside the control\r
- Rectangle bounds = control.getBounds();\r
- bounds.x = 0;\r
- bounds.y = 0;\r
- if(bounds.contains(e.x, e.y))\r
- panel.expandChart(resource);\r
+ panel.expandChart(resource);\r
\r
if(!name.isDisposed() && !minimize.isDisposed()) {\r
if(isMinimized()) {\r
name.setToolTipText("Minimize");\r
minimize.setToolTipText("Minimize");\r
}\r
- }\r
+ } \r
+ }\r
+\r
+ @Override\r
+ public void widgetDefaultSelected(SelectionEvent e) {\r
+ widgetSelected(e);\r
}\r
\r
}\r
\r
/**\r
- * Mouse listener for removing this chart from the chart panel.\r
+ * Listener for removing this chart from the chart panel.\r
* \r
* @author Teemu Lempinen\r
*\r
*/\r
- private class RemoveChartListener implements MouseListener {\r
-\r
- Control control;\r
-\r
- public RemoveChartListener(Control control) {\r
- this.control = control;\r
- }\r
-\r
- @Override\r
- public void mouseDoubleClick(MouseEvent e) {\r
- }\r
-\r
- @Override\r
- public void mouseDown(MouseEvent e) {\r
- panel.setFocus();\r
- }\r
-\r
+ private class RemoveChartListener implements SelectionListener {\r
@Override\r
- public void mouseUp(MouseEvent e) {\r
+ public void widgetSelected(SelectionEvent e) {\r
if(!ChartPanelHeader.this.isDisposed()) {\r
- // Remove only if mouse was released inside the control\r
- Rectangle bounds = control.getBounds();\r
- bounds.x = 0;\r
- bounds.y = 0;\r
- if(bounds.contains(e.x, e.y))\r
- panel.removeChart(resource);\r
+ panel.removeChart(resource);\r
}\r
+ }\r
\r
-\r
+ @Override\r
+ public void widgetDefaultSelected(SelectionEvent e) {\r
+ widgetSelected(e);\r
}\r
\r
}\r
*******************************************************************************/\r
package org.simantics.sysdyn.ui.trend.chart;\r
\r
+import org.jfree.chart.labels.StandardCategoryToolTipGenerator;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
\r
\r
@Override\r
public org.jfree.chart.renderer.AbstractRenderer getRenderer() {\r
- if(renderer == null)\r
+ if(renderer == null) {\r
renderer = new org.jfree.chart.renderer.category.BarRenderer();\r
+ renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());\r
+ }\r
return renderer;\r
}\r
\r
import org.jfree.chart.axis.ValueAxis;\r
import org.jfree.chart.plot.Plot;\r
import org.jfree.chart.renderer.category.CategoryItemRenderer;\r
+import org.jfree.ui.RectangleInsets;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.exception.DatabaseException;\r
plot.setDomainGridlinesVisible(false);\r
}\r
\r
+ // Cleaner look: no outline borders\r
+ plot.setInsets(new RectangleInsets(2,2,2,2), false);\r
+ plot.setOutlineVisible(false);\r
+ \r
return plot;\r
}\r
\r
*******************************************************************************/\r
package org.simantics.sysdyn.ui.trend.chart;\r
\r
+import java.awt.Color;\r
+import java.awt.Font;\r
import java.lang.reflect.InvocationTargetException;\r
import java.util.Collection;\r
\r
import javax.swing.SwingUtilities;\r
\r
-import org.jfree.chart.title.LegendTitle;\r
+import org.jfree.ui.RectangleInsets;\r
import org.simantics.databoard.Bindings;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
@Override\r
public void run() {\r
jfreechart = new org.jfree.chart.JFreeChart(plot.getPlot());\r
+ \r
+ jfreechart.setBackgroundPaint(Color.WHITE);\r
+ jfreechart.getLegend().setBorder(0, 0, 0, 0);\r
+ int size = jfreechart.getLegend().getItemFont().getSize();\r
+ jfreechart.getLegend().setItemFont(new Font("helvetica", Font.PLAIN, size));\r
+ \r
org.jfree.chart.title.TextTitle t = (org.jfree.chart.title.TextTitle)title.getTitle();\r
- if(t.isVisible())\r
+ if(t.isVisible()) {\r
+ t.setFont(new Font("georgia", Font.BOLD, 13));\r
+ t.setPadding(new RectangleInsets(4, 0, 0, 0));\r
jfreechart.setTitle(t);\r
+ }\r
\r
if(legendVisible != null && !legendVisible) {\r
- for(Object title : jfreechart.getSubtitles()) {\r
- if(title instanceof LegendTitle) {\r
- jfreechart.removeLegend();\r
- }\r
- }\r
+ jfreechart.removeLegend();\r
}\r
}\r
});\r
package org.simantics.sysdyn.ui.trend.chart;\r
\r
import java.awt.Color;\r
+import java.awt.Font;\r
import java.util.HashMap;\r
\r
+import org.jfree.chart.labels.StandardPieSectionLabelGenerator;\r
+import org.jfree.chart.labels.StandardPieToolTipGenerator;\r
import org.jfree.chart.plot.DefaultDrawingSupplier;\r
import org.jfree.chart.plot.Plot;\r
import org.jfree.data.general.Dataset;\r
import org.jfree.data.general.DatasetChangeEvent;\r
import org.jfree.data.general.DatasetChangeListener;\r
+import org.jfree.ui.RectangleInsets;\r
+import org.simantics.databoard.Bindings;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.JFreeChartResource;\r
\r
/**\r
* Class representing a PiePlot in JFreeChart ontology\r
*/\r
public class PiePlot extends AbstractPlot {\r
\r
- org.jfree.chart.plot.PiePlot plot;\r
- org.jfree.data.general.PieDataset pieDataset;\r
- DatasetChangeListener listener;\r
+ private org.jfree.chart.plot.PiePlot plot;\r
+ private org.jfree.data.general.PieDataset pieDataset;\r
+ private DatasetChangeListener listener;\r
+ \r
+ private Boolean labelsVisible;\r
\r
public PiePlot(ReadGraph graph, Resource resource) {\r
super(graph, resource);\r
+ \r
+ try {\r
+ labelsVisible = graph.getPossibleRelatedValue(resource, JFreeChartResource.getInstance(graph).Plot_visibleLabels, Bindings.BOOLEAN);\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
}\r
\r
@Override\r
public Plot getPlot() {\r
if(plot == null) {\r
plot = new MyPiePlot();\r
+ plot.setToolTipGenerator(new StandardPieToolTipGenerator());\r
}\r
\r
if(!datasets.isEmpty()) {\r
final IDataset ds = datasets.get(0);\r
Dataset dataset = ((PieDataset)ds).getDataset();\r
\r
- plot.clearSectionPaints(true);\r
- plot.setDrawingSupplier(new DefaultDrawingSupplier());\r
-\r
if(pieDataset != null && listener != null) {\r
pieDataset.removeChangeListener(listener);\r
}\r
\r
pieDataset = (org.jfree.data.general.PieDataset)dataset;\r
plot.setDataset(pieDataset);\r
+ if(Boolean.FALSE.equals(labelsVisible))\r
+ plot.setLabelGenerator(null);\r
+ else if(plot.getLabelGenerator() == null)\r
+ plot.setLabelGenerator(new StandardPieSectionLabelGenerator());\r
\r
listener = new DatasetChangeListener() {\r
\r
if(Boolean.TRUE.equals(exploded))\r
plot.setExplodePercent(name, 0.3);\r
} \r
- \r
+ plot.clearSectionPaints(false);\r
plot.setDrawingSupplier(new DefaultDrawingSupplier());\r
-\r
for(String name : colorMap.keySet())\r
plot.setSectionPaint(name, colorMap.get(name));\r
}\r
\r
pieDataset.addChangeListener(listener);\r
}\r
+ \r
+ // Cleaner look: no outline borders\r
+ plot.setInsets(new RectangleInsets(0,0,0,0), false);\r
+ plot.setOutlineVisible(false);\r
+ plot.setLabelBackgroundPaint(Color.WHITE);\r
+ plot.setLabelFont(new Font("helvetica", Font.PLAIN, 11));\r
+ \r
return plot;\r
}\r
\r
*******************************************************************************/\r
package org.simantics.sysdyn.ui.trend.chart;\r
\r
+import org.jfree.chart.labels.StandardCategoryToolTipGenerator;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
\r
\r
@Override\r
public org.jfree.chart.renderer.AbstractRenderer getRenderer() {\r
- if(renderer == null)\r
+ if(renderer == null) {\r
renderer = new org.jfree.chart.renderer.category.StackedBarRenderer();\r
+ renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());\r
+ }\r
return renderer;\r
}\r
\r
\r
import java.awt.BasicStroke;\r
import java.awt.Color;\r
+import java.awt.Paint;\r
import java.awt.Stroke;\r
import java.util.ArrayList;\r
import java.util.List;\r
\r
import javax.swing.SwingUtilities;\r
\r
+import org.jfree.chart.ChartColor;\r
+import org.jfree.chart.labels.StandardXYToolTipGenerator;\r
import org.jfree.chart.plot.DefaultDrawingSupplier;\r
import org.jfree.chart.plot.ValueMarker;\r
import org.jfree.chart.renderer.AbstractRenderer;\r
// Get a variable for the series\r
Variable v = Variables.getVariable(graph, realizationURI + rvi);\r
\r
- \r
+\r
// Get values\r
Object object = v.getPossiblePropertyValue(graph, SysdynVariableProperties.ACTIVE_DATASETS , Bindings.VARIANT);\r
if(object == null || !(object instanceof ArrayList<?>))\r
return series;\r
- \r
+\r
ArrayList<SysdynDataSet> datasets = new ArrayList<SysdynDataSet>();\r
\r
for(Object o : (ArrayList<?>)object) {\r
if(o instanceof SysdynDataSet)\r
datasets.add((SysdynDataSet)o);\r
}\r
- \r
- \r
+\r
+\r
String[] filter = graph.getPossibleRelatedValue(r, jfree.variableFilter);\r
if(filter != null) {\r
ArrayList<SysdynDataSet> result2 = VariableRVIUtils.getDataset(datasets, filter);\r
datasets = result2;\r
}\r
}\r
- \r
+\r
for(SysdynDataSet dataset : datasets) {\r
double[] va = dataset.values;\r
\r
}\r
\r
if(timeListener == null || timeListener.isDisposed()) {\r
- timeListener = new TimeListener(new ValueMarker(0.0));\r
+ timeListener = new TimeListener();\r
SimanticsUI.getSession().asyncRequest(new Read<Double>() {\r
@Override\r
public Double perform(ReadGraph graph) throws DatabaseException {\r
return dataset;\r
}\r
\r
+ /**\r
+ * Class for identifying a time marker in a plot\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+ private class TimeMarker extends ValueMarker {\r
+ private static final long serialVersionUID = 2018755066561629172L;\r
+\r
+ public TimeMarker(double value, Paint paint, Stroke stroke) {\r
+ super(value, paint, stroke);\r
+ }\r
+ }\r
\r
private class DataSetListener implements Listener<ArrayList<TempSeries>> {\r
\r
\r
@Override\r
public void run() {\r
- ((AbstractXYItemRenderer)getRenderer()).getPlot().setDrawingSupplier(new DefaultDrawingSupplier());\r
+\r
+ /*\r
+ * Drawing supplier with a modified first yellow. The default first\r
+ * yellow is too light to be visible against a white background\r
+ */\r
+ Paint[] paintSequence = ChartColor.createDefaultPaintArray();\r
+ paintSequence[3] = new Color(0xFF, 0xDD, 0x00);\r
+ DefaultDrawingSupplier drawingsupplier = new DefaultDrawingSupplier(\r
+ paintSequence,\r
+ DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE,\r
+ DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,\r
+ DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,\r
+ DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,\r
+ DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE);\r
+ ((AbstractXYItemRenderer)getRenderer()).getPlot().setDrawingSupplier(drawingsupplier);\r
// Remove all series\r
for(int i = dataset.getSeriesCount() - 1; i >= 0; i-- ) {\r
dataset.removeSeries(dataset.getSeriesKey(i));\r
}\r
\r
\r
+ /**\r
+ * Listener for updating the time indicator for XY plots\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
private class TimeListener implements Listener<Double> {\r
\r
private ValueMarker marker;\r
private boolean disposed = false;\r
+ private Stroke dashStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT,\r
+ BasicStroke.JOIN_MITER, 10.0f, new float[] {5.0f, 3.0f, 1.0f, 3.0f}, 0.0f);\r
\r
- public TimeListener(ValueMarker marker) {\r
- this.marker = marker;\r
+ public TimeListener() {\r
+ this.marker = new TimeMarker(0.0, Color.red, dashStroke);\r
}\r
\r
public void dispose() {\r
this.disposed = true;\r
+ if(marker != null) {\r
+ org.jfree.chart.plot.XYPlot plot = ((AbstractXYItemRenderer)getRenderer()).getPlot();\r
+ if(plot != null)\r
+ plot.removeDomainMarker(marker);\r
+ }\r
}\r
\r
@Override\r
public void run() {\r
org.jfree.chart.plot.XYPlot plot = ((AbstractXYItemRenderer)getRenderer()).getPlot();\r
\r
- int i = 0;\r
- for(i = 0; i < plot.getDatasetCount(); i++) {\r
- if(plot.getDataset(i).equals(dataset))\r
- break;\r
- }\r
+ if(plot == null)\r
+ return;\r
\r
plot.removeDomainMarker(marker);\r
if(time != null) {\r
- Stroke dashStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT,\r
- BasicStroke.JOIN_MITER, 10.0f, new float[] {5.0f, 3.0f, 1.0f, 3.0f}, 0.0f);\r
- marker = new ValueMarker(time, Color.red, dashStroke);\r
- plot.addDomainMarker(i, marker, Layer.FOREGROUND);\r
+ marker.setValue(time);\r
+ if(plot.getDomainMarkers(Layer.FOREGROUND) == null || !plot.getDomainMarkers(Layer.FOREGROUND).contains(marker)) {\r
+ int i = 0;\r
+ for(i = 0; i < plot.getDatasetCount(); i++) {\r
+ if(plot.getDataset(i) != null && plot.getDataset(i).equals(dataset))\r
+ break;\r
+ }\r
+ plot.addDomainMarker(i, marker, Layer.FOREGROUND);\r
+ }\r
}\r
\r
}\r
\r
@Override\r
public AbstractRenderer getRenderer() {\r
- if(renderer == null)\r
+ if(renderer == null) {\r
renderer = new XYLineAndShapeRenderer(true, false);\r
+ renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());\r
+ }\r
return renderer;\r
}\r
}\r
import org.jfree.chart.plot.Plot;\r
import org.jfree.chart.renderer.xy.XYItemRenderer;\r
import org.jfree.data.xy.XYDataset;\r
+import org.jfree.ui.RectangleInsets;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.exception.DatabaseException;\r
plot.setRangeGridlinesVisible(visibleGrid);\r
plot.setDomainGridlinesVisible(visibleGrid);\r
\r
+ // Cleaner look: no outline borders\r
+ plot.setInsets(new RectangleInsets(2,2,2,2), false);\r
+ plot.setOutlineVisible(false);\r
+ \r
return plot;\r
}\r
\r
\r
private ScrolledComposite sc;\r
private Composite composite;\r
- private Button htitle, hlegend;\r
+ private Button htitle, hlegend, hlabels;\r
private TrackedText name, title;\r
\r
@Override\r
hlegend.setText("Legend");\r
hlegend.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Chart_visibleLegend, true));\r
hlegend.addSelectionListener(new BooleanSelectionListener(context, null, JFreeChartResource.URIs.Chart_visibleLegend));\r
+ hlabels = new Button(hideGroup, support, SWT.CHECK);\r
+ hlabels.setText("Section labels");\r
+ hlabels.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleLabels, true));\r
+ hlabels.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleLabels));\r
\r
sc.setContent(composite);\r
Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r