Package com.google.gwt.safecss.shared

Examples of com.google.gwt.safecss.shared.SafeStylesBuilder


  public Element getImgElement(Image image) {
    return image.getElement();
  }

  public SafeHtml getSafeHtml(SafeUri url, int left, int top, int width, int height) {
    SafeStylesBuilder builder = new SafeStylesBuilder();
    builder.width(width, Unit.PX).height(height, Unit.PX).trustedNameAndValue("background",
        "url(" + url.asString() + ") " + "no-repeat " + (-left + "px ") + (-top + "px"));

    return getTemplate().image(clearImage,
        SafeStylesUtils.fromTrustedString(builder.toSafeStyles().asString()));
  }
View Full Code Here


      case LARGE:
        cls += " " + style.large();
        break;
    }

    SafeStylesBuilder stylesBuilder = new SafeStylesBuilder();

    int width = -1;

    if (cell.getWidth() != -1) {
      int w = cell.getWidth();
      if (w < cell.getMinWidth()) {
        w = cell.getMinWidth();
      }
      stylesBuilder.appendTrustedString("width:" + w + "px;");
      cls += " " + style.hasWidth() + " x-has-width";
      width = w;
    } else {

      if (cell.getMinWidth() != -1) {
        TextMetrics.get().bind(style.text());
        int length = TextMetrics.get().getWidth(text);
        length += 6; // frames

        if (icon != null) {
          switch (iconAlign) {
            case LEFT:
            case RIGHT:
              length += icon.getWidth();
              break;
          }
        }

        if (cell.getMinWidth() > length) {
          stylesBuilder.appendTrustedString("width:" + cell.getMinWidth() + "px;");
          cls += " " + style.hasWidth() + " x-has-width";
          width = cell.getMinWidth();
        }
      }
    }

    final int height = cell.getHeight();
    if (height != -1) {
      stylesBuilder.appendTrustedString("height:" + height + "px;");
    }

    if (icon != null) {
      switch (iconAlign) {
        case TOP:
          arrowCls += " " + style.iconTop();
          break;
        case BOTTOM:
          arrowCls += " " + style.iconBottom();
          break;
        case LEFT:
          arrowCls += " " + style.iconLeft();
          break;
        case RIGHT:
          arrowCls += " " + style.iconRight();
          break;
      }

    } else {
      arrowCls += " " + style.noIcon();
    }

    // toggle button
    if (value == Boolean.TRUE) {
      cls += " " + frame.pressedClass();
    }

    sb.append(templates.outer(cls, new SafeStylesBuilder().toSafeStyles()));

    SafeHtmlBuilder inside = new SafeHtmlBuilder();

    String innerWrap = arrowCls;
    if (GXT.isIE6() || GXT.isIE7()) {
      arrowCls += " " + CommonStyles.get().inlineBlock();
    }

    inside.appendHtmlConstant("<div class='" + innerWrap + "'>");
    inside.appendHtmlConstant("<table cellpadding=0 cellspacing=0 class='" + style.mainTable() + "'>");

    if (icon != null) {
      switch (iconAlign) {
        case LEFT:
          inside.appendHtmlConstant("<tr>");
          writeIcon(inside, icon, height);
          if (text != null) {
            int w = width - (icon != null ? icon.getWidth() : 0) - 4;
            writeText(inside, text, w, height);
          }
          inside.appendHtmlConstant("</tr>");
          break;
        case RIGHT:
          inside.appendHtmlConstant("<tr>");
          if (text != null) {
            int w = width - (icon != null ? icon.getWidth() : 0) - 4;
            writeText(inside, text, w, height);
          }
          writeIcon(inside, icon, height);
          inside.appendHtmlConstant("</tr>");
          break;
        case TOP:
          inside.appendHtmlConstant("<tr>");
          writeIcon(inside, icon, height);
          inside.appendHtmlConstant("</tr>");
          if (text != null) {
            inside.appendHtmlConstant("<tr>");
            writeText(inside, text, width, height);
            inside.appendHtmlConstant("</tr>");
          }
          break;
        case BOTTOM:
          if (text != null) {
            inside.appendHtmlConstant("<tr>");
            writeText(inside, text, width, height);
            inside.appendHtmlConstant("</tr>");
          }
          inside.appendHtmlConstant("<tr>");
          writeIcon(inside, icon, height);
          inside.appendHtmlConstant("</tr>");
          break;
      }

    } else {
      inside.appendHtmlConstant("<tr>");
      if (text != null) {
        writeText(inside, text, width, height);
      }
      inside.appendHtmlConstant("</tr>");
    }
    inside.appendHtmlConstant("</table>");
    inside.appendHtmlConstant("</div>");

    frame.render(sb, new Frame.FrameOptions(0, CommonStyles.get().noFocusOutline(), stylesBuilder.toSafeStyles()),
        inside.toSafeHtml());

    sb.appendHtmlConstant("</div>");

  }
View Full Code Here

      builder.append(templates.iconWithStyles(style.iconWrap(), heightStyle, iconHtml));
    }
  }

  private void writeText(SafeHtmlBuilder builder, String text, int width, int height) {
    SafeStylesBuilder sb = new SafeStylesBuilder();
    if (height > 0) {
      int adjustedHeight = height - heightOffset;
      sb.append(SafeStylesUtils.fromTrustedString("height:" + adjustedHeight + "px;"));
    }
    if (width > 0) {
      sb.append(SafeStylesUtils.fromTrustedString("width:" + width + "px;"));
    }
    builder.append(templates.textWithStyles(style.text(), sb.toSafeStyles(), SafeHtmlUtils.fromTrustedString(text)));
  }
View Full Code Here

      AbstractImagePrototype proto = AbstractImagePrototype.create(res);
      image = SafeHtmlUtils.fromTrustedString(proto.getHTML());
    }

    // Create the wrapper based on the vertical alignment.
    SafeStylesBuilder cssStyles =
        new SafeStylesBuilder().appendTrustedString(direction + ":0px;");
    if (HasVerticalAlignment.ALIGN_TOP == valign) {
      return template.imageWrapperTop(cssStyles.toSafeStyles(), image);
    } else if (HasVerticalAlignment.ALIGN_BOTTOM == valign) {
      return template.imageWrapperBottom(cssStyles.toSafeStyles(), image);
    } else {
      int halfHeight = (int) Math.round(res.getHeight() / 2.0);
      cssStyles.appendTrustedString("margin-top:-" + halfHeight + "px;");
      return template.imageWrapperMiddle(cssStyles.toSafeStyles(), image);
    }
  }
View Full Code Here

  private SafeHtml getImageHtml(ImageResource res) {
    // Right-justify image if LTR, left-justify if RTL
    AbstractImagePrototype proto = AbstractImagePrototype.create(res);
    SafeHtml image = SafeHtmlUtils.fromTrustedString(proto.getHTML());

    SafeStylesBuilder cssBuilder = new SafeStylesBuilder();
    if (LocaleInfo.getCurrentLocale().isRTL()) {
      cssBuilder.appendTrustedString("left:0px;");
    } else {
      cssBuilder.appendTrustedString("right:0px;");
    }
    cssBuilder.appendTrustedString("width: " + res.getWidth() + "px;");
    cssBuilder.appendTrustedString("height: " + res.getHeight() + "px;");
    return template.imageWrapper(cssBuilder.toSafeStyles(), image);
  }
View Full Code Here

    if (isTop) {
      classesBuilder.append(" ").append(style.cellTreeTopItemImage());
    }

    // Build the css.
    SafeStylesBuilder cssBuilder = new SafeStylesBuilder();
    if (LocaleInfo.getCurrentLocale().isRTL()) {
      cssBuilder.appendTrustedString("right: 0px;");
    } else {
      cssBuilder.appendTrustedString("left: 0px;");
    }
    cssBuilder.appendTrustedString("width: " + res.getWidth() + "px;");
    cssBuilder.appendTrustedString("height: " + res.getHeight() + "px;");

    AbstractImagePrototype proto = AbstractImagePrototype.create(res);
    SafeHtml image = SafeHtmlUtils.fromTrustedString(proto.getHTML());
    return template
        .imageWrapper(classesBuilder.toString(), cssBuilder.toSafeStyles(), image);
  }
View Full Code Here

    if (isCellIconVisible(context))
    {
      final ImageResource icon = cell.getIcon(context);
      final IconAlign iconAlign = cell.getIconAlign(context);

      final SafeStylesBuilder stylesBuilder = new SafeStylesBuilder();

      // int width = -1;

      if (cell.getWidth() != -1)
      {
        int w = cell.getWidth();
        if (w < cell.getMinWidth())
        {
          w = cell.getMinWidth();
        }
        stylesBuilder.appendTrustedString("width:" + w + "px;");
        // width = w;
      }
      else
      {

        if (cell.getMinWidth() != -1)
        {
          int length = 0;
          if (icon != null)
          {
            switch (iconAlign)
            {
              case LEFT:
              case RIGHT:
                length += icon.getWidth();
                break;
              default:
                break;
            }
          }

          if (cell.getMinWidth() > length)
          {
            stylesBuilder.appendTrustedString("width:" + cell.getMinWidth() + "px;");
            // width = cell.getMinWidth();
          }
        }
      }
      final int height = cell.getHeight();
      if (height != -1)
      {
        stylesBuilder.appendTrustedString("height:" + height + "px;");
      }

      final StringBuilder stringBuilder = new StringBuilder();
      stringBuilder.append("<div style='");
      stringBuilder.append(new SafeStylesBuilder().toSafeStyles().asString());
      final String tooltip = cell.getTooltip(context);
      if (DkStringUtils.hasText(tooltip))
      {
        stringBuilder.append("' qtip='").append(SafeHtmlUtils.htmlEscape(tooltip));
      }
View Full Code Here

  private SafeHtml getImageHtml(ImageResource res) {
    // Right-justify image if LTR, left-justify if RTL
    AbstractImagePrototype proto = AbstractImagePrototype.create(res);
    SafeHtml image = SafeHtmlUtils.fromTrustedString(proto.getHTML());

    SafeStylesBuilder cssBuilder = new SafeStylesBuilder();
    if (LocaleInfo.getCurrentLocale().isRTL()) {
      cssBuilder.appendTrustedString("left:0px;");
    } else {
      cssBuilder.appendTrustedString("right:0px;");
    }
    cssBuilder.appendTrustedString("width: " + res.getWidth() + "px;");
    cssBuilder.appendTrustedString("height: " + res.getHeight() + "px;");
    return template.imageWrapper(cssBuilder.toSafeStyles(), image);
  }
View Full Code Here

      AbstractImagePrototype proto = AbstractImagePrototype.create(res);
      image = SafeHtmlUtils.fromTrustedString(proto.getHTML());
    }

    // Create the wrapper based on the vertical alignment.
    SafeStylesBuilder cssStyles =
        new SafeStylesBuilder().appendTrustedString(direction + ":0px;");
    if (HasVerticalAlignment.ALIGN_TOP == valign) {
      return template.imageWrapperTop(cssStyles.toSafeStyles(), image);
    } else if (HasVerticalAlignment.ALIGN_BOTTOM == valign) {
      return template.imageWrapperBottom(cssStyles.toSafeStyles(), image);
    } else {
      int halfHeight = (int) Math.round(res.getHeight() / 2.0);
      cssStyles.appendTrustedString("margin-top:-" + halfHeight + "px;");
      return template.imageWrapperMiddle(cssStyles.toSafeStyles(), image);
    }
  }
View Full Code Here

    if (isTop) {
      classesBuilder.append(" ").append(style.cellTreeTopItemImage());
    }

    // Build the css.
    SafeStylesBuilder cssBuilder = new SafeStylesBuilder();
    if (LocaleInfo.getCurrentLocale().isRTL()) {
      cssBuilder.appendTrustedString("right: 0px;");
    } else {
      cssBuilder.appendTrustedString("left: 0px;");
    }
    cssBuilder.appendTrustedString("width: " + res.getWidth() + "px;");
    cssBuilder.appendTrustedString("height: " + res.getHeight() + "px;");

    AbstractImagePrototype proto = AbstractImagePrototype.create(res);
    SafeHtml image = SafeHtmlUtils.fromTrustedString(proto.getHTML());
    return template
        .imageWrapper(classesBuilder.toString(), cssBuilder.toSafeStyles(), image);
  }
View Full Code Here

TOP

Related Classes of com.google.gwt.safecss.shared.SafeStylesBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.