001/* 002 * Copyright 2012 GWT-Bootstrap 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.github.gwtbootstrap.client.ui; 017 018import com.github.gwtbootstrap.client.ui.base.HasType; 019import com.github.gwtbootstrap.client.ui.base.StyleHelper; 020import com.github.gwtbootstrap.client.ui.constants.BadgeType; 021import com.google.gwt.user.client.ui.InlineLabel; 022 023//@formatter:off 024/** 025 * Badge to show some kind of count. 026 * 027 * <p> 028 * <h3>UiBinder Usage:</h3> 029 * 030 * <pre> 031 * {@code <b:Badge type="ERROR">2</b:Badge>} 032 * </pre> 033 * 034 * All arguments are optional. 035 * </p> 036 * 037 * @since 2.0.4.0 038 * 039 * @author Dominik Mayer 040 * 041 * @see <a href="http://twitter.github.com/bootstrap/components.html#badges">Bootstrap documentation</a> 042 * @see Label 043 */ 044//@formatter:on 045public class Badge extends InlineLabel implements HasType<BadgeType> { 046 047 /** 048 * Creates an empty default type Badge. 049 */ 050 public Badge() { 051 this(BadgeType.DEFAULT); 052 } 053 054 /** 055 * Creates a default type Badge with the text set. 056 * 057 * @param text 058 * the text of the Badge 059 * 060 * @see #Badge(int) 061 */ 062 public Badge(String text) { 063 this(); 064 setText(text); 065 } 066 067 /** 068 * Creates a default type Badge with the text set. 069 * 070 * @param number 071 * text to be set 072 * 073 * @see #Badge(String) 074 */ 075 public Badge(int number) { 076 this(); 077 setText(String.valueOf(number)); 078 } 079 080 /** 081 * Creates an empty Badge of the provided type. 082 * 083 * @param type 084 * the badge's type 085 */ 086 public Badge(BadgeType type) { 087 setType(type); 088 } 089 090 /** 091 * Sets the type of the Badge. 092 * 093 * @param type 094 * the new type 095 */ 096 public void setType(BadgeType type) { 097 StyleHelper.changeStyle(this, type, BadgeType.class); 098 } 099}