/* * Created on 12.08.2004 * * @author Jens Guenther */ package de.unirostock.AbstractFactory.example.awt; import javax.swing.JPanel; import de.unirostock.AbstractFactory.example.ShipFactory; public class MainController { // ------------------------------------------------------------------- // // ---- private classes ---------------------------------------------- // // ------------------------------------------------------------------- // private class MainControllerState extends State { /** * * @uml.property name="controller" * @uml.associationEnd multiplicity="(0 1)" */ protected MainController itsController; protected JPanel itsPanel; } private class ChooseFactoryState extends MainControllerState { public ChooseFactoryState( MainController controller ){ itsController = controller; } public void entry() { // set formerly choosed ShipFactory to null itsController.setShipFactory( null ); // init HeadPane itsController.setHeadline( "Auswahl der ShipFactory" ); // init ChooseFactoryPanel if( itsPanel == null ){ itsPanel = new ChooseFactoryPanel( itsController ); } itsController.setContentPanel( itsPanel ); // init ButtonPane itsController.setCancelVisible( false ); itsController.setOkText( "Blaupausen ansehen >" ); itsController.getMainPanel().getMainButtonPanel().setCancelState( null ); itsController.getMainPanel().getMainButtonPanel().setOkState( itsController.getViewComponentState()); } public void exit() { // set ShipFactory to selected ShipFactory ShipFactory selFactory = ((ChooseFactoryPanel)itsPanel).getSelectedShipFactory(); itsController.setShipFactory( selFactory ); } } private class ViewComponentState extends MainControllerState { public ViewComponentState( MainController controller ){ itsController = controller; } public void entry() { // init HeadPane itsController.setHeadline( "Ansicht der ShipComponents" ); // init ViewComponentPane if( itsPanel == null ){ itsPanel = new ViewComponentPanel(); } itsController.setContentPanel( itsPanel ); ((ViewComponentPanel)itsPanel).init( itsController.getSelectedShipFactory()); // init ButtonPane itsController.setCancelVisible( true ); itsController.setOkText( "Schiff herstellen >" ); itsController.getMainPanel().getMainButtonPanel().setCancelState( itsController.getChooseFactoryState()); itsController.getMainPanel().getMainButtonPanel().setOkState( itsController.getAssembledShipState()); } } private class AssembledShipState extends MainControllerState { public AssembledShipState( MainController controller ){ itsController = controller; } public void entry() { // init HeadPane itsController.setHeadline( "Zusammenbau mittels Shipyard" ); // init AssembledShipPane if( itsPanel == null ){ itsPanel = new AssembledShipPanel(); } itsController.setContentPanel( itsPanel ); ((AssembledShipPanel)itsPanel).init( itsController.getSelectedShipFactory()); // init ButtonPane itsController.setCancelVisible( false ); itsController.setOkText( "Nächstes Schiff >" ); itsController.getMainPanel().getMainButtonPanel().setCancelState( null ); itsController.getMainPanel().getMainButtonPanel().setOkState( itsController.getChooseFactoryState()); } } /** * * @uml.property name="chooseFactoryState" * @uml.associationEnd multiplicity="(0 1)" */ // ------------------------------------------------------------------- // // ---- attributes --------------------------------------------------- // // ------------------------------------------------------------------- // private State itsChooseFactoryState = null; /** * * @uml.property name="viewComponentState" * @uml.associationEnd multiplicity="(0 1)" */ private State itsViewComponentState = null; /** * * @uml.property name="assembledShipState" * @uml.associationEnd multiplicity="(0 1)" */ private State itsAssembledShipState = null; /** * * @uml.property name="mainPanel" * @uml.associationEnd multiplicity="(0 1)" */ private MainPanel itsMainPanel; /** * * @uml.property name="avaiableFactorys" * @uml.associationEnd multiplicity="(0 -1)" */ private ShipFactory[] itsAvaiableFactorys; /** * * @uml.property name="shipFactory" * @uml.associationEnd multiplicity="(0 1)" */ private ShipFactory itsShipFactory; /** * * @uml.property name="state" * @uml.associationEnd multiplicity="(0 1)" */ private State itsState = null; // ------------------------------------------------------------------- // // ---- constructor -------------------------------------------------- // // ------------------------------------------------------------------- // public MainController( MainPanel view ) { itsMainPanel = view; } // ------------------------------------------------------------------- // // ---- state management --------------------------------------------- // // ------------------------------------------------------------------- // public void init() { MainHeadPanel mhp = new MainHeadPanel(); MainButtonPanel mbp = new MainButtonPanel( this ); itsMainPanel.setHeadPanel( mhp ); itsMainPanel.setButtonPanel( mbp ); setState( getChooseFactoryState()); } /** * * @uml.property name="state" */ protected void setState(State state) { if (itsState != null) itsState.exit(); itsState = state; if (itsState != null) itsState.entry(); itsMainPanel.repaint(); } /** * * @uml.property name="chooseFactoryState" */ private State getChooseFactoryState() { if (itsChooseFactoryState == null) { itsChooseFactoryState = new ChooseFactoryState(this); } return itsChooseFactoryState; } /** * * @uml.property name="viewComponentState" */ private State getViewComponentState() { if (itsViewComponentState == null) { itsViewComponentState = new ViewComponentState(this); } return itsViewComponentState; } /** * * @uml.property name="assembledShipState" */ private State getAssembledShipState() { if (itsAssembledShipState == null) { itsAssembledShipState = new AssembledShipState(this); } return itsAssembledShipState; } /** * * @uml.property name="mainPanel" */ // ------------------------------------------------------------------- // // ---- data model --------------------------------------------------- // // ------------------------------------------------------------------- // protected MainPanel getMainPanel() { return itsMainPanel; } public void setAvaiableShipFactorys( ShipFactory[] factorys ){ itsAvaiableFactorys = factorys; } public ShipFactory[] getAvaiableShipFactorys(){ return itsAvaiableFactorys; } /** * * @uml.property name="shipFactory" */ protected void setShipFactory(ShipFactory factory) { itsShipFactory = factory; } public ShipFactory getSelectedShipFactory(){ return itsShipFactory; } protected void setHeadline( String headline ){ itsMainPanel.getMainHeadPanel().setHeadline( headline ); } protected void setCancelVisible( boolean visible ){ itsMainPanel.getMainButtonPanel().setCancelVisible( visible ); } protected void setOkText( String okText ){ itsMainPanel.getMainButtonPanel().setOkText( okText ); } protected void setContentPanel( JPanel contentPanel ){ itsMainPanel.setContentPanel( contentPanel ); } }