PCM Development/EDP2/Visualization/Create Custom View
< PCM Development | EDP2 | Visualization
This guide describes how a new JFreeChart-view can be created and added to the list of visualizations available in EDP2.
Important information
- The extension point for registering new charts is:
de.uka.ipd.sdq.edp2.visualization.datasink
- All charts using the JFreeChart library must subclass JFreeChartEditorInput
- The existing implementation of HistogramEditorInput can be used as a guideline
- In addition to the input element itself, a factory for the element is required, see also step 2 in the #Step-by-step guide below.
- A JFreeChartEditorInput should not be confused with a DefaultSequence.
Thus, if you wish to create a particular type of chart, e.g. utilisation, you should first consider using an existing chart (e.g. PieChart) and setting title and properties in a way to represent the desired measure graphically.
Step-by-step guide
Guide for creating a new chart, using the PieChartEditorInput-class as an example:
- Create the class "PieChartEditorInput<PieDataset>", subclassing JFreeChartEditorInput.
- Note that the class is typed, the type must be the dataset required by this JFreeChart
- Add required constants for persisting PieChart-elements and its properties
- the
ELEMENT_NAME
"-constant is required to identify the element itself:private static final String ELEMENT_NAME = "PieChartEditorInput";
- other constants are keys for storing different options of the chart, for example for showing values on the chart:
public final static String SHOW_RELATIVE_AMOUNT_KEY = "showRelativeAmount";
public final static String SHOW_ABSOLUTE_AMOUNT_KEY = "showAbsoluteAmount";
- the
- Add fields for the properties and corresponding getters/setters, as well as field(s) containing the data to be displayed by this chart:
private double[][] data;
- Create two constructors, one default-constructor, which is required for persistence, and one setting default values and the source of the input:
public PieChartEditorInput() {
- this(null);
- }
- public PieChartEditorInput(AbstractDataSource source) {
- super();
- setShowAbsoluteAmount(false);
- setShowRelativeAmount(true);
}
- Implement
public void updateInputData()
- This method is central. It should contain appropriate code to accomplish the following:- Create a new instance of the data which is used by this JFreeChartEditorInput's chart
- Unwrap the data provided in the DataSource and use them to fill the data-field
- Finally, add the following to make sure changes to this element are propagated to the JFreeChartEditorInputHandle and the JFreeChartEditor classes.
setChanged();
notifyObservers();
- Implement the remaining inherited methods. Their purpose is documented in the respective interfaces / super-classes. Let's take a look at a few special ones:
public boolean canAccept(AbstractDataSource source)
- Method to check if a specified source contains valid data for this IDataSink-instance
public PieChartEditorInput createCopyForSource(AbstractDataSource source)
- Return a new instance of this class for a provided source
public HashMap<String, Object> getProperties()
- Add all properties and their current values to the inherited properties field here
public void setProperties(HashMap<String, Object> newProperties)
- Check which properties are contained in newProperties, parse the values and use setters to change field values
public JFreeChart getChart()
- Return a JFreeChart using the appropriate plot and/or renderer. If multiple inputs are supported by the encapsulated Chart, they must be retrieved from the JFreeChartEditorInputHandle and added here.
- Create a factory class for the input, subclassing ElementFactory
- You can basically copy an existing Factory-class, e.g. HistogramEditorInputFactory
- change the type of the "restoredElement" to the type of the class this factory is for, i.e. PieChartEditorInput
- You can basically copy an existing Factory-class, e.g. HistogramEditorInputFactory