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.github.gwtbootstrap.client.ui.constants.Constants; 022import com.google.gwt.user.client.ui.InlineLabel; 023 024//@formatter:off 025/** 026 * Badge to show some kind of count. 027 * 028 * <p> 029 * <h3>UiBinder Usage:</h3> 030 * 031 * <pre> 032 * {@code <b:Badge type="ERROR">2</b:Badge>} 033 * </pre> 034 * 035 * All arguments are optional. 036 * </p> 037 * 038 * @since 2.0.4.0 039 * 040 * @author Dominik Mayer 041 * 042 * @see <a href="http://getbootstrap.com/2.3.2/components.html#labels-badges">Bootstrap documentation</a> 043 * @see Label 044 */ 045//@formatter:on 046public class Badge extends InlineLabel implements HasType<BadgeType> { 047 048 /** 049 * Creates an empty default type Badge. 050 */ 051 public Badge() { 052 setStyleName(Constants.BADGE); 053 } 054 055 /** 056 * Creates a default type Badge with the text set. 057 * 058 * @param text 059 * the text of the Badge 060 * 061 * @see #Badge(int) 062 */ 063 public Badge(String text) { 064 this(); 065 setText(text); 066 } 067 068 /** 069 * Creates a default type Badge with the text set. 070 * 071 * @param number 072 * text to be set 073 * 074 * @see #Badge(String) 075 */ 076 public Badge(int number) { 077 this(); 078 setText(String.valueOf(number)); 079 } 080 081 /** 082 * Creates an empty Badge of the provided type. 083 * 084 * @param type 085 * the badge's type 086 */ 087 public Badge(BadgeType type) { 088 this(); 089 setType(type); 090 } 091 092 /** 093 * Sets the type of the Badge. 094 * 095 * @param type 096 * the new type 097 */ 098 public void setType(BadgeType type) { 099 StyleHelper.changeStyle(this, type, BadgeType.class); 100 } 101}