javauis/lcdui_qt/src/javax/microedition/lcdui/ChoiceGroupLayouter.java
changeset 21 2a9601315dfc
child 23 98ccebc37403
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 package javax.microedition.lcdui;
       
    18 
       
    19 import org.eclipse.swt.SWT;
       
    20 import org.eclipse.swt.events.*;
       
    21 import org.eclipse.swt.graphics.Point;
       
    22 import org.eclipse.swt.internal.extension.TableExtension;
       
    23 import org.eclipse.swt.widgets.*;
       
    24 
       
    25 /**
       
    26  * Responsible for layouting ChoiceGroup item.
       
    27  */
       
    28 class ChoiceGroupLayouter extends ItemLayouter {
       
    29 
       
    30     /**
       
    31      * Key name for selection listener.
       
    32      */
       
    33     private static final String SELECTION_LISTENER = "selection";
       
    34     private static final String TRAVERSE_LISTENER = "traverse";
       
    35     private static final String FOCUS_LISTENER = "focus";
       
    36 
       
    37     private static TableExtension staticTable;
       
    38 
       
    39     private static Shell dialogShell;
       
    40     private static TableExtension popupTable;
       
    41     
       
    42     private MouseListener mouseListener = new MouseListener();
       
    43 
       
    44     /**
       
    45      * Constructor.
       
    46      */
       
    47     ChoiceGroupLayouter(DefaultFormLayoutPolicy dflp) {
       
    48         super(dflp);
       
    49     }
       
    50 
       
    51     /**
       
    52      * Get static eSWT Table widget for size calculations.
       
    53      *
       
    54      * @param numItems
       
    55      */
       
    56     static Table eswtGetStaticTable(int numItems) {
       
    57         if (staticTable == null) {
       
    58             staticTable = new TableExtension(eswtGetStaticShell(), SWT.NONE);
       
    59             staticTable.getHorizontalBar().setVisible(false);
       
    60             staticTable.getVerticalBar().setVisible(false);
       
    61         }
       
    62         staticTable.removeAll();
       
    63         for (int i = 0; i < numItems; i++) {
       
    64             new TableItem(staticTable, SWT.NONE);
       
    65         }
       
    66         return staticTable;
       
    67     }
       
    68 
       
    69     /**
       
    70      * Set table contents.
       
    71      *
       
    72      * @param table
       
    73      * @param choice
       
    74      */
       
    75     static void eswtSetTableContents(Table table, ChoiceGroup choice) {
       
    76 
       
    77         if (choice.getType() == Choice.POPUP) {
       
    78             // set the only TableItem to be the selected item
       
    79             TableItem ti = table.getItem(0);
       
    80             int sel = choice.getSelectedIndex();
       
    81             if (sel >= 0) {
       
    82                 ti.setImage(0, Image.getESWTImage(choice.getImage(sel)));
       
    83                 ti.setText(0, choice.getString(sel));
       
    84                 ti.setFont(0, Font.getESWTFont(choice.getFont(sel)));
       
    85             }
       
    86             if( ESWTUIThreadRunner.getInstance().getDisplay().getActiveShell()
       
    87                 == dialogShell ) {
       
    88                     // The popup dialog is open, update and set the items in the popup dialog
       
    89                     popupTable.removeAll();
       
    90                     popupTable.getHorizontalBar().setVisible(false);
       
    91                     popupTable.getVerticalBar().setVisible(false);
       
    92 
       
    93                     TableItem titem = null;
       
    94                     for (int i = 0; i < choice.size(); i++) {
       
    95                         titem= new TableItem(popupTable, SWT.NONE);
       
    96                         titem.setImage(0, Image.getESWTImage(choice.getImage(i)));
       
    97                         titem.setText(0, choice.getString(i));
       
    98                         titem.setFont(0, Font.getESWTFont(choice.getFont(i)));
       
    99                     }
       
   100 
       
   101                     // calculate table size, allow maximum dialogshell's height
       
   102                     // and enable vertical scroll bar if needed
       
   103                     Point compSize = popupTable.computeSize(
       
   104                             dialogShell.getClientArea().width, SWT.DEFAULT);
       
   105                     if (compSize.y > dialogShell.getClientArea().height) {
       
   106                         popupTable.getVerticalBar().setVisible(true);
       
   107                         int itemH = popupTable.getItemHeight() + 2;
       
   108                         // make height a multiple of item height
       
   109                         compSize.y = (dialogShell.getClientArea().height / itemH) * itemH;
       
   110                     }
       
   111                     popupTable.setSize(compSize);
       
   112             }
       
   113             
       
   114         }
       
   115         else {
       
   116             int size = choice.size();
       
   117             if (size == table.getItemCount()) {
       
   118                 TableItem titem = null;
       
   119                 for (int i = 0; i < size; i++) {
       
   120                     titem = table.getItem(i);
       
   121                     titem.setImage(0, Image.getESWTImage(choice.getImage(i)));
       
   122                     titem.setText(0, choice.getString(i));
       
   123                     titem.setFont(0, Font.getESWTFont(choice.getFont(i)));
       
   124                 }
       
   125                 // update selection
       
   126                 if (choice.getType() == Choice.EXCLUSIVE) {
       
   127                     table.setSelection(choice.getSelectedIndex());
       
   128                 }
       
   129                 else {
       
   130                     boolean[] sel = new boolean[size];
       
   131                     choice.getSelectedFlags(sel);
       
   132                     for (int i = 0; i < size; i++) {
       
   133                         if (sel[i]) {
       
   134                             table.select(i);
       
   135                         }
       
   136                         else {
       
   137                             table.deselect(i);
       
   138                         }
       
   139                     }
       
   140                 }
       
   141             }
       
   142         }
       
   143     }
       
   144 
       
   145     /**
       
   146      * Creates the eSWT Table for this item.
       
   147      */
       
   148     Control eswtGetControl(Composite parent, Item item) {
       
   149         ChoiceGroup choice = (ChoiceGroup) item;
       
   150         // create Table
       
   151         TableExtension table = new TableExtension(parent,
       
   152                 getTableStyle(choice.getType()));
       
   153         table.getHorizontalBar().setVisible(false);
       
   154         table.getVerticalBar().setVisible(false);
       
   155         table.setWordWrap(choice.getFitPolicy() == Choice.TEXT_WRAP_ON);
       
   156         if (choice.getType() == Choice.POPUP) {
       
   157             // create one TableItem
       
   158             new TableItem(table, SWT.NONE);
       
   159         }
       
   160         else {
       
   161             // add all items to table
       
   162             for (int i = 0; i < choice.size(); i++) {
       
   163                 new TableItem(table, SWT.NONE, i);
       
   164             }
       
   165         }
       
   166         eswtUpdateItem(choice, table, Item.UPDATE_NONE, null);
       
   167         return table;
       
   168     }
       
   169 
       
   170     /**
       
   171      * Add listeners to Layouter specific control.
       
   172      */
       
   173     void eswtAddSpecificListeners(Item item, Control control) {
       
   174         super.eswtAddSpecificListeners(item, control);
       
   175         Table table = (Table) control;
       
   176         SelectionListener sl = new ChoiceGroupSelectionListener((ChoiceGroup) item);
       
   177         table.addSelectionListener(sl);
       
   178         table.setData(SELECTION_LISTENER, sl);
       
   179         TraverseListener tl = new ChoiceGroupTraverseListener((ChoiceGroup) item);
       
   180         table.addTraverseListener(tl);
       
   181         table.setData(TRAVERSE_LISTENER, tl);
       
   182         FocusListener fl = new ChoiceGroupFocusListener((ChoiceGroup) item);
       
   183         table.addFocusListener(fl);
       
   184         table.setData(FOCUS_LISTENER, fl);
       
   185     }
       
   186 
       
   187     /**
       
   188      * Remove listeners from Layouter specific control.
       
   189      */
       
   190     void eswtRemoveSpecificListeners(Item item, Control control) {
       
   191         super.eswtRemoveSpecificListeners(item, control);
       
   192         Table table = (Table) control;
       
   193         SelectionListener sl = (SelectionListener) table.getData(SELECTION_LISTENER);
       
   194         if (sl != null) {
       
   195             table.removeSelectionListener(sl);
       
   196             table.setData(SELECTION_LISTENER, null);
       
   197         }
       
   198         TraverseListener tl = (TraverseListener) table.getData(TRAVERSE_LISTENER);
       
   199         if (tl != null) {
       
   200             table.removeTraverseListener(tl);
       
   201             table.setData(TRAVERSE_LISTENER, null);
       
   202         }
       
   203         FocusListener fl = (FocusListener) table.getData(FOCUS_LISTENER);
       
   204         if (fl != null) {
       
   205             table.removeFocusListener(fl);
       
   206             table.setData(FOCUS_LISTENER, null);
       
   207         }
       
   208     }
       
   209 
       
   210     /**
       
   211      * Returns if this eSWT control is Layouter specific.
       
   212      */
       
   213     boolean eswtIsSpecificControl(Item item, Control control) {
       
   214         return (control instanceof TableExtension);
       
   215     }
       
   216 
       
   217     /**
       
   218      * Updates the values and selections of ChoiceGroup.
       
   219      */
       
   220     void eswtUpdateItem(Item item, Control control, int reason, Object param) {
       
   221         eswtSetTableContents((Table) control, (ChoiceGroup) item);
       
   222     }
       
   223 
       
   224     /**
       
   225      * Returns whether the key event was consumed by ChoiceGroup or not.
       
   226      *
       
   227      * @param item ChoiceGroup.
       
   228      * @param key key code.
       
   229      */
       
   230     boolean eswtOfferKeyPressed(Item item, int key) {
       
   231         LayoutObject lo = dfi.getFirstLayoutObjectOfItem(item);
       
   232         TableExtension tempExt;
       
   233         ChoiceGroup chgr = (ChoiceGroup) item;
       
   234         tempExt = (TableExtension) eswtFindSpecificControl(item,
       
   235                 lo.getControl());
       
   236         boolean ret;
       
   237         if (isPopupDialogOpen()) {
       
   238             ret =  true;
       
   239         }
       
   240         else if ((tempExt.getFocusIndex() == 0 && key == SWT.ARROW_UP)
       
   241                 || (tempExt.getFocusIndex() == (tempExt.getItemCount() - 1)
       
   242                         && key == SWT.ARROW_DOWN)
       
   243                 || (chgr.getType() == Choice.POPUP
       
   244                         && !isPopupDialogOpen())) {
       
   245             ret = false;
       
   246         }
       
   247         /*else if (tempExt.getFocusIndex() == (tempExt.getItemCount() - 1)
       
   248                 && key == SWT.ARROW_DOWN) {
       
   249             return false;
       
   250         }
       
   251         if (chgr.getType() == Choice.POPUP && !isPopupDialogOpen()) {
       
   252             return false;
       
   253         } */
       
   254         else if (key == SWT.ARROW_UP || key == SWT.ARROW_DOWN) {
       
   255             ret = true;
       
   256         }
       
   257         else {
       
   258             ret = false;
       
   259         }
       
   260         return ret;
       
   261     }
       
   262 
       
   263     /**
       
   264      * Returns the minimum area needed to display a ChoiceGroup.
       
   265      *
       
   266      * @param choicegroup ChoiceGroup object.
       
   267      * @return Minimum area needed to display ChoiceGroup.
       
   268      */
       
   269     static Point calculateMinimumBounds(final ChoiceGroup choicegroup) {
       
   270         final Point minSize = new Point(0, 0);
       
   271         ESWTUIThreadRunner.syncExec(new Runnable() {
       
   272             public void run() {
       
   273                 Table table = eswtGetStaticTable(1);
       
   274                 minSize.x = getMaximumItemWidth(choicegroup);
       
   275                 minSize.y = table.computeSize(minSize.x, SWT.DEFAULT).y;
       
   276                 applyMinMargins(choicegroup, minSize);
       
   277             }
       
   278         });
       
   279         return minSize;
       
   280     }
       
   281 
       
   282     /**
       
   283      * Returns the preferred area needed to display an Item.
       
   284      *
       
   285      * @param item Item.
       
   286      * @return Preferred area needed to display Item. x is width and y is
       
   287      *         height.
       
   288      */
       
   289     static Point calculatePreferredBounds(Item item) {
       
   290         final Point prefSize = new Point(0, 0);
       
   291         final ChoiceGroup cg = (ChoiceGroup) item;
       
   292         ESWTUIThreadRunner.syncExec(new Runnable() {
       
   293             public void run() {
       
   294                 int numItem = (cg.getType() == Choice.POPUP ? 1 : cg.size());
       
   295                 Table table = eswtGetStaticTable(numItem);
       
   296                 eswtSetTableContents(table, cg);
       
   297                 prefSize.x = getMaximumItemWidth(cg);
       
   298                 prefSize.y = table.computeSize(prefSize.x, SWT.DEFAULT).y;
       
   299                 applyPrefMargins(cg, prefSize);
       
   300             }
       
   301         });
       
   302         return prefSize;
       
   303     }
       
   304 
       
   305     /**
       
   306      * Get eSWT style based on List type.
       
   307      */
       
   308     private int getTableStyle(int listType) {
       
   309         int tableStyle = SWT.NONE;
       
   310         switch (listType) {
       
   311             case Choice.EXCLUSIVE:
       
   312                 tableStyle |= SWT.SINGLE | SWT.RADIO;
       
   313                 break;
       
   314             case Choice.MULTIPLE:
       
   315                 tableStyle |= /*SWT.MULTI |*/ SWT.CHECK;
       
   316                 break;
       
   317             default:
       
   318                 break;
       
   319         }
       
   320         return tableStyle;
       
   321     }
       
   322 
       
   323     private boolean isPopupDialogOpen() {
       
   324         return (ESWTUIThreadRunner.getInstance().getDisplay().getActiveShell()
       
   325                 == dialogShell);
       
   326     }
       
   327 
       
   328     /**
       
   329      * Open POPUP dialog.
       
   330      *
       
   331      * @param choiceGroup ChoiceGroup
       
   332      * @param control already layouted control
       
   333      */
       
   334     private void eswtOpenPopupDialog(final ChoiceGroup choiceGroup,
       
   335             final Control control) {
       
   336 
       
   337         final Shell parentShell = choiceGroup.getParent().getShell();
       
   338         dialogShell = new Shell(parentShell, SWT.DIALOG_TRIM | SWT.SYSTEM_MODAL);
       
   339 
       
   340         dialogShell.setText(choiceGroup.getLabel());
       
   341         //org.eclipse.swt.widgets.Display d = parentShell.getDisplay();
       
   342         // add Back command
       
   343         org.eclipse.ercp.swt.mobile.Command backCommand =
       
   344             new org.eclipse.ercp.swt.mobile.Command(dialogShell,
       
   345                     org.eclipse.ercp.swt.mobile.Command.BACK, 0);
       
   346         backCommand.setText(Command.getDefaultLabel(Command.BACK));
       
   347 
       
   348         popupTable = new TableExtension(dialogShell, SWT.NONE);
       
   349         popupTable.getHorizontalBar().setVisible(false);
       
   350         popupTable.getVerticalBar().setVisible(false);
       
   351 
       
   352         TableItem ti = null;
       
   353         for (int i = 0; i < choiceGroup.size(); i++) {
       
   354             ti = new TableItem(popupTable, SWT.NONE);
       
   355             ti.setImage(0, Image.getESWTImage(choiceGroup.getImage(i)));
       
   356             ti.setText(0, choiceGroup.getString(i));
       
   357             ti.setFont(0, Font.getESWTFont(choiceGroup.getFont(i)));
       
   358         }
       
   359 
       
   360         // calculate table size, allow maximum dialogshell's height
       
   361         // and enable vertical scroll bar if needed
       
   362         Point compSize = popupTable.computeSize(
       
   363                 dialogShell.getClientArea().width, SWT.DEFAULT);
       
   364         if (compSize.y > dialogShell.getClientArea().height) {
       
   365             popupTable.getVerticalBar().setVisible(true);
       
   366             int itemH = popupTable.getItemHeight() + 2;
       
   367             // make height a multiple of item height
       
   368             compSize.y = (dialogShell.getClientArea().height / itemH) * itemH;
       
   369         }
       
   370         popupTable.setSize(compSize);
       
   371 
       
   372         Listener disposeHandler = new Listener() {
       
   373             public void handleEvent(Event se) {
       
   374                 dialogShell.close();
       
   375                 dialogShell.dispose();
       
   376                 dialogShell = null;
       
   377                 org.eclipse.swt.widgets.Display.getCurrent().
       
   378                                     removeFilter(SWT.MouseDown, mouseListener);
       
   379             }
       
   380         };
       
   381 
       
   382         // if Back command is pressed - dispose
       
   383         backCommand.addListener(SWT.Selection, disposeHandler);
       
   384 
       
   385         popupTable.addListener(SWT.DefaultSelection, new Listener() {
       
   386             public void handleEvent(Event se) {
       
   387                 int index = ((Table) se.widget).indexOf((TableItem) se.item);
       
   388                 // if table gets selected - save selection and dispose dialog
       
   389                 choiceGroup.internalSetSelectedIndex(index, true);
       
   390                 eswtUpdateItem(choiceGroup, control, Item.UPDATE_NONE, null);
       
   391                 dialogShell.close();
       
   392                 dialogShell.dispose();
       
   393                 dialogShell = null;
       
   394                 org.eclipse.swt.widgets.Display.getCurrent().
       
   395                                     removeFilter(SWT.MouseDown, mouseListener);
       
   396             }
       
   397         });
       
   398 
       
   399         dialogShell.pack();
       
   400         // place dialogShell to bottom of screen
       
   401         Point location = dialogShell.getLocation();
       
   402         location.y = parentShell.getSize().y - dialogShell.getSize().y;
       
   403         dialogShell.setLocation(location);
       
   404         dialogShell.open();
       
   405         //Add a mouse listener to the display to listen to a screen tap
       
   406         org.eclipse.swt.widgets.Display.getCurrent().
       
   407                                         addFilter(SWT.MouseDown, mouseListener);
       
   408     }
       
   409 
       
   410     /**
       
   411      * Class that receives events from Table and updates ChoiceGroup's value.
       
   412      */
       
   413     class ChoiceGroupSelectionListener implements SelectionListener {
       
   414 
       
   415         private ChoiceGroup choiceGroup;
       
   416 
       
   417         /**
       
   418          * Constructor.
       
   419          *
       
   420          * @param choiceGroup ChoiceGroup to be updated.
       
   421          */
       
   422         public ChoiceGroupSelectionListener(ChoiceGroup choiceGroup) {
       
   423             this.choiceGroup = choiceGroup;
       
   424         }
       
   425 
       
   426         private void update(SelectionEvent se) {
       
   427             //int vPosition = dfi.vPosition;
       
   428             int index = ((Table) se.widget).indexOf((TableItem) se.item);
       
   429             choiceGroup.internalSetSelectedIndex(index,
       
   430                     !choiceGroup.isSelected(index));
       
   431             eswtSetTableContents(eswtGetStaticTable(1), choiceGroup);
       
   432             
       
   433         }
       
   434 
       
   435         public void widgetDefaultSelected(SelectionEvent se) {
       
   436             if (choiceGroup.getType() == Choice.EXCLUSIVE) {
       
   437                 update(se);
       
   438                 
       
   439                 // because Table doesn't update our custom selection
       
   440                 // we have to do it ourselves
       
   441                 // eswtUpdateItem(choiceGroup, ((Table) se.widget),
       
   442                         // Item.UPDATE_NONE, null);
       
   443             }
       
   444             else if (choiceGroup.getType() == Choice.POPUP) {
       
   445                 eswtOpenPopupDialog(choiceGroup, ((Table) se.widget));
       
   446             }
       
   447         }
       
   448 
       
   449         public void widgetSelected(SelectionEvent se) {
       
   450             if (choiceGroup.getType() == Choice.MULTIPLE) {
       
   451                 if (se.detail == SWT.CHECK) {
       
   452                     update(se);
       
   453                 }
       
   454             }
       
   455             else if(choiceGroup.getType() == Choice.EXCLUSIVE) {
       
   456                 update(se);
       
   457                 //run the default command if it exists for a exclusive choice group upon selection
       
   458                 if( choiceGroup.getDefaultCommand()!= null) {
       
   459                     choiceGroup.callCommandAction(choiceGroup.getDefaultCommand());
       
   460                 }
       
   461             }
       
   462         }
       
   463     }
       
   464 
       
   465     /**
       
   466      * ChoiceGroupTraverseListener listens to KeyTraverseEvent and scrolls
       
   467      * ChoiceGroup if needed.
       
   468      */
       
   469     class ChoiceGroupTraverseListener implements TraverseListener {
       
   470         private ChoiceGroup choicegroup;
       
   471 
       
   472         public ChoiceGroupTraverseListener(ChoiceGroup choiceGr) {
       
   473             choicegroup = choiceGr;
       
   474         }
       
   475 
       
   476         public void keyTraversed(TraverseEvent te) {
       
   477             TableExtension table = (TableExtension) te.widget;
       
   478             int focusedIndex = table.getFocusIndex();
       
   479             // compute focused item location
       
   480             int itemHeight = table.getItemHeight();
       
   481             int topOfTable = table.getLocation().y;
       
   482             if (choicegroup.hasLabel()) {
       
   483                 LayoutObject lo = dfi.getFirstLayoutObjectOfItem(choicegroup);
       
   484                 topOfTable += lo.getY();
       
   485             }
       
   486             int topYOfSelectedItem = topOfTable + (focusedIndex * itemHeight);
       
   487             if (te.keyCode == SWT.ARROW_DOWN) {
       
   488                 topYOfSelectedItem += itemHeight;
       
   489                 dfi.eswtScrollIfNeeded(topYOfSelectedItem,
       
   490                                        topYOfSelectedItem + itemHeight);
       
   491             }
       
   492             else if (te.keyCode == SWT.ARROW_UP) {
       
   493                 topYOfSelectedItem -= itemHeight;
       
   494                 dfi.eswtScrollIfNeeded(topYOfSelectedItem,
       
   495                                        topYOfSelectedItem + itemHeight);
       
   496             }
       
   497         }
       
   498 
       
   499     }
       
   500 
       
   501     /**
       
   502      * ChoiceGroupFocusListener reacts on eSWT focusGained event.
       
   503      */
       
   504     class ChoiceGroupFocusListener implements FocusListener {
       
   505 
       
   506         private ChoiceGroup choicegroup;
       
   507 
       
   508         ChoiceGroupFocusListener(ChoiceGroup cg) {
       
   509             choicegroup = cg;
       
   510         }
       
   511 
       
   512         public void focusGained(FocusEvent focusEvent) {
       
   513             TableExtension te = (TableExtension) focusEvent.widget;
       
   514             int direction = dfi.getDirection();
       
   515             if (choicegroup.getType() != ChoiceGroup.POPUP) {
       
   516                 if (direction == -1) {
       
   517                   //do nothing
       
   518                 }
       
   519                 else {
       
   520                     if (direction == SWT.ARROW_UP || direction == SWT.ARROW_LEFT) {
       
   521                         te.setFocusIndex(te.getItemCount() - 1);
       
   522                     }
       
   523                     else if (direction == SWT.ARROW_DOWN || direction == SWT.ARROW_RIGHT) {
       
   524                         te.setFocusIndex(0);
       
   525                     }
       
   526                 }
       
   527             }
       
   528 
       
   529             int focusedIndex = te.getFocusIndex();
       
   530             //compute focused item location
       
   531             int itemHeight = te.getItemHeight();
       
   532             int topOfTable = te.getLocation().y;
       
   533             if (choicegroup.hasLabel()) {
       
   534                 LayoutObject lo = dfi.getFirstLayoutObjectOfItem(choicegroup);
       
   535                 topOfTable += lo.getY();
       
   536             }
       
   537 
       
   538             int topYOfSelectedItem = topOfTable + (focusedIndex * itemHeight);
       
   539             if (direction == SWT.ARROW_DOWN || direction == SWT.ARROW_RIGHT) {
       
   540                 topYOfSelectedItem += itemHeight;
       
   541                 dfi.eswtScrollIfNeeded(topYOfSelectedItem,
       
   542                                        topYOfSelectedItem + itemHeight);
       
   543             }
       
   544             else if (direction == SWT.ARROW_UP || direction == SWT.ARROW_LEFT) {
       
   545                 topYOfSelectedItem -= itemHeight;
       
   546                 dfi.eswtScrollIfNeeded(topYOfSelectedItem,
       
   547                                        topYOfSelectedItem + itemHeight);
       
   548             }
       
   549         }
       
   550 
       
   551         public void focusLost(FocusEvent fe) {
       
   552         }
       
   553     }
       
   554     
       
   555      /**
       
   556      * Mouse listener for disposing popup choice group on screen tap.
       
   557      */
       
   558     class MouseListener implements Listener {
       
   559 
       
   560         public void handleEvent(Event e) {
       
   561             if (e.type == SWT.MouseDown) {
       
   562                     //Mouse button pressed
       
   563                     if (isPopupDialogOpen()) {
       
   564                         //popup choice group popup is open
       
   565                         if( e.y < 0 ) {
       
   566                             //Tapping done outside of the popup dialog, close and dispose the popup
       
   567                             dialogShell.close();
       
   568                             dialogShell.dispose();
       
   569                             dialogShell = null;
       
   570                             //remove the listener as it is no more needed
       
   571                             org.eclipse.swt.widgets.Display.getCurrent().removeFilter(
       
   572                                 SWT.MouseDown, mouseListener);
       
   573                         }
       
   574                     }
       
   575             }
       
   576         }
       
   577     }//end Listener
       
   578 }