Skip to content
Snippets Groups Projects
Commit 6bb2b88f authored by pompert's avatar pompert
Browse files

BugID: 701

Additions:
-modifyPlot/updateData methods throughout the structure to support altering a plot's dataset and meta information. PlotSGTImpl will be able to handle this in a future version.
Mods:
-None
Removals:
-PlotGroup is deemed SAS/OTB specific and therefore no longer fits in the generic plotter project.
parent 64dacdfb
No related branches found
No related tags found
No related merge requests found
......@@ -50,6 +50,16 @@ public interface IPlot{
*/
public JComponent createPlot(int type, String name, HashMap data, boolean separateLegend) throws PlotterException;
/**
* Modifies a given plot using a given dataset.
* @param aPlot A plot JComponent
* @param data The data to be displayed in the plot.
* @return A legend JComponent of plot aPlot
* @return the JComponent plot with the new dataset embedded.
* @throws PlotterException will be thrown if the plot could not be generated for any reason.
*/
public JComponent modifyPlot(JComponent aPlot, HashMap data) throws PlotterException;
/**
* Returns the current dataset used in the plot
* @return the dataset currently in use.
......
......@@ -48,5 +48,16 @@ public interface IPlotDataAccess{
*/
public HashMap retrieveData(Object constraints) throws PlotterDataAccessException;
/**
* This method will update the dataset provided using an object with any
* possible information and it must return a HashMap dataset understandable by the plotter.
* @param currentDataSet The dataset to be updated
* @param constraints An object with constraints to be passed to the implementing class
* @return The dataset that has been generated
* @throws PlotterDataAccessException will be thrown if the dataset could not
* be generated for any reason, like database exceptions, file errors, etc.
*/
public HashMap updateData(HashMap currentDataSet, Object constraints) throws PlotterDataAccessException;
}
......@@ -4,7 +4,7 @@
* Copyright (C) 2002-2007
* ASTRON (Netherlands Foundation for Research in Astronomy)
* P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
......@@ -42,158 +42,187 @@ import nl.astron.lofar.java.gui.plotter.exceptions.PlotterFrameworkNotFoundExcep
* users input and the configured data access layer<br>
* - The Utility Component IPlot, which makes the plot using the configured framework and the dataset<br>
* - The plot will then be returned to the PlotPanel.
*
*
* @created 11-04-2006, 15:00
* @author pompert
* @version $Id$
* @updated 13-apr-2006 11:19:43
*/
public class PlotController{
private PlotDataManager m_PlotDataManager;
private PlotGroup m_PlotGroup;
private IPlot m_IPlot;
private PlotDataManager m_PlotDataManager;
private PlotGroup m_PlotGroup;
private IPlot m_PlotFrameWork;
private HashMap<String,Object> m_plotData;
/**
* Creates a new instance of PlotController
*/
public PlotController(){
m_PlotDataManager = PlotDataManager.getInstance();
//Initialise and load plotter classes and data interfaces
}
/**
* Cleans up the instance variables
*/
public void finalize() throws Throwable {
m_PlotDataManager = null;
m_PlotGroup = null;
m_PlotFrameWork = null;
}
/**
* This method will attempt to create a JComponent plot using the
* framework class and Data Access layer in the plotter_config.properties file.
*
* @param type A plot type (as defined in PlotConstants.PLOT_*)
* @param separateLegend True to generate a separate legend JComponent,
* false to have a legend embedded in the plot
* @param constraints A data access object to be passed on to the data access layer
* @return the JComponent plot that has been generated by the configured
* framework
* @throws PlotterException will be thrown when either the Data Access
* layer or the Plotter Framework have run into an exception that the
* user needs to be aware of.
*/
public JComponent createPlot(int type, boolean separateLegend, Object constraints) throws PlotterException{
JComponent newPlotComponent = null;
if(m_PlotFrameWork == null){
initializePlotterFramework();
}
if(type == PlotConstants.PLOT_BAR
|| type == PlotConstants.PLOT_GRID
|| type == PlotConstants.PLOT_SCATTER
|| type == PlotConstants.PLOT_XYLINE
|| type == PlotConstants.PLOT_POINTS){
m_plotData = m_PlotDataManager.retrieveData(constraints);
newPlotComponent = m_PlotFrameWork.createPlot(type,constraints.toString(),m_plotData,separateLegend);
}else{
throw new NotSupportedException("The requested plot type ("+type+") is not supported by the plotter at this time.");
}
return newPlotComponent;
}
/**
* This method will attempt to retrieve a JComponent legend for the supplied JComponent plot.
*
* Important: The JComponent plot you provide must have been generated by the plotter framework
* implementation class (for example PlotSGTImpl). An exception can be thrown if you attempt
* to retrieve a Legend for say a JPanel or JButton.
*
* @param aPlot The JComponent plot that needs to have a separate legend
* @return the legend JComponent for the plot JComponent specified
* @throws PlotterException will be thrown if the legend could not be generated for the given JComponent.
*/
public JComponent getLegendForPlot(JComponent aPlot) throws PlotterException{
JComponent legendComponent = null;
if(m_PlotFrameWork == null){
initializePlotterFramework();
}
legendComponent = m_PlotFrameWork.getLegend(aPlot);
/**
* Creates a new instance of PlotController
*/
public PlotController(){
m_PlotDataManager = PlotDataManager.getInstance();
//Initialise and load plotter classes and data interfaces
return legendComponent;
}
/**
* This method will create an Image of a plot. It works identically to
* getPlot() as this method too accepts an object with constraints.
* @param constraints The Object with constraints to be passed to the data access layer
* @return image file of the plot requested
* @throws PlotterException will be thrown when either the Data Access
* layer or the Plotter Framework have run into an exception that the
* user needs to be aware of.
*/
public Image createPlotImage(Object constraints) throws PlotterException{
throw new NotImplementedException("Image exportation is not yet implemented in this release.");
}
/**
* This method will attempt to export a plot using the
* Data Export layer specified in the plotter_config.properties file.
* @param arguments The object containing arguments to be passed to the data export layer
* @throws PlotterException will be thrown when the Data Export
* layer has run into an exception that the user needs to be aware of.
*/
public void exportData(Object arguments) throws PlotterException{
throw new NotImplementedException("Export of data is not yet implemented in this release.");
}
/**
* This method allows a user to modify a plot currently in memory by
* altering its dataset
* @param newConstraints An object containing instructions what to do with the dataset prior to rebuilding the plot
* @throws PlotterException will be thrown when either the Data Access
* layer or the Plotter Framework have run into an exception that the
* user needs to be aware of.
*/
public JComponent modifyPlot(JComponent currentPlot, Object newConstraints) throws PlotterException{
JComponent newPlotComponent = null;
if(m_PlotFrameWork == null){
initializePlotterFramework();
}
/**
* Cleans up the instance variables
*/
public void finalize() throws Throwable {
m_PlotDataManager = null;
m_PlotGroup = null;
m_IPlot = null;
}
/**
* This method will attempt to create a JComponent plot using the
* framework class and Data Access layer in the plotter_config.properties file.
*
* @param type A plot type (as defined in PlotConstants.PLOT_*)
* @param separateLegend True to generate a separate legend JComponent,
* false to have a legend embedded in the plot
* @param constraints A data access object to be passed on to the data access layer
* @return the JComponent plot that has been generated by the configured
* framework
* @throws PlotterException will be thrown when either the Data Access
* layer or the Plotter Framework have run into an exception that the
* user needs to be aware of.
*/
public JComponent createPlot(int type, boolean separateLegend, Object constraints) throws PlotterException{
String plotFrameworkClass = "";
Object aPlotter = null;
IPlot aNewPlot = null;
ResourceBundle resources = PlotDataManager.getPlotterConfigurationFile();
try {
plotFrameworkClass = resources.getString(("FRAMEWORK"));
Class implementator = PlotController.class.forName(plotFrameworkClass);
aPlotter = implementator.newInstance();
aNewPlot = (IPlot)aPlotter;
} catch (IllegalAccessException ex) {
//TODO Log!
PlotterFrameworkInitializationException exx = new PlotterFrameworkInitializationException();
exx.initCause(ex);
throw exx;
} catch (ClassNotFoundException ex) {
//TODO Log!
PlotterFrameworkNotFoundException exx = new PlotterFrameworkNotFoundException("(used:"+ plotFrameworkClass + " )");
exx.initCause(ex);
throw exx;
} catch (MissingResourceException ex) {
//TODO Log!
PlotterFrameworkNotFoundException exx = new PlotterFrameworkNotFoundException("(The property 'FRAMEWORK' was not found in the plotter_config.properties file)");
exx.initCause(ex);
throw exx;
} catch (InstantiationException ex) {
//TODO Log!
PlotterFrameworkInitializationException exx = new PlotterFrameworkInitializationException();
exx.initCause(ex);
throw exx;
} catch (ClassCastException ex) {
//TODO LOG!
PlotterFrameworkNotCompatibleException exx = new PlotterFrameworkNotCompatibleException();
exx.initCause(ex);
throw exx;
} catch (Exception ex) {
//TODO Log!
PlotterFrameworkInitializationException exx = new PlotterFrameworkInitializationException();
exx.initCause(ex);
throw exx;
}
m_plotData = m_PlotDataManager.updateData(m_plotData,newConstraints);
newPlotComponent = m_PlotFrameWork.modifyPlot(currentPlot,m_plotData);
return newPlotComponent;
}
/**
* This method allows a user to get the dataset for the plot currently in memory.
* @throws PlotterException will be thrown if the dataset does not exist.
*
*/
public HashMap getPlotData() throws PlotterException{
if(m_plotData == null){
throw new NotSupportedException("No data was present in the PlotController. Please create a plot first, or set the data manually.");
}
return m_plotData;
}
private void initializePlotterFramework() throws PlotterException{
String plotFrameworkClass = "";
Object aPlotter = null;
IPlot aNewPlot = null;
ResourceBundle resources = PlotDataManager.getPlotterConfigurationFile();
try {
plotFrameworkClass = resources.getString(("FRAMEWORK"));
Class implementator = PlotController.class.forName(plotFrameworkClass);
aPlotter = implementator.newInstance();
aNewPlot = (IPlot)aPlotter;
} catch (IllegalAccessException ex) {
//TODO Log!
PlotterFrameworkInitializationException exx = new PlotterFrameworkInitializationException();
exx.initCause(ex);
throw exx;
} catch (ClassNotFoundException ex) {
//TODO Log!
PlotterFrameworkNotFoundException exx = new PlotterFrameworkNotFoundException("(used:"+ plotFrameworkClass + " )");
exx.initCause(ex);
throw exx;
} catch (MissingResourceException ex) {
//TODO Log!
PlotterFrameworkNotFoundException exx = new PlotterFrameworkNotFoundException("(The property 'FRAMEWORK' was not found in the plotter_config.properties file)");
exx.initCause(ex);
throw exx;
} catch (InstantiationException ex) {
//TODO Log!
PlotterFrameworkInitializationException exx = new PlotterFrameworkInitializationException();
exx.initCause(ex);
throw exx;
if(aPlotter != null){
if(type == PlotConstants.PLOT_BAR
|| type == PlotConstants.PLOT_GRID
|| type == PlotConstants.PLOT_SCATTER
|| type == PlotConstants.PLOT_XYLINE
|| type == PlotConstants.PLOT_POINTS){
HashMap retrieveableData =
m_PlotDataManager.retrieveData(constraints);
m_IPlot = aNewPlot;
return m_IPlot.createPlot(type,constraints.toString(),retrieveableData,separateLegend);
}else{
throw new NotSupportedException("The requested plot type ("+type+") is not supported by the plotter at this time.");
}
}
return null;
}
/**
* This method will attempt to retrieve a JComponent legend for the supplied JComponent plot.
*
* Important: The JComponent plot you provide must have been generated by the plotter framework
* implementation class (for example PlotSGTImpl). An exception can be thrown if you attempt
* to retrieve a Legend for say a JPanel or JButton.
*
* @param aPlot The JComponent plot that needs to have a separate legend
* @return the legend JComponent for the plot JComponent specified
* @throws PlotterException will be thrown if the legend could not be generated for the given JComponent.
*/
public JComponent getLegendForPlot(JComponent aPlot) throws PlotterException{
return m_IPlot.getLegend(aPlot);
} catch (ClassCastException ex) {
//TODO LOG!
PlotterFrameworkNotCompatibleException exx = new PlotterFrameworkNotCompatibleException();
exx.initCause(ex);
throw exx;
} catch (Exception ex) {
//TODO Log!
PlotterFrameworkInitializationException exx = new PlotterFrameworkInitializationException();
exx.initCause(ex);
throw exx;
}
/**
* This method will create an Image of a plot. It works identically to
* getPlot() as this method too reads an array of constraints.
* @param constraints The Object with constraints to be passed to the data access layer
* @return image file of the plot requested
* @throws PlotterException will be thrown when either the Data Access
* layer or the Plotter Framework have run into an exception that the
* user needs to be aware of.
*/
public Image createPlotImage(Object constraints) throws PlotterException{
throw new NotImplementedException("Image exportation is not yet implemented in this release.");
}
/**
* This method will attempt to export a plot using the
* Data Export layer specified in the plotter_config.properties file.
* @param arguments The object containing arguments to be passed to the data export layer
* @throws PlotterException will be thrown when the Data Export
* layer has run into an exception that the user needs to be aware of.
*/
public void exportData(Object arguments) throws PlotterException{
throw new NotImplementedException("Export of data is not yet implemented in this release.");
}
/**
* This method allows a user to modify a plot currently in memory by
* altering its dataset
* @param data The dataset to be inserted into the plot
* @throws PlotterException will be thrown when either the Data Access
* layer or the Plotter Framework have run into an exception that the
* user needs to be aware of.
*/
public JComponent modifyPlot(HashMap data) throws PlotterException{
return null;
}
if(aNewPlot!=null){
m_PlotFrameWork = aNewPlot;
}
}
}
\ No newline at end of file
......@@ -105,6 +105,34 @@ public class PlotDataManager{
}
return null;
}
/**
* This method updates a Plotter compliant dataset using
* the current dataset and new constraints provided by the PlotPanel.
* It will call the Data Access
* class provided in the plotter_config.properties file.
*
* @param currentData The current dataset
* @param constraints The String array containing update constraints for the data
* access class
* @return the data set generated
* @throws PlotterException will be thrown when an Exception occurs
* inside the Data Access class, or when the Data Access class itself could not
* be properly accessed due to errors in the plotter_config.properties file.
*/
public HashMap updateData(HashMap currentData, Object constraints) throws PlotterException{
if(aDataAccessor == null){
initializeDataAccessLayer();
}
if(aDataAccessor != null){
HashMap retrieveableData =
aDataAccessor.updateData(currentData, constraints);
return retrieveableData;
}
return null;
}
/**
* This method exports a Plotter compliant dataset using
* the parameters provided. It will call the Data Export
......
/*
* PlotGroup.java
*
* Copyright (C) 2002-2007
* ASTRON (Netherlands Foundation for Research in Astronomy)
* P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package nl.astron.lofar.java.gui.plotter;
import java.util.HashMap;
import java.util.HashSet;
/**
* This class will serve as a container of plots,
* to be further implemented in future versions.
*
* @created 12-04-2006, 15:00
* @author pompert
* @version $Id$
* @updated 13-apr-2006 11:19:48
*/
public class PlotGroup{
public HashSet<IPlot> m_IPlot;
private HashMap<String,Object> data;
/**
* Creates a new instance of PlotGroup
*/
public PlotGroup(){
}
/**
* Cleans up the instance variables
*/
public void finalize() throws Throwable {
}
/**
* TODO: JavaDoc
*/
public HashMap getDataSlice(){
return null;
}
}
\ No newline at end of file
......@@ -25,9 +25,9 @@ package nl.astron.lofar.java.gui.plotter;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.PrintJob;
import java.util.HashMap;
import javax.swing.JComponent;
import javax.swing.JPanel;
import nl.astron.lofar.java.gui.plotter.exceptions.PlotterException;
......@@ -75,7 +75,7 @@ public class PlotPanel extends JPanel{
* -Object constraints (These are the arguments you need for the data access layer to get the data
* you want, which can be anything, as long as your configured data access layer
* supports it!)
* The plot will be added to this class' ContentPane so you can view it directly. It can also be retrieved separately
* The plot will be added to this class' contents so you can view it directly. It can also be retrieved separately
* by calling the getPlot() method.
*
* @param type The type of plot to be generated (these types are defined in PlotConstants.PLOT_* )
......@@ -123,11 +123,30 @@ public class PlotPanel extends JPanel{
public void exportData(Object arguments) throws PlotterException{
m_PlotController.exportData(arguments);
}
/**
* TODO: JavaDoc!
*/
public void modifyDataSelection() throws PlotterException{
/**
* This method will attempt to modify the current plot using one key argument:
* -Object newConstraints (These are the arguments you need for the data access layer to get the data
* you want, which can be anything, as long as your configured data access layer
* supports it!)
* The plot will be updated to this class' contents so you can view it directly. It can also be retrieved separately
* by calling the getPlot() method.
*
* @param newConstraints The arguments to be passed to the configured data access layer
* @throws PlotterException will be thrown if an Exception is detected in the plotter that the user needs to be aware of.
* Please handle this exception in a way that your application does not suffer from it, and make sure the user will be shown a message
* that something has gone wrong.
*/
public void modifyPlot(Object newConstraints) throws PlotterException{
this.removeAll();
currentDataConstraint = newConstraints;
plot = m_PlotController.modifyPlot(plot, newConstraints);
try {
legend = m_PlotController.getLegendForPlot(plot);
} catch (PlotterException ex) {
}
this.add(plot,BorderLayout.CENTER);
}
/**
* This method will attempt to print the current plot
......@@ -158,5 +177,16 @@ public class PlotPanel extends JPanel{
return legend;
}
/**
* This method will return the dataset for the plot currently in memory.
* It will throw a NotSupportedException should the plot not have a dataset available.
* @return The plot dataset currently in memory
* @throws PlotterException will be thrown if an Exception is detected in the plotter that the user needs to be aware of.
* Please handle this exception in a way that your application does not suffer from it, and make sure the user will be shown a message
* that something has gone wrong.
*/
public HashMap getDataForPlot() throws PlotterException{
return m_PlotController.getPlotData();
}
}
......@@ -102,6 +102,20 @@ public class PlotSGTImpl implements IPlot{
lad = null;
pma = null;
}
/**
* Modifies a given SGT plot using a given dataset.
* @param aPlot A plot JComponent
* @param data The data to be displayed in the plot.
* @return A legend JComponent of plot aPlot
* @return the JComponent plot with the new dataset embedded.
* @throws PlotterException will be thrown if the plot could not be generated for any reason.
*/
public JComponent modifyPlot(JComponent aPlot, HashMap data) throws PlotterException{
throw new NotImplementedException("The Modifying of plots is not yet implemented in the plotter's SGT plugin.");
}
/**
* Creates a SGT JPlotLayout plot using several key arguments
* @param type Type of plot as dictated by PlotConstants.PLOT_*
......
......@@ -27,6 +27,7 @@ import java.util.HashMap;
import java.util.LinkedList;
import nl.astron.lofar.java.gui.plotter.IPlotDataAccess;
import nl.astron.lofar.java.gui.plotter.PlotConstants;
import nl.astron.lofar.java.gui.plotter.exceptions.NotImplementedException;
import nl.astron.lofar.java.gui.plotter.exceptions.PlotterDataAccessException;
/**
......@@ -209,4 +210,14 @@ public class PlotDataAccessTestImpl implements IPlotDataAccess{
}
return data;
}
}
/**
* This method returns a test data set that can be plotted using the PlotSGTImpl plotter
* @param currentData The already existing dataset to be updated
* @param constraints the information needed to update the dataset
* @throws PlotterDataAccessException will be thrown if something goes wrong during the making of the
* test data set (not likely though as no other classes are called!)
*/
public HashMap updateData(HashMap currentData, Object constraints) throws PlotterDataAccessException{
throw new PlotterDataAccessException("Modifying existing datasets is not supported in "+this.getClass().getName().toString());
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment