/Users/lyon/j4p/src/addBk/addressBook/AddressBookFrame.java

1    package addBk.addressBook; 
2     
3    //AddressBookFrame.javaAddressBookFrame.java 
4     
5     
6    import java.awt.BorderLayout; 
7    import java.awt.Frame; 
8    import java.awt.MenuBar; 
9    import java.awt.TextField; 
10   import java.awt.event.TextEvent; 
11   import java.awt.event.TextListener; 
12    
13   public class AddressBookFrame 
14           extends Frame 
15           implements TextListener { 
16    
17       private static boolean indexToggle = false; 
18       private static boolean editMode = false; 
19       private static boolean runOnce = false; 
20    
21       private AddressPanel ap = 
22               new AddressPanel(); 
23       private TextButtonPanel tbp = 
24               new TextButtonPanel(); 
25       private TextField tf = 
26               new TextField("Name Field"); 
27       private IndexPanel ip = 
28               new IndexPanel(); 
29       private EditPanel ep = 
30               new EditPanel(); 
31       private MenuBar abmb = 
32               new AddressBookMenu(); 
33    
34       public AddressBookFrame() { 
35    
36    
37       }// end of constructor Closable JFrame 
38    
39    
40       // init gets called each time you need to toggle editMode or indexpanel 
41       public void init() { 
42           setMenuBar(abmb); 
43           setLayout(new BorderLayout()); 
44           add(tf, "North"); 
45           add(ap, "Center"); 
46           add(tbp, "South"); 
47           add(ep, "South"); 
48           if (!editMode) { 
49               remove(ep); 
50               add(tbp, "South"); 
51           } else { 
52               remove(tbp); 
53               add(ep, "South"); 
54           } 
55           add(ip, "East"); 
56           if (!indexToggle) remove(ip); 
57    
58           if (!runOnce) { // to protect any resizing 
59               setSize(400, 400); 
60               tf.setEditable(false); 
61               ap.t0.setEditable(false); 
62               ap.t1.setEditable(false); 
63           } 
64           setVisible(true); 
65           tf.addTextListener(this); 
66           runOnce = true; 
67           AddressBookMediator.setTextFieldValues(AddressBookMediator.getAbd() 
68                                                  .getEmptyDbRecord()); 
69           AddressBookMediator.setEditFlag(false); 
70    
71       } // end init 
72    
73       public void textValueChanged(TextEvent e) { 
74           //System.out.println(e); 
75           AddressBookMediator display = 
76                   new AddressBookMediator(); 
77           display.setEditFlag(); 
78       } 
79    
80       public static boolean isIndexToggle() { 
81           return indexToggle; 
82       } 
83    
84       public static void setIndexToggle( 
85               boolean indexToggle) { 
86           AddressBookFrame.indexToggle = 
87           indexToggle; 
88       } 
89    
90       public static boolean isEditMode() { 
91           return editMode; 
92       } 
93    
94       public static void setEditMode( 
95               boolean editMode) { 
96           AddressBookFrame.editMode = editMode; 
97       } 
98    
99       public static boolean isRunOnce() { 
100          return runOnce; 
101      } 
102   
103      public static void setRunOnce( 
104              boolean runOnce) { 
105          AddressBookFrame.runOnce = runOnce; 
106      } 
107   
108      public AddressPanel getAp() { 
109          return ap; 
110      } 
111   
112      public void setAp(AddressPanel ap) { 
113          this.ap = ap; 
114      } 
115   
116      public TextButtonPanel getTbp() { 
117          return tbp; 
118      } 
119   
120      public void setTbp(TextButtonPanel tbp) { 
121          this.tbp = tbp; 
122      } 
123   
124      public TextField getTf() { 
125          return tf; 
126      } 
127   
128      public void setTf(TextField tf) { 
129          this.tf = tf; 
130      } 
131   
132      public IndexPanel getIndexPanel() { 
133          return ip; 
134      } 
135   
136   
137      public EditPanel getEditPanel() { 
138          return ep; 
139      } 
140   
141   
142  } // end class AddressBookFrame 
143