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.base;
017
018import com.github.gwtbootstrap.client.ui.constants.Device;
019import com.google.gwt.user.client.ui.HTMLPanel;
020
021/**
022 * Widget with support for HTML.
023 * 
024 * <p>
025 * When extendind this class, the child class should always expose a constructor
026 * with a String argument. This argument is HTML text. The constructor is used
027 * by the {@link com.google.gwt.uibinder.elementparsers.HTMLPanelParser
028 * HTMLPanelParser} to parse UiBinder XML.
029 * </p>
030 * <h3>Child Class Constructor Example</h3>
031 * 
032 * <pre>
033 * public ChildPanel extends HtmlWidget {
034 *     public ChildPanel(String html) {
035 *         super("label", html); //"label" is the HTML tag used for the child class.
036 *     }
037 * }
038 * </pre>
039 * 
040 * @since 2.0.4.0
041 * 
042 * @author ohashi keisuke
043 */
044public class HtmlWidget extends HTMLPanel implements HasStyle, IsResponsive {
045
046        /**
047         * Creates an empty widget.
048         * 
049         * @param tag
050         *            the tag of the root element
051         */
052        protected HtmlWidget(String tag) {
053                super(tag, "");
054        }
055
056        /**
057         * Creates an HTML panel whose root element has the given tag, and with the
058         * specified HTML contents. Any element within this HTML that has a
059         * specified id can contain a child widget.
060         * 
061         * @param tag
062         *            the tag of the root element
063         * @param html
064         *            the panel's HTML
065         */
066        public HtmlWidget(String tag, String html) {
067                super(tag, html);
068        }
069
070        /**
071         * {@inheritDoc}
072         */
073        public void setShowOn(Device device) {
074                ResponsiveHelper.setShowOn(this, device);
075        }
076
077        /**
078         * {@inheritDoc}
079         */
080        public void setHideOn(Device device) {
081                ResponsiveHelper.setHideOn(this, device);
082        }
083
084        /**
085         * {@inheritDoc}
086         */
087        public void setStyle(Style style) {
088                StyleHelper.setStyle(this, style);
089        }
090
091        /**
092         * {@inheritDoc}
093         */
094        public void addStyle(Style style) {
095                StyleHelper.addStyle(this, style);
096        }
097
098        /**
099         * {@inheritDoc}
100         */
101        public void removeStyle(Style style) {
102                StyleHelper.removeStyle(this, style);
103        }
104}