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 <code>tooltip</code> and <code>tooltiptext</code> styles that should be 027 * present in the stylesheet for the document. 028 * 029 * <h5 class='section'>See Also:</h5> 030 * <ul> 031 * <li class='link'>{@doc juneau-rest-server.HtmlDocAnnotation.PredefinedWidgets} 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 043 * The normal display text. 044 * <br>This is what gets rendered normally. 045 * <br>The format is raw HTML and can contain markup. 046 * @param content 047 * The hover contents. 048 * <br>Typically a list of strings, but can also include any HTML5 beans as well. 049 */ 050 public Tooltip(String display, Object...content) { 051 this.display = new HtmlText(display); 052 this.content = new ArrayList<>(Arrays.asList(content)); 053 } 054 055 /** 056 * The swap method. 057 * 058 * <p> 059 * Converts this bean into a div tag with contents. 060 * 061 * @param session The bean session. 062 * @return The swapped contents of this bean. 063 */ 064 public Div swap(BeanSession session) { 065 return div( 066 small(display), 067 span()._class("tooltiptext").children(content) 068 )._class("tooltip"); 069 } 070}