main
Class Session

java.lang.Object
  extended by main.Session
All Implemented Interfaces:
java.io.Serializable

public class Session
extends java.lang.Object
implements java.io.Serializable

Stores all relevant information of a session.

References to the DataSheet and all active Charts are stored in session class instances. When the user saves his Session, this information is serialized and can be retrieved at a later time.

Care has been taken to avoid serializing swing objects. Therefore, no such objects should be referenced from within this class, only the information needed to reconstruct the chart frames.

See Also:
Serialized Form

Field Summary
private  java.util.Vector<Chart> charts
          All active charts.
private  DataSheet currentDataSheet
          The current data sheet.
(package private) static boolean printLog
          Flag to enable debug message printing for this class.
(package private) static long serialVersionUID
          The version tracking unique identifier for Serialization.
private  java.lang.String sessionDirectory
          The directory where the session was saved.
static java.lang.String sessionFileExtension
          The when storing session files this file extension will be used.
private  java.lang.String sessionName
          The session name.
 
Constructor Summary
Session()
          Instantiates a new session.
 
Method Summary
 void addChart(Chart chart)
          Adds a chart to the session.
 void clearAllCharts()
          Clear all charts.
 Chart getChart(int index)
          Gets a chart from this session.
 int getChartCount()
          Gets the number of charts
 DataSheet getCurrentDataSheet()
          Gets the current data sheet.
 java.lang.String getSessionDirectory()
          Gets the directory where the session was saved.
 java.lang.String getSessionName()
          Gets the session name.
private  void log(java.lang.String message)
          Prints debug information to stdout when printLog is set to true.
static Session readFromFile(Main mainWindow, java.lang.String pathToFile)
          Read from file.
 boolean removeChart(Chart chart)
          Removes a chart from the session.
 void saveToFile(java.lang.String pathToFile)
          Serializes the session to a file.
 void setCurrentDataSheet(DataSheet currentDataSheet)
          Sets the current data sheet.
 void setSessionDirectory(java.lang.String sessionDirectory)
          Sets the directory where the session is saved.
 void setSessionName(java.lang.String sessionName)
          Sets the session name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
The version tracking unique identifier for Serialization.

See Also:
Constant Field Values

printLog

static final boolean printLog
Flag to enable debug message printing for this class.

See Also:
Constant Field Values

sessionFileExtension

public static final java.lang.String sessionFileExtension
The when storing session files this file extension will be used.

See Also:
Constant Field Values

sessionName

private java.lang.String sessionName
The session name.


sessionDirectory

private java.lang.String sessionDirectory
The directory where the session was saved.


currentDataSheet

private DataSheet currentDataSheet
The current data sheet.


charts

private java.util.Vector<Chart> charts
All active charts.

Constructor Detail

Session

public Session()
Instantiates a new session.

Method Detail

saveToFile

public void saveToFile(java.lang.String pathToFile)
                throws java.io.IOException
Serializes the session to a file.

Parameters:
pathToFile - the path to file
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

readFromFile

public static Session readFromFile(Main mainWindow,
                                   java.lang.String pathToFile)
                            throws java.io.InvalidClassException,
                                   java.io.IOException,
                                   java.lang.ClassNotFoundException
Read from file.

Parameters:
mainWindow - the main window
pathToFile - the path where the file is saved
Returns:
the session instance
Throws:
InvalidClassException - thrown when the selected file is not a valid serialized session
java.io.IOException - Signals that an I/O exception has occurred.
java.lang.ClassNotFoundException - thrown when the class was not found.

getChart

public Chart getChart(int index)
Gets a chart from this session.

Parameters:
index - the index of the chart
Returns:
the chart

getChartCount

public int getChartCount()
Gets the number of charts

Returns:
the chart count

addChart

public void addChart(Chart chart)
Adds a chart to the session.

Parameters:
chart - the chart

removeChart

public boolean removeChart(Chart chart)
Removes a chart from the session.

Parameters:
chart - the chart
Returns:
true, if chart was successfully removed

clearAllCharts

public void clearAllCharts()
Clear all charts.


getCurrentDataSheet

public DataSheet getCurrentDataSheet()
Gets the current data sheet.

Returns:
the current data sheet

setCurrentDataSheet

public void setCurrentDataSheet(DataSheet currentDataSheet)
Sets the current data sheet.

Parameters:
currentDataSheet - the new current data sheet

getSessionName

public java.lang.String getSessionName()
Gets the session name.

Returns:
the session name

setSessionName

public void setSessionName(java.lang.String sessionName)
Sets the session name.

Parameters:
sessionName - the new session name

getSessionDirectory

public java.lang.String getSessionDirectory()
Gets the directory where the session was saved.

Returns:
the session directory

setSessionDirectory

public void setSessionDirectory(java.lang.String sessionDirectory)
Sets the directory where the session is saved.

Parameters:
sessionDirectory - the new session directory

log

private void log(java.lang.String message)
Prints debug information to stdout when printLog is set to true.

Parameters:
message - the message