001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.rest.widget;
014
015import static org.apache.juneau.dto.html5.HtmlBuilder.*;
016import static org.apache.juneau.internal.CollectionUtils.*;
017
018import java.util.*;
019
020import org.apache.juneau.*;
021import org.apache.juneau.dto.html5.*;
022
023/**
024 * Simple template for adding tooltips to HTML5 bean constructs, typically in menu item widgets.
025 *
026 * <p>
027 * Tooltips depend on the existence of the <c>tooltip</c> and <c>tooltiptext</c> styles that should be present in the stylesheet for the document.
028 *
029 * <h5 class='section'>See Also:</h5><ul>
030 *    <li class='link'><a class="doclink" href="../../../../../index.html#jrs.HtmlPredefinedWidgets">Predefined Widgets</a>
031 *    <li class='link'><a class="doclink" href="../../../../../index.html#jrs.HtmlWidgets">Widgets</a>
032 * </ul>
033 */
034public class Tooltip {
035
036   private final HtmlText display;
037   private final List<Object> content;
038
039   /**
040    * Constructor.
041    *
042    * @param display The normal display text. <br>
043    *    This is what gets rendered normally. <br>
044    *    The format is raw HTML and can contain markup.
045    * @param content The hover contents. <br>
046    *    Typically a list of strings, but can also include any HTML5 beans as well.
047    */
048   public Tooltip(String display, Object... content) {
049      this.display = new HtmlText(display);
050      this.content = ulist(content);
051   }
052
053   /**
054    * The swap method.
055    *
056    * <p>
057    * Converts this bean into a div tag with contents.
058    *
059    * @param session The bean session.
060    * @return The swapped contents of this bean.
061    */
062   public Div swap(BeanSession session) {
063      return div(small(display), span()._class("tooltiptext").children(content))._class("tooltip");
064   }
065}