下面列出了怎么用com.vaadin.server.ThemeResource的API类实例代码及写法,或者点击链接到github查看源代码。
private void initLayoutHeader() {
headerLayout.setWidth("100%");
headerLayout.setHeight("80px");
headerLayout.setId("header");
Link rdfunit = new Link("",
new ExternalResource("http://rdfunit.aksw.org/"));
rdfunit.setIcon(new ThemeResource("images/logo-rdfunit.png"));
headerLayout.addComponent(rdfunit);
Link aksw = new Link("",
new ExternalResource("http://aksw.org/"));
aksw.setIcon(new ThemeResource("images/logo-aksw.png"));
aksw.addStyleName("align-right");
headerLayout.addComponent(aksw);
}
public Resource get(boolean isImage, int imageSize) {
if (!isImage) {
if (++this.iconCount >= ICONS.size()) {
this.iconCount = 0;
}
return ICONS.get(this.iconCount);
}
return new ThemeResource("../runo/icons/" + imageSize + "/document.png");
}
@Override
public Resource getIconResource(String iconPath) {
Preconditions.checkNotEmptyString(iconPath, "Icon path should not be empty");
String icon = iconPath.substring(THEME_PREFIX.length());
return new ThemeResource(icon);
}
public Resource get(boolean isImage, int imageSize) {
if (!isImage) {
if (++this.iconCount >= ICONS.size()) {
this.iconCount = 0;
}
return ICONS.get(this.iconCount);
}
return new ThemeResource("../runo/icons/" + imageSize + "/document.png");
}
private static Resource getImage(final boolean gravatar) {
if (!gravatar) {
return new ThemeResource("images/profile-pic-57px.jpg");
}
return UserDetailsFormatter.getCurrentUserEmail().map(email -> (Resource) new GravatarResource(email))
.orElse(new ThemeResource("images/profile-pic-57px.jpg"));
}
/**
* Adds the logo to header.
*
* @param topHeader
* the top header
*/
private static void addLogoToHeader(final HorizontalLayout topHeader) {
final ThemeResource ciaLogoResource = new ThemeResource("cia-logo.png");
final Image ciaLogoImage = new Image(null,ciaLogoResource);
topHeader.addComponent(ciaLogoImage);
ciaLogoImage.setWidth("60px");
ciaLogoImage.setHeight("60px");
topHeader.setComponentAlignment(ciaLogoImage, Alignment.MIDDLE_LEFT);
topHeader.setExpandRatio(ciaLogoImage, ContentRatio.SMALL);
}
public Resource getIcon() {
if (this.data instanceof PolicySetType) {
return new ThemeResource("../runo/icons/16/folder.png");
}
if (this.data instanceof RuleType) {
if (((RuleType) this.data).getEffect() == null) {
logger.warn("Rule has a null Effect");
return new ThemeResource("icons/deny-16.png");
}
if (((RuleType) this.data).getEffect() == EffectType.DENY) {
return new ThemeResource("icons/deny-16.png");
}
return new ThemeResource("icons/permit-16.png");
}
if (this.data instanceof PolicyType) {
return new ThemeResource("../runo/icons/16/document-txt.png");
}
if (this.data instanceof TargetType) {
return new ThemeResource("icons/target-green-16.png");
}
if (this.data instanceof ObligationExpressionType) {
return new ThemeResource("icons/obligation-16.png");
}
if (this.data instanceof AdviceExpressionType) {
return new ThemeResource("icons/advice-16.png");
}
if (this.data instanceof ConditionType) {
return new ThemeResource("icons/condition-16.png");
}
if (this.data instanceof VariableDefinitionType) {
return new ThemeResource("icons/variable-16.png");
}
return null;
}
private HorizontalLayout getButtonPanel() {
HorizontalLayout hLayout = new HorizontalLayout();
hLayout.setSpacing(true);
btUpdateTextEditor = new Button();
btUpdateTextEditor.setDescription("Update text area");
btUpdateTextEditor.setIcon(new ThemeResource("images/arrow_down.png"));
btUpdateTextEditor.addClickListener(new CSCToolToTextClickListener(this));
hLayout.addComponent(btUpdateTextEditor);
btUpdateToolEditor = new Button();
btUpdateToolEditor.setDescription("Update tool elements");
btUpdateToolEditor.setIcon(new ThemeResource("images/arrow_up.png"));
btUpdateToolEditor.addClickListener(new CSCTextToToolClickListener(this));
hLayout.addComponent(btUpdateToolEditor);
Button btClearAll = new Button("Clear All");
btClearAll.addClickListener(new ClickListener() {
private static final long serialVersionUID = 1487893808578560989L;
@Override
public void buttonClick(ClickEvent event) {
ToolEditorUI.this.addWindow(new ConfirmClearAll(ToolEditorUI.this));
}
});
hLayout.addComponent(btClearAll);
return hLayout;
}
private Button getDeleteButton(final Object itemId) {
Button btDelete = new Button();
btDelete.setIcon(new ThemeResource("images/close.png"));
btDelete.setStyleName(BaseTheme.BUTTON_LINK);
btDelete.addClickListener(new ClickListener() {
private static final long serialVersionUID = -3695725710938486562L;
@Override
public void buttonClick(ClickEvent event) {
typeTable.removeItem(itemId);
enumDefaultValue.removeItem(itemId);
}
});
return btDelete;
}
public Component generateCell(Table source, final Object itemId,
Object columnId) {
Property<?> prop = source.getItem(itemId).getItemProperty(JobLogContainer.ERROR_MESSAGE);
if (prop != null && prop.getType() != null && prop.getType().equals(String.class)) {
String errorMessage = (String) prop.getValue();
if (errorMessage != null) {
Button link = new Button();
link.setIcon(new ThemeResource("../admin/crystal/agt_update_critical.png"));
link.setStyleName(BaseTheme.BUTTON_LINK);
link.setDescription("Show job error message");
link.addClickListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
select(itemId);
view.showErrorOutput(itemId);
}
});
return link;
}
}
return null;
}
@Override
public Resource getIconResource(String iconPath) {
Preconditions.checkNotEmptyString(iconPath, "Icon path should not be empty");
return new ThemeResource(iconPath);
}
private void fillMenu(ContextMenu menu) {
final MenuItem item = menu.addItem("Checkable \u00d6",
e -> Notification.show("checked: " + e.isChecked())
);
item.setCheckable(true);
item.setChecked(true);
MenuItem item2 = menu.addItem("Disabled",new ClassResource("/images/tiger.jpg"),
e -> Notification.show("disabled")
);
item2.setDescription("Disabled item");
item2.setEnabled(false);
MenuItem item3 = menu.addItem("Invisible",
e -> Notification.show("invisible")
);
item3.setVisible(false);
menu.addSeparator();
//The path is /resources/images/kitten.jpg
ClassResource ico = new ClassResource("/images/kitten.jpg");
MenuItem item4 = menu.addItem("Icon + Description + <b>HTML</b>",ico,
e -> Notification.show("icon")
);
item4.setDescription("Test tooltip");
but3.addClickListener(e -> item4.setDescription(""));
MenuItem item5 = menu.addItem("Custom stylename",
e -> Notification.show("stylename")
);
//The path is /webapp/VAADIN/themes/contextmenu/images
ThemeResource resource = new ThemeResource("images/cat.jpg");
item5.setIcon(resource);
item5.setStyleName("teststyle");
MenuItem item6 = menu.addItem("Submenu");
item6.addItem("Subitem", VaadinIcons.OPTION, e -> Notification.show("SubItem"));
item6.addSeparator();
item6.addItem("Subitem",new ThemeResource("images/cat2.jpg"), e -> Notification.show("SubItem"))
.setDescription("Test");
MenuItem openWindowNotification = item6.addItem(
"Open Window + Notification",
e -> Notification.show("Open Vaadin.com"));
new BrowserWindowOpener("https://vaadin.com").extend(openWindowNotification);
MenuItem openWindowDummy = item6.addItem("Open Google");
new BrowserWindowOpener("https://google.com").extend(openWindowDummy);
new BrowserWindowOpener("https://yahoo.com")
.extend(item6.addItem("SubMenu2").addItem("Yahoo!"));
}
@AutoGenerated
private HorizontalLayout buildHorizontalLayout_1() {
// common part: create layout
horizontalLayout_1 = new HorizontalLayout();
horizontalLayout_1.setImmediate(false);
horizontalLayout_1.setWidth("100.0%");
horizontalLayout_1.setHeight("40px");
horizontalLayout_1.setMargin(false);
// embedded_1
embedded_1 = new Embedded();
embedded_1.setImmediate(false);
embedded_1.setWidth("30px");
embedded_1.setHeight("30px");
embedded_1.setSource(new ThemeResource("img/att.png"));
embedded_1.setType(1);
embedded_1.setMimeType("image/png");
horizontalLayout_1.addComponent(embedded_1);
horizontalLayout_1.setComponentAlignment(embedded_1, new Alignment(33));
// caption
caption = new Label();
caption.setImmediate(false);
caption.setWidth("-1px");
caption.setHeight("-1px");
caption.setValue("AT&T Policy Engine Admin Console");
horizontalLayout_1.addComponent(caption);
horizontalLayout_1.setExpandRatio(caption, 1.0f);
horizontalLayout_1.setComponentAlignment(caption, new Alignment(33));
// labelWelcome
labelWelcome = new Label();
labelWelcome.setImmediate(false);
labelWelcome.setWidth("-1px");
labelWelcome.setHeight("40px");
labelWelcome.setValue("Label");
horizontalLayout_1.addComponent(labelWelcome);
horizontalLayout_1.setComponentAlignment(labelWelcome,
new Alignment(34));
return horizontalLayout_1;
}
public Button createRefreshButton(ClickListener listener) {
refreshButton = new Button("Refresh");
refreshButton.addClickListener(listener);
refreshButton.setIcon(new ThemeResource("../runo/icons/32/reload.png"));
return refreshButton;
}
public JobLogFilter(final JobLogView view, String column, String search) {
this.view = view;
searchStringField = new TextField();
if (search != null) {
searchStringField.setValue(search);
}
searchStringField.setDescription("Search for values starting with this string. Question mark (?) is a wildcard for a single character and asterisk (*) for any number of characters.");
searchStringField.addShortcutListener(new ShortcutListener("Search", ShortcutAction.KeyCode.ENTER, null) {
@Override
public void handleAction(Object sender, Object target) {
view.update();
}
});
columnToSearch = new NativeSelect();
Button clearButton = new Button();
clearButton.setIcon(new ThemeResource("crystal/button_cancel-bw.png"));
clearButton.setDescription("Remove filter");
clearButton.addStyleName("search-button");
for (int i = 0; i < JobLogContainer.NATURAL_COL_ORDER.length; i++) {
//Do not search from generated columns
if (SEARCH_COLUMNS.contains(JobLogContainer.NATURAL_COL_ORDER[i])) {
columnToSearch.addItem(JobLogContainer.NATURAL_COL_ORDER[i]);
columnToSearch.setItemCaption(JobLogContainer.NATURAL_COL_ORDER[i],
JobLogContainer.COL_HEADERS_ENGLISH[i]);
}
}
if (column != null) {
columnToSearch.setValue(column);
} else {
columnToSearch.setValue(JobLogContainer.USERNAME);
}
columnToSearch.setNullSelectionAllowed(false);
clearButton.addClickListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
getView().clearFilter(JobLogFilter.this);
}
});
addComponent(columnToSearch);
addComponent(searchStringField);
addComponent(clearButton);
addStyleName("search-filter-bg");
addStyleName("search-filter");
}
public CancelAction() {
setIcon(new ThemeResource(DEFAULT_ICON));
}
/**
* @param persistentService
* @param view
*/
public ViewSaveAction(VaadinView view, Dao persistentService) {
this.persistentService = persistentService;
setView(view);
setIcon(new ThemeResource(DEFAULT_ICON));
}
public FindAction() {
setIcon(new ThemeResource("images/table/edit-find.png"));
}
private Button createButton(String icon) {
Button b = nativeButtons ? new NativeButton() : new Button() ;
b.setIcon(new ThemeResource(icon));
return b;
}
public RefreshAction() {
setIcon(new ThemeResource("images/table/reload.png"));
}
public ClearFilterAction() {
setIcon(new ThemeResource("images/table/edit-clear.png"));
}
public RemoveAction() {
setIcon(new ThemeResource("images/table/edit-delete.png"));
}
public AddAction() {
setIcon(new ThemeResource("images/table/filenew.png"));
}
public CloseAction() {
setIcon(new ThemeResource(DEFAULT_ICON));
}
public AddAction() {
setIcon(new ThemeResource("images/16x16/list-add.png"));
}
public RemoveAction() {
setIcon(new ThemeResource("images/16x16/list-remove.png"));
}