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 * ID for serialization.
020 */
021 private static final long serialVersionUID = 5774706836031417066L;
022
023 /**
024 * @param s the SalesPoints name.
025 */
026 public SPListenable(String s) {
027 super(s);
028 attach(new DataBasketImpl());
029 }
030
031 /**
032 * @return the default FormSheet.
033 */
034 protected FormSheet getDefaultFormSheet() {
035 return new FSEmpty();
036 }
037
038 /**
039 * Sets the image icon when a SalesPoint is opened.
040 * @param e the fired Event
041 */
042 public void formSheetSet(FormSheetEvent e) {
043 super.formSheetSet(e);
044 IconSetter.setIcon((JDisplayFrame)getDisplay());
045 }
046
047 /**
048 * Sets SalesPoint's icon after it is loaded from persistence file.
049 */
050 public void resume() {
051 super.resume();
052 IconSetter.setIcon((JDisplayFrame)getDisplay());
053 }
054
055 /**
056 * @return <code>true</code> if no SaleProcess is running, otherwise <code>false</code>.
057 * This forces the user to quit the SaleProcess before he closes the SalesPoint.
058 */
059 protected boolean onCanQuit() {
060 return getCurrentProcess() == null;
061 }
062
063 /**
064 * Reaction on event: The market is about to close.
065 */
066 public void notifyOnMarketClosing() {
067 getDisplay().getFormSheet().setCaption(SMarket.MARKET_CLOSES_SHORT);
068 }
069
070 /**
071 * Reaction en event: The market isn't about to close anymore.
072 */
073 public void notifyOnMarketNotClosing() {
074 getDisplay().getFormSheet().setCaption(SMarket.MARKET_CLOSES_NOT);
075 }
076
077 /**
078 * Reaction on event: The market has just closed.
079 */
080 public void marketClosed() {
081 getDisplay().getFormSheet().setCaption(SMarket.MARKET_CLOSED);
082 }
083
084 /**
085 * Reaction on event: The market has just opened.
086 */
087 public void marketOpened() {
088 getDisplay().getFormSheet().setCaption(SMarket.MARKET_OPENED);
089 }
090
091 /**
092 * Reaction on event: The time has advanced.
093 */
094 public void timeAdvanced() {
095 }
096
097 /**
098 * Reaction on event: A new order for workers arrived or a worker logged on.
099 */
100 public void workerInformationChanged(){
101 if(this.getCurrentProcess() instanceof SProcessWorker){
102 if(this.getDisplay().getFormSheet() instanceof FSWorkerDefault){
103 ((SProcessWorker)this.getCurrentProcess()).getInitialGate();
104 }
105 }
106 }
107 }