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.Constants; 021import com.github.gwtbootstrap.client.ui.constants.LabelType; 022import com.google.gwt.user.client.ui.InlineLabel; 023 024//@formatter:off 025/** 026 * Colored label to show warnings, tags, ... You could have multiple types :) 027 * 028 * <p> 029 * <h3>UiBinder Usage:</h3> 030 * 031 * <pre> 032 * {@code 033 * <b:Label type="INFO">I'm the text!</b:Label> 034 * } 035 * </pre> 036 * All arguments are optional. 037 * </p> 038 * 039 * @since 2.0.4.0 040 * 041 * @author Carlos Alexandro Becker 042 * 043 * @author Dominik Mayer 044 * 045 * @see <a href="http://getbootstrap.com/2.3.2/components.html#labels-badges">Bootstrap documentation</a> 046 * @see Badge 047 */ 048//@formatter:on 049public class Label extends InlineLabel implements HasType<LabelType> { 050 051 /** 052 * Creates an empty Label. 053 */ 054 public Label() { 055 setStyleName(Constants.LABEL); 056 } 057 058 /** 059 * Creates a Label with the given text. 060 * 061 * @param text 062 * the text for the Label 063 */ 064 public Label(String text) { 065 this(); 066 setText(text); 067 } 068 069 /** 070 * Creates a Label of given Type with the given text. 071 * 072 * @param type 073 * the type of the Label 074 * @param text 075 * the text of the Label 076 */ 077 public Label(LabelType type, String text) { 078 this(text); 079 setType(type); 080 } 081 082 /** 083 * {@inheritDoc} 084 */ 085 public void setType(LabelType type) { 086 StyleHelper.changeStyle(this, type, LabelType.class); 087 } 088 089}