javauis/lcdui_qt/src/javax/microedition/lcdui/StringItemLayouter.java
changeset 57 59b3b4473dc8
parent 23 98ccebc37403
child 67 63b81d807542
equal deleted inserted replaced
56:abc41079b313 57:59b3b4473dc8
    44     private HyperLinkListener hLinkListener = new HyperLinkListener();
    44     private HyperLinkListener hLinkListener = new HyperLinkListener();
    45 
    45 
    46     /**
    46     /**
    47      * Constructor.
    47      * Constructor.
    48      *
    48      *
    49      * @param dflp DefaultFormLayoutPolicy
    49      * @param aFormLayouter FormLayouter used for layouting.
    50      */
    50      */
    51     StringItemLayouter(DefaultFormLayoutPolicy dflp)
    51     StringItemLayouter(FormLayouter aFormLayouter)
    52     {
    52     {
    53         super(dflp);
    53         super(aFormLayouter);
    54     }
    54     }
    55 
    55 
    56     /**
    56     /**
    57      * Creates the eSWT control. This method creates only StringItems of type
    57      * Creates the eSWT control. This method creates only StringItems of type
    58      * BUTTON and those items must have at least one command. Otherwise
    58      * BUTTON and those items must have at least one command. Otherwise
   160         if(stringItem.getNumCommands() > 0)
   160         if(stringItem.getNumCommands() > 0)
   161         {
   161         {
   162             if(stringItem.getAppearanceMode() == StringItem.BUTTON)
   162             if(stringItem.getAppearanceMode() == StringItem.BUTTON)
   163             {
   163             {
   164                 // BUTTON
   164                 // BUTTON
   165                 dfi.eswtAddNewLayoutObject(
   165                 LayoutObject lo = formLayouter.getLayoutObject(item);
   166                     new LayoutObject(item, eswtGetCaptionedControl(item)));
   166                 formLayouter.eswtAddNewLayoutObject(lo == null ? 
       
   167 					new LayoutObject(item, eswtGetCaptionedControl(item)) : lo);
   167             }
   168             }
   168             else
   169             else
   169             {
   170             {
   170                 // HYPERLINK
   171                 // HYPERLINK
   171                 eswtLayoutPlainStringItem(row, stringItem, true);
   172                 eswtLayoutPlainStringItem(row, stringItem, true);
   201         }
   202         }
   202 
   203 
   203         String label = item.getLabel();
   204         String label = item.getLabel();
   204 
   205 
   205         Vector strings = StringWrapper.wrapString(item.getText(),
   206         Vector strings = StringWrapper.wrapString(item.getText(),
   206                          item.getFont(), dfi.getForm().getLeftRightLanguage(),
   207                          item.getFont(), formLayouter.getForm().getLeftRightLanguage(),
   207                          row.getRowWidth(), row.getFreeSpace());
   208                          row.getRowWidth(), row.getFreeSpace());
   208 
   209 
   209         if(strings != null)
   210         if(strings != null)
   210         {
   211         {
   211             for(int i = 0; i < strings.size(); i++)
   212             for(int i = 0; i < strings.size(); i++)
   212             {
   213             {
   213                 // create primitive StringItem
   214                 // create primitive StringItem
   214                 Control control = eswtCreateLabeledPrimitiveStringItem(
   215                 Control control = eswtCreateLabeledPrimitiveStringItem(
   215                                       dfi.getForm().getFormComposite(),
   216                                       formLayouter.getForm().getFormComposite(),
   216                                       (String) strings.elementAt(i),
   217                                       (String) strings.elementAt(i),
   217                                       label, item.getFont(), isHyperlink,
   218                                       label, item.getFont(), isHyperlink,
   218                                       getMaximumItemWidth(item));
   219                                       getMaximumItemWidth(item));
   219 
   220 
   220                 // because add label to first primitive only:
   221                 // because add label to first primitive only:
   221                 label = null;
   222                 label = null;
   222 
   223 
   223                 // layoutObject which represent primitive StringItem
   224                 // layoutObject which represent primitive StringItem
   224                 dfi.eswtAddNewLayoutObject(
   225                 LayoutObject lo = formLayouter.getLayoutObject(item);
   225                     new LayoutObject(item, control), i != 0);
   226                 formLayouter.eswtAddNewLayoutObject((lo == null ?
       
   227                     new LayoutObject(item, control) : lo), i != 0);
   226             }
   228             }
   227         }
   229         }
   228     }
   230     }
   229 
   231 
   230     /**
   232     /**
   244 
   246 
   245         int width = item.getPreferredWidth();
   247         int width = item.getPreferredWidth();
   246         int height = item.getPreferredHeight();
   248         int height = item.getPreferredHeight();
   247 
   249 
   248         Vector strings = StringWrapper.wrapString(item.getText(),
   250         Vector strings = StringWrapper.wrapString(item.getText(),
   249                          item.getFont(), dfi.getForm().getLeftRightLanguage(),
   251                          item.getFont(), formLayouter.getForm().getLeftRightLanguage(),
   250                          width, width);
   252                          width, width);
   251 
   253 
   252         // Create composite which will contain the lines of locked stringitem:
   254         // Create composite which will contain the lines of locked stringitem:
   253         Composite comp = new Composite(formComposite, SWT.NONE);
   255         Composite comp = new Composite(formComposite, SWT.NONE);
   254         comp.setSize(width, height);
   256         comp.setSize(width, height);
   299 
   301 
   300                 // because add label to first primitive only:
   302                 // because add label to first primitive only:
   301                 label = null;
   303                 label = null;
   302             }
   304             }
   303         }
   305         }
   304         dfi.eswtAddNewLayoutObject(new LayoutObject(item, comp), false);
   306 		LayoutObject lo = formLayouter.getLayoutObject(item);
       
   307         formLayouter.eswtAddNewLayoutObject((lo == null ? new LayoutObject(item, comp) : lo), false);
   305     }
   308     }
   306 
   309 
   307     /**
   310     /**
   308      * Create labeled 'primitive' one-row StringItems.
   311      * Create labeled 'primitive' one-row StringItems.
   309      *
   312      *
   352             }
   355             }
   353             int textWidth = text.getBounds().width;
   356             int textWidth = text.getBounds().width;
   354             int objectWidth = Math.max(textWidth, headerWidth);
   357             int objectWidth = Math.max(textWidth, headerWidth);
   355 
   358 
   356             header.setLocation(ItemLayouter.getXLocation(objectWidth,
   359             header.setLocation(ItemLayouter.getXLocation(objectWidth,
   357                                headerWidth, dfi.getLanguageSpecificLayoutDirective()), 0);
   360                                headerWidth, formLayouter.getLanguageSpecificLayoutDirective()), 0);
   358 
   361 
   359             text.setLocation(ItemLayouter.getXLocation(objectWidth, textWidth,
   362             text.setLocation(ItemLayouter.getXLocation(objectWidth, textWidth,
   360                              dfi.getLanguageSpecificLayoutDirective()),
   363                              formLayouter.getLanguageSpecificLayoutDirective()),
   361                              header.getBounds().height);
   364                              header.getBounds().height);
   362 
   365 
   363             comp.pack();
   366             comp.pack();
   364             return comp;
   367             return comp;
   365         }
   368         }
   655      */
   658      */
   656     private void eswtHighlightHyperlinkItem(Item item, boolean highlight)
   659     private void eswtHighlightHyperlinkItem(Item item, boolean highlight)
   657     {
   660     {
   658         LayoutObject lo = null;
   661         LayoutObject lo = null;
   659         Control c = null;
   662         Control c = null;
   660         while((lo = dfi.getNextLayoutObjectOfItem(lo, item)) != null)
   663         while((lo = formLayouter.getNextLayoutObjectOfItem(lo, item)) != null)
   661         {
   664         {
   662             if((c = lo.getControl()) != null)
   665             if((c = lo.getControl()) != null)
   663             {
   666             {
   664                 eswtHighlightHyperlink(c, highlight);
   667                 eswtHighlightHyperlink(c, highlight);
   665             }
   668             }
   776 
   779 
   777         public void widgetSelected(SelectionEvent e)
   780         public void widgetSelected(SelectionEvent e)
   778         {
   781         {
   779             Logger.method(this, "widgetSelected");
   782             Logger.method(this, "widgetSelected");
   780             e.doit = false;
   783             e.doit = false;
   781             Item item = dfi.getCurrentSelectedItem();
   784             Item item = formLayouter.getCurrentSelectedItem();
   782             item.callCommandAction(item.getMSKCommand());
   785             item.callCommandAction(item.getMSKCommand());
   783         }
   786         }
   784     }
   787     }
   785 
   788 
   786 }
   789 }