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