/* * [Image.java] * * Summary: Generate a reference to an Image. * * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.8 2009-02-06 include go package in ZIP bundle. * <!-- macro Image people/bush.jpg "George Bush" right --> * <!-- macro Image people/bush.jpg caption "George Bush" right --> * <!-- macro Image people/bush.jpg link "George Bush" http://whitehouse.gov right --> caption * and alignment are * optional */ package com.mindprod.htmlmacros.macro; import com.mindprod.entities.DeEntifyStrings; import com.mindprod.fastcat.FastCat; import com.mindprod.htmlmacros.support.BuildImage; import com.mindprod.htmlmacros.support.ImageAlignment; import static com.mindprod.htmlmacros.macro.Global.configuration; import static java.lang.System.*; /** * Generate a reference to an Image. * * @author Roedy Green, Canadian Mind Products * @version 1.8 2009-02-06 include go package in ZIP bundle. * <!-- macro Image people/bush.jpg "George Bush" right --> * <!-- macro Image people/bush.jpg caption "George Bush" right --> * <!-- macro Image people/bush.jpg link "George Bush" http://whitehouse.gov right --> caption and * alignment are * optional * @see com.mindprod.htmlmacros.support.ImageAlignment * @since 2009 */ public final class Image extends Macro { /** * suffix for a tag */ private static final String TAG_TAIL = configuration.getTagTail(); /** * how to use the macro. Link=where to jump if clicks caption. */ private static final String USAGE = "\nImage macro needs image file, [caption] altText [link url] [align]"; /** * Generate HTML for an image * * @param image URL to the image * @param hasCaption true if want image captioned with the alt text * @param hasLink true if want link on caption * @param alt alt text * @param link where to jump if user clicks the caption. * @param align alignment enumeration * * @return HTML to display that (captioned) image. */ private String expand( String image, boolean hasCaption, boolean hasLink, String alt, String link, ImageAlignment align ) { // null link will result in null css class. final String cssClassForLink = Global.assignCSSClasses.assignCSSClass( link, fileBeingDistributed ); if ( hasCaption ) { // enclose image and caption in a two-row table. final FastCat sb = new FastCat( 36 ); int width = BuildImage.getProjectImageDimensions( image )[ 0 ]; sb.append( "
" ); if ( hasLink ) { // make both image and caption clickable sb.append( "" ); } sb.append( BuildImage.buildImgTag( image, alt, ImageAlignment.none, null, fileBeingDistributed ) ); if ( hasLink ) { sb.append( "" ); } sb.append( " |
" ); if ( hasLink ) { // make both image and caption clickable sb.append( "" ); } sb.append( alt ); if ( hasLink ) { sb.append( "" ); } sb.append( " |