Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

DocumentList.java

Go to the documentation of this file.
00001 
00066 package com.arcle.rmt.superwaba.vc;
00067 
00068 import waba.ui.ListBox;
00069 import waba.ui.Button;
00070 import waba.ui.Event;
00071 import waba.ui.ControlEvent;
00072 import waba.ui.MenuBar;
00073 
00074 import com.arcle.rmt.superwaba.AboutDialog;
00075 import com.arcle.rmt.superwaba.ui.CommandWindow;
00076 import com.arcle.rmt.superwaba.framework.View;
00077 import com.arcle.rmt.superwaba.framework.Model;
00078 import com.arcle.rmt.superwaba.model.DocumentManager;
00079 import com.arcle.rmt.superwaba.vc.DocumentListController;
00080 
00081 
00088 public final class DocumentList extends CommandWindow implements View {
00089 
00093     private DocumentList() {
00094         super("Document List", TAB_ONLY_BORDER);
00095     }
00096 
00100     public static DocumentList getInstance() {
00101         if (_instance == null) {
00102             _instance = new DocumentList();
00103         }
00104         return _instance;
00105     }
00106 
00107     //-----------------------------------------------------------------------
00108     // View implementation
00109 
00113     public void modelUpdated() {
00114         DocumentManager dm = DocumentManager.getInstance();
00115         listView.removeAll();
00116         String[] docNames = dm.listDocuments();
00117         if (docNames != null) {
00118             listView.add(docNames);
00119         }
00120         listView.repaint();
00121     }
00122 
00123     //-----------------------------------------------------------------------
00124     // Public methods
00125 
00129     protected DocumentListController getController() {
00130         /* Even though that the controller is a singleton (thus accessible
00131            from anywhere), this method exists so that access to the
00132            controller is localized. Therefore, should the controller no
00133            longer be a singleton, only this method need to be changed. */
00134         return DocumentListController.getInstance();
00135     }
00136 
00137 
00138     //-----------------------------------------------------------------------
00139     // Implemented Abstract Methods
00140 
00141     public void initChildren() {
00142         btNew = createButton("New");
00143         listView = createDocumentListView();
00144         setMenuBar(createMenuBar());
00145     }
00146 
00147     public Button[] getCommandButtons() {
00148         return new Button[] {
00149             btNew
00150         };
00151     }
00152 
00153     //-----------------------------------------------------------------------
00154     // Overridden Methods
00155 
00156     public void layoutChildren() {
00157         super.layoutChildren();
00158         add(listView);
00159         listView.setRect(LEFT, TOP, FILL, FILL - getBottomMargin());
00160     }
00161 
00162     public void initCompleted() {
00163         modelUpdated();
00164     }
00165 
00166     public void onEvent(Event event) {
00167         switch (event.type) {
00168         case ControlEvent.PRESSED:
00169             if (event.target == null) {
00170                 // ignore event
00171             } else if (event.target == btNew) {
00172                 getController().cmdNewDocument();
00173                 event.consumed = true;
00174             } else if(event.target == listView) {
00175                 String documentName = (String) listView.getSelectedItem();
00176                 if (documentName != null) {
00177                     getController().cmdEditDocument(documentName);
00178                     event.consumed = true;
00179                 }
00180             }
00181         case ControlEvent.WINDOW_CLOSED:
00182             if (event.target == menubar) {
00183                 handleMenuEvent(((MenuBar) menubar).getSelectedMenuItem());
00184             }
00185         }
00186     }
00187 
00188     //-----------------------------------------------------------------------
00189     // Factory Methods
00190 
00191     protected ListBox createDocumentListView() {
00192         ListBox lb = new ListBox();
00193         lb.setSimpleBorder(true);
00194         return lb;
00195     }
00196 
00197     protected MenuBar createMenuBar() {
00198         String menuItems[][] = {
00199             {"Document",
00200                 "New Document"},
00201             {"Help",
00202                 "About"}
00203         };
00204         return new MenuBar(menuItems);
00205     }
00206 
00207     //-----------------------------------------------------------------------
00208 
00212     protected void handleMenuEvent(int selectedItem) {
00213         if (0 <= selectedItem && selectedItem < 100) {
00214             // an item from the first pulldown menu was seleted
00215             switch (selectedItem) {
00216             case 1: // new document
00217                 getController().cmdNewDocument();
00218             }
00219         } else if (selectedItem < 200 ) {
00220             // an item from the second pulldown menu was selected
00221             selectedItem -= 100;
00222             switch (selectedItem) {
00223             case 1: // "about"
00224                 AboutDialog.show();
00225             }
00226         }
00227     }
00228 
00229 
00230     //-----------------------------------------------------------------------
00231     // Member Variables
00232 
00236     private Button btNew;
00237 
00238     // not necessary?
00239     private Button btDetails;
00240 
00244     private ListBox listView;
00245 
00249     private static DocumentList _instance;
00250 
00251 }

Generated on Fri Jun 18 19:51:19 2004 for Arcle Rambutan by doxygen 1.3.5