【问题标题】:How to import image from one ClientBundle to use it in style of another ClientBundle如何从一个 ClientBundle 导入图像以使用另一个 ClientBundle 的样式
【发布时间】:2014-03-13 18:03:41
【问题描述】:

我有一个客户端捆绑包:

public interface FirstClientBundle extends ClientBundle {

  public static final FirstClientBundle INSTANCE = 
  GWT.create(FirstClientBundle.class);

  @Source("panel-top-bg.png")
  public ImageResource panelTopBg();
}

我想在另一个 Bundle 的样式中使用来自第一个 Bundle 的图像。像这样的:

public interface SecondClientBundle extends ClientBundle {

  public static final SecondClientBundle INSTANCE = 
  GWT.create(SecondClientBundle.class);

  public interface Style extends CssResource {
    @ClassName("panelTop")
    String panelTop();
  }

  @Source({ "style.css" })
  public Style style();
}

结束CSS文件的样子:

@sprite .panel-top {
  gwt-image: "FirstClientBundle.panelTopBg";
  height: 18px;
  cursor: move;
}

有可能吗?还是我应该做不同的事情?

【问题讨论】:

    标签: css gwt clientbundle cssresource


    【解决方案1】:

    你能把第二个ClientBundle写成第一个的子接口吗?

    public interface SecondClientBundle extends FirstClientBundle
    

    【讨论】:

    • Ups,那里应该有 SecondClientBundle 实例。在这种情况下我宁愿不使用继承,因为我应该通过多个接口扩展 SecondClientBulndle。
    • 虽然它是一种解决方案,但我认为它可能会使代码变得混乱。
    • 我不明白为什么继承不是你想要的,因为它很“混乱”。你能解释一下为什么,或者你想要什么样的解决方案?
    • 我认为这里不需要继承,所以我想避免它。这里解释得很好:javaworld.com/article/2076814/core-java/…
    • 我了解其中的区别,但我认为在这里您仅限于 GWT 实际可以做什么和不能做什么。来自gwtproject.org/doc/latest/DevGuideClientBundle.html:“@sprite 对声明 CSSResource 的 FooBundle 很敏感;@sprite 声明中命名的同级 ImageResource 方法将用于组成背景 sprite。”
    猜你喜欢
    • 1970-01-01
    • 2011-07-18
    • 1970-01-01
    • 2011-08-08
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    相关资源
    最近更新 更多