ca.sqlpower.wabit.report.chart
Class Chart

java.lang.Object
  extended by ca.sqlpower.wabit.AbstractWabitObject
      extended by ca.sqlpower.wabit.report.chart.Chart
All Implemented Interfaces:
WabitObject

public class Chart
extends AbstractWabitObject


Constructor Summary
Chart()
          Creates a new chart with a new unique ID.
Chart(java.lang.String uuid)
          Creates a new chart having the given unique ID (primarily meant for reading objects from storage).
 
Method Summary
 void addChartColumn(ChartColumn newColumnIdentifier)
          For internal use only (while reading a Workspace file or refreshing the column list when a new result set comes in).
 void addChartColumn(ChartColumn newColumnIdentifier, int index)
          For internal use only (while reading a Workspace file or refreshing the column list when a new result set comes in).
 void addChartDataListener(ChartDataListener l)
          Registers the given listener to receive an event every time the dataset returned by createDataset() might be different.
protected  void addChildImpl(WabitObject child, int index)
          This is the object specific implementation of #addChild(WabitObject).
 void addMissingIdentifier(ChartColumn ci)
          Adds the given column identifier to the end of the missing identifiers list.
 boolean allowsChildren()
          Returns true if this object may contain children.
 int childPositionOffset(java.lang.Class<? extends WabitObject> childType)
          Returns the position in the list that would be returned by getChildren() that the first object of type childClass is, or where it would be if there were any children of that type.
 CleanupExceptions cleanup()
          Default cleanup method that does nothing.
 void clearMissingIdentifiers()
          Resets the missing identifiers list.
 org.jfree.data.general.Dataset createDataset()
          Creates an independent JFreeChart dataset based on the current data available in this chart's underlying query.
 java.util.List<ChartColumn> findRoleColumns(ColumnRole role)
          Returns a list of the identifiers for all columns labeled as a given role in a bar chart.
 java.awt.Color getBackgroundColour()
           
 java.util.List<? extends WabitObject> getChildren()
          Alias for getColumns().
 java.util.List<ChartColumn> getColumns()
          Returns an unmodifiable view of the result set columns this chart knows about, along with information about their role in the chart.
 java.util.List<WabitObject> getDependencies()
          Returns a list of all WabitObjects that this Wabit object is dependent on.
 LegendPosition getLegendPosition()
           
 java.util.List<ChartColumn> getMissingIdentifiers()
          Returns an unmodifiable view of the missing identifiers list.
 ResultSetProducer getQuery()
          Returns the current query that this chart gets its datasets from.
 java.sql.ResultSet getResultSet()
          Returns the current result set of the query that supplies data to this chart.
 ca.sqlpower.sql.RowFilter getResultSetFilter()
           
 java.util.List<java.lang.String> getSeriesColours()
           
 ChartType getType()
          Returns the currently-selected chart type.
 ca.sqlpower.sql.CachedRowSet getUnfilteredResultSet()
          Returns the current result set of the query that supplies data to this chart.
 double getXAxisLabelRotation()
          Returns the desired rotation for the X-axis category/item labels.
 java.lang.String getXaxisName()
           
 java.lang.String getYaxisName()
           
 boolean isGratuitouslyAnimated()
           
 void removeChartDataListener(ChartDataListener l)
          Removes the given listener from the list of parties interested in data change events.
protected  boolean removeChildImpl(WabitObject child)
          This is the object specific implementation of removeChild.
 void removeDependency(WabitObject dependency)
          Removes the given object as a dependency of this object.
 void setBackgroundColour(java.awt.Color backgroundColour)
           
 void setGratuitouslyAnimated(boolean gratuitouslyAnimated)
           
 void setLegendPosition(LegendPosition selectedLegendPosition)
           
 void setParent(WabitObject parent)
          Sets the parent of this object to the given object.
 void setQuery(ResultSetProducer newQuery)
          Replaces this chart's source of result sets with the given result set producer, firing a property change event.
 void setType(ChartType newType)
          Selects a new chart type for this chart.
 void setXAxisLabelRotation(double xAxisLabelRotation)
          Sets the desired rotation for the X-axis category/item labels.
 void setXaxisName(java.lang.String xaxisName)
           
 void setYaxisName(java.lang.String yaxisName)
           
 
Methods inherited from class ca.sqlpower.wabit.AbstractWabitObject
addChild, addWabitListener, begin, beginTransaction, commit, commitTransaction, equals, fireChildAdded, fireChildRemoved, firePropertyChange, firePropertyChange, firePropertyChange, fireTransactionEnded, fireTransactionRollback, fireTransactionStarted, generateNewUUID, getChildren, getName, getParent, getSession, getUUID, isForegroundThread, removeChild, removeWabitListener, rollback, rollbackTransaction, runInBackground, runInForeground, setName, setUUID, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Chart

public Chart()
Creates a new chart with a new unique ID.


Chart

public Chart(java.lang.String uuid)
Creates a new chart having the given unique ID (primarily meant for reading objects from storage).

Parameters:
uuid - The uuid the new object should have.
Method Detail

clearMissingIdentifiers

public void clearMissingIdentifiers()
Resets the missing identifiers list. This list contains all of the column identifiers that are defined in the chart but do not exist in the query that is being used to get values for this chart. The reason why some of the columns are missing is usually due to the query being modified.


getMissingIdentifiers

public java.util.List<ChartColumn> getMissingIdentifiers()
Returns an unmodifiable view of the missing identifiers list. The missing identifiers are the parts of the chart's underlying data set which the chart refers to but can no longer find (probably because the data set's structure has changed since the chart was originally configured).

Returns:
the current missing identifier list. It is not modifiable by you, but it may appear to change.

addMissingIdentifier

public void addMissingIdentifier(@Nonnull
                                 ChartColumn ci)
Adds the given column identifier to the end of the missing identifiers list. This method is only of practical use for code that's restoring the state of a chart that's being read from a file.

Parameters:
ci - The column identifier to add. Must not be null.

getBackgroundColour

public java.awt.Color getBackgroundColour()

setBackgroundColour

public void setBackgroundColour(java.awt.Color backgroundColour)

getResultSet

public java.sql.ResultSet getResultSet()
                                throws java.sql.SQLException,
                                       QueryInitializationException,
                                       java.lang.InterruptedException
Returns the current result set of the query that supplies data to this chart. If the query is an OlapQuery, its CellSet will be converted to a ResultSet by calling OlapUtil#toResultSet(CellSet).

No matter how the result set was obtained, it will be filtered through the current resultSetFilter before being returned.

Returns:
The current result set that should be charted, filtered through resultSetFilter. If #refreshData() has not been called on this chart instance since its creation or since the most recent call to #defineQuery(WabitObject), this method returns null.
Throws:
java.sql.SQLException
QueryInitializationException
java.lang.InterruptedException
See Also:
getUnfilteredResultSet()

getUnfilteredResultSet

public ca.sqlpower.sql.CachedRowSet getUnfilteredResultSet()
                                                    throws java.sql.SQLException
Returns the current result set of the query that supplies data to this chart. If the query is an OlapQuery, its CellSet will be converted to a ResultSet by calling OlapUtil#toResultSet(CellSet).

The result set returned will contain all the rows supplied by the current query. Specifically, it will not be subject to the resultSetFilter. This is useful in user interfaces, which can show all the rows and visually indicate which ones are being used in the chart and which are not.

Returns:
The unfiltered version of the current result set. If #refreshData() has not been called on this chart instance since its creation or since the most recent call to #defineQuery(WabitObject), this method returns null.
Throws:
java.sql.SQLException
See Also:
getResultSet()

createDataset

public org.jfree.data.general.Dataset createDataset()
Creates an independent JFreeChart dataset based on the current data available in this chart's underlying query. The type of dataset returned depends on the current chart type setting.

Returns:
A JFreeChart dataset; either XYDataSet or CategoryDataSet.
See Also:
#setQuery(), setType(ChartType)

setParent

public void setParent(WabitObject parent)
Description copied from interface: WabitObject
Sets the parent of this object to the given object. This should only be done when this object is being added as a child to another object.

Specified by:
setParent in interface WabitObject
Overrides:
setParent in class AbstractWabitObject
Parameters:
parent - The new parent of this object.

allowsChildren

public boolean allowsChildren()
Description copied from interface: WabitObject
Returns true if this object may contain children. Not all types of WabitObjects can be a child to any WabitObject.

See Also:
WabitObject.childPositionOffset(Class)

childPositionOffset

public int childPositionOffset(java.lang.Class<? extends WabitObject> childType)
Description copied from interface: WabitObject
Returns the position in the list that would be returned by getChildren() that the first object of type childClass is, or where it would be if there were any children of that type.


getChildren

public java.util.List<? extends WabitObject> getChildren()
Alias for getColumns(). Provided to satisfy WabitObject interface.


getDependencies

public java.util.List<WabitObject> getDependencies()
Description copied from interface: WabitObject
Returns a list of all WabitObjects that this Wabit object is dependent on. Children of a WabitObject are not dependencies and will not be returned in this list. If there are no objects this Wabit object is dependent on an empty list should be returned. These are only the immediate dependencies of this object. If you want to find the dependencies of this object's dependencies as well it may be useful to look at WorkspaceGraphModel to make a full graph of all of the dependencies.


removeDependency

public void removeDependency(WabitObject dependency)
Description copied from interface: WabitObject
Removes the given object as a dependency of this object. For this object to no longer be dependent on the given dependency all of its children must also not be dependent on the given dependency when this method returns. This may remove this object from its parent if necessary.


getType

public ChartType getType()
Returns the currently-selected chart type.


setType

public void setType(ChartType newType)
Selects a new chart type for this chart.


getLegendPosition

public LegendPosition getLegendPosition()

setLegendPosition

public void setLegendPosition(LegendPosition selectedLegendPosition)

setYaxisName

public void setYaxisName(java.lang.String yaxisName)

getYaxisName

public java.lang.String getYaxisName()

setXaxisName

public void setXaxisName(java.lang.String xaxisName)

getXaxisName

public java.lang.String getXaxisName()

getSeriesColours

public java.util.List<java.lang.String> getSeriesColours()

setQuery

public void setQuery(@Nullable
                     ResultSetProducer newQuery)
              throws java.sql.SQLException
Replaces this chart's source of result sets with the given result set producer, firing a property change event. The current result set filter will also be set to an OlapRowFilter or null (depending on newQuery's type) as a side effect of calling this method.

You'll probably want to call #refreshData() after defining a new query. TODO nothing in here throws SQLException, remove it.

Parameters:
newQuery -
Throws:
java.lang.IllegalArgumentException - if the query is not of a supported type.
java.sql.SQLException

getResultSetFilter

public ca.sqlpower.sql.RowFilter getResultSetFilter()

getQuery

public ResultSetProducer getQuery()
Returns the current query that this chart gets its datasets from. Can be null.


getColumns

public java.util.List<ChartColumn> getColumns()
Returns an unmodifiable view of the result set columns this chart knows about, along with information about their role in the chart.

Returns:
the current column list. It is not modifiable by you, but it may appear to change.

addChartColumn

public void addChartColumn(@Nonnull
                           ChartColumn newColumnIdentifier)
For internal use only (while reading a Workspace file or refreshing the column list when a new result set comes in). Adds the given column identifier to the end of the column names list. Fires a childAdded event once the new column identifier has been added.

Parameters:
newColumnIdentifier - The new column identifier to add. Must not be null.

addChartColumn

public void addChartColumn(@Nonnull
                           ChartColumn newColumnIdentifier,
                           int index)
For internal use only (while reading a Workspace file or refreshing the column list when a new result set comes in). Adds the given column identifier to the end of the column names list. Fires a childAdded event once the new column identifier has been added.

Parameters:
newColumnIdentifier - The new column identifier to add. Must not be null.
index - The index to add the chart column at. Cannot be greater than the current number of identifiers in the chart.

findRoleColumns

public java.util.List<ChartColumn> findRoleColumns(ColumnRole role)
Returns a list of the identifiers for all columns labeled as a given role in a bar chart. If there are no such columns, an empty list will be returned. If multiple columns are selected, the values in each column will be appended to each other to create the value's name. The returned column identifiers will be ordered the same as in the columnNamesInOrder list, which gives users the ability to define the column name order.


getXAxisLabelRotation

public double getXAxisLabelRotation()
Returns the desired rotation for the X-axis category/item labels. 0 means horizontal; -90 means read bottom to top; 90 means read top to bottom.


setXAxisLabelRotation

public void setXAxisLabelRotation(double xAxisLabelRotation)
Sets the desired rotation for the X-axis category/item labels. 0 means horizontal; -90 means read bottom to top; 90 means read top to bottom.

Fires a property change if the new value differs from the existing value.

Parameters:
xAxisLabelRotation - The desired rotation. Must be between -90 and 90 inclusive.

setGratuitouslyAnimated

public void setGratuitouslyAnimated(boolean gratuitouslyAnimated)

isGratuitouslyAnimated

public boolean isGratuitouslyAnimated()

removeChildImpl

protected boolean removeChildImpl(WabitObject child)
Description copied from class: AbstractWabitObject
This is the object specific implementation of removeChild. There are checks in the removeChild method to ensure the child being removed has no dependencies and is a child of this object.

Specified by:
removeChildImpl in class AbstractWabitObject
See Also:
AbstractWabitObject.removeChild(WabitObject)

addChildImpl

protected void addChildImpl(WabitObject child,
                            int index)
Description copied from class: AbstractWabitObject
This is the object specific implementation of #addChild(WabitObject). There are checks in the #addChild(WabitObject) method to ensure that the object given here is a valid child type of this object.

This method should be overwritten if children are allowed.

Overrides:
addChildImpl in class AbstractWabitObject
Parameters:
child - The child to add to this object.
index - The index to add the child at.

addChartDataListener

public void addChartDataListener(@Nonnull
                                 ChartDataListener l)
Registers the given listener to receive an event every time the dataset returned by createDataset() might be different. These events typically happen whenever the chart's result set provider changes, as well as when a streaming query delivers a new row of data.

Parameters:
l - the listener to add. Must not be null.

removeChartDataListener

public void removeChartDataListener(@Nullable
                                    ChartDataListener l)
Removes the given listener from the list of parties interested in data change events. If the given listener was registered multiple times, this call only removes one of the registrations. If the given listener is not currently registered, this method has no effect.

Parameters:
l - the listener to remove. Null is silently ignored.

cleanup

public CleanupExceptions cleanup()
Description copied from class: AbstractWabitObject
Default cleanup method that does nothing. Override and implement this method if cleanup is necessary.

Specified by:
cleanup in interface WabitObject
Overrides:
cleanup in class AbstractWabitObject
Returns:
A collection of exceptions and errors that occurred during cleanup if any occurred.


Copyright © 2009. All Rights Reserved.