Class Scenario

java.lang.Object
  extended by Scenario

public class Scenario
extends java.lang.Object

Contains the information of an MMS file. This is the main object of manipulation for the GUIs.

Author:
Michael Latham

Field Summary
private  java.lang.String m_boardHeight
           
private  java.lang.String m_boardWidth
           
(package private)  int M_CANCEL
           
private  java.lang.String m_desc
           
private  java.lang.String m_error
           
private  java.lang.String m_factions
           
private  java.util.Vector<Faction> m_factionVector
           
private  java.lang.String m_fName
          Attributes
private  boolean m_isNew
           
private  java.lang.String m_mapHeight
           
private  java.lang.String m_maps
           
private  java.lang.String m_mapWidth
           
(package private)  int M_MAX_FILE_CHARS
           
private  java.lang.String m_name
           
(package private)  int M_NO
          Constants
private  java.lang.String m_version
           
(package private)  int M_YES
           
 
Constructor Summary
Scenario()
          Default constructor
Scenario(java.lang.String fName, boolean isNew)
          Constructor with filename (or scenario name, if new) and new indicator
 
Method Summary
 void addFaction(Faction newFaction)
          Add the given faction to the faction vector
 void buildFactionListDisplay(javax.swing.JList factionList, java.lang.String factionFilter)
          Builds a list of Faction information in the given list
 void buildFactionNameComboBox(javax.swing.JComboBox cbNames, boolean addAllText, boolean clearCombo)
          Builds a combo box of Faction names; sets selected to first item
 void buildFactionVector(java.lang.String factionList)
          Build the faction vector of Faction objects given the list of factions
 java.lang.String getAttribute(java.lang.String attrib)
          Returns the desired attribute
 java.lang.String getAttributeValue(java.lang.String attrib)
          returns the desired attribute value (i.e.
 java.lang.String getError()
           
 Faction getFactionByName(java.lang.String lName)
          Returns the Faction given the exact name
 Faction getFactionByProperty(java.lang.String lProp)
          Returns the Faction given a full property string
 java.lang.String getFileName()
           
private  void initAttributes(boolean isNew)
          Called from the constructors and initializes all the attributes
 void removeFaction(Faction delFaction)
          Removes the given faction from the faction vector
 void replaceFaction(Faction oldFaction, Faction newFaction)
          Replace an existing faction with a new faction
 boolean save()
          Saves the scenario to disk.
 void setAsNew()
          Set Scenario as a new scenario, while maintaining most attributes
 void setAttribute(java.lang.String attrib, java.lang.String val)
          Set the desired attribute
 void setAttributeFromParam(java.lang.String mmsParam, java.lang.String mmsLine)
          Given the parameter name and the string for the parameter, set the correct attribute
 int setAttributesFromFile()
          Called after object is constructed to set (or re-set) the attributes from the file
 void setFactionAttribute(java.lang.String mmsParam, java.lang.String mmsLine)
          Given the parameter name and the string for the parameter, set the correct Faction attribute
 void setFileName(java.lang.String fName)
          Set Scenario filename
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

M_NO

final int M_NO
Constants

See Also:
Constant Field Values

M_YES

final int M_YES
See Also:
Constant Field Values

M_CANCEL

final int M_CANCEL
See Also:
Constant Field Values

M_MAX_FILE_CHARS

final int M_MAX_FILE_CHARS
See Also:
Constant Field Values

m_fName

private java.lang.String m_fName
Attributes


m_isNew

private boolean m_isNew

m_error

private java.lang.String m_error

m_version

private java.lang.String m_version

m_name

private java.lang.String m_name

m_desc

private java.lang.String m_desc

m_boardWidth

private java.lang.String m_boardWidth

m_boardHeight

private java.lang.String m_boardHeight

m_mapWidth

private java.lang.String m_mapWidth

m_mapHeight

private java.lang.String m_mapHeight

m_maps

private java.lang.String m_maps

m_factions

private java.lang.String m_factions

m_factionVector

private java.util.Vector<Faction> m_factionVector
Constructor Detail

Scenario

public Scenario()
Default constructor


Scenario

public Scenario(java.lang.String fName,
                boolean isNew)
Constructor with filename (or scenario name, if new) and new indicator

Parameters:
fName - Filename (full path) if isNew = false; scenario name if isNew = true
isNew - False if scenario exists on disk; true if new scenario
Method Detail

initAttributes

private void initAttributes(boolean isNew)
Called from the constructors and initializes all the attributes

Parameters:
isNew - True if new scenario (not on harddisk); false if file exists

setAttributesFromFile

public int setAttributesFromFile()
Called after object is constructed to set (or re-set) the attributes from the file

Returns:
M_YES if ok; any other return is a failure

setAttributeFromParam

public void setAttributeFromParam(java.lang.String mmsParam,
                                  java.lang.String mmsLine)
Given the parameter name and the string for the parameter, set the correct attribute

Parameters:
mmsParam - Parameter that the line is for (e.g. BoardWidth)
mmsLine - The line for the attribute (e.g. BoardWidth=1)

buildFactionVector

public void buildFactionVector(java.lang.String factionList)
Build the faction vector of Faction objects given the list of factions

Parameters:
factionList - List of factions (e.g. Factions=Rangers,Scouts)

setFactionAttribute

public void setFactionAttribute(java.lang.String mmsParam,
                                java.lang.String mmsLine)
Given the parameter name and the string for the parameter, set the correct Faction attribute

Parameters:
mmsParam - Parameter that the line is for (e.g. Unit_Rangers_1)
mmsLine - The line for the attribute (e.g. Unit_Rangers_1=Stone Rhino SERO,Capt Black,3,3)

getAttribute

public java.lang.String getAttribute(java.lang.String attrib)
Returns the desired attribute

Parameters:
attrib - Attribute parameter name
Returns:
Attribute string

setAttribute

public void setAttribute(java.lang.String attrib,
                         java.lang.String val)
Set the desired attribute

Parameters:
attrib - Attribute parameter name (e.g. Version)
val - Attribute value (e.g. 1)

getAttributeValue

public java.lang.String getAttributeValue(java.lang.String attrib)
returns the desired attribute value (i.e. after the "=")

Parameters:
attrib - Attribute parameter name
Returns:
Attribute value string

buildFactionListDisplay

public void buildFactionListDisplay(javax.swing.JList factionList,
                                    java.lang.String factionFilter)
Builds a list of Faction information in the given list

Parameters:
factionList - List object to hold Faction information
factionFilter - Name by which to filter; blank or "All" will add all

buildFactionNameComboBox

public void buildFactionNameComboBox(javax.swing.JComboBox cbNames,
                                     boolean addAllText,
                                     boolean clearCombo)
Builds a combo box of Faction names; sets selected to first item

Parameters:
cbNames - Combo to be built
addAllText - True will add text "All" to beginning of list
clearCombo - True will clear list, first

getFactionByName

public Faction getFactionByName(java.lang.String lName)
Returns the Faction given the exact name

Returns:
Faction object from the given name

getFactionByProperty

public Faction getFactionByProperty(java.lang.String lProp)
Returns the Faction given a full property string

Returns:
Faction object that contains the given property

replaceFaction

public void replaceFaction(Faction oldFaction,
                           Faction newFaction)
Replace an existing faction with a new faction

Parameters:
oldFaction - Old Faction to be replaced
newFaction - New Faction to take the old one's place

addFaction

public void addFaction(Faction newFaction)
Add the given faction to the faction vector

Parameters:
newFaction - New Faction object to add to the Faction list

removeFaction

public void removeFaction(Faction delFaction)
Removes the given faction from the faction vector

Parameters:
delFaction - Faction object to be deleted from Faction list

getFileName

public java.lang.String getFileName()
Returns:
Current filename (full path) for the Scenario

setFileName

public void setFileName(java.lang.String fName)
Set Scenario filename

Parameters:
fName - Filename (full path) for the Scenario

getError

public java.lang.String getError()
Returns:
Last error

save

public boolean save()
Saves the scenario to disk. Call getError() if save returns false.

Returns:
True if successful save; false otherwise

setAsNew

public void setAsNew()
Set Scenario as a new scenario, while maintaining most attributes