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.*;
016
017import java.util.*;
018
019import org.apache.juneau.*;
020import org.apache.juneau.dto.html5.*;
021
022/**
023 * Simple template for adding tooltips to HTML5 bean constructs, typically in menu item widgets.
024 *
025 * <p>
026 * Tooltips depend on the existence of the <c>tooltip</c> and <c>tooltiptext</c> styles that should be
027 * present in the stylesheet for the document.
028 *
029 * <ul class='seealso'>
030 *    <li class='link'>{@doc juneau-rest-server.HtmlDocAnnotation.PredefinedWidgets}
031 * </ul>
032 */
033public class Tooltip {
034
035   private final HtmlText display;
036   private final List<Object> content;
037
038   /**
039    * Constructor.
040    *
041    * @param display
042    *    The normal display text.
043    *    <br>This is what gets rendered normally.
044    *    <br>The format is raw HTML and can contain markup.
045    * @param content
046    *    The hover contents.
047    *    <br>Typically a list of strings, but can also include any HTML5 beans as well.
048    */
049   public Tooltip(String display, Object...content) {
050      this.display = new HtmlText(display);
051      this.content = new ArrayList<>(Arrays.asList(content));
052   }
053
054   /**
055    * The swap method.
056    *
057    * <p>
058    * Converts this bean into a div tag with contents.
059    *
060    * @param session The bean session.
061    * @return The swapped contents of this bean.
062    */
063   public Div swap(BeanSession session) {
064      return div(
065         small(display),
066         span()._class("tooltiptext").children(content)
067      )._class("tooltip");
068   }
069}