Example #1
0
  private void setDelWOConfCG(boolean selected) {
    // TODO Hack around J2ME Polish bug that cause the items to not get focus when
    // re-enabled
    mDelWOConfSubCG.deleteAll();

    if (selected) {
      // #style ChoiceItem
      UiAccess.setAccessible(mDWOCConvCI, true);
      // #style ChoiceItem
      UiAccess.setAccessible(mDWOCMsgCI, true);
    } else {
      // #style ChoiceItemDisabled
      UiAccess.setAccessible(mDWOCConvCI, false);
      // #style ChoiceItemDisabled
      UiAccess.setAccessible(mDWOCMsgCI, false);
    }

    // TODO Continue of hack above
    // #if true
    // # mDelWOConfSubCG.append(mDWOCConvCI);
    // # mDelWOConfSubCG.append(mDWOCMsgCI);
    // #endif

    mSettings.setDelWOConf(selected);
  }
  /* (non-Javadoc)
   * @see javax.microedition.lcdui.ItemCommandListener#commandAction(javax.microedition.lcdui.Command, javax.microedition.lcdui.Item)
   */
  public void commandAction(Command command, Item item) {
    // System.out.println("DefaultRssItemCommandListner: command ="+ command.getLabel() );
    if (command == RssTagHandler.CMD_RSS_ITEM_SELECT) {
      RssItem rssItem = (RssItem) UiAccess.getAttribute(item, RssItem.ATTRIBUTE_KEY);
      String rssUrl = rssItem.getLink();
      if (rssUrl != null && this.rssBrowser != null) {
        this.rssBrowser.getRssTagHandler().onViewUrl(rssUrl, item);
      }

      if (rssItem != null && StyleSheet.display != null) {
        // #style rssDescriptionAlert
        Alert alert =
            new Alert(
                rssItem.getTitle(),
                rssItem.getDescription(),
                null,
                AlertType.INFO,
                de.enough.polish.ui.StyleSheet.rssdescriptionalertStyle);
        alert.setTimeout(Alert.FOREVER);
        alert.addCommand(RssTagHandler.CMD_GO_TO_ARTICLE);
        alert.addCommand(HtmlTagHandler.CMD_BACK);
        alert.setCommandListener(this);
        StyleSheet.display.setCurrent(alert);
        this.url = rssItem.getLink();
      }
    } else {
      this.rssBrowser.handleCommand(command);
    }
  }
  public LoginForm(
      Model model,
      Controller controller,
      final String title,
      boolean firstLogin,
      final Style style) {
    super(model, controller, null, style);
    this.model = model;
    this.titleitem = new TitleBarItem(title, model);

    // #if polish.blackberry.isTouchBuild == true
    this.title = this.titleitem;
    // #else
    // add title item
    this.append(titleitem);
    // #endif

    // #if polish.blackberry
    titleitem.setAppearanceMode(Item.PLAIN);
    // #endif

    initForm(firstLogin);

    // focus on TextField of UserName input
    if (!usernameReadonly) {
      UiAccess.focus(this, userName);
    }
  }
Example #4
0
  public void initWidget(FormEntryPrompt fep, Container c) {
    // #style container
    UiAccess.setStyle(
        c); // it is dubious whether this works properly; Chatterbox.babysitStyles() takes care of
            // this for now

    // #style questiontext
    fullPrompt = new Container(false);

    // #style prompttext
    prompt = new StringItem(null, null);
    fullPrompt.add(prompt);
    // #style button
    ok = new StringItem(null, Localization.get("button.Next"));
    scrHeight = J2MEDisplay.getScreenHeight(ExpandedWidget.fallback);
    scrWidth = J2MEDisplay.getScreenWidth(ExpandedWidget.fallback);

    c.add(fullPrompt);
    c.add(ok);
  }
  private void initForm(boolean firstLogin) {
    // #if !polish.blackberry
    this.addCommand(cmdSave);

    if (firstLogin) this.addCommand(cmdCancel);
    else this.addCommand(cmdExit);
    // #endif

    StringItem headLine;
    // #if polish.blackberry
    // #if polish.blackberry.isTouchBuild == false
    // #style .login_headline
    headLine = new StringItem(null, Locale.get("nowplus.client.java.loginform.headline"));
    this.append(headLine);
    // #endif
    // #else
    // #style .login_headline
    headLine = new StringItem(null, Locale.get("nowplus.client.java.loginform.headline"));
    this.append(headLine);

    // #endif

    // #if polish.blackberry && polish.blackberry.isTouchBuild == false
    headLine.setAppearanceMode(Item.PLAIN);
    // #endif

    String usernameString = model.getUserName();
    String passwordString = "";

    // #if username:defined
    // #message Username is set
    // #= usernameString = "${username}";
    // #endif

    // #if password:defined
    // #message Password is set
    // #= passwordString = "${password}";
    // #endif

    if (usernameString == null) usernameString = "";
    if (passwordString == null) passwordString = "";

    // username textfield

    // #if polish.blackberry
    userName =
        UiFactory.createTextField(
            Locale.get("nowplus.client.java.loginform.username.hint"),
            usernameString,
            255,
            TextField.NON_PREDICTIVE,
            this);
    // fix for PBLA-816 Touch device: predictive text while disabling the surepress
    userName.setNoComplexInput(true);
    // #else
    userName = UiFactory.createTextField(null, usernameString, 255, TextField.NON_PREDICTIVE, this);
    // #endif

    UiAccess.setTextfieldHelp(userName, Locale.get("nowplus.client.java.loginform.username.hint"));
    // #if using.native.textfield:defined
    userName.setTitle(Locale.get("nowplus.client.java.loginform.username.hint"));
    // #if (${lowercase(polish.vendor)}==samsung)
    UiFactory.fixSamsungNativeTextField(userName);
    // #endif
    // #endif

    if (userName.getText().length() > 0) {
      // Change username textfield into uneditable field once authenticated once to keep users from
      // switching username
      userName.setConstraints(TextField.NON_PREDICTIVE | TextField.UNEDITABLE);

      usernameReadonly = true;

      // #if not polish.blackberry
      // #style .login_textfield_readonly
      // #= userName.setStyle();
      // #endif
    }

    // password textfield

    // #if polish.blackberry
    passWord =
        UiFactory.createTextField(
            Locale.get("nowplus.client.java.loginform.password.hint"),
            passwordString,
            255,
            TextField.NON_PREDICTIVE | TextField.INITIAL_CAPS_NEVER | TextField.PASSWORD,
            this);
    // #else
    passWord =
        UiFactory.createTextField(
            null, passwordString, 255, TextField.INITIAL_CAPS_NEVER | TextField.PASSWORD, this);
    // #endif

    UiAccess.setTextfieldHelp(passWord, Locale.get("nowplus.client.java.loginform.password.hint"));
    // #if using.native.textfield:defined
    passWord.setTitle(Locale.get("nowplus.client.java.loginform.password.hint"));
    // #if (${lowercase(polish.vendor)}==samsung)
    UiFactory.fixSamsungNativeTextField(passWord);
    // #elif polish.device.textField.requires.initialCapsNeverFix:defined
    UiFactory.fixS40NativeTextField(passWord);
    // #endif
    // #endif

    rememberMeItem =
        UiFactory.createChoiceCheckBoxItem(
            Locale.get("nowplus.client.java.loginform.rememberme.label"), Choice.MULTIPLE);
    rememberMeItem.select(model.stayLoggedIn());
    UiFactory.createChoiceGroup(
        null,
        ChoiceGroup.MULTIPLE,
        new ChoiceItem[] {rememberMeItem},
        0,
        rememberMeItem.isSelected,
        null,
        this);

    // #if !polish.blackberry
    if (usernameReadonly) {
      this.focus(passWord);
    }
    // #endif

    // #if polish.blackberry
    // #style ui_factory_button_item
    StringItem loginButton =
        UiFactory.createButtonItem(
            null, cmdSave.getLabel(), (de.enough.polish.ui.Command) cmdSave, null, null);
    append(loginButton);

    if (firstLogin) {
      cmdQuit = cmdCancel;
    } else {
      cmdQuit = cmdExit;
    }
    // #endif
  }
  /**
   * Arranges the items in this view.
   *
   * @param lineWidth the available line width
   * @param availHeight the available height in pixels
   * @param myItems all items
   * @param length the number of items
   * @param maxWidth the maximum width of one item
   * @param maxHeight the maximum height of one item
   */
  protected void initItemArrangement(
      int lineWidth, int availHeight, Item[] myItems, int length, int maxWidth, int maxHeight) {
    // #debug
    // # System.out.println("initItemArrangement: lineWidth=" + lineWidth + ", availHeight=" +
    // availHeight + ", maxWidth="  + maxWidth + ", maxHeight=" + maxHeight + ", length=" + length);
    if (length == 0) {
      return;
    }
    this.referenceXCenterPositions = new int[length];
    this.referenceXCenterPositions[this.focusedIndex] = lineWidth >> 1;
    this.referenceFocusedIndex = this.focusedIndex;
    if (maxWidth == 0) {
      maxWidth = lineWidth;
    }
    if (maxHeight == 0) {
      maxHeight = availHeight;
    }
    int completeWidth;
    // #if polish.midp2
    completeWidth =
        maxWidth
            + ((maxWidth * this.scaleFactor) / 100) * (length - 1)
            + (length - 1) * this.paddingHorizontal;
    // #else
    // # completeWidth = maxWidth * length + ( length - 1 ) * this.paddingHorizontal;
    // #endif

    if (this.focusedStyle != null && this.focusedItem != null) {
      UiAccess.focus(this.focusedItem, this.focusedDirection, this.focusedStyle);
      this.focusedWidth = this.focusedItem.getItemWidth(lineWidth, lineWidth, maxHeight);
      this.focusedItem.relativeX = (lineWidth - this.focusedWidth) >> 1;
    } else if (this.focusedWidth == 0) {
      this.focusedWidth = maxWidth;
    }

    int availWidth;
    if ((completeWidth > lineWidth && this.includeAllItems)
        || (completeWidth < lineWidth && isLayoutExpand())) {
      availWidth = ((lineWidth - this.focusedWidth) >> 1) - this.paddingHorizontal;
    } else {
      availWidth = ((completeWidth - this.focusedWidth) >> 1) - this.paddingHorizontal;
    }
    //		System.out.println("available=" + availableWidth + ", lineWidth=" + lineWidth + ",
    // completeWidth=" + completeWidth + ", maxItemWidth=" + maxWidth + ", paddingHorizontal=" +
    // this.paddingHorizontal);
    int availableWidthPerItem = (availWidth << 8) / (length - 1);
    // process items on the left side:
    int index = this.focusedIndex - 1;
    int processed = 0;
    int halfLength = (length - 1) >> 1;
    int startX = availWidth;
    //		System.out.println("left: startX=" + startX + ", center=" + (lineWidth/2) );
    while (processed < halfLength) {
      if (index < 0) {
        index = length - 1;
      }
      this.referenceXCenterPositions[index] =
          startX
              - ((processed * availableWidthPerItem) >>> 8)
              - (processed * this.paddingHorizontal); //  - (maxItemWidth >> 1);
      //			System.out.println( index + "=" + this.referenceXCenterPositions[index]);
      index--;
      processed++;
    }
    // process items on the right side:
    index = this.focusedIndex + 1;
    processed = 0;
    halfLength = length >> 1;
    startX =
        lineWidth
            - availWidth
            - (this.paddingHorizontal >> 1); // (lineWidth >> 1) +  ((lineWidth >> 1) - startX);
    //		System.out.println("right: startX=" + startX + ", center=" + (lineWidth/2) );
    while (processed < halfLength) {
      if (index >= length) {
        index = 0;
      }
      this.referenceXCenterPositions[index] =
          startX
              + ((processed * availableWidthPerItem) >>> 8)
              + (processed * this.paddingHorizontal); // + (maxWidth >> 1);
      //			System.out.println( index + "=" + this.referenceXCenterPositions[index]);
      index++;
      processed++;
    }
  }
  /* (non-Javadoc)
   * @see de.enough.polish.ui.ContainerView#initContent(de.enough.polish.ui.Container, int, int)
   */
  protected void initContent(
      Item parentContainerItem, int firstLineWidth, int availWidth, int availHeight) {
    synchronized (this.lock) {
      this.isVertical = false;
      this.isHorizontal = true;
      Container parent = (Container) parentContainerItem;
      // #debug
      System.out.println(
          "CoverFlow: intialising content for "
              + this
              + " with vertical-padding "
              + this.paddingVertical);

      this.parentContainer = parent;
      Item[] myItems = parent.getItems();
      int length = myItems.length;
      if (this.focusedIndex == -1 && length != 0) {
        // this.parentContainer.focus(0);
        if (parent.focusedIndex != -1) {
          this.focusedIndex = parent.focusedIndex;
        } else {
          this.focusedIndex = 0;
        }
        // System.out.println("AUTO-FOCUSSING ITEM " + this.focusedIndex );
        this.focusedItem = myItems[this.focusedIndex];
        this.focusedStyle = this.focusedItem.getFocusedStyle();
      }
      if (this.referenceXCenterPositions != null
          && this.referenceXCenterPositions.length == length) {
        return;
      }

      // #if polish.css.show-text-in-title
      if (this.isRemoveText && this.focusedLabel == null && !this.isShowTextInTitle) {
        this.focusedLabel = new StringItem(null, null);
      }
      // #else
      if (this.isRemoveText && this.focusedLabel == null) {
        this.focusedLabel = new StringItem(null, null);
      }
      // #endif

      if (this.isRemoveText && (this.labels == null || this.labels.length != length)) {
        this.labels = new String[length];
      }

      int maxWidth = 0;
      int maxHeight = 0;
      boolean hasFocusableItem = false;
      // #if polish.midp2
      this.originalRgbData = new int[length][];
      this.originalRgbDataWidths = new int[length];
      this.shownRgbData = new int[length][];
      this.shownRgbDataWidths = new int[length];
      this.shownRgbDataHeights = new int[length];
      // #endif
      for (int i = 0; i < length; i++) {
        Item item = myItems[i];
        if (this.isRemoveText) {
          String text = item.getLabel();
          if (text != null) {
            this.labels[i] = text;
            item.setLabel(null);
          } else if (item instanceof IconItem) {
            IconItem iconItem = (IconItem) item;
            text = iconItem.getText();
            if (text != null) {
              this.labels[i] = text;
              iconItem.setTextVisible(false);
              // iconItem.setText(null);
            }
          }
        }
        int width = item.getItemWidth(firstLineWidth, availWidth, availHeight);
        int height = item.getItemHeight(firstLineWidth, availWidth, availHeight);
        // #if polish.midp2
        int[] data = UiAccess.getRgbData(item);
        this.originalRgbData[i] = data;
        this.originalRgbDataWidths[i] = width;
        if (this.scaleFactorWidth == 100) {
          this.shownRgbData[i] = data;
          this.shownRgbDataWidths[i] = width;
          this.shownRgbDataHeights[i] = height;
        } else {
          int newWidth = (width * this.scaleFactorWidth) / 100;
          int newHeightInner = (height * this.scaleFactorInnerHeight) / 100;
          int newHeightOuter = (height * this.scaleFactorOuterHeight) / 100;
          this.shownRgbData[i] = new int[data.length];
          if (isLeftOfFocus(i, this.focusedIndex, length)) {
            ImageUtil.perspectiveShear(
                data,
                this.shownRgbData[i],
                width,
                newWidth,
                newHeightOuter,
                newHeightInner,
                255,
                ImageUtil.EDGEDETECTION_MAP_FAST_AND_SIMPLE);
          } else {
            ImageUtil.perspectiveShear(
                data,
                this.shownRgbData[i],
                width,
                newWidth,
                newHeightInner,
                newHeightOuter,
                255,
                ImageUtil.EDGEDETECTION_MAP_FAST_AND_SIMPLE);
          }
          //					System.out.println("newWidth=" + newWidth);
          this.shownRgbDataWidths[i] = width;
          this.shownRgbDataHeights[i] = height;
        }
        // #endif
        if (item.appearanceMode != Item.PLAIN) {
          hasFocusableItem = true;
        }
        if (width > maxWidth) {
          maxWidth = width;
        }
        if (height > maxHeight) {
          maxHeight = height;
        }
      }
      this.maxItemHeight = maxHeight;
      if (hasFocusableItem) {
        this.appearanceMode = Item.INTERACTIVE;
      } else {
        this.appearanceMode = Item.PLAIN;
      }

      initItemArrangement(availWidth, myItems, length, maxWidth, maxHeight);

      // use reference positions to set the position for the items:
      for (int i = 0; i < length; i++) {
        Item item = myItems[i];
        int distance = getDistance(i, this.focusedIndex, length);
        if (distance != 0) {
          distance--;
        }
        int halfItemWidth = (item.getItemWidth(availWidth, availWidth, availHeight) >> 1);
        int halfItemHeight = (item.getItemHeight(availWidth, availWidth, availHeight) >> 1);
        // #if polish.midp2
        if (i != this.focusedIndex) {
          int factor = getScaleFactor(distance, length);
          halfItemWidth = (halfItemWidth * factor) / 100;
          halfItemHeight = (halfItemHeight * factor) / 100;
        }
        // #endif
        // System.out.println(i + ": initContent:  with distance " + distance + ", halfItemWidth=" +
        // halfItemWidth + ", focusedIndex=" + this.focusedIndex);
        item.relativeX = this.referenceXCenterPositions[i] - halfItemWidth;
        if (this.referenceYCenterPositions != null) {
          item.relativeY = this.referenceYCenterPositions[i] - halfItemHeight;
        }
        // System.out.println( i + ": relativeX=" + item.relativeX);

        //			System.out.println("item.relativeX for " + i + "=" + item.relativeX);
      }
      if (this.focusedStyle != null) {
        focusItem(this.focusedIndex, this.focusedItem, this.focusedDirection, this.focusedStyle);
        this.focusedItem.relativeX =
            this.referenceXCenterPositions[this.focusedIndex]
                - (this.focusedItem.getItemWidth(availWidth, availWidth, availHeight) >> 1);
        if (this.referenceYCenterPositions != null) {
          this.focusedItem.relativeY =
              this.referenceYCenterPositions[this.focusedIndex]
                  - (this.focusedItem.getItemHeight(availWidth, availWidth, availHeight) >> 1);
        }
        //			System.out.println("focused.relativeX=" + this.focusedItem.relativeX);
        this.focusedStyle = null;
      }

      this.contentWidth = availWidth; // TODO: this can change when no expanded layout is used
      this.contentHeight =
          this.focusedLabel == null
              ? maxHeight
              : maxHeight
                  + this.focusedLabel.getItemHeight(
                      availWidth,
                      availWidth,
                      availHeight); // maxItemHeight + this.paddingVertical +
      // this.focusedLabel.getItemHeight(lineWidth, lineWidth);

      if (!this.isFocused) {
        AnimationThread.addAnimationItem(parent);
      }
      animate(System.currentTimeMillis(), null);
    }
  }
  /* (non-Javadoc)
   * @see de.enough.polish.browser.TagHandler#handleTag(de.enough.polish.ui.Container, de.enough.polish.xml.PullParser, java.lang.String, boolean, de.enough.polish.util.HashMap, de.enough.polish.ui.Style)
   */
  public boolean handleTag(
      Container parentItem,
      SimplePullParser parser,
      String tagName,
      boolean opening,
      HashMap attributeMap,
      Style style) {
    // #debug
    System.out.println((opening ? "<" : "</") + tagName + ">");
    tagName = tagName.toLowerCase();
    if (TAG_DIV.equals(tagName) || TAG_SPAN.equals(tagName)) {
      if (opening) {
        String itemStyleName = (String) attributeMap.get("textclass");
        Style itemStyle = (itemStyleName == null ? null : StyleSheet.getStyle(itemStyleName));
        if (itemStyle != null) {
          this.textStyle = itemStyle;
        }
        if (this.isDivOrSpanOpened == null) {
          this.isDivOrSpanOpened = new BooleanStack();
        }
        //				System.out.println("opening <div> with style " + (style == null ? null : style.name));
        if (style != null) {
          this.browser.openContainer(style);
        }
        this.isDivOrSpanOpened.push(style != null);
        //				this.browser.openContainer( style );
        //				this.isDivOrSpanOpened.push( true );
      } else {
        this.textStyle = null;
        // System.out.println("closing <div> with container=" + this.isDivOrSpanOpened.peek());
        if (this.isDivOrSpanOpened.pop()) {
          Container container = this.browser.closeContainer();
          if (UiAccess.cast(container) instanceof TableItem) {
            this.currentTable = (TableItem) UiAccess.cast(container);
          }
        }
        //				Style divStyle = container.getStyle();
        //					if (divStyle != null) {
        //					Object[] items = container.getInternalArray();
        //					for (int i = 0; i < items.length; i++)
        //					{
        //						Item item = (Item) items[i];
        //						if (item == null) {
        //							break;
        //						}
        //						item.setStyle( divStyle );
        //					}
        //				}
      }
    } else if (TAG_SELECT.equals(tagName)) {
      if (opening) {
        if (this.currentSelect != null) {
          // #debug error
          System.out.println(
              "Error in HTML-Code: You cannot open a <select>-tag inside another <select>-tag.");

          ChoiceGroup choiceGroup = this.currentSelect.getChoiceGroup();
          add(choiceGroup);
          if (this.currentForm == null) {
            // #debug error
            System.out.println("Error in HTML-Code: no <form> for <select> element found!");
          } else {
            this.currentForm.addItem(choiceGroup);
          }
          this.currentSelect = null;
        }

        String name = parser.getAttributeValue(ATTR_NAME);
        String sizeStr = parser.getAttributeValue(ATTR_SIZE);
        int size;

        try {
          size = Integer.parseInt(sizeStr);
        } catch (NumberFormatException e) {
          size = -1;
        }

        boolean isMultiple = parser.getAttributeValue(ATTR_MULTIPLE) != null;
        this.currentSelect = new HtmlSelect(name, size, isMultiple, style);
      } else { // tag is closed
        if (this.currentSelect != null) {
          ChoiceGroup choiceGroup = this.currentSelect.getChoiceGroup();
          add(choiceGroup);
          if (this.currentForm == null) {
            // #debug error
            System.out.println("Error in HTML-Code: no <form> for <select> element found!");
          } else {
            this.currentForm.addItem(choiceGroup);
          }
          this.currentSelect = null;
        }
        // #mdebug error
        else {
          // #debug error
          System.out.println(
              "Error in HTML-Code. You cannot close a <select>-tag without opening one.");
        }
        // #enddebug
      }
      return true;
    } else if (TAG_OPTION.equals(tagName)) {
      if (this.currentSelect != null && opening) {
        // TODO: handle "selected" attribute.
        String value = parser.getAttributeValue(ATTR_VALUE);
        String selected = parser.getAttributeValue("selected");
        parser.next();
        String name = handleText(parser.getText());

        if (value == null) {
          value = name;
        }

        this.currentSelect.addOption(name, value, selected != null, style);
      }
      return true;
    } else if (TAG_A.equals(tagName)) {
      if (opening) {
        this.anchorHref = (String) attributeMap.get(ATTR_HREF);
        // #if polish.debug.error
        if (this.anchorHref == null) {
          // #debug error
          System.out.println(
              "Unable to handle anchor tag <a> without "
                  + ATTR_HREF
                  + " attribute: "
                  + attributeMap);
        }
        // #endif
        this.browser.openContainer(style);
        if (style == null) {
          Container container = this.browser.getCurrentContainer();
          // #style browserLink
          UiAccess.setStyle(container);
        }
      } else {
        // apply link to last item(s):
        Container container = this.browser.removeCurrentContainer();
        Style contStyle = container.getStyle();
        Item linkItem;
        if (container.size() == 0) {
          linkItem = new StringItem(null, null);
        } else if (container.size() == 1) {
          linkItem = container.get(0);
        } else {
          // check if all elements are StringItems - then we should combine them:
          boolean allItemsAreStringItems = true;
          StringBuffer text = new StringBuffer();
          for (int i = 0; i < container.size(); i++) {
            Item item = container.get(i);
            if (!(item instanceof StringItem)) {
              allItemsAreStringItems = false;
              break;
            } else {
              if (text.length() > 0) {
                text.append(' ');
              }
              text.append(((StringItem) item).getText());
            }
          }
          if (allItemsAreStringItems) {
            linkItem = new StringItem(null, text.toString());
          } else {
            linkItem = container;
          }
        }
        //				System.out.println("closing <a>: container.size()=" + container.size() + ", linkItem="
        // + linkItem + ", style=" + (contStyle != null ? contStyle.name : "<no style>") );
        if (this.anchorHref != null) {
          if (contStyle != null) {
            linkItem.setStyle(contStyle);
          } else if (linkItem.getStyle() == null) {
            // #style browserLink
            UiAccess.setStyle(linkItem);
          }
          linkItem.setDefaultCommand(CMD_LINK);
          linkItem.setItemCommandListener(this);
          linkItem.setAttribute(ATTR_HREF, this.anchorHref);
          addCommands(TAG_A, linkItem);
          add(linkItem);
        }

        // this.browser.closeContainer();
      }
    }

    if (opening) {
      //			if (TAG_A.equals(tagName))
      //			{
      //				String href = (String) attributeMap.get(ATTR_HREF);
      //				parser.next();
      //				Item linkItem;
      //				if (href != null)
      //				{
      //					String anchorText = handleText(parser.getText());
      //					// hack for image links:
      //					if ("".equals(anchorText) && TAG_IMG.equals(parser.getName())) {
      //						// this is an image link:
      //						attributeMap.clear();
      //						for (int i = 0; i < parser.getAttributeCount(); i++)
      //						{
      //							String attributeName = parser.getAttributeName(i);
      //							String attributeValue = parser.getAttributeValue(i);
      //							attributeMap.put(attributeName, attributeValue);
      //						}
      //						String src = (String) attributeMap.get("src");
      //						String url = this.browser.makeAbsoluteURL(src);
      //						Image image = this.browser.loadImage(url);
      //						//#style browserLink
      //						linkItem = new ImageItem(null, image, 0, (String) attributeMap.get("alt") );
      //						//this.browser.loadImageLater( url, (ImageItem) linkItem );
      //
      //					} else {
      //						//#style browserLink
      //						linkItem = new StringItem(null, anchorText);
      //					}
      //					linkItem.setDefaultCommand(CMD_LINK);
      //					linkItem.setItemCommandListener( this );
      //					linkItem.setAttribute(ATTR_HREF, href );
      //					addCommands(TAG_A, linkItem);
      //				}
      //				else
      //				{
      //					//#style browserText
      //					linkItem = new StringItem(null, handleText(parser.getText()));
      //				}
      //				if (style != null) {
      //					linkItem.setStyle(style);
      //				}
      //				add(linkItem);
      //				return true;
      //			}
      //			else
      if (TAG_BR.equals(tagName)) {
        addLineBreak();
        return true;
      } else if (TAG_P.equals(tagName)) {
        addLineBreak();
        if (opening) {
          this.textStyle = style;
        }
        return true;
      } else if (TAG_IMG.equals(tagName)) {
        String src = (String) attributeMap.get("src");
        String url = this.browser.makeAbsoluteURL(src);
        Dimension width = parseSizeValue((String) attributeMap.get("width"));
        Dimension height = parseSizeValue((String) attributeMap.get("height"));
        Style imageStyle = new Style();
        imageStyle.addAttribute(58 /* "min-width" */, width);
        imageStyle.addAttribute(144 /* "min-height" */, height);
        ImageItem item;

        if (width != null || height != null) {
          item = new ScaledImageItem(null, null, width, height, Item.LAYOUT_DEFAULT, "");
        } else {
          item = new ImageItem(null, null, Item.LAYOUT_DEFAULT, "");
        }

        if (imageStyle != null) {
          item.setStyle(imageStyle);
        }

        this.browser.loadImageLater(item, url);
        add(item);
        return true;
      } else if (TAG_TITLE.equals(tagName)) {
        // Hack to read title.
        parser.next();
        String name = handleText(parser.getText());
        Screen myScreen = this.browser.getScreen();
        if (name != null && myScreen != null) {
          myScreen.setTitle(name);
        }
        return true;
      } else if (TAG_STYLE.equals(tagName)) {
        // Hack to read style content.
        parser.next();
        String cssCode = parser.getText();
        try {
          CssInterpreter reader = new CssInterpreter(cssCode, this.browser);
          this.browser.setCssStyles(reader.getAllStyles());
        } catch (Exception e) {
          // #debug error
          System.out.println("Unable to parse CSS" + e);
        }
        // parser.next();
        return true;
      } else if (TAG_META.equals(tagName)) {
        String httpEquiv = (String) attributeMap.get("http-equiv");
        if (httpEquiv != null && TextUtil.equalsIgnoreCase("refresh", httpEquiv)) {
          String content = (String) attributeMap.get("content");
          if (content != null) {
            int semicolonPos = content.indexOf(';');
            int waitTime = 0;
            String url = content;
            if (semicolonPos != -1) {
              try {
                waitTime = Integer.parseInt(content.substring(0, semicolonPos));
                url = content.substring(semicolonPos + 1);
              } catch (Exception e) {
                if (semicolonPos == 0) {
                  url = content.substring(1);
                }
              }
            }
            int equalsPos = url.indexOf('=');
            if (equalsPos != -1) {
              url = url.substring(equalsPos + 1).trim();
            }
            if (url.indexOf(':') == -1) {
              // assuming resource protocol:
              if (url.charAt(0) != '/') {
                url = "resource://" + url;
              } else {
                url = "resource:/" + url;
              }
            }
            if (waitTime > 0) {
              (new RedirectThread(this.browser, waitTime * 1000L, url)).start();
            } else {
              // consume rest of document:
              while (parser.next() != SimplePullParser.END_DOCUMENT) {
                // read document..
              }
              this.browser.go(url);
            }
            return true;
          }
        }
        return false;
      }
      // #if polish.Browser.supportTextInput != false
      else if (TAG_TEXT_AREA.equals(tagName)) {
        parser.next();
        String value = handleText(parser.getText());
        int maxCharNumber = 500;
        String cols = (String) attributeMap.get("cols");
        String rows = (String) attributeMap.get("rows");
        if (cols != null && rows != null) {
          try {
            maxCharNumber = Integer.parseInt(cols) * Integer.parseInt(rows);
          } catch (Exception e) {
            // #debug error
            System.out.println(
                "Unable to parse textarea cols or rows attribute: cols=" + cols + ", rows=" + rows);
          }
        }
        // #style browserInput
        TextField textField = new TextField(null, value, maxCharNumber, TextField.ANY);
        if (style != null) {
          textField.setStyle(style);
        }
        add(textField);
        if (this.currentForm != null) {
          this.currentForm.addItem(textField);
          textField.setAttribute(ATTR_FORM, this.currentForm);
          String name = (String) attributeMap.get(INPUT_NAME);
          if (value == null) {
            value = name;
          }
          if (name != null) {
            textField.setAttribute(ATTR_NAME, name);
            textField.setAttribute(ATTR_VALUE, value);
          }
        }
        return true;
      }
      // #endif
      else if (TAG_BUTTON.equals(tagName) && this.currentForm != null) {
        String name = (String) attributeMap.get(INPUT_NAME);
        String value = (String) attributeMap.get(INPUT_VALUE);

        if (value == null) {
          value = name;
        }

        // #style browserLink
        StringItem buttonItem = new StringItem(null, value);
        if (style != null) {
          buttonItem.setStyle(style);
        }
        buttonItem.setDefaultCommand(CMD_SUBMIT);
        buttonItem.setItemCommandListener(this);
        addCommands(TAG_INPUT, INPUT_TYPE, INPUTTYPE_SUBMIT, buttonItem);
        add(buttonItem);

        this.currentForm.addItem(buttonItem);
        buttonItem.setAttribute(ATTR_FORM, this.currentForm);
        buttonItem.setAttribute(ATTR_TYPE, "submit");

        if (name != null) {
          buttonItem.setAttribute(ATTR_NAME, name);
          buttonItem.setAttribute(ATTR_VALUE, value);
        }
      } else if (TAG_INPUT.equals(tagName)) {
        if (this.currentForm != null) {
          String type = (String) attributeMap.get(INPUT_TYPE);
          String name = (String) attributeMap.get(INPUT_NAME);
          String value = (String) attributeMap.get(INPUT_VALUE);
          if (type != null) {
            type = type.toLowerCase();
          }

          if (this.formListener != null && name != null) {
            value =
                this.formListener.verifyInitialFormValue(this.currentForm.getAction(), name, value);
          }
          // #if polish.Browser.supportTextInput != false
          if (INPUTTYPE_TEXT.equals(type)
              || INPUTTYPE_PASSWORD.equals(type)
              || INPUTTYPE_NUMERIC.equals(type)) {
            int constraints;
            if (INPUTTYPE_NUMERIC.equals(type)) {
              constraints = TextField.NUMERIC;
            } else {
              constraints = INPUTTYPE_TEXT.equals(type) ? TextField.ANY : TextField.PASSWORD;
            }
            // #style browserInput
            TextField textField =
                new TextField((String) attributeMap.get("label"), value, 100, constraints);
            if (style != null) {
              textField.setStyle(style);
            }
            add(textField);

            this.currentForm.addItem(textField);
            textField.setAttribute(ATTR_FORM, this.currentForm);

            if (name != null) {
              textField.setAttribute(ATTR_NAME, name);
              if (value == null) {
                value = "";
              }
              textField.setAttribute(ATTR_VALUE, value);
            }
          } else
          // #endif
          if (INPUTTYPE_SUBMIT.equals(type)) {

            if (value == null) {
              value = name;
            }

            // #style browserLink
            StringItem buttonItem = new StringItem((String) attributeMap.get("label"), value);
            if (style != null) {
              buttonItem.setStyle(style);
            }
            buttonItem.setDefaultCommand(CMD_SUBMIT);
            buttonItem.setItemCommandListener(this);
            addCommands(TAG_INPUT, INPUT_TYPE, INPUTTYPE_SUBMIT, buttonItem);
            add(buttonItem);

            this.currentForm.addItem(buttonItem);
            buttonItem.setAttribute(ATTR_FORM, this.currentForm);
            buttonItem.setAttribute(ATTR_TYPE, "submit");

            if (name != null) {
              buttonItem.setAttribute(ATTR_NAME, name);
              buttonItem.setAttribute(ATTR_VALUE, value);
            }
          } else if (INPUTTYPE_HIDDEN.equals(type)) {
            this.currentForm.addHiddenElement(name, value);
          } else if (INPUTTYPE_CHECKBOX.equals(type) || INPUTTYPE_RADIO.equals(type)) {
            boolean isCheckBox = INPUTTYPE_CHECKBOX.equals(type);
            parser.next();
            String label = parser.getText().trim();
            int labelLength = label.length();
            if (labelLength == 0) {
              parser.next();
              label = parser.getText().trim();
              labelLength = label.length();
            }
            if ((labelLength > 0) && label.charAt(labelLength - 1) == '\n') {
              label = label.substring(0, labelLength - 1);
            }
            ChoiceGroup choiceGroup;
            if (isCheckBox) {
              choiceGroup = this.currentCheckBoxChoiceGroup;
            } else {
              choiceGroup = this.currentRadioChoiceGroup;
            }
            if (choiceGroup == null || !name.equals(choiceGroup.getAttribute(ATTR_NAME))) {
              // create a new choice group:
              String groupLabel = (String) attributeMap.get("label");
              if (isCheckBox) {
                // #style browserChoiceGroupMultiple
                choiceGroup = new ChoiceGroup(groupLabel, Choice.MULTIPLE);
              } else {
                String choiceType = (String) attributeMap.get("choice");
                if ("popup".equals(choiceType)) {
                  // #style browserChoiceGroupPopup
                  choiceGroup = new ChoiceGroup(groupLabel, Choice.POPUP);
                  this.currentRadioChoiceGroup = choiceGroup;
                } else {
                  // #style browserChoiceGroupExclusive
                  choiceGroup = new ChoiceGroup(groupLabel, Choice.EXCLUSIVE);
                  this.currentRadioChoiceGroup = choiceGroup;
                }
              }
              choiceGroup.setAttribute(ATTR_NAME, name);
              String styleName = (String) attributeMap.get("groupclass");
              if (styleName != null) {
                Style groupStyle = StyleSheet.getStyle(styleName);
                if (groupStyle != null) {
                  choiceGroup.setStyle(groupStyle);
                }
              }
              add(choiceGroup);
              if (this.currentForm == null) {
                // #debug error
                System.out.println("Error in HTML-Code: no <form> for <select> element found!");
              } else {
                this.currentForm.addItem(choiceGroup);
              }
              // end of creating a new choice group
            }
            ChoiceItem item;
            if (isCheckBox) {
              // #style browserCheckBox
              item = new ChoiceItem(label, null, Choice.MULTIPLE);
            } else {
              // #style browserRadio
              item = new ChoiceItem(label, null, choiceGroup.getType());
            }
            item.setAttribute(ATTR_VALUE, value);
            choiceGroup.append(item);
            if (attributeMap.get("checked") != null) {
              choiceGroup.setSelectedIndex(choiceGroup.size() - 1, true);
            }
            if (style != null) {
              item.setStyle(style);
            }
          }
          // #if polish.debug.debug
          else {
            // #debug
            System.out.println("unhandled html form input type: " + type);
          }
          // #endif
        }

        return true;
      } else if (TAG_SCRIPT.equals(tagName)) {
        // Consume javascript code.
        parser.next();
        return true;
      } else if (TAG_TABLE.equals(tagName)) {
        // #style browserTable?
        TableItem table = new TableItem();
        table.setSelectionMode(
            TableItem.SELECTION_MODE_CELL | TableItem.SELECTION_MODE_INTERACTIVE);
        table.setCellContainerStyle(this.browser.getStyle());
        if (style != null) {
          table.setStyle(style);
        }

        this.currentTable = table;
        this.browser.openContainer(table);
        return true;
      } else if (this.currentTable != null && TAG_TR.equals(tagName)) {
        this.currentTable.moveToNextRow();
        return true;
      } else if (this.currentTable != null && TAG_TH.equals(tagName)) {
        // TODO differentiate between th and td
        this.currentTable.moveToNextColumn();
        return true;
      } else if (this.currentTable != null && TAG_TD.equals(tagName)) {
        // TODO differentiate between th and td
        this.currentTable.moveToNextColumn();
        return true;
      } else if (TAG_CODE.equals(tagName)) {
        // #if polish.css.style.browsertextcode && !polish.LibraryBuild
        // #style browserTextCode
        // # this.textStyle = ();
        // #endif
      }
    } else {
      // the tag is being closed:
      if (TAG_TABLE.equals(tagName)) {
        Container container = this.browser.closeContainer();
        if (UiAccess.cast(container) instanceof TableItem) {
          this.currentTable = (TableItem) UiAccess.cast(container);
        } else {
          this.currentTable = null;
        }
        return true;
      }
      if (TAG_CODE.equals(tagName)) {
        this.textStyle = null;
      }
    }

    if (TAG_B.equals(tagName) || TAG_STRONG.equals(tagName)) {
      this.textBold = opening;
      return true;
    } else if (TAG_I.equals(tagName) || TAG_EM.equals(tagName)) {
      this.textItalic = opening;
      return true;
    } else if (TAG_FORM.equals(tagName)) {
      if (opening) {
        String name = (String) attributeMap.get("name");
        String action = (String) attributeMap.get("action");
        String method = (String) attributeMap.get("method");
        String encoding = (String) attributeMap.get("enctype");

        if (method == null) {
          method = "GET";
        }
        this.currentForm =
            new HtmlForm(name, action, method, encoding, this.browser, this.formListener);
        this.browser.addForm(this.currentForm);
        this.browser.openContainer(style);
      } else {
        this.browser.closeContainer();
        this.currentForm = null;
        this.currentCheckBoxChoiceGroup = null;
        this.currentRadioChoiceGroup = null;
      }

      return true;
    } else if (opening && TAG_BODY.equals(tagName)) {
      if (style != null) {
        // System.out.println("applying style " + style.name + " for body with bg=" +
        // style.background);
        this.browser.setBackground(style.background);
        this.browser.setBorder(style.border);
        this.browser.setStyle(style, false);
      }
    }

    return false;
  }