de.upb.swtpra05.group03.companycontrol
Class CompanyMainControl

java.lang.Object
  extended byde.upb.swtpra05.group03.companycontrol.CompanyMainControl

public class CompanyMainControl
extends java.lang.Object

The Main Class of the CompanyControl. This Class inhabits the public static void main Method.

Version:
$Revision: 1.3 $

Field Summary
private  Accounting accountObj
          Reference on the account data control
private  CompanyControlClient client
          Reference on CompanyControlClient
private  Control controlObj
          Reference on the control panel included in the frame
private  Display displayObj
          Reference on the display panel included in the frame
private  UserInterface frame
          Reference on CompanyControlFrame
 float[] lastMarginValues
          saves the last sent margin values TODO set private after finishing tests
 int lastRiskFactor
          saves the last sent risk factor TODO set private after finishing tests
 boolean lastSelfAdopt
          saves the last sent self adopt value TODO set private after finishing tests
private  Log logObj
          Reference on the control panel in the frame
 java.util.Map orderList
          This hashmap contains the current offered orders.
private  PluginLoader pluginloader
          The PluginLoader
 int priceDifference
          the difference of the price for a shuttle between a station with x and a station with x+1 shuttles.
 boolean priceDifferenceNotSet
          helper for priceDifference TODO set private after finishing tests
 java.util.Map shuttleListCopy
          copy of current shuttle ist.
private  int shuttleListSize
          the current size of the shuttleList.
 java.util.Map shuttleStockCopy
          copy of current shuttle stock.
private  int shuttleStockSize
          the current size of the shuttleStock.
private  java.lang.String simTime
          the current simulation time
 
Constructor Summary
(package private) CompanyMainControl()
          The constructor is called from the main method (see below).
 
Method Summary
 void addOrder(OrderInformation order)
          This method is called by CompanyControlClient to add the given order to the orderList.
 void applyNewParams(float margin, float minMargin, float marginStep, int riskFactor, boolean selfAdopt)
          This method sends a message to the shuttles concerning the changing of shuttle parameters.
 void buyShuttle(java.lang.String stationName, int maxPrice)
          This method is called from the GUI when the user presses the "Buy Shuttle" button.
 void calculatePriceDifference(java.util.Map shuttleStock)
          This method is called by updateShuttleStock to calculate the value of priceDifference (see above).
 java.util.Map calculateRevenues(java.util.Map shuttleList)
          This message is called by ControlMainControl itself after being informed about changes of the positions of the shuttles.
 int[] calculateTradeAdverts(java.util.Map shuttleStock)
          This message is called by ControlMainControl itself after being informed about changes in the station's shuttle stock.
 void createAndShowGUI()
          Create the GUI and show it.
 PluginLoader getPluginloader()
           
 int getPriceToShuttle(int shuttleID)
          This method is called by TradePanel when the user chooses a shuttle from the combo box.
 int getPriceToStation(java.lang.String stationName)
          This method is called by TradePanel when user chose a station from the combo box.
 java.lang.String getSimTime()
          accessor method for the current simulation time
 int getStationIDofOrder(int orderID)
          This method is called by CompanyControlClient to get the start station ID of the order with the given ID
private  boolean lessProfitableThan(int champPrice, int champTotalOrders, int champCurrentOrders, int challPrice, int challTotalOrders, int challCurrentOrders)
          This method is called by calculateTradeAdverts to find out if the current most profitable price is worse than the one to test.
static void main(java.lang.String[] args)
           
 void removeOrder(int orderID)
          This method is called by CompanyControlClient the remove the order with the given ID from the orderList.
 void sellShuttle(int shuttleID, int minPrice)
          this method is called from the GUI when the user presses the "Sell Shuttle" button.
 void sendParamsForNewShuttle()
          This method is called by CompanyControlClient when a new shuttle was successfully bought.
 void setDisconnectState()
          This method is called when Kernel is disconnected.
 void setReferencesForTesting(CompanyControlClient client, Log logObj)
          METHOD JUST FOR TESTING
 void setSimTime(int time)
          This method is called by the CompanyControlClient to inform the MainControl about the current simulation time for logging.
 void setWaitState()
          This method is called when the client tries to connect to the Kernel or has already connected, but no data for the different parts of the GUI have been sent.
private  void showNoParamsChangedDialog()
          This method is called by applyNewParams (see below), when the user pressed the "Apply"-button without changing any parameters before.
private  boolean showStopShuttleDialog()
          This method is called by the method sellShuttle (see below) when the user tries to sell a shuttle that is working at the moment.
 void updateAccountBalance(int balance, int time)
          This method is called from the CompanyControlClient, when a message concerning the company's money has arrived.
 void updateLogText(java.lang.String message)
          This method is called by itself or by CompanyControlClient when new news exist that could be interesting for the company.
 void updateShuttleList(java.util.Map shuttleList)
          This method is called by CompanyControlClient when the shuttle list or the positions of the shuttles have changed and the GUI's shuttle shuttle list table and the shuttle combo box have to be updated.
 void updateShuttleStock(java.util.Map shuttleStock)
          This method is called by CompanyControlClient when the shuttle stock has changed and the GUI's stock list table and the stock combo box have to be updated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

frame

private UserInterface frame
Reference on CompanyControlFrame


client

private CompanyControlClient client
Reference on CompanyControlClient


controlObj

private Control controlObj
Reference on the control panel included in the frame


displayObj

private Display displayObj
Reference on the display panel included in the frame


logObj

private Log logObj
Reference on the control panel in the frame


accountObj

private Accounting accountObj
Reference on the account data control


simTime

private java.lang.String simTime
the current simulation time


shuttleListSize

private int shuttleListSize
the current size of the shuttleList. Used for testing if number of shuttles changed.


shuttleListCopy

public java.util.Map shuttleListCopy
copy of current shuttle ist. Used for trade panel functions. TODO Set private after finishing tests


shuttleStockSize

private int shuttleStockSize
the current size of the shuttleStock. Used for testing if number of stations changed.


shuttleStockCopy

public java.util.Map shuttleStockCopy
copy of current shuttle stock. Used for calculating revenues. TODO Set private after finishing tests


orderList

public java.util.Map orderList
This hashmap contains the current offered orders. It is used to calculate which is the most profitable trade advert. TODO Set private after finishing tests


priceDifference

public int priceDifference
the difference of the price for a shuttle between a station with x and a station with x+1 shuttles. Used for finding the most profitable advert. TODO set private after finishing tests


priceDifferenceNotSet

public boolean priceDifferenceNotSet
helper for priceDifference TODO set private after finishing tests


lastRiskFactor

public int lastRiskFactor
saves the last sent risk factor TODO set private after finishing tests


lastMarginValues

public float[] lastMarginValues
saves the last sent margin values TODO set private after finishing tests


lastSelfAdopt

public boolean lastSelfAdopt
saves the last sent self adopt value TODO set private after finishing tests


pluginloader

private PluginLoader pluginloader
The PluginLoader

Constructor Detail

CompanyMainControl

CompanyMainControl()
The constructor is called from the main method (see below). Further actions take place in createAndShowGUI() (see below) to avoid exceptions.

Method Detail

setReferencesForTesting

public void setReferencesForTesting(CompanyControlClient client,
                                    Log logObj)
METHOD JUST FOR TESTING

Parameters:
client - the client to set
logObj - the log object to test TODO Delete aftre finishing tests

setWaitState

public void setWaitState()
This method is called when the client tries to connect to the Kernel or has already connected, but no data for the different parts of the GUI have been sent. Sets the wait outputs of the GUI.


setDisconnectState

public void setDisconnectState()
This method is called when Kernel is disconnected. Resets outputs of the GUI.


updateAccountBalance

public void updateAccountBalance(int balance,
                                 int time)
This method is called from the CompanyControlClient, when a message concerning the company's money has arrived. The MainControl gives the AccountDataControl the order to update the account graph.

Parameters:
balance - the current company's account balance
time - the current simulation time

setSimTime

public void setSimTime(int time)
This method is called by the CompanyControlClient to inform the MainControl about the current simulation time for logging. The method sets the local string for the time

Parameters:
time - current simulation time

getSimTime

public java.lang.String getSimTime()
accessor method for the current simulation time

Returns:
the current simulation time

updateLogText

public void updateLogText(java.lang.String message)
This method is called by itself or by CompanyControlClient when new news exist that could be interesting for the company. Lets log panel show the news.

Parameters:
message - news to be shown in the log text

updateShuttleList

public void updateShuttleList(java.util.Map shuttleList)
This method is called by CompanyControlClient when the shuttle list or the positions of the shuttles have changed and the GUI's shuttle shuttle list table and the shuttle combo box have to be updated. Executes necessary operations before and for updatating the list and the box.

Parameters:
shuttleList - includes information about the company's shuttles

getPriceToShuttle

public int getPriceToShuttle(int shuttleID)
This method is called by TradePanel when the user chooses a shuttle from the combo box. The revenue of the shuttle at its location is to be found.

Parameters:
shuttleID - the shuttle to find the revenue of
Returns:
the revenue

calculateRevenues

public java.util.Map calculateRevenues(java.util.Map shuttleList)
This message is called by ControlMainControl itself after being informed about changes of the positions of the shuttles. It calculates for what price each shuttle can be sold. Afterwards, the shuttle list table gets updated. TODO set private after finishing tests

Parameters:
shuttleList - includes information about the company's shuttles
Returns:
Map the completed shuttle list

updateShuttleStock

public void updateShuttleStock(java.util.Map shuttleStock)
This method is called by CompanyControlClient when the shuttle stock has changed and the GUI's stock list table and the stock combo box have to be updated. Executes necessary operations before and for updating the table and the box.

Parameters:
shuttleStock - includes information about the station's stocks

getPriceToStation

public int getPriceToStation(java.lang.String stationName)
This method is called by TradePanel when user chose a station from the combo box. The price the chosen station sells a shuttle for is to be found.

Parameters:
stationName - the station to get the sale price of
Returns:
the sale price

calculatePriceDifference

public void calculatePriceDifference(java.util.Map shuttleStock)
This method is called by updateShuttleStock to calculate the value of priceDifference (see above). Once calculated, this method is not called, again. TODO Set this method private after finishing tests

Parameters:
shuttleStock - the current shuttle stock

lessProfitableThan

private boolean lessProfitableThan(int champPrice,
                                   int champTotalOrders,
                                   int champCurrentOrders,
                                   int challPrice,
                                   int challTotalOrders,
                                   int challCurrentOrders)
This method is called by calculateTradeAdverts to find out if the current most profitable price is worse than the one to test. The calculation is based on the factors price, current and total number of orders. For further information, look at comments between the lines of code below.

Parameters:
champPrice - the price of the current most profitable station
champCurrentOrders - the current number of orders of the current most profitable station
champTotalOrders - the totally counted number of orders of the current most profitable station
challPrice - the price of the station to test
challCurrentOrders - the current number of orders of the station to test
challTotalOrders - the total number of orders of the station to test
Returns:
true for "the challenger wins", false for "the champion wins"

calculateTradeAdverts

public int[] calculateTradeAdverts(java.util.Map shuttleStock)
This message is called by ControlMainControl itself after being informed about changes in the station's shuttle stock. Calculates which is the cheepest, the most expensive and the most profitable station concerning purchase and sale of shuttles. Afterwards, the shuttle stock table gets updated. TODO Set this method private after finishing tests

Parameters:
shuttleStock - includes information about the station's stocks
Returns:
int [] contains the ID of cheepest [0], the most expensive [1] and the most profitable station [2]

addOrder

public void addOrder(OrderInformation order)
This method is called by CompanyControlClient to add the given order to the orderList.

Parameters:
order - the order to add

removeOrder

public void removeOrder(int orderID)
This method is called by CompanyControlClient the remove the order with the given ID from the orderList.

Parameters:
orderID - the order to remove

getStationIDofOrder

public int getStationIDofOrder(int orderID)
This method is called by CompanyControlClient to get the start station ID of the order with the given ID

Parameters:
orderID - the order of which to get the start station ID
Returns:
the start station ID

showNoParamsChangedDialog

private void showNoParamsChangedDialog()
This method is called by applyNewParams (see below), when the user pressed the "Apply"-button without changing any parameters before. A message dialog is shown to inform the user about this.


applyNewParams

public void applyNewParams(float margin,
                           float minMargin,
                           float marginStep,
                           int riskFactor,
                           boolean selfAdopt)
This method sends a message to the shuttles concerning the changing of shuttle parameters. It is called by StrategyPanel when the user presses "Apply". The method look rather complex, but most is just for senseful user output.

Parameters:
margin - the size of the margin, its
minMargin - the minimum marging
marginStep - the size of the margin's steps
riskFactor - the parameter for the risc of the shuttles
selfAdopt - true when shuttles shall self-adopt, false else

sendParamsForNewShuttle

public void sendParamsForNewShuttle()
This method is called by CompanyControlClient when a new shuttle was successfully bought. The current shuttle parameters are sent, so the new shuttle gets to know them.


buyShuttle

public void buyShuttle(java.lang.String stationName,
                       int maxPrice)
This method is called from the GUI when the user presses the "Buy Shuttle" button. Finds out which station ID is linked to the given station name and then lets CompanyControlClient send a message to the kernel about the user's wish.

Parameters:
stationName - the stationID where to buy a shuttle
maxPrice - the maximum price to buy a shuttle for

showStopShuttleDialog

private boolean showStopShuttleDialog()
This method is called by the method sellShuttle (see below) when the user tries to sell a shuttle that is working at the moment. A message dialog is shown that lets the user decide whether the shuttle shall be stopped after finishing current orders, so it can be sold afterwards.

Returns:
true if the user wants the shuttle to stop, false else.

sellShuttle

public void sellShuttle(int shuttleID,
                        int minPrice)
this method is called from the GUI when the user presses the "Sell Shuttle" button. Lets CompanyControlClient send a message to the kernel about the user's wish.

Parameters:
shuttleID - the shuttleID of the shuttle to be sold
minPrice - the minimum price to sell the shuttle for.

createAndShowGUI

public void createAndShowGUI()
Create the GUI and show it. For thread safety, this method should be invoked from the event-dispatching thread.


getPluginloader

public PluginLoader getPluginloader()
Returns:
Returns the pluginloader.

main

public static void main(java.lang.String[] args)
Parameters:
args -