1 /*
2 * Created on Sep 28, 2004
3 *
4 */
5 package ubc.midp.mobilephoto.core.ui.controller;
6
7 import javax.microedition.lcdui.Command;
8
9 import ubc.midp.mobilephoto.core.ui.MainUIMidlet;
10 import ubc.midp.mobilephoto.core.ui.datamodel.AlbumData;
11 import ubc.midp.mobilephoto.core.ui.screens.AlbumListScreen;
12 import ubc.midp.mobilephoto.core.util.Constants;
13
14 /**
15 * @author tyoung
16 *
17 * This is the base controller class used in the MVC architecture.
18 * It controls the flow of screens for the MobilePhoto application.
19 * Commands handled by this class should only be for the core application
20 * that runs on any MIDP platform. Each device or class of devices that supports
21 * optional features will extend this class to handle feature specific commands.
22 *
23 */
24 public class BaseController extends AbstractController {
25
26 // [EF] Attributes albumController and photoController were commented because
27 // I'm not sure which one is the best solution:
28 // [EF] (i) Declare controllers here and have only one instance or
29 // [EF] (ii) create controllerns when needed (current solution)
30 // private AlbumController albumController;
31 // private PhotoController photoController;
32
33 /**
34 * Pass a handle to the main Midlet for this controller
35 * @param midlet
36 */
37 public BaseController(MainUIMidlet midlet, AlbumData model, AlbumListScreen albumListScreen) {
38 super(midlet, model, albumListScreen);
39 }
40
41 /**
42 * Initialize the controller
43 */
44 public void init(AlbumData model) {
45 //Get all MobilePhoto defined albums from the record store
46 String[] albumNames = model.getAlbumNames();
47 for (int i = 0; i < albumNames.length; i++) {
48 if (albumNames[i] != null) {
49 //Add album name to menu list
50 getAlbumListScreen().append(albumNames[i], null);
51
52 }
53 }
54 getAlbumListScreen().initMenu();
55
56 //Set the current screen to the photo album listing
57 setCurrentScreen(getAlbumListScreen());
58 }
59
60 /*
61 * TODO [EF] Why this method receives Displayable and never uses?
62 */
63 public boolean handleCommand(Command command) {
64 String label = command.getLabel();
65
66 //Can this controller handle the desired action?
67 //If yes, handleCommand will return true, and we're done
68 //If no, handleCommand will return false, and postCommand
69 //will pass the request to the next controller in the chain if one exists.
70
71 System.out.println( this.getClass().getName() + "::handleCommand: " + label);
72
73 /** Case: Exit Application **/
74 if (label.equals("Exit")) {
75 midlet.destroyApp(true);
76 return true;
77
78 /** Case: Go to the Previous or Fallback screen * */
79 } else if (label.equals("Back")) {
80 return goToPreviousScreen();
81
82 /** Case: Cancel the current screen and go back one* */
83 } else if (label.equals("Cancel")) {
84 return goToPreviousScreen();
85
86 }
87
88 //If we couldn't handle the current command, return false
89 return false;
90 }
91
92 private boolean goToPreviousScreen() {
93 System.out.println("<* AlbumController.goToPreviousScreen() *>");
94 String currentScreenName = ScreenSingleton.getInstance().getCurrentScreenName();
95 if ( (currentScreenName.equals(Constants.IMAGELIST_SCREEN)) ||
96 (currentScreenName.equals(Constants.NEWALBUM_SCREEN)) ||
97 (currentScreenName.equals(Constants.CONFIRMDELETEALBUM_SCREEN)) ){
98 getAlbumListScreen().repaintListAlbum(getAlbumData().getAlbumNames());
99 setCurrentScreen( getAlbumListScreen() );
100 ScreenSingleton.getInstance().setCurrentScreenName(Constants.ALBUMLIST_SCREEN);
101 return true;
102 }
103
104 return false;
105 }
106 }
|