All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gwt.material.design.client.ui.MaterialChip Maven / Gradle / Ivy

There is a newer version: 2.8.3
Show newest version
/*
 * #%L
 * GwtMaterial
 * %%
 * Copyright (C) 2015 - 2017 GwtMaterialDesign
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */
package gwt.material.design.client.ui;

import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Style;
import com.google.gwt.event.logical.shared.CloseEvent;
import com.google.gwt.event.logical.shared.CloseHandler;
import com.google.gwt.event.logical.shared.HasCloseHandlers;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.safehtml.shared.HtmlSanitizer;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.HasValue;
import gwt.material.design.client.base.*;
import gwt.material.design.client.base.mixin.ActiveMixin;
import gwt.material.design.client.base.mixin.CssTypeMixin;
import gwt.material.design.client.base.mixin.ImageMixin;
import gwt.material.design.client.base.mixin.LetterMixin;
import gwt.material.design.client.constants.*;
import gwt.material.design.client.ui.html.Span;

//@formatter:off

/**
 * Chips can be used to represent small blocks of information.
 * They are most commonly used either for contacts or for tags.
 * 

*

UiBinder Usage:

*
 * {@code Simple Chips
 * 
 *
 * // Static Chip
 * 
 *
 * // Contact Chips
 * 
 * }
 * 
* * @author kevzlou7979 * @author Ben Dol * @see Material Chips * @see Material Design Specification */ //@formatter:on public class MaterialChip extends AbstractValueWidget implements HasImage, HasIcon, HasLetter, HasValue, HasCloseHandlers, HasType, HasActive, HasSafeText, HasText { private MaterialIcon icon = new MaterialIcon(IconType.CLOSE); private Span chipLabel = new Span(); private MaterialImage image = new MaterialImage(); private ImageMixin imageMixin; private LetterMixin letterMixin; private CssTypeMixin typeMixin; private ActiveMixin activeMixin; public MaterialChip() { super(Document.get().createDivElement(), CssName.CHIP); add(chipLabel); } public MaterialChip(String text) { this(); setText(text); } public MaterialChip(String text, IconType icon) { this(text); setIconType(icon); } public MaterialChip(String text, String imageUrl) { this(text); setUrl(imageUrl); } public MaterialChip(String text, Color bgColor, Color textColor) { this(text); setBackgroundColor(bgColor); setTextColor(textColor); } @Deprecated public MaterialChip(String text, String bgColor, String textColor) { this(text, Color.fromStyleName(bgColor), Color.fromStyleName(textColor)); } @Override protected void onLoad() { super.onLoad(); registerHandler(icon.addClickHandler(clickEvent -> close())); } public void close() { if (isAttached()) { removeFromParent(); CloseEvent.fire(this, this); } } public void setText(String text) { setValue(text, true); } public String getText() { return getValue(); } @Override public void setHtml(SafeHtml html) { chipLabel.setHtml(html); } @Override public void setSanitizer(HtmlSanitizer sanitizer) { chipLabel.setSanitizer(sanitizer); } @Override public HtmlSanitizer getSanitizer() { return chipLabel.getSanitizer(); } @Override public void setValue(String value, boolean fireEvents) { chipLabel.setText(value); super.setValue(value, fireEvents); } @Override public String getValue() { return chipLabel.getText(); } @Override public void setUrl(String url) { getImageMixin().setUrl(url); add(image); } @Override public String getUrl() { return getImageMixin().getUrl(); } @Override public void setResource(ImageResource resource) { getImageMixin().setResource(resource); add(image); } @Override public ImageResource getResource() { return getImageMixin().getResource(); } @Override public void setAlt(String alt) { getImageMixin().setAlt(alt); } @Override public String getAlt() { return getImageMixin().getAlt(); } @Override public MaterialIcon getIcon() { return icon; } @Override public void setIconType(IconType iconType) { icon.setIconType(iconType); add(icon); } @Override public void setIconPosition(IconPosition position) { icon.setIconPosition(position); } @Override public void setIconSize(IconSize size) { icon.setIconSize(size); } @Override public void setIconFontSize(double size, Style.Unit unit) { icon.setIconFontSize(size, unit); } @Override public void setIconColor(Color iconColor) { icon.setIconColor(iconColor); } @Override public Color getIconColor() { return icon.getIconColor(); } @Override public void setIconPrefix(boolean prefix) { icon.setIconPrefix(prefix); } @Override public boolean isIconPrefix() { return icon.isIconPrefix(); } @Override public void setCustomIconType(String iconType) { icon.setCustomIconType(iconType); } @Override public String getCustomIconType() { return icon.getCustomIconType(); } @Override public void setLetter(String letter) { getLetterMixin().setLetter(letter); } @Override public String getLetter() { return getLetterMixin().getLetter(); } @Override public Span getLetterLabel() { return getLetterMixin().getLetterLabel(); } @Override public void setLetterColor(Color letterColor) { getLetterMixin().setLetterColor(letterColor); } @Override public void setLetterBackgroundColor(Color letterBackgroundColor) { getLetterMixin().setLetterBackgroundColor(letterBackgroundColor); } @Override public void setType(ChipType type) { getTypeMixin().setType(type); } @Override public ChipType getType() { return getTypeMixin().getType(); } public MaterialImage getImage() { return image; } public void setImage(MaterialImage image) { this.image = image; } @Override public void setActive(boolean active) { getActiveMixin().setActive(active); } @Override public boolean isActive() { return getActiveMixin().isActive(); } public Span getChipLabel() { return chipLabel; } @Override public HandlerRegistration addCloseHandler(CloseHandler closeHandler) { return addHandler(closeHandler, CloseEvent.getType()); } protected LetterMixin getLetterMixin() { if (letterMixin == null) { letterMixin = new LetterMixin<>(this); } return letterMixin; } protected ImageMixin getImageMixin() { if (imageMixin == null) { imageMixin = new ImageMixin<>(image); } return imageMixin; } public CssTypeMixin getTypeMixin() { if (typeMixin == null) { typeMixin = new CssTypeMixin<>(this); } return typeMixin; } public ActiveMixin getActiveMixin() { if (activeMixin == null) { activeMixin = new ActiveMixin<>(this); } return activeMixin; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy