Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何实现GXT外观?_Java_Gwt_Extjs_Gxt_Appearance - Fatal编程技术网

Java 如何实现GXT外观?

Java 如何实现GXT外观?,java,gwt,extjs,gxt,appearance,Java,Gwt,Extjs,Gxt,Appearance,我想把外观图案加进去。 我创建了TestApp类: public class TestApp implements EntryPoint { public void onModuleLoad() { AppearancePushButton button = new AppearancePushButton("Hi"); button.addClickHandler(new ClickHandler() { public void

我想把外观图案加进去。 我创建了TestApp类:

public class TestApp implements EntryPoint {
    public void onModuleLoad() {
        AppearancePushButton button = new AppearancePushButton("Hi");
        button.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                Info.display("Title", "Message");
            }
        });

        RootPanel.get().add(button);
    }
}
外观按钮类是:

public class AppearancePushButton extends Component {
    private final Appearance appearance;

    public AppearancePushButton(String text) {
        this(text, (Appearance) GWT.create(DefaultAppearance.class));
    }

    @SuppressWarnings("deprecation")
    public AppearancePushButton(String text, Appearance appearance) {
        this.appearance = appearance;
        SafeHtmlBuilder sb = new SafeHtmlBuilder();

        this.appearance.render(sb);

        setElement(XDOM.create(sb.toSafeHtml()));
        setText(text);
        sinkEvents(Event.ONCLICK);
    }

    public HandlerRegistration addClickHandler (ClickHandler handler) {
        return addDomHandler(handler, ClickEvent.getType());
    }

    public void setText(String text) {
        appearance.onUpdateText(getElement(), text);
    }

    public void setImage(Image icon) {
        appearance.onUpdateIcon(getElement(), icon);
    }
}
public class DefaultAppearance implements Appearance {
    public interface Template extends XTemplates {
        @XTemplate(source = "DefaultAppearance.html")
        SafeHtml template(Style style);
    }

    public interface Style extends CssResource {
        String testButton();
        String testButtonImage();
        String testButtonText();
    }

    private final Style style;
    private final Template template;

    public interface Resources extends ClientBundle {
        @Source("TestApp.css")
        Style style();
    }

    public DefaultAppearance() {
        this((Resources) GWT.create(Resources.class));
    }

    public DefaultAppearance(Resources resources) {
        this.style = resources.style();
        this.style.ensureInjected();
        this.template = GWT.create(Template.class);
    }

    @Override
    public void render(SafeHtmlBuilder sb) {
        sb.append(template.template(style));
    }

    @Override
    public void onUpdateText(XElement parent, String text) {
        XElement element = parent.selectNode("." + style.testButtonText());
        element.setInnerText(text);
    }

    @Override
    public void onUpdateIcon(XElement parent, Image icon) {
        XElement element = parent.selectNode("." + style.testButtonImage());
        element.removeChildren();
        element.appendChild(icon.getElement());
    }
}
DefaultAppearance类是:

public class AppearancePushButton extends Component {
    private final Appearance appearance;

    public AppearancePushButton(String text) {
        this(text, (Appearance) GWT.create(DefaultAppearance.class));
    }

    @SuppressWarnings("deprecation")
    public AppearancePushButton(String text, Appearance appearance) {
        this.appearance = appearance;
        SafeHtmlBuilder sb = new SafeHtmlBuilder();

        this.appearance.render(sb);

        setElement(XDOM.create(sb.toSafeHtml()));
        setText(text);
        sinkEvents(Event.ONCLICK);
    }

    public HandlerRegistration addClickHandler (ClickHandler handler) {
        return addDomHandler(handler, ClickEvent.getType());
    }

    public void setText(String text) {
        appearance.onUpdateText(getElement(), text);
    }

    public void setImage(Image icon) {
        appearance.onUpdateIcon(getElement(), icon);
    }
}
public class DefaultAppearance implements Appearance {
    public interface Template extends XTemplates {
        @XTemplate(source = "DefaultAppearance.html")
        SafeHtml template(Style style);
    }

    public interface Style extends CssResource {
        String testButton();
        String testButtonImage();
        String testButtonText();
    }

    private final Style style;
    private final Template template;

    public interface Resources extends ClientBundle {
        @Source("TestApp.css")
        Style style();
    }

    public DefaultAppearance() {
        this((Resources) GWT.create(Resources.class));
    }

    public DefaultAppearance(Resources resources) {
        this.style = resources.style();
        this.style.ensureInjected();
        this.template = GWT.create(Template.class);
    }

    @Override
    public void render(SafeHtmlBuilder sb) {
        sb.append(template.template(style));
    }

    @Override
    public void onUpdateText(XElement parent, String text) {
        XElement element = parent.selectNode("." + style.testButtonText());
        element.setInnerText(text);
    }

    @Override
    public void onUpdateIcon(XElement parent, Image icon) {
        XElement element = parent.selectNode("." + style.testButtonImage());
        element.removeChildren();
        element.appendChild(icon.getElement());
    }
}
外观界面为:

public interface Appearance {
    void render(SafeHtmlBuilder sb);
    void onUpdateText(XElement parent, String text);
    void onUpdateIcon(XElement parent, Image icon);
}
CSS文件是:

.testButton {
    border: 1px solid navy;
    font-size: 12px;
    padding: 4px;
}

.testButtonImage {
    float: left;
}

.testButtonText {
    text-align: center;
}
如何修复它以使其正常工作?