javauis/lcdui_qt/src/javax/microedition/lcdui/ChoiceGroupLayouter.java
changeset 57 59b3b4473dc8
parent 23 98ccebc37403
equal deleted inserted replaced
56:abc41079b313 57:59b3b4473dc8
    43     private MouseListener mouseListener = new MouseListener();
    43     private MouseListener mouseListener = new MouseListener();
    44 
    44 
    45     /**
    45     /**
    46      * Constructor.
    46      * Constructor.
    47      */
    47      */
    48     ChoiceGroupLayouter(DefaultFormLayoutPolicy dflp)
    48     ChoiceGroupLayouter(FormLayouter aFormLayouter)
    49     {
    49     {
    50         super(dflp);
    50         super(aFormLayouter);
    51     }
    51     }
    52 
    52 
    53     /**
    53     /**
    54      * Get static eSWT Table widget for size calculations.
    54      * Get static eSWT Table widget for size calculations.
    55      *
    55      *
   257      * @param item ChoiceGroup.
   257      * @param item ChoiceGroup.
   258      * @param key key code.
   258      * @param key key code.
   259      */
   259      */
   260     boolean eswtOfferKeyPressed(Item item, int key)
   260     boolean eswtOfferKeyPressed(Item item, int key)
   261     {
   261     {
   262         LayoutObject lo = dfi.getFirstLayoutObjectOfItem(item);
   262         LayoutObject lo = formLayouter.getFirstLayoutObjectOfItem(item);
   263         TableExtension tempExt;
   263         TableExtension tempExt;
   264         ChoiceGroup chgr = (ChoiceGroup) item;
   264         ChoiceGroup chgr = (ChoiceGroup) item;
   265         tempExt = (TableExtension) eswtFindSpecificControl(item,
   265         tempExt = (TableExtension) eswtFindSpecificControl(item,
   266                   lo.getControl());
   266                   lo.getControl());
   267         boolean ret;
   267         boolean ret;
   476             this.choiceGroup = choiceGroup;
   476             this.choiceGroup = choiceGroup;
   477         }
   477         }
   478 
   478 
   479         private void update(SelectionEvent se)
   479         private void update(SelectionEvent se)
   480         {
   480         {
   481             //int vPosition = dfi.vPosition;
   481             //int vPosition = formLayouter.vPosition;
   482             int index = ((Table) se.widget).indexOf((TableItem) se.item);
   482             int index = ((Table) se.widget).indexOf((TableItem) se.item);
   483             choiceGroup.internalSetSelectedIndex(index,
   483             choiceGroup.internalSetSelectedIndex(index,
   484                                                  !choiceGroup.isSelected(index));
   484                                                  !choiceGroup.isSelected(index));
   485             eswtSetTableContents(eswtGetStaticTable(1), choiceGroup);
   485             eswtSetTableContents(eswtGetStaticTable(1), choiceGroup);
   486 
   486 
   544             // compute focused item location
   544             // compute focused item location
   545             int itemHeight = table.getItemHeight();
   545             int itemHeight = table.getItemHeight();
   546             int topOfTable = table.getLocation().y;
   546             int topOfTable = table.getLocation().y;
   547             if(choicegroup.hasLabel())
   547             if(choicegroup.hasLabel())
   548             {
   548             {
   549                 LayoutObject lo = dfi.getFirstLayoutObjectOfItem(choicegroup);
   549                 LayoutObject lo = formLayouter.getFirstLayoutObjectOfItem(choicegroup);
   550                 topOfTable += lo.getY();
   550                 topOfTable += lo.getY();
   551             }
   551             }
   552             int topYOfSelectedItem = topOfTable + (focusedIndex * itemHeight);
   552             int topYOfSelectedItem = topOfTable + (focusedIndex * itemHeight);
   553             if(te.keyCode == SWT.ARROW_DOWN)
   553             if(te.keyCode == SWT.ARROW_DOWN)
   554             {
   554             {
   555                 topYOfSelectedItem += itemHeight;
   555                 topYOfSelectedItem += itemHeight;
   556                 dfi.eswtScrollIfNeeded(topYOfSelectedItem,
   556                 formLayouter.eswtScrollIfNeeded(topYOfSelectedItem,
   557                                        topYOfSelectedItem + itemHeight);
   557                                        topYOfSelectedItem + itemHeight);
   558             }
   558             }
   559             else if(te.keyCode == SWT.ARROW_UP)
   559             else if(te.keyCode == SWT.ARROW_UP)
   560             {
   560             {
   561                 topYOfSelectedItem -= itemHeight;
   561                 topYOfSelectedItem -= itemHeight;
   562                 dfi.eswtScrollIfNeeded(topYOfSelectedItem,
   562                 formLayouter.eswtScrollIfNeeded(topYOfSelectedItem,
   563                                        topYOfSelectedItem + itemHeight);
   563                                        topYOfSelectedItem + itemHeight);
   564             }
   564             }
   565         }
   565         }
   566 
   566 
   567     }
   567     }
   580         }
   580         }
   581 
   581 
   582         public void focusGained(FocusEvent focusEvent)
   582         public void focusGained(FocusEvent focusEvent)
   583         {
   583         {
   584             TableExtension te = (TableExtension) focusEvent.widget;
   584             TableExtension te = (TableExtension) focusEvent.widget;
   585             int direction = dfi.getDirection();
   585             int direction = formLayouter.getDirection();
   586             if(choicegroup.getType() != ChoiceGroup.POPUP)
   586             if(choicegroup.getType() != ChoiceGroup.POPUP)
   587             {
   587             {
   588                 if(direction == -1)
   588                 if(direction == -1)
   589                 {
   589                 {
   590                     //do nothing
   590                     //do nothing
   606             //compute focused item location
   606             //compute focused item location
   607             int itemHeight = te.getItemHeight();
   607             int itemHeight = te.getItemHeight();
   608             int topOfTable = te.getLocation().y;
   608             int topOfTable = te.getLocation().y;
   609             if(choicegroup.hasLabel())
   609             if(choicegroup.hasLabel())
   610             {
   610             {
   611                 LayoutObject lo = dfi.getFirstLayoutObjectOfItem(choicegroup);
   611                 LayoutObject lo = formLayouter.getFirstLayoutObjectOfItem(choicegroup);
   612                 topOfTable += lo.getY();
   612                 topOfTable += lo.getY();
   613             }
   613             }
   614 
   614 
   615             int topYOfSelectedItem = topOfTable + (focusedIndex * itemHeight);
   615             int topYOfSelectedItem = topOfTable + (focusedIndex * itemHeight);
   616             if(direction == SWT.ARROW_DOWN || direction == SWT.ARROW_RIGHT)
   616             if(direction == SWT.ARROW_DOWN || direction == SWT.ARROW_RIGHT)
   617             {
   617             {
   618                 topYOfSelectedItem += itemHeight;
   618                 topYOfSelectedItem += itemHeight;
   619                 dfi.eswtScrollIfNeeded(topYOfSelectedItem,
   619                 formLayouter.eswtScrollIfNeeded(topYOfSelectedItem,
   620                                        topYOfSelectedItem + itemHeight);
   620                                        topYOfSelectedItem + itemHeight);
   621             }
   621             }
   622             else if(direction == SWT.ARROW_UP || direction == SWT.ARROW_LEFT)
   622             else if(direction == SWT.ARROW_UP || direction == SWT.ARROW_LEFT)
   623             {
   623             {
   624                 topYOfSelectedItem -= itemHeight;
   624                 topYOfSelectedItem -= itemHeight;
   625                 dfi.eswtScrollIfNeeded(topYOfSelectedItem,
   625                 formLayouter.eswtScrollIfNeeded(topYOfSelectedItem,
   626                                        topYOfSelectedItem + itemHeight);
   626                                        topYOfSelectedItem + itemHeight);
   627             }
   627             }
   628         }
   628         }
   629 
   629 
   630         public void focusLost(FocusEvent fe)
   630         public void focusLost(FocusEvent fe)