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 */
016 package com.github.gwtbootstrap.client.ui;
017
018 import com.github.gwtbootstrap.client.ui.base.AbstractTypography;
019 import com.github.gwtbootstrap.client.ui.resources.Bootstrap;
020 import com.google.gwt.uibinder.client.UiConstructor;
021 import com.google.gwt.user.client.DOM;
022
023 /**
024 * A text element that shows more information in a tooltip.
025 *
026 * <p>
027 * It is usually used to show the meaning of abbreviations. The text is lightly
028 * underlined and on hover, the default cursor is replaced with a help cursor.
029 * </p>
030 * <p>
031 * <h3>UiBinder Usage:</h3>
032 * <code>{@code <b:Abbreviation title="This is the tooltip.">Some text</b:Abbreviation>}</code>
033 * </p>
034 *
035 * @author Carlos Alexandro Becker
036 * @author Dominik Mayer
037 *
038 * @since 2.0.4.0
039 *
040 * @see <a
041 * href="http://twitter.github.com/bootstrap/base-css.html#typography">Bootstrap
042 * documentation</a>
043 */
044 public class Abbreviation extends AbstractTypography {
045
046 /**
047 * Creates a new Abbreviation with both text and title set.
048 *
049 * @param text
050 * the underlined text
051 * @param title
052 * the content of the popup
053 */
054 public Abbreviation(String text, String title) {
055 this(title);
056 setText(text);
057 }
058
059 /**
060 * Creates an empty Abbreviation with only the content for the tooltip set.
061 *
062 * @param title
063 * The content of the popup
064 */
065 public @UiConstructor
066 Abbreviation(String title) {
067 setElement(DOM.createElement("abbr"));
068 setTitle(title);
069 }
070
071 /**
072 * Specifies whether a slightly smaller text size should be used for the
073 * abbreviation. This does not affect the tooltip.
074 *
075 * @param initialism
076 * <code>true</code> for the slightly smaller size. Default:
077 * <code>false</code>
078 */
079 public void setInitalism(boolean initialism) {
080 if (initialism)
081 addStyleName(Bootstrap.initialism);
082 else
083 removeStyleName(Bootstrap.initialism);
084 }
085
086 }