001 package market;
002
003 import market.event.MarketEventListener;
004 import market.resource.IconSetter;
005 import market.stdform.FSEmpty;
006 import market.stdform.FSWorkerDefault;
007 import sale.FormSheet;
008 import sale.JDisplayFrame;
009 import sale.SalesPoint;
010 import sale.events.FormSheetEvent;
011 import data.ooimpl.DataBasketImpl;
012
013 /**
014 * A SalesPoint that can react to MarketEvents.
015 */
016 public class SPListenable extends SalesPoint implements MarketEventListener {
017
018 /**
019 * @param s the SalesPoints name.
020 */
021 public SPListenable(String s) {
022 super(s);
023 attach(new DataBasketImpl());
024 }
025
026 /**
027 * @return the default FormSheet.
028 */
029 protected FormSheet getDefaultFormSheet() {
030 return new FSEmpty();
031 }
032
033 /**
034 * Sets the image icon when a SalesPoint is opened.
035 * @param e the fired Event
036 */
037 public void formSheetSet(FormSheetEvent e) {
038 super.formSheetSet(e);
039 IconSetter.setIcon((JDisplayFrame)getDisplay());
040 }
041
042 /**
043 * Sets SalesPoint's icon after it is loaded from persistence file.
044 */
045 public void resume() {
046 super.resume();
047 IconSetter.setIcon((JDisplayFrame)getDisplay());
048 }
049
050 /**
051 * @return <code>true</code> if no SaleProcess is running, otherwise <code>false</code>.
052 * This forces the user to quit the SaleProcess before he closes the SalesPoint.
053 */
054 protected boolean onCanQuit() {
055 return getCurrentProcess() == null;
056 }
057
058 /**
059 * Reaction on event: The market is about to close.
060 */
061 public void notifyOnMarketClosing() {
062 getDisplay().getFormSheet().setCaption(SMarket.MARKET_CLOSES_SHORT);
063 }
064
065 /**
066 * Reaction en event: The market isn't about to close anymore.
067 */
068 public void notifyOnMarketNotClosing() {
069 getDisplay().getFormSheet().setCaption(SMarket.MARKET_CLOSES_NOT);
070 }
071
072 /**
073 * Reaction on event: The market has just closed.
074 */
075 public void marketClosed() {
076 getDisplay().getFormSheet().setCaption(SMarket.MARKET_CLOSED);
077 }
078
079 /**
080 * Reaction on event: The market has just opened.
081 */
082 public void marketOpened() {
083 getDisplay().getFormSheet().setCaption(SMarket.MARKET_OPENED);
084 }
085
086 /**
087 * Reaction on event: The time has advanced.
088 */
089 public void timeAdvanced() {
090 }
091
092 /**
093 * Reaction on event: A new order for workers arrived or a worker logged on.
094 */
095 public void workerInformationChanged(){
096 if(this.getCurrentProcess() instanceof SProcessWorker){
097 if(this.getDisplay().getFormSheet() instanceof FSWorkerDefault){
098 ((SProcessWorker)this.getCurrentProcess()).getInitialGate();
099 }
100 }
101 }
102 }