00001 00066 package com.arcle.rmt.superwaba.ui; 00067 00068 import waba.ui.ComboBox; 00069 import waba.ui.Container; 00070 import waba.ui.Window; 00071 import waba.ui.Button; 00072 import waba.ui.Event; 00073 import waba.ui.ControlEvent; 00074 import com.arcle.rmt.xplat.util.List; 00075 00088 public abstract class CategoryWindow extends CommandWindow { 00089 00090 public CategoryWindow(String title) { 00091 super(title,TAB_ONLY_BORDER); 00092 } 00093 00094 00095 //----------------------------------------------------------------------- 00096 // New Abstract Methods 00097 00103 protected abstract List createPanels(); 00104 00111 protected abstract String getPanelCaptionAt(int index); 00112 00113 //----------------------------------------------------------------------- 00114 // Placeholder methods 00115 00121 protected void onPanelSwitched() { } 00122 00123 //----------------------------------------------------------------------- 00124 // Inherited Abstract Methods 00125 00126 public abstract Button[] getCommandButtons(); 00127 00128 00129 //----------------------------------------------------------------------- 00130 // Implemented Abstract Methods 00131 00135 protected void initChildren() { 00136 panels = createPanels(); 00137 cbSwitch = createCategoryComboBox(getPanelCaptions()); 00138 } 00139 00140 00141 00142 //----------------------------------------------------------------------- 00143 // Overridden Methods 00144 00148 protected void layoutChildren() { 00149 super.layoutChildren(); 00150 add(cbSwitch); 00151 cbSwitch.setRect(RIGHT, 0, PREFERRED, PREFERRED - 2); 00152 00153 } 00154 00158 protected void onPopup() { 00159 super.onPopup(); 00160 switchPanel(); 00161 } 00162 00163 00164 public void onEvent(Event event) { 00165 switch (event.type) { 00166 case ControlEvent.PRESSED: 00167 if (event.target == cbSwitch) { 00168 switchPanel(); 00169 event.consumed = true; 00170 } 00171 } 00172 } 00173 00174 //----------------------------------------------------------------------- 00175 // Own Protected Methods 00176 00180 protected Container getPanelAt(int index) { 00181 return (Container) getPanels().get(index); 00182 } 00183 00187 protected Container getActivePanel() { 00188 return activePanel; 00189 } 00190 00194 protected int getPanelCount() { 00195 return getPanels().size(); 00196 } 00197 00202 protected void setActivePanel(int index) { 00203 cbSwitch.select(index); 00204 switchPanel(); 00205 } 00206 00207 00208 //----------------------------------------------------------------------- 00209 // Own Private Methods 00210 00211 00215 private List getPanels() { 00216 return panels; 00217 } 00218 00219 00226 private String[] getPanelCaptions() { 00227 List panels = getPanels(); 00228 String[] captions = new String[panels.size()]; 00229 for (int i=0; i<captions.length; i++) { 00230 captions[i] = getPanelCaptionAt(i); 00231 } 00232 return captions; 00233 } 00234 00238 private void switchPanel() { 00239 if(activePanel != null) { 00240 remove(activePanel); 00241 } 00242 00243 int i = cbSwitch.getSelectedIndex(); 00244 if(i < 0) { 00245 i = 0; 00246 cbSwitch.select(i); 00247 } 00248 00249 activePanel = (Container) getPanels().get(i); 00250 add(activePanel); 00251 activePanel.setRect(LEFT, TOP, FILL, FILL - getBottomMargin() - 1); 00252 onPanelSwitched(); 00253 } 00254 00255 00256 00257 //----------------------------------------------------------------------- 00258 // Factory Methods 00259 00260 00265 protected ComboBox createCategoryComboBox(Object[] items) { 00266 return new ComboBox(items); 00267 } 00268 00269 //----------------------------------------------------------------------- 00270 // Member Variables 00271 00272 00276 private Container activePanel = null; 00277 00281 private ComboBox cbSwitch; 00282 00286 private List panels; 00287 }