private void setBallPosition(TileIndex index) {
   GridPosition position = m_tileManager.getGridPosition(index);
   int x = position.getLeft() + (m_tileManager.getGridElementWidth() - m_ball.getWidth()) / 2;
   int y = position.getTop() + (m_tileManager.getGridElementHeight() + m_ball.getHeight()) / 2;
   setWidgetTopHeight(m_ball, y, Unit.PX, m_ball.getHeight(), Unit.PX);
   setWidgetLeftWidth(m_ball, x, Unit.PX, m_ball.getWidth(), Unit.PX);
 }
Example #2
0
  public static void scaleImage(AbsolutePanel container, Image image, Dimension area) {
    float blockRatio = (float) area.width / (float) area.height;
    int imgHeight = image.getHeight();
    int imgWidth = image.getWidth();
    float imgRatio = (float) imgWidth / (float) imgHeight;

    int resultWidth = 0;
    int resultHeight = 0;
    if (blockRatio > imgRatio) {
      resultWidth = area.width;
      resultHeight = (int) ((float) imgHeight * ((float) resultWidth / (float) imgWidth));
    } else {
      resultHeight = area.height;
      resultWidth = (int) ((float) imgWidth * ((float) resultHeight / (float) imgHeight));
    }
    image.setPixelSize(resultWidth, resultHeight);

    int xOffset = 0;
    int yOffset = 0;
    if (resultWidth > area.width) {
      xOffset = (resultWidth - area.width) / 2;
    }
    if (resultHeight > area.height) {
      yOffset = (resultHeight - area.height) / 2;
    }

    container.setWidgetPosition(image, -xOffset, -yOffset);
  }
  public final void onLoad(LoadEvent event) {
    int w = image.getWidth();
    int h = image.getHeight();

    double ratioW = maxW / (w * 1.0);
    double ratioH = maxH / (h * 1.0);

    double ratio = getRatio(ratioW, ratioH);

    int newW = (int) Math.floor(ratio * w);
    int newH = (int) Math.floor(ratio * h);
    setNewSize(newW, newH);
  }
Example #4
0
    PageSelectorItem(final WizardPageInfo pageInfo, ClickHandler clickHandler) {
      WizardResources res = WizardResources.INSTANCE;
      WizardResources.Styles styles = res.styles();

      LayoutPanel layoutPanel = new LayoutPanel();
      layoutPanel.addStyleName(styles.wizardPageSelectorItem());

      ImageResource pageImageResource = pageInfo.getImage();
      Image image = null;
      if (pageImageResource != null) {
        image = new Image(pageImageResource);
        layoutPanel.add(image);
        layoutPanel.setWidgetLeftWidth(image, 10, Unit.PX, image.getWidth(), Unit.PX);
        layoutPanel.setWidgetTopHeight(
            image, 40 - (image.getHeight() / 2), Unit.PX, image.getHeight(), Unit.PX);
      }

      FlowPanel captionPanel = new FlowPanel();
      Label titleLabel = new Label(pageInfo.getTitle());
      titleLabel.addStyleName(styles.headerLabel());
      captionPanel.add(titleLabel);
      Label subTitleLabel = new Label(pageInfo.getSubTitle());
      subTitleLabel.addStyleName(styles.subcaptionLabel());
      captionPanel.add(subTitleLabel);
      layoutPanel.add(captionPanel);
      layoutPanel.setWidgetLeftWidth(
          captionPanel, 10 + (image == null ? 0 : image.getWidth()) + 12, Unit.PX, 450, Unit.PX);
      layoutPanel.setWidgetTopHeight(captionPanel, 19, Unit.PX, 55, Unit.PX);

      Image arrowImage = new Image(res.wizardDisclosureArrow());
      layoutPanel.add(arrowImage);
      layoutPanel.setWidgetRightWidth(arrowImage, 20, Unit.PX, arrowImage.getWidth(), Unit.PX);
      layoutPanel.setWidgetTopHeight(
          arrowImage, 40 - (arrowImage.getHeight() / 2), Unit.PX, arrowImage.getHeight(), Unit.PX);

      layoutPanel.addDomHandler(clickHandler, ClickEvent.getType());

      initWidget(layoutPanel);
    }
    private DefaultHeader(final DisclosurePanelImages images, final String text) {
      super(DOM.createAnchor());
      this.images = images;

      final Element elem = getElement();

      DOM.setElementProperty(elem, "href", "javascript:void(0);");
      // Avoids layout problems from having blocks in inlines.
      DOM.setStyleAttribute(elem, "display", "block");
      sinkEvents(Event.ONCLICK);
      setStyleName(STYLENAME_HEADER);

      iconImage =
          isOpen
              ? images.disclosurePanelOpen().createImage()
              : images.disclosurePanelClosed().createImage();

      // I do not need any Widgets here, just a DOM structure.
      final Element root = DOM.createTable();
      final Element tbody = DOM.createTBody();
      final Element tr = DOM.createTR();
      final Element imageTD = DOM.createTD();
      labelTD = DOM.createTD();

      setElement(root);

      DOM.appendChild(root, tbody);
      DOM.appendChild(tbody, tr);
      DOM.appendChild(tr, imageTD);
      DOM.appendChild(tr, labelTD);

      // set image TD to be same width as image.
      DOM.setElementProperty(imageTD, "align", "center");
      DOM.setElementProperty(imageTD, "valign", "middle");
      DOM.setStyleAttribute(imageTD, "width", iconImage.getWidth() + "px");

      DOM.appendChild(imageTD, iconImage.getElement());

      setText(text);

      addEventHandler(this);
      setStyle();
    }